diff options
author | 2024-08-14 17:17:29 -0700 | |
---|---|---|
committer | 2024-08-14 19:09:14 -0700 | |
commit | cc94ab704af171acc58532c0cb73eb80620561c2 (patch) | |
tree | 1d0247e35cab737a30c432bfe506b7907f081a24 | |
parent | 9b8eabf0363134e2ad5562db73e18446a8b33576 (diff) | |
download | v2-cc94ab704af171acc58532c0cb73eb80620561c2.tar.gz v2-cc94ab704af171acc58532c0cb73eb80620561c2.tar.zst v2-cc94ab704af171acc58532c0cb73eb80620561c2.zip |
feat: validate OAUTH2_PROVIDER value
-rw-r--r-- | internal/cli/cli.go | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 56cf13fa..ca4f47bd 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -89,6 +89,23 @@ func Parse() { printErrorAndExit(err) } + if oauth2Provider := config.Opts.OAuth2Provider(); oauth2Provider != "" { + if oauth2Provider != "oidc" && oauth2Provider != "google" { + printErrorAndExit(fmt.Errorf(`unsupported OAuth2 provider: %q (Possible values are "google" or "oidc")`, oauth2Provider)) + } + } + + if config.Opts.DisableLocalAuth() { + switch { + case config.Opts.OAuth2Provider() == "" && config.Opts.AuthProxyHeader() == "": + printErrorAndExit(errors.New("DISABLE_LOCAL_AUTH is enabled but neither OAUTH2_PROVIDER nor AUTH_PROXY_HEADER is not set. Please enable at least one authentication source")) + case config.Opts.OAuth2Provider() != "" && !config.Opts.IsOAuth2UserCreationAllowed(): + printErrorAndExit(errors.New("DISABLE_LOCAL_AUTH is enabled and an OAUTH2_PROVIDER is configured, but OAUTH2_USER_CREATION is not enabled")) + case config.Opts.AuthProxyHeader() != "" && !config.Opts.IsAuthProxyUserCreationAllowed(): + printErrorAndExit(errors.New("DISABLE_LOCAL_AUTH is enabled and an AUTH_PROXY_HEADER is configured, but AUTH_PROXY_USER_CREATION is not enabled")) + } + } + if flagConfigDump { fmt.Print(config.Opts) return @@ -226,17 +243,6 @@ func Parse() { return } - if config.Opts.DisableLocalAuth() { - switch { - case config.Opts.OAuth2Provider() == "" && config.Opts.AuthProxyHeader() == "": - printErrorAndExit(errors.New("DISABLE_LOCAL_AUTH is enabled but neither OAUTH2_PROVIDER nor AUTH_PROXY_HEADER is not set. Please enable at least one authentication source")) - case config.Opts.OAuth2Provider() != "" && !config.Opts.IsOAuth2UserCreationAllowed(): - printErrorAndExit(errors.New("DISABLE_LOCAL_AUTH is enabled and an OAUTH2_PROVIDER is configured, but OAUTH2_USER_CREATION is not enabled")) - case config.Opts.AuthProxyHeader() != "" && !config.Opts.IsAuthProxyUserCreationAllowed(): - printErrorAndExit(errors.New("DISABLE_LOCAL_AUTH is enabled and an AUTH_PROXY_HEADER is configured, but AUTH_PROXY_USER_CREATION is not enabled")) - } - } - startDaemon(store) } |