Authz: Only have two modes for authz client (#100803)

* Only have "inproc" and "clod" mode
This commit is contained in:
Karl Persson
2025-02-17 14:37:25 +01:00
committed by GitHub
parent 8edfff1bba
commit e9b2f69137
3 changed files with 71 additions and 119 deletions
+59
View File
@@ -0,0 +1,59 @@
package authz
import (
"fmt"
"github.com/grafana/grafana/pkg/setting"
)
type clientMode string
func (s clientMode) IsValid() bool {
switch s {
case clientModeInproc, clientModeCloud:
return true
}
return false
}
const (
clientModeCloud clientMode = "cloud"
clientModeInproc clientMode = "inproc"
)
type authzClientSettings struct {
remoteAddress string
mode clientMode
token string
tokenExchangeURL string
tokenNamespace string
}
func readAuthzClientSettings(cfg *setting.Cfg) (*authzClientSettings, error) {
authzSection := cfg.SectionWithEnvOverrides("authorization")
grpcClientAuthSection := cfg.SectionWithEnvOverrides("grpc_client_authentication")
mode := clientMode(authzSection.Key("mode").MustString(string(clientModeInproc)))
if !mode.IsValid() {
return nil, fmt.Errorf("authorization: invalid mode %q", mode)
}
s := &authzClientSettings{}
s.mode = mode
if s.mode == clientModeInproc {
return s, nil
}
s.remoteAddress = authzSection.Key("remote_address").MustString("")
s.token = grpcClientAuthSection.Key("token").MustString("")
s.tokenNamespace = grpcClientAuthSection.Key("token_namespace").MustString("stacks-" + cfg.StackID)
s.tokenExchangeURL = grpcClientAuthSection.Key("token_exchange_url").MustString("")
// When running in cloud mode, the token and tokenExchangeURL are required.
if s.token == "" || s.tokenExchangeURL == "" {
return nil, fmt.Errorf("authorization: missing token or tokenExchangeUrl")
}
return s, nil
}