Skip to content
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

Add configmap mounting for RBAC teams ENG-3182 #3803

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 51 additions & 9 deletions cost-analyzer/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ will result in failure. Users are asked to select one of the two presently-avail
RBAC exclusivity check: make sure either RBAC or RBAC Teams is enabled, not both
*/}}
{{- define "rbacCheck" -}}
{{- if or (and ((.Values.saml).rbac).teamsEnabled ((.Values.saml).rbac).enabled) (and ((.Values.oidc).rbac).teamsEnabled ((.Values.oidc).rbac).enabled) -}}
{{- if and (or ((.Values.saml).rbac).enabled ((.Values.oidc).rbac).enabled) (.Values.rbacTeams).enabled -}}
{{- fail "\nSimple RBAC and RBAC Teams are mutually exclusive. Please specify only one." -}}
{{- end -}}
{{- end -}}
Expand Down Expand Up @@ -1014,10 +1014,14 @@ Begin Kubecost 2.0 templates
{{- end }}
{{- end }}
{{- end }}
{{- if or .Values.oidc.rbac.teamsEnabled .Values.saml.rbac.teamsEnabled }}
{{- if eq (include "rbacTeamsEnabled" .) "true" }}
- name: kubecost-rbac-secret
mountPath: /var/configs/kubecost-rbac-secret
{{- end }}
{{- if eq (include "rbacTeamsConfigEnabled" .) "true" }}
- name: kubecost-rbac-teams-config
mountPath: /var/configs/rbac-teams-configs
{{- end }}
{{- if .Values.global.integrations.postgres.enabled }}
- name: postgres-creds
mountPath: /var/configs/integrations/postgres-creds
Expand Down Expand Up @@ -1166,11 +1170,21 @@ Begin Kubecost 2.0 templates
value: "true"
- name: OIDC_SKIP_ONLINE_VALIDATION
value: {{ (quote .Values.oidc.skipOnlineTokenValidation) | default (quote false) }}
{{- if .Values.oidc.rbac.teamsEnabled }}
{{- end}}
{{- if eq (include "rbacTeamsEnabled" .) "true" }}
{{- if .Values.oidc.enabled }}
- name: OIDC_RBAC_TEAMS_ENABLED
value: "true"
{{- end }}
{{- end}}
{{- if .Values.saml.enabled }}
- name: SAML_RBAC_TEAMS_ENABLED
value: "true"
{{- end }}
{{- end }}
{{- if eq (include "rbacTeamsConfigEnabled" .) "true" }}
- name: RBAC_TEAMS_HELM_CONFIG_PATH
value: "/var/configs/rbac-teams-configs/rbac-teams-configs.json"
{{- end }}
{{- if .Values.kubecostAggregator }}
{{- if .Values.kubecostAggregator.collections }}
{{- if (((.Values.kubecostAggregator).collections).cache) }}
Expand Down Expand Up @@ -1215,10 +1229,6 @@ Begin Kubecost 2.0 templates
- name: SAML_RBAC_ENABLED
value: "true"
{{- end }}
{{- if .Values.saml.rbac.teamsEnabled }}
- name: SAML_RBAC_TEAMS_ENABLED
value: "true"
{{- end }}
{{- if and .Values.saml.encryptionCertSecret .Values.saml.decryptionKeySecret }}
- name: SAML_RESPONSE_ENCRYPTED
value: "true"
Expand Down Expand Up @@ -1367,7 +1377,7 @@ SSO enabled flag for nginx configmap
To use the Kubecost built-in Teams UI RBAC< you must enable SSO and RBAC and not specify any groups.
Groups is only used when using external RBAC.
*/}}
{{- define "rbacTeamsEnabled" -}}
{{- define "rbacTeamsLegacyEnabled" -}}
{{- if or (.Values.saml).enabled (.Values.oidc).enabled -}}
{{- if or ((.Values.saml).rbac).enabled ((.Values.oidc).rbac).enabled -}}
{{- if not (or (.Values.saml).groups (.Values.oidc).groups) -}}
Expand All @@ -1383,6 +1393,38 @@ Groups is only used when using external RBAC.
{{- end -}}
{{- end -}}

