Skip to content

Commit

Permalink
cs namespace and service account parameterization (#1102)
Browse files Browse the repository at this point in the history
Signed-off-by: Gerd Oberlechner <[email protected]>
  • Loading branch information
geoberle authored Jan 15, 2025
1 parent 0d48c33 commit 35408ec
Show file tree
Hide file tree
Showing 27 changed files with 125 additions and 29 deletions.
9 changes: 5 additions & 4 deletions cluster-service/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ ZONE_NAME ?= "${REGIONAL_DNS_SUBDOMAIN}.${CX_PARENT_DNS_ZONE_NAME}"


deploy:
@kubectl create namespace cluster-service --dry-run=client -o json | kubectl apply -f - && \
kubectl label namespace cluster-service "istio.io/rev=${ISTO_TAG}" --overwrite=true && \
AZURE_CS_MI_CLIENT_ID=$(shell az identity show -g ${RESOURCEGROUP} -n clusters-service --query clientId -o tsv) && \
@kubectl create namespace ${NAMESPACE} --dry-run=client -o json | kubectl apply -f - && \
kubectl label namespace ${NAMESPACE} "istio.io/rev=${ISTO_TAG}" --overwrite=true && \
AZURE_CS_MI_CLIENT_ID=$(shell az identity show -g ${RESOURCEGROUP} -n ${MI_NAME} --query clientId -o tsv) && \
CS_SERVICE_PRINCIPAL_CREDS_BASE64='$(shell az keyvault secret show --vault-name "${SERVICE_KV}" --name "aro-hcp-dev-sp-cs" | jq .value -r | base64 | tr -d '\n')' && \
TENANT_ID=$(shell az account show --query tenantId --output tsv) && \
OIDC_BLOB_SERVICE_ENDPOINT=$(shell az storage account show -n ${OIDC_STORAGE_ACCOUNT} -g ${RESOURCEGROUP} --query primaryEndpoints.blob -o tsv) && \
Expand All @@ -27,8 +27,9 @@ deploy:
CX_SECRETS_KV_URL=$(shell az keyvault show -n ${CX_SECRETS_KV_NAME} -g ${MGMT_RESOURCEGROUP} --query properties.vaultUri -o tsv) && \
CX_MI_KV_URL=$(shell az keyvault show -n ${CX_MI_KV_NAME} -g ${MGMT_RESOURCEGROUP} --query properties.vaultUri -o tsv) && \
${HELM_CMD} cluster-service deploy/helm \
--namespace cluster-service \
--namespace ${NAMESPACE} \
-f deploy/helm/$${OVERRIDES} \
--set serviceAccountName=${SERVICE_ACCOUNT_NAME} \
--set azureCsMiClientId=$${AZURE_CS_MI_CLIENT_ID} \
--set oidcIssuerBlobServiceUrl=$${OIDC_BLOB_SERVICE_ENDPOINT} \
--set oidcIssuerBaseUrl=$${OIDC_ISSUER_BASE_ENDPOINT} \
Expand Down
4 changes: 2 additions & 2 deletions cluster-service/deploy/helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ spec:
checksum/cs: {{ include (print $.Template.BasePath "/clusters-service.secret.yaml") . | sha256sum }}
checksum/runtime: {{ include (print $.Template.BasePath "/azure-runtime-config.configmap.yaml") . | sha256sum }}
spec:
serviceAccount: clusters-service
serviceAccountName: clusters-service
serviceAccount: {{ .Values.serviceAccountName }}
serviceAccountName: {{ .Values.serviceAccountName }}
volumes:
- name: service
secret:
Expand Down
12 changes: 6 additions & 6 deletions cluster-service/deploy/helm/templates/istio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
name: default
namespace: cluster-service
namespace: {{ .Release.Namespace }}
spec:
selector:
matchLabels:
Expand All @@ -15,7 +15,7 @@ apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata:
name: allow-metrics
namespace: cluster-service
namespace: {{ .Release.Namespace }}
spec:
action: "ALLOW"
rules:
Expand All @@ -32,14 +32,14 @@ apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata:
name: allow-nothing
namespace: cluster-service
namespace: {{ .Release.Namespace }}
spec: {}
---
apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata:
name: allow-frontend
namespace: cluster-service
namespace: {{ .Release.Namespace }}
spec:
action: "ALLOW"
rules:
Expand All @@ -61,13 +61,13 @@ apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata:
name: allow-intra-namespace
namespace: cluster-service
namespace: {{ .Release.Namespace }}
spec:
action: "ALLOW"
rules:
- from:
- source:
principals: ["cluster.local/ns/cluster-service/sa/clusters-service"]
principals: ["cluster.local/ns/{{ .Release.Namespace }}/sa/{{ .Values.serviceAccountName }}"]
to:
- operation:
ports:
Expand Down
2 changes: 1 addition & 1 deletion cluster-service/deploy/helm/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: clusters-service
name: {{ .Values.serviceAccountName }}
namespace: {{ .Release.Namespace }}
labels:
app: clusters-service
Expand Down
4 changes: 4 additions & 0 deletions cluster-service/deploy/helm/values.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# service account name
serviceAccountName: clusters-service


# TODO: This parameter isn't currently used, but kept to avoid failures in the
# execution of saasherder. It will be removed once the version of the service
# that doesn't use it is deployed to all environments.
Expand Down
6 changes: 6 additions & 0 deletions cluster-service/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ resourceGroups:
configRef: clusterService.azureOperatorsManagedIdentities.cloudNetworkConfig.roleName
- name: ISTO_TAG
configRef: svc.istio.tag
- name: MI_NAME
configRef: clusterService.managedIdentityName
- name: NAMESPACE
configRef: clusterService.k8s.namespace
- name: SERVICE_ACCOUNT_NAME
configRef: clusterService.k8s.serviceAccountName


# this is maestro consumer registration stuff
Expand Down
4 changes: 4 additions & 0 deletions config/config.msft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ defaults:
deploy: true
private: false
minTLSVersion: 'TLSV1.2'
managedIdentityName: clusters-service
k8s:
namespace: cluster-service
serviceAccountName: clusters-service

# Image Sync
imageSync:
Expand Down
23 changes: 23 additions & 0 deletions config/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@
"imageTag": {
"type": "string"
},
"managedIdentityName": {
"type": "string",
"description": "The name of the MSI that will be used by CS to interact with Azure"
},
"k8s": {
"type": "object",
"properties": {
"namespace": {
"type": "string"
},
"serviceAccountName": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"namespace",
"serviceAccountName"
]
},
"postgres": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -125,6 +145,9 @@
"acrRG",
"imageRepo",
"imageTag",
"managedIdentityName",
"k8s",
"azureOperatorsManagedIdentities",
"postgres"
]
},
Expand Down
4 changes: 4 additions & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ defaults:
deploy: true
private: false
minTLSVersion: 'TLSV1.2'
managedIdentityName: clusters-service
k8s:
namespace: cluster-service
serviceAccountName: clusters-service

