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

post-infra creation task for local CS development permissions #918

Merged
merged 3 commits into from
Dec 4, 2024
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
22 changes: 20 additions & 2 deletions dev-infrastructure/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,18 @@ svc.aks.kubeconfigfile:
.PHONY: svc.aks.kubeconfigfile

svc.oidc.storage.permissions:
STORAGEACCOUNTID=$(shell az storage account show -n ${OIDC_STORAGE_ACCOUNT} -g ${SVC_RESOURCEGROUP} --query id -o tsv) && \
@STORAGEACCOUNTID=$(shell az storage account show -n ${OIDC_STORAGE_ACCOUNT} -g ${SVC_RESOURCEGROUP} --query id -o tsv) && \
az role assignment create \
--role "Storage Blob Data Contributor" \
--assignee ${PRINCIPAL_ID} \
--scope "$${STORAGEACCOUNTID}"
--scope "$${STORAGEACCOUNTID}" \
--only-show-errors
.PHONY: svc.oidc.storage.permissions

svc.kv.permission:
@scripts/kv-permissions.sh $(PRINCIPAL_ID) $(SVC_KV_RESOURCEGROUP) $(SVC_KV_NAME)
.PHONY: svc.kv.permission

svc.init: region svc svc.aks.admin-access svc.aks.kubeconfig metrics-infra svc.enable-aks-metrics svc.oidc.storage.permissions
.PHONY: svc.init

Expand Down Expand Up @@ -356,6 +361,12 @@ mgmt.clean:
fi
.PHONY: mgmt.clean

mgmt.kv.permission:
@scripts/kv-permissions.sh $(PRINCIPAL_ID) $(MGMT_RESOURCEGROUP) $(CX_KV_NAME)
@scripts/kv-permissions.sh $(PRINCIPAL_ID) $(MGMT_RESOURCEGROUP) $(MSI_KV_NAME)
@scripts/kv-permissions.sh $(PRINCIPAL_ID) $(MGMT_RESOURCEGROUP) $(MGMT_KV_NAME)
.PHONY: mgmt.kv.permission

# ACR

global.rg:
Expand Down Expand Up @@ -501,3 +512,10 @@ infra: region svc.init mgmt.init

clean: svc.clean mgmt.clean region.clean
.PHONY: clean

#
# Local CS Development
#

local-cs-permissions: svc.oidc.storage.permissions svc.kv.permission mgmt.kv.permission
.PHONY: local-cs-permissions
4 changes: 4 additions & 0 deletions dev-infrastructure/config.tmpl.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ MGMT_RESOURCEGROUP ?= {{ .mgmt.rg }}
REGIONAL_RESOURCEGROUP ?= {{ .regionRG }}
SVC_KV_RESOURCEGROUP ?= {{ .serviceKeyVault.rg }}
GLOBAL_RESOURCEGROUP ?= {{ .globalRG }}
SVC_KV_NAME ?= {{ .serviceKeyVault.name }}
IMAGE_SYNC_RESOURCEGROUP ?= {{ .imageSync.rg }}
IMAGE_SYNC_ENVIRONMENT ?= {{ .imageSync.environmentName }}
ARO_HCP_IMAGE_ACR ?= {{ .svcAcrName }}
Expand All @@ -12,3 +13,6 @@ AKS_NAME ?= {{ .aksName }}
CS_PG_NAME ?= {{ .clusterService.postgres.name }}
MAESTRO_PG_NAME ?= {{ .maestro.postgres.name }}
OIDC_STORAGE_ACCOUNT ?= {{ .oidcStorageAccountName }}
CX_KV_NAME ?= {{ .cxKeyVault.name }}
MSI_KV_NAME ?= {{ .msiKeyVault.name }}
MGMT_KV_NAME ?= {{ .mgmtKeyVault.name }}
30 changes: 30 additions & 0 deletions dev-infrastructure/scripts/kv-permissions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

PRINCIPAL_ID=$1
RG_NAME=$2
KV_NAME=$3

KV_RESOURCE_ID=$(az keyvault show --name ${KV_NAME} --resource-group ${RG_NAME} --query id -o tsv 2>/dev/null)

if [ -z "${KV_RESOURCE_ID}" ]; then
echo "Error: Key Vault resource ID for ${KV_NAME} in ${RG_NAME} could not be retrieved."
exit 0
fi

az role assignment create \
--role "Key Vault Secrets Officer" \
--assignee ${PRINCIPAL_ID} \
--scope ${KV_RESOURCE_ID} \
--only-show-errors

az role assignment create \
--role "Key Vault Certificates Officer" \
geoberle marked this conversation as resolved.
Show resolved Hide resolved
--assignee ${PRINCIPAL_ID} \
--scope ${KV_RESOURCE_ID} \
--only-show-errors

az role assignment create \
--role "Key Vault Certificate User" \
--assignee ${PRINCIPAL_ID} \
--scope ${KV_RESOURCE_ID} \
--only-show-errors
Loading