AuthZ: Make `NewGrpcTokenAuth` public (#101352)

* AuthZ: Expose NewGrpcTokenAuth

* Lint
pull/101370/head
Gabriel MABILLE 10 months ago committed by GitHub
parent 6614f5c3b2
commit c3505f0864
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      pkg/services/authz/rbac.go
  2. 3
      pkg/services/authz/token_auth.go
  3. 4
      pkg/services/authz/zanzana.go

@ -33,8 +33,8 @@ import (
"github.com/grafana/grafana/pkg/storage/legacysql" "github.com/grafana/grafana/pkg/storage/legacysql"
) )
// `authzService` is hardcoded in authz-service // AuthzServiceAudience is the audience for the authz service.
const authzServiceAudience = "authzService" const AuthzServiceAudience = "authzService"
// ProvideAuthZClient provides an AuthZ client and creates the AuthZ service. // ProvideAuthZClient provides an AuthZ client and creates the AuthZ service.
func ProvideAuthZClient( func ProvideAuthZClient(
@ -123,7 +123,7 @@ func newRemoteRBACClient(clientCfg *authzClientSettings, tracer tracing.Tracer)
clientCfg.remoteAddress, clientCfg.remoteAddress,
grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithPerRPCCredentials( grpc.WithPerRPCCredentials(
newGRPCTokenAuth(authzServiceAudience, clientCfg.tokenNamespace, tokenClient), NewGRPCTokenAuth(AuthzServiceAudience, clientCfg.tokenNamespace, tokenClient),
), ),
) )
if err != nil { if err != nil {

@ -6,7 +6,8 @@ import (
"github.com/grafana/authlib/authn" "github.com/grafana/authlib/authn"
) )
func newGRPCTokenAuth(audience, namespace string, tc authn.TokenExchanger) *tokenAuth { // TODO: move this to authlib
func NewGRPCTokenAuth(audience, namespace string, tc authn.TokenExchanger) *tokenAuth {
return &tokenAuth{audience, namespace, tc} return &tokenAuth{audience, namespace, tc}
} }

@ -57,7 +57,7 @@ func ProvideZanzana(cfg *setting.Cfg, db db.DB, tracer tracing.Tracer, features
// TODO: add TLS support // TODO: add TLS support
grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithPerRPCCredentials( grpc.WithPerRPCCredentials(
newGRPCTokenAuth(authzServiceAudience, fmt.Sprintf("stacks-%s", cfg.StackID), tokenClient), NewGRPCTokenAuth(AuthzServiceAudience, fmt.Sprintf("stacks-%s", cfg.StackID), tokenClient),
), ),
} }
@ -172,7 +172,7 @@ func (z *Zanzana) start(ctx context.Context) error {
authenticator := authnlib.NewAccessTokenAuthenticator( authenticator := authnlib.NewAccessTokenAuthenticator(
authnlib.NewAccessTokenVerifier( authnlib.NewAccessTokenVerifier(
authnlib.VerifierConfig{AllowedAudiences: []string{authzServiceAudience}}, authnlib.VerifierConfig{AllowedAudiences: []string{AuthzServiceAudience}},
authnlib.NewKeyRetriever(authnlib.KeyRetrieverConfig{ authnlib.NewKeyRetriever(authnlib.KeyRetrieverConfig{
SigningKeysURL: z.cfg.ZanzanaServer.SigningKeysURL, SigningKeysURL: z.cfg.ZanzanaServer.SigningKeysURL,
}), }),

Loading…
Cancel
Save