{{/*
RBAC teams enabled requires that it be explicitly enabled in addition to SAML or OIDC being enabled
and legacy RBAC being disabled.
*/}}
{{- define "rbacTeamsEnabled" -}}
{{- if or (.Values.saml).enabled (.Values.oidc).enabled -}}
{{- if and (not ((.Values.saml).rbac).enabled) (not ((.Values.oidc).rbac).enabled) -}}
{{- if (.Values.rbacTeams).enabled -}}
{{- printf "true" -}}
{{- else -}}
{{- printf "false" -}}
{{- end -}}
{{- else -}}
{{- printf "false" -}}
{{- end -}}
{{- else -}}
{{- printf "false" -}}
{{- end -}}
{{- end }}

{{- define "rbacTeamsConfigEnabled" -}}
{{- if eq (include "rbacTeamsEnabled" .) "true" -}}
{{- if (.Values.rbacTeams).teamsConfig -}}
{{- printf "true" -}}
{{- else -}}
{{- printf "false" -}}
{{- end }}
{{- else -}}
{{- printf "false" -}}
{{- end }}
{{- end }}

{{/*
Backups configured flag for nginx configmap
*/}}
Expand Down
14 changes: 7 additions & 7 deletions cost-analyzer/templates/aggregator-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,6 @@ spec:
configMap:
name: {{ template "cost-analyzer.fullname" . }}-saml
{{- end }}
{{- if .Values.saml.rbac.teamsEnabled }}
- name: kubecost-rbac-secret
secret:
secretName: kubecost-rbac-secret
{{- end }}
{{- end }}
{{- end }}
{{- if .Values.oidc }}
Expand All @@ -167,12 +162,17 @@ spec:
secret:
secretName: {{ .Values.oidc.existingCustomSecret.name }}
{{- end }}
{{- if .Values.oidc.rbac.teamsEnabled }}
{{- end }}
{{- end }}
{{- if eq (include "rbacTeamsEnabled" .) "true" }}
- name: kubecost-rbac-secret
secret:
secretName: kubecost-rbac-secret
{{- end }}
{{- end }}
{{- if eq (include "rbacTeamsConfigEnabled" .) "true" }}
- name: kubecost-rbac-teams-config
configMap:
name: kubecost-rbac-teams-config
{{- end }}
{{- if .Values.global.integrations.postgres.enabled }}
- name: postgres-creds
Expand Down
34 changes: 18 additions & 16 deletions cost-analyzer/templates/cost-analyzer-deployment-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,6 @@ spec:
configMap:
name: {{ template "cost-analyzer.fullname" . }}-saml
{{- end }}
{{- if .Values.saml.rbac.teamsEnabled }}
- name: kubecost-rbac-secret
secret:
secretName: kubecost-rbac-secret
{{- end }}
{{- end }}
{{- end }}
{{- if .Values.oidc }}
Expand All @@ -270,12 +265,17 @@ spec:
secret:
secretName: {{ .Values.oidc.existingCustomSecret.name }}
{{- end }}
{{- if .Values.oidc.rbac.teamsEnabled }}
{{- end }}
{{- end }}
{{- if eq (include "rbacTeamsEnabled" .) "true" }}
- name: kubecost-rbac-secret
secret:
secretName: kubecost-rbac-secret
{{- end }}
{{- end }}
{{- if eq (include "rbacTeamsConfigEnabled" .) "true" }}
- name: kubecost-rbac-teams-config
configMap:
name: kubecost-rbac-teams-config
{{- end }}
{{- if .Values.extraVolumes }}
# Extra volume(s)
Expand Down Expand Up @@ -699,7 +699,7 @@ spec:
{{- end }}
{{- end }}
{{- end }}
{{- if or .Values.oidc.rbac.teamsEnabled .Values.saml.rbac.teamsEnabled }}
{{- if eq (include "rbacTeamsEnabled" .) "true" }}
- name: kubecost-rbac-secret
mountPath: /var/configs/kubecost-rbac-secret
{{- end }}
Expand Down Expand Up @@ -746,8 +746,8 @@ spec:
value: {{ .Values.assetReportConfigmapName }}
{{- end }}
{{- if .Values.cloudCostReportConfigmapName }}
- name: CLOUD_COST_REPORT_CONFIGMAP_NAME
value: {{ .Values.cloudCostReportConfigmapName }}
- name: CLOUD_COST_REPORT_CONFIGMAP_NAME
value: {{ .Values.cloudCostReportConfigmapName }}
{{- end }}
{{- if .Values.savedReportConfigmapName }}
- name: SAVED_REPORT_CONFIGMAP_NAME
Expand Down Expand Up @@ -977,10 +977,6 @@ spec:
value: "true"
- name: OIDC_SKIP_ONLINE_VALIDATION
value: {{ (quote .Values.oidc.skipOnlineTokenValidation) | default (quote false) }}
{{- if .Values.oidc.rbac.teamsEnabled }}
- name: OIDC_RBAC_TEAMS_ENABLED
value: "true"
{{- end }}
{{- end }}
{{- if .Values.saml }}
{{- if .Values.saml.enabled }}
Expand Down Expand Up @@ -1018,10 +1014,16 @@ spec:
- name: SAML_RESPONSE_ENCRYPTED
value: "true"
{{- end}}
{{- if .Values.saml.rbac.teamsEnabled }}
- name: SAML_RBAC_TEAMS_ENABLED
{{- end }}
{{- end }}
{{- if eq (include "rbacTeamsEnabled" .) "true" }}
{{- if .Values.oidc.enabled }}
- name: OIDC_RBAC_TEAMS_ENABLED
value: "true"
{{- end }}
{{- if .Values.saml.enabled }}
- name: SAML_RBAC_TEAMS_ENABLED
value: "true"
{{- end }}
{{- end }}
{{- if and (.Values.prometheus.server.global.external_labels.cluster_id) (not .Values.prometheus.server.clusterIDConfigmap) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ data:
return 200 '\n
{
"ssoConfigured": "{{ template "ssoEnabled" . }}",
"rbacTeamsEnabled": "{{ template "rbacTeamsEnabled" . }}",
"rbacTeamsEnabled": "{{ template "rbacTeamsLegacyEnabled" . }}",
"dataBackupConfigured": "{{ template "dataBackupConfigured" . }}",
"costEventsAuditEnabled": "{{ template "costEventsAuditEnabled" . }}",
"frontendDeployMethod": "{{ template "frontend.deployMethod" . }}",
Expand Down
6 changes: 1 addition & 5 deletions cost-analyzer/templates/kubecost-rbac-secret-template.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{{- if or .Values.oidc.enabled .Values.saml.enabled }}
{{- if and (not .Values.oidc.rbac.enabled) (not .Values.saml.rbac.enabled) }}
{{- if or .Values.oidc.rbac.teamsEnabled .Values.saml.rbac.teamsEnabled }}
{{- if eq (include "rbacTeamsEnabled" .) "true" }}
apiVersion: v1
kind: Secret
type: Opaque
Expand All @@ -18,5 +16,3 @@ stringData:
{{ .Values.saml.authSecret | default (randAlphaNum 32 | quote) }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{- if eq (include "rbacTeamsConfigEnabled" .) "true" }}
apiVersion: v1
kind: ConfigMap
metadata:
name: "kubecost-rbac-teams-config"
namespace: {{ .Release.Namespace }}
labels:
{{- include "cost-analyzer.commonLabels" . | nindent 4 }}
data:
rbac-teams-configs.json: '{{ toJson .Values.rbacTeams.teamsConfig }}'
{{- end }}
Loading