Zanzana: Inject client into standalone AuthZ client (#113293)

This commit is contained in:
Alexander Zobnin
2025-10-31 16:15:45 +01:00
committed by GitHub
parent 33b4d43248
commit cfc8989d24
2 changed files with 41 additions and 1 deletions
+23 -1
View File
@@ -149,12 +149,34 @@ func ProvideStandaloneAuthZClient(
return nil, nil
}
//nolint:staticcheck // not yet migrated to OpenFeature
zanzanaEnabled := features.IsEnabledGlobally(featuremgmt.FlagZanzana)
zanzanaClient, err := ProvideStandaloneZanzanaClient(cfg, features)
if err != nil {
return nil, err
}
//nolint:staticcheck // not yet migrated to OpenFeature
if zanzanaEnabled && features.IsEnabledGlobally(featuremgmt.FlagZanzanaNoLegacyClient) {
return zanzanaClient, nil
}
authCfg, err := readAuthzClientSettings(cfg)
if err != nil {
return nil, err
}
return newRemoteRBACClient(authCfg, tracer, reg)
remoteRBACClient, err := newRemoteRBACClient(authCfg, tracer, reg)
if err != nil {
return nil, err
}
if zanzanaEnabled {
return zClient.WithShadowClient(remoteRBACClient, zanzanaClient, reg)
}
return remoteRBACClient, nil
}
func newRemoteRBACClient(clientCfg *authzClientSettings, tracer trace.Tracer, reg prometheus.Registerer) (authlib.AccessClient, error) {
+18
View File
@@ -95,6 +95,24 @@ func ProvideZanzanaClient(cfg *setting.Cfg, db db.DB, tracer tracing.Tracer, fea
}
}
// ProvideStandaloneZanzanaClient provides a standalone Zanzana client, without registering the Zanzana service.
// Client connects to a remote Zanzana server specified in the configuration.
func ProvideStandaloneZanzanaClient(cfg *setting.Cfg, features featuremgmt.FeatureToggles) (zanzana.Client, error) {
//nolint:staticcheck // not yet migrated to OpenFeature
if !features.IsEnabledGlobally(featuremgmt.FlagZanzana) {
return zClient.NewNoopClient(), nil
}
zanzanaConfig := ZanzanaClientConfig{
URL: cfg.ZanzanaClient.Addr,
Token: cfg.ZanzanaClient.Token,
TokenExchangeURL: cfg.ZanzanaClient.TokenExchangeURL,
ServerCertFile: cfg.ZanzanaClient.ServerCertFile,
}
return NewRemoteZanzanaClient(fmt.Sprintf("stacks-%s", cfg.StackID), zanzanaConfig)
}
type ZanzanaClientConfig struct {
URL string
Token string