@@ -89,6 +89,7 @@ type Interceptor struct {
8989 authHeaderName string
9090 authExtraHeaderName string
9191 enableCrossNamespaceCommands dynamicconfig.BoolPropertyFn
92+ disableStreamingAuthorizer dynamicconfig.BoolPropertyFn
9293}
9394
9495// NewInterceptor creates an authorization interceptor.
@@ -102,6 +103,7 @@ func NewInterceptor(
102103 authHeaderName string ,
103104 authExtraHeaderName string ,
104105 enableCrossNamespaceCommands dynamicconfig.BoolPropertyFn ,
106+ disableStreamingAuthorizer dynamicconfig.BoolPropertyFn ,
105107) * Interceptor {
106108 return & Interceptor {
107109 claimMapper : claimMapper ,
@@ -113,6 +115,7 @@ func NewInterceptor(
113115 authExtraHeaderName : cmp .Or (authExtraHeaderName , defaultAuthExtraHeaderName ),
114116 audienceGetter : audienceGetter ,
115117 enableCrossNamespaceCommands : enableCrossNamespaceCommands ,
118+ disableStreamingAuthorizer : disableStreamingAuthorizer ,
116119 }
117120}
118121
@@ -174,34 +177,37 @@ func (a *Interceptor) InterceptStream(
174177 handler grpc.StreamHandler ,
175178) error {
176179 ctx := ss .Context ()
177- tlsConnection := TLSInfoFromContext (ctx )
178-
179- authInfo := a .GetAuthInfo (tlsConnection , headers .NewGRPCHeaderGetter (ctx ), func () string {
180- // JWTAudienceMapper only supports UnaryServerInfo; no request is available at stream init.
181- return ""
182- })
183-
184- var claims * Claims
185- if authInfo != nil {
186- var err error
187- claims , err = a .GetClaims (authInfo )
188- if err != nil {
189- a .logger .Error ("Authorization error" , tag .Error (err ))
190- return errUnauthorized
180+ bypassAuth := a .disableStreamingAuthorizer ()
181+ if ! bypassAuth {
182+ tlsConnection := TLSInfoFromContext (ctx )
183+
184+ authInfo := a .GetAuthInfo (tlsConnection , headers .NewGRPCHeaderGetter (ctx ), func () string {
185+ // JWTAudienceMapper only supports UnaryServerInfo; no request is available at stream init.
186+ return ""
187+ })
188+
189+ var claims * Claims
190+ if authInfo != nil {
191+ var err error
192+ claims , err = a .GetClaims (authInfo )
193+ if err != nil {
194+ a .logger .Error ("Authorization error" , tag .Error (err ))
195+ return errUnauthorized
196+ }
197+ ctx = a .EnhanceContext (ctx , authInfo , claims )
191198 }
192- ctx = a .EnhanceContext (ctx , authInfo , claims )
193- }
194199
195- if a .authorizer != nil {
196- // Namespace is not available in the stream handshake (no initial request body).
197- ct := & CallTarget {
198- Namespace : "" ,
199- APIName : info .FullMethod ,
200- Request : nil ,
201- }
202- if err := a .Authorize (ctx , claims , ct ); err != nil {
203- a .logger .Error ("Authorization error" , tag .Error (err ))
204- return err
200+ if a .authorizer != nil {
201+ // Namespace is not available in the stream handshake (no initial request body).
202+ ct := & CallTarget {
203+ Namespace : "" ,
204+ APIName : info .FullMethod ,
205+ Request : nil ,
206+ }
207+ if err := a .Authorize (ctx , claims , ct ); err != nil {
208+ a .logger .Error ("Authorization error" , tag .Error (err ))
209+ return err
210+ }
205211 }
206212 }
207213
0 commit comments