@@ -90,6 +90,7 @@ type Interceptor struct {
9090 authExtraHeaderName string
9191 exposeAuthorizerErrors dynamicconfig.BoolPropertyFn
9292 enableCrossNamespaceCommands dynamicconfig.BoolPropertyFn
93+ disableStreamingAuthorizer dynamicconfig.BoolPropertyFn
9394}
9495
9596// NewInterceptor creates an authorization interceptor.
@@ -104,6 +105,7 @@ func NewInterceptor(
104105 authExtraHeaderName string ,
105106 exposeAuthorizerErrors dynamicconfig.BoolPropertyFn ,
106107 enableCrossNamespaceCommands dynamicconfig.BoolPropertyFn ,
108+ disableStreamingAuthorizer dynamicconfig.BoolPropertyFn ,
107109) * Interceptor {
108110 return & Interceptor {
109111 claimMapper : claimMapper ,
@@ -116,6 +118,7 @@ func NewInterceptor(
116118 audienceGetter : audienceGetter ,
117119 exposeAuthorizerErrors : exposeAuthorizerErrors ,
118120 enableCrossNamespaceCommands : enableCrossNamespaceCommands ,
121+ disableStreamingAuthorizer : disableStreamingAuthorizer ,
119122 }
120123}
121124
@@ -177,34 +180,37 @@ func (a *Interceptor) InterceptStream(
177180 handler grpc.StreamHandler ,
178181) error {
179182 ctx := ss .Context ()
180- tlsConnection := TLSInfoFromContext (ctx )
181-
182- authInfo := a .GetAuthInfo (tlsConnection , headers .NewGRPCHeaderGetter (ctx ), func () string {
183- // JWTAudienceMapper only supports UnaryServerInfo; no request is available at stream init.
184- return ""
185- })
186-
187- var claims * Claims
188- if authInfo != nil {
189- var err error
190- claims , err = a .GetClaims (authInfo )
191- if err != nil {
192- a .logger .Error ("Authorization error" , tag .Error (err ))
193- return errUnauthorized
183+ bypassAuth := a .disableStreamingAuthorizer ()
184+ if ! bypassAuth {
185+ tlsConnection := TLSInfoFromContext (ctx )
186+
187+ authInfo := a .GetAuthInfo (tlsConnection , headers .NewGRPCHeaderGetter (ctx ), func () string {
188+ // JWTAudienceMapper only supports UnaryServerInfo; no request is available at stream init.
189+ return ""
190+ })
191+
192+ var claims * Claims
193+ if authInfo != nil {
194+ var err error
195+ claims , err = a .GetClaims (authInfo )
196+ if err != nil {
197+ a .logger .Error ("Authorization error" , tag .Error (err ))
198+ return errUnauthorized
199+ }
200+ ctx = a .EnhanceContext (ctx , authInfo , claims )
194201 }
195- ctx = a .EnhanceContext (ctx , authInfo , claims )
196- }
197202
198- if a .authorizer != nil {
199- // Namespace is not available in the stream handshake (no initial request body).
200- ct := & CallTarget {
201- Namespace : "" ,
202- APIName : info .FullMethod ,
203- Request : nil ,
204- }
205- if err := a .Authorize (ctx , claims , ct ); err != nil {
206- a .logger .Error ("Authorization error" , tag .Error (err ))
207- return err
203+ if a .authorizer != nil {
204+ // Namespace is not available in the stream handshake (no initial request body).
205+ ct := & CallTarget {
206+ Namespace : "" ,
207+ APIName : info .FullMethod ,
208+ Request : nil ,
209+ }
210+ if err := a .Authorize (ctx , claims , ct ); err != nil {
211+ a .logger .Error ("Authorization error" , tag .Error (err ))
212+ return err
213+ }
208214 }
209215 }
210216
0 commit comments