-
Notifications
You must be signed in to change notification settings - Fork 38
fix: move Keycloak admin credentials from ConfigMap to Secret (rebased #161) #179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,9 @@ rules: | |
| - apiGroups: [""] | ||
| resources: ["configmaps"] | ||
| verbs: ["get", "list", "watch"] | ||
| - apiGroups: [""] | ||
| resources: ["secrets"] | ||
| verbs: ["get", "list", "watch"] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Good least-privilege: only |
||
| - apiGroups: [""] | ||
| resources: ["serviceaccounts"] | ||
| verbs: ["get", "create", "update"] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,3 +134,55 @@ func TestBuildClientRegistrationContainer_HasPlatformClientIDsEnv(t *testing.T) | |
| t.Error("client-registration container missing PLATFORM_CLIENT_IDS env var") | ||
| } | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: This test silently passes if neither |
||
|
|
||
| func TestBuildClientRegistrationContainer_AdminCredentialsFromSecret(t *testing.T) { | ||
| builder := NewContainerBuilder(config.CompiledDefaults()) | ||
| container := builder.BuildClientRegistrationContainerWithSpireOption("my-app", "my-ns", true) | ||
|
|
||
| sensitiveKeys := []string{"KEYCLOAK_ADMIN_USERNAME", "KEYCLOAK_ADMIN_PASSWORD"} | ||
| for _, key := range sensitiveKeys { | ||
| found := false | ||
| for _, env := range container.Env { | ||
| if env.Name != key { | ||
| continue | ||
| } | ||
| found = true | ||
| if env.ValueFrom == nil || env.ValueFrom.SecretKeyRef == nil { | ||
| t.Errorf("env %q must use SecretKeyRef, got ConfigMapKeyRef or literal", key) | ||
| continue | ||
| } | ||
| if env.ValueFrom.SecretKeyRef.Name != "keycloak-admin-secret" { | ||
| t.Errorf("env %q SecretKeyRef.Name = %q, want %q", key, env.ValueFrom.SecretKeyRef.Name, "keycloak-admin-secret") | ||
| } | ||
| } | ||
| if !found { | ||
| t.Errorf("client-registration container missing env var %q", key) | ||
| } | ||
| } | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Same as above — silently passes if |
||
|
|
||
| func TestBuildClientRegistrationContainer_NonSensitiveKeysFromConfigMap(t *testing.T) { | ||
| builder := NewContainerBuilder(config.CompiledDefaults()) | ||
| container := builder.BuildClientRegistrationContainerWithSpireOption("my-app", "my-ns", true) | ||
|
|
||
| nonSensitiveKeys := []string{"KEYCLOAK_URL", "KEYCLOAK_REALM"} | ||
| for _, key := range nonSensitiveKeys { | ||
| found := false | ||
| for _, env := range container.Env { | ||
| if env.Name != key { | ||
| continue | ||
| } | ||
| found = true | ||
| if env.ValueFrom == nil || env.ValueFrom.ConfigMapKeyRef == nil { | ||
| t.Errorf("env %q must use ConfigMapKeyRef", key) | ||
| continue | ||
| } | ||
| if env.ValueFrom.ConfigMapKeyRef.Name != "environments" { | ||
| t.Errorf("env %q ConfigMapKeyRef.Name = %q, want %q", key, env.ValueFrom.ConfigMapKeyRef.Name, "environments") | ||
| } | ||
| } | ||
| if !found { | ||
| t.Errorf("client-registration container missing env var %q", key) | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: The
---+ Secret header insertion causes thePLATFORM_CLIENT_IDScomment block (the lines afterKEYCLOAK_ADMIN_PASSWORD) to land under the Secret'sstringData:instead of the ConfigMap'sdata:. The comments are YAML comments so it's not functionally broken, but it's misleading — a reader would thinkPLATFORM_CLIENT_IDSbelongs in the Secret. Consider moving thePLATFORM_CLIENT_IDScomment block back above the---separator under the ConfigMap.