Check for Kubernetes secret name in oAuthSecret, fallback to plain text

pull/1836/head
Gregory Guydo 2024-05-07 14:46:02 +00:00
parent e007fce1a4
commit 6a01670385
1 changed files with 25 additions and 1 deletions

View File

@ -99,6 +99,30 @@ skip_provider_button = false
skipAuthConfig(ctx.CheCluster)) skipAuthConfig(ctx.CheCluster))
} }
func getSecretValue(ctx *chetypes.DeployContext) string {
secret := &corev1.Secret{}
exists, err := deploy.GetNamespacedObject(ctx, ctx.CheCluster.Spec.Networking.Auth.OAuthSecret, secret)
if err != nil {
logrus.Debug(err)
}
if !exists {
logrus.Infof("Kubernetes secret with name '%s' not found. Assuming oAuthSecret provided is the actual secret.", ctx.CheCluster.Spec.Networking.Auth.OAuthSecret)
return ctx.CheCluster.Spec.Networking.Auth.OAuthSecret
}
// Retrieve the value associated with the key "oAuthSecret"
value, found := secret.Data["oAuthSecret"]
if !found {
logrus.Warn("Key 'oAuthSecret' not found. Assuming oAuthSecret provided is the actual secret.")
return ctx.CheCluster.Spec.Networking.Auth.OAuthSecret
}
// Convert the byte slice to a string
logrus.Infof("Using oAuthSecret found in Kubernetes secret %s", ctx.CheCluster.Spec.Networking.Auth.OAuthSecret)
secretValue := string(value)
return secretValue
}
func kubernetesOauthProxyConfig(ctx *chetypes.DeployContext, cookieSecret string) string { func kubernetesOauthProxyConfig(ctx *chetypes.DeployContext, cookieSecret string) string {
return fmt.Sprintf(` return fmt.Sprintf(`
proxy_prefix = "/oauth" proxy_prefix = "/oauth"
@ -128,7 +152,7 @@ cookie_domains = "%s"
ctx.CheHost, ctx.CheHost,
ctx.CheCluster.Spec.Networking.Auth.IdentityProviderURL, ctx.CheCluster.Spec.Networking.Auth.IdentityProviderURL,
ctx.CheCluster.Spec.Networking.Auth.OAuthClientName, ctx.CheCluster.Spec.Networking.Auth.OAuthClientName,
ctx.CheCluster.Spec.Networking.Auth.OAuthSecret, getSecretValue(ctx),
cookieSecret, cookieSecret,
cookieExpireAsString(ctx.CheCluster), cookieExpireAsString(ctx.CheCluster),
utils.Whitelist(ctx.CheHost), utils.Whitelist(ctx.CheHost),