# Image Sync
imageSync:
Expand Down
5 changes: 5 additions & 0 deletions config/public-cloud-cs-pr.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
},
"imageRepo": "app-sre/uhc-clusters-service",
"imageTag": "a51079c",
"k8s": {
"namespace": "cluster-service",
"serviceAccountName": "clusters-service"
},
"managedIdentityName": "clusters-service",
"postgres": {
"deploy": true,
"minTLSVersion": "TLSV1.2",
Expand Down
5 changes: 5 additions & 0 deletions config/public-cloud-dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
},
"imageRepo": "app-sre/uhc-clusters-service",
"imageTag": "a51079c",
"k8s": {
"namespace": "cluster-service",
"serviceAccountName": "clusters-service"
},
"managedIdentityName": "clusters-service",
"postgres": {
"deploy": true,
"minTLSVersion": "TLSV1.2",
Expand Down
5 changes: 5 additions & 0 deletions config/public-cloud-msft-int.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
},
"imageRepo": "app-sre/uhc-clusters-service",
"imageTag": "ecd15ad",
"k8s": {
"namespace": "cluster-service",
"serviceAccountName": "clusters-service"
},
"managedIdentityName": "clusters-service",
"postgres": {
"deploy": true,
"minTLSVersion": "TLSV1.2",
Expand Down
5 changes: 5 additions & 0 deletions config/public-cloud-personal-dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
},
"imageRepo": "app-sre/uhc-clusters-service",
"imageTag": "a51079c",
"k8s": {
"namespace": "cluster-service",
"serviceAccountName": "clusters-service"
},
"managedIdentityName": "clusters-service",
"postgres": {
"deploy": false,
"minTLSVersion": "TLSV1.2",
Expand Down
2 changes: 1 addition & 1 deletion dev-infrastructure/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ cs-current-user-pg-connect:
.PHONY: cs-current-user-pg-connect

cs-miwi-pg-connect:
@scripts/cs-miwi-pg-connect.sh $(SVC_RESOURCEGROUP) $(CS_PG_NAME) "clusters-service" "cluster-service" "clusters-service"
@scripts/cs-miwi-pg-connect.sh $(SVC_RESOURCEGROUP) $(CS_PG_NAME) $(CS_MI_NAME) $(CS_NS_NAME) $(CS_SA_NAME)
.PHONY: cs-miwi-pg-connect

maestro-current-user-pg-connect:
Expand Down
3 changes: 3 additions & 0 deletions dev-infrastructure/config.tmpl.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ IMAGE_SYNC_ENVIRONMENT ?= {{ .imageSync.environmentName }}
ARO_HCP_IMAGE_ACR ?= {{ .svcAcrName }}
AKS_NAME ?= {{ .aksName }}
CS_PG_NAME ?= {{ .clusterService.postgres.name }}
CS_MI_NAME ?= {{ .clusterService.managedIdentityName }}
CS_NS_NAME ?= {{ .clusterService.k8s.namespace }}
CS_SA_NAME ?= {{ .clusterService.k8s.serviceAccountName }}
MAESTRO_PG_NAME ?= {{ .maestro.postgres.name }}
OIDC_STORAGE_ACCOUNT ?= {{ .oidcStorageAccountName }}
CX_KV_NAME ?= {{ .cxKeyVault.name }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using '../templates/cs-integration-msi.bicep'

param namespaceFormatString = 'sandbox-jenkins-{0}-aro-hcp'
param clusterServiceManagedIdentityName = 'clusters-service'
param clusterServiceManagedIdentityName = '{{ .clusterService.managedIdentityName }}'
param clusterName = '{{ .aksName }}'
param clusterServiceServiceAccountName = '{{ .clusterService.k8s.serviceAccountName }}'
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
using '../templates/output-region.bicep'

param csMIName = '{{ .clusterService.managedIdentityName }}'
3 changes: 3 additions & 0 deletions dev-infrastructure/configurations/svc-cluster.tmpl.bicepparam
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ param csPostgresDeploy = {{ .clusterService.postgres.deploy }}
param csPostgresServerName = '{{ .clusterService.postgres.name }}'
param csPostgresServerMinTLSVersion = '{{ .clusterService.postgres.minTLSVersion }}'
param clusterServicePostgresPrivate = {{ .clusterService.postgres.private }}
param csMIName = '{{ .clusterService.managedIdentityName }}'
param csNamespace = '{{ .clusterService.k8s.namespace }}'
param csServiceAccountName = '{{ .clusterService.k8s.serviceAccountName }}'

param serviceKeyVaultName = '{{ .serviceKeyVault.name }}'
param serviceKeyVaultResourceGroup = '{{ .serviceKeyVault.rg }}'
Expand Down
5 changes: 4 additions & 1 deletion dev-infrastructure/templates/cs-integration-msi.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ param clusterServiceManagedIdentityName string
@description('The name of the cluster to integrate with')
param clusterName string

@description('The name of the CS service account')
param clusterServiceServiceAccountName string

resource uami 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' existing = {
name: clusterServiceManagedIdentityName
}
Expand All @@ -25,7 +28,7 @@ resource uami_fedcred 'Microsoft.ManagedIdentity/userAssignedIdentities/federate
'api://AzureADTokenExchange'
]
issuer: aksCluster.properties.oidcIssuerProfile.issuerURL
subject: 'system:serviceaccount:${format(namespaceFormatString, i)}:clusters-service'
subject: 'system:serviceaccount:${format(namespaceFormatString, i)}:${clusterServiceServiceAccountName}'
}
}
]
5 changes: 4 additions & 1 deletion dev-infrastructure/templates/output-region.bicep
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
@description('The name of the CS managed identity')
param csMIName string

resource csMSI 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
name: 'clusters-service'
name: csMIName
location: resourceGroup().location
}

Expand Down
24 changes: 14 additions & 10 deletions dev-infrastructure/templates/svc-cluster.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,14 @@ param frontendIngressCertName string
@description('The name of the Azure Monitor Workspace (stores prometheus metrics)')
param azureMonitorWorkspaceName string

var clusterServiceMIName = 'clusters-service'
@description('The name of the CS managed identity')
param csMIName string

@description('The namespace of the CS managed identity')
param csNamespace string

@description('The service account name of the CS managed identity')
param csServiceAccountName string

resource serviceKeyVault 'Microsoft.KeyVault/vaults@2024-04-01-preview' existing = {
name: serviceKeyVaultName
Expand Down Expand Up @@ -195,9 +202,9 @@ module svcCluster '../modules/aks-cluster-base.bicep' = {
serviceAccountName: maestroServiceAccountName
}
cs_wi: {
uamiName: clusterServiceMIName
namespace: 'cluster-service'
serviceAccountName: 'clusters-service'
uamiName: csMIName
namespace: csNamespace
serviceAccountName: csServiceAccountName
}
image_sync_wi: {
uamiName: 'image-sync'
Expand Down Expand Up @@ -303,10 +310,7 @@ module serviceKeyVaultPrivateEndpoint '../modules/private-endpoint.bicep' = {
// C L U S T E R S E R V I C E
//

var csManagedIdentityPrincipalId = filter(
svcCluster.outputs.userAssignedIdentities,
id => id.uamiName == clusterServiceMIName
)[0].uamiPrincipalID
var csManagedIdentityPrincipalId = filter(svcCluster.outputs.userAssignedIdentities, id => id.uamiName == csMIName)[0].uamiPrincipalID

module cs '../modules/cluster-service.bicep' = {
name: 'cluster-service'
Expand All @@ -318,7 +322,7 @@ module cs '../modules/cluster-service.bicep' = {
deployPostgres: csPostgresDeploy
postgresServerPrivate: clusterServicePostgresPrivate
clusterServiceManagedIdentityPrincipalId: csManagedIdentityPrincipalId
clusterServiceManagedIdentityName: clusterServiceMIName
clusterServiceManagedIdentityName: csMIName
serviceKeyVaultName: serviceKeyVault.name
serviceKeyVaultResourceGroup: serviceKeyVaultResourceGroup
regionalCXDNSZoneName: regionalCXDNSZoneName
Expand All @@ -338,7 +342,7 @@ module oidc '../modules/oidc/main.bicep' = {
params: {
location: location
storageAccountName: oidcStorageAccountName
rpMsiName: clusterServiceMIName
rpMsiName: csMIName
skuName: oidcStorageAccountSku
msiId: aroDevopsMsiId
deploymentScriptLocation: location
Expand Down
2 changes: 2 additions & 0 deletions frontend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ deploy:
--set deployment.imageName=${ARO_HCP_FRONTEND_IMAGE} \
--set pullBinding.registry=${ARO_HCP_IMAGE_REGISTRY} \
--set pullBinding.scope=repository:${ARO_HCP_IMAGE_REPOSITORY}:pull \
--set clusterService.namespace=${CS_NAMESPACE} \
--set clusterService.serviceAccount=${CS_SERVICE_ACCOUNT_NAME} \
--namespace aro-hcp
.PHONY: deploy

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ spec:
- name: aro-hcp-frontend
image: '{{ .Values.deployment.imageName }}'
imagePullPolicy: Always
args: ["--clusters-service-url", "http://clusters-service.cluster-service.svc.cluster.local:8000"]
args: ["--clusters-service-url", "http://clusters-service.{{ .Values.clusterService.namespace }}.svc.cluster.local:8000"]
env:
- name: DB_NAME
valueFrom:
Expand Down
3 changes: 3 additions & 0 deletions frontend/deploy/helm/frontend/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ pullBinding:
scope: ""
workloadIdentityClientId: ""
workloadIdentityTenantId: ""
clusterService:
namespace: cluster-service
serviceAccount: clusters-service
4 changes: 4 additions & 0 deletions frontend/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ resourceGroups:
configRef: frontend.cert.name
- name: ISTO_TAG
configRef: svc.istio.tag
- name: CS_NAMESPACE
configRef: clusterService.k8s.namespace
- name: CS_SERVICE_ACCOUNT_NAME
configRef: clusterService.k8s.serviceAccountName
4 changes: 3 additions & 1 deletion maestro/server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ deploy:
--set image.base=${IMAGE_BASE} \
--set image.tag=${IMAGE_TAG} \
--set database.host=$${DATABASE_HOST} \
--set database.name=${DATABASE_NAME}
--set database.name=${DATABASE_NAME} \
--set clusterService.namespace=${CS_NAMESPACE} \
--set clusterService.serviceAccount=${CS_SERVICE_ACCOUNT_NAME}
.PHONY: deploy
Loading

0 comments on commit 35408ec

Please sign in to comment.