Skip to content

Commit

Permalink
split acr and role creation from mirror config
Browse files Browse the repository at this point in the history
Signed-off-by: Gerd Oberlechner <[email protected]>
  • Loading branch information
geoberle committed Dec 1, 2024
1 parent 927c884 commit c545548
Show file tree
Hide file tree
Showing 24 changed files with 114 additions and 109 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/aro-hcp-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
cd dev-infrastructure/
# Manage ACR
make acr-svc acr-ocp
make global acr-svc acr-ocp
# Setup operator roles for platform workload identity
make operator-roles
Expand Down
8 changes: 3 additions & 5 deletions config/config.msft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ defaults:
global:
rg: b-gerdo-global-shared-resources
subscription: hcp-{{ .ctx.region }}
manageTokenCustomRole: false
region: uksouth

# General AKS config
kubernetesVersion: 1.30.5
Expand All @@ -17,9 +19,6 @@ defaults:
podSubnetPrefix: "10.128.64.0/18"
aksName: aro-hcp-aks

# ACR
serviceComponentAcrResourceGroups: '{{ .ctx.region }}-shared-resources'

# Hypershift
hypershift:
namespace: hypershift
Expand Down Expand Up @@ -72,7 +71,7 @@ defaults:

# Cluster Service
clusterService:
#acrRG: '{{ .ctx.region }}-shared-resources'
#acrRG: 'b-gerdo-global-shared-resources'
acrRG: ''
postgres:
name: arohcp-cs-{{ .ctx.regionShort }}
Expand Down Expand Up @@ -171,7 +170,6 @@ clouds:
regionalDNSSubdomain: '{{ .ctx.region }}'

# ACR
acrName: arohcpint
svcAcrName: arohcpsvcint
ocpAcrName: arohcpocpint

Expand Down
18 changes: 9 additions & 9 deletions config/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"title": "Generated schema for Root",
"type": "object",
"properties": {
"acrName": {
"type": "string"
},
"aksName": {
"type": "string"
},
Expand Down Expand Up @@ -150,11 +147,19 @@
},
"subscription": {
"type": "string"
},
"manageTokenCustomRole": {
"type": "boolean"
},
"region": {
"type": "string"
}
},
"required": [
"rg",
"subscription"
"subscription",
"manageTokenCustomRole",
"region"
]
},
"hypershift": {
Expand Down Expand Up @@ -507,9 +512,6 @@
"regionalDNSSubdomain": {
"type": "string"
},
"serviceComponentAcrResourceGroups": {
"type": "string"
},
"serviceKeyVault": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -612,7 +614,6 @@
},
"additionalProperties": false,
"required": [
"acrName",
"aksName",
"aroDevopsMsiId",
"baseDnsZoneName",
Expand Down Expand Up @@ -640,7 +641,6 @@
"region",
"regionRG",
"regionalDNSSubdomain",
"serviceComponentAcrResourceGroups",
"serviceKeyVault",
"subnetPrefix",
"svc",
Expand Down
8 changes: 3 additions & 5 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ defaults:
regionRG: hcp-underlay-{{ .ctx.regionShort }}

global:
rg: global-shared-resources
rg: global
subscription: hcp-{{ .ctx.region }}
manageTokenCustomRole: true
region: westus3

# General AKS config
kubernetesVersion: 1.30.5
Expand All @@ -15,9 +17,6 @@ defaults:
podSubnetPrefix: "10.128.64.0/18"
aksName: aro-hcp-aks

# ACR
serviceComponentAcrResourceGroups: global

# Hypershift
hypershift:
namespace: hypershift
Expand Down Expand Up @@ -182,7 +181,6 @@ clouds:
kvSoftDelete: false
subscription: ARO Hosted Control Planes (EA Subscription 1)
# Shared ACRs
acrName: arohcpdev
svcAcrName: arohcpsvcdev
ocpAcrName: arohcpocpdev
# Shared Image Sync
Expand Down
6 changes: 3 additions & 3 deletions config/public-cloud-cs-pr.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"acrName": "arohcpdev",
"aksName": "aro-hcp-aks",
"aroDevopsMsiId": "/subscriptions/1d3378d3-5a3f-4712-85a1-2485495dfc4b/resourceGroups/global/providers/Microsoft.ManagedIdentity/userAssignedIdentities/aro-hcp-devops",
"baseDnsZoneName": "hcp.osadev.cloud",
Expand Down Expand Up @@ -34,7 +33,9 @@
}
},
"global": {
"rg": "global-shared-resources",
"manageTokenCustomRole": true,
"region": "westus3",
"rg": "global",
"subscription": "hcp-westus3"
},
"hypershift": {
Expand Down Expand Up @@ -127,7 +128,6 @@
"region": "westus3",
"regionRG": "hcp-underlay-cspr",
"regionalDNSSubdomain": "westus3-cs",
"serviceComponentAcrResourceGroups": "global",
"serviceKeyVault": {
"name": "aro-hcp-dev-svc-kv",
"private": false,
Expand Down
6 changes: 3 additions & 3 deletions config/public-cloud-dev.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"acrName": "arohcpdev",
"aksName": "aro-hcp-aks",
"aroDevopsMsiId": "/subscriptions/1d3378d3-5a3f-4712-85a1-2485495dfc4b/resourceGroups/global/providers/Microsoft.ManagedIdentity/userAssignedIdentities/aro-hcp-devops",
"baseDnsZoneName": "hcp.osadev.cloud",
Expand Down Expand Up @@ -34,7 +33,9 @@
}
},
"global": {
"rg": "global-shared-resources",
"manageTokenCustomRole": true,
"region": "westus3",
"rg": "global",
"subscription": "hcp-westus3"
},
"hypershift": {
Expand Down Expand Up @@ -127,7 +128,6 @@
"region": "westus3",
"regionRG": "hcp-underlay-dev",
"regionalDNSSubdomain": "westus3",
"serviceComponentAcrResourceGroups": "global",
"serviceKeyVault": {
"name": "aro-hcp-dev-svc-kv",
"private": false,
Expand Down
4 changes: 2 additions & 2 deletions config/public-cloud-msft-int.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"acrName": "arohcpint",
"aksName": "aro-hcp-aks",
"aroDevopsMsiId": "/subscriptions/5299e6b7-b23b-46c8-8277-dc1147807117/resourcegroups/global-shared-resources/providers/Microsoft.ManagedIdentity/userAssignedIdentities/aroint-int-public-oidc",
"baseDnsZoneName": "aro-hcp.azure-test.net",
Expand Down Expand Up @@ -34,6 +33,8 @@
}
},
"global": {
"manageTokenCustomRole": false,
"region": "uksouth",
"rg": "b-gerdo-global-shared-resources",
"subscription": "hcp-westus3"
},
Expand Down Expand Up @@ -127,7 +128,6 @@
"region": "westus3",
"regionRG": "westus3-shared-resources",
"regionalDNSSubdomain": "westus3",
"serviceComponentAcrResourceGroups": "westus3-shared-resources",
"serviceKeyVault": {
"name": "arohcp-svc-int",
"private": false,
Expand Down
6 changes: 3 additions & 3 deletions config/public-cloud-personal-dev.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"acrName": "arohcpdev",
"aksName": "aro-hcp-aks",
"aroDevopsMsiId": "/subscriptions/1d3378d3-5a3f-4712-85a1-2485495dfc4b/resourceGroups/global/providers/Microsoft.ManagedIdentity/userAssignedIdentities/aro-hcp-devops",
"baseDnsZoneName": "hcp.osadev.cloud",
Expand Down Expand Up @@ -34,7 +33,9 @@
}
},
"global": {
"rg": "global-shared-resources",
"manageTokenCustomRole": true,
"region": "westus3",
"rg": "global",
"subscription": "hcp-westus3"
},
"hypershift": {
Expand Down Expand Up @@ -127,7 +128,6 @@
"region": "westus3",
"regionRG": "hcp-underlay-usw3tst",
"regionalDNSSubdomain": "usw3tst",
"serviceComponentAcrResourceGroups": "global",
"serviceKeyVault": {
"name": "aro-hcp-dev-svc-kv",
"private": false,
Expand Down
2 changes: 2 additions & 0 deletions dev-infrastructure/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ configurations/acr-ocp.bicepparam
configurations/image-sync.bicepparam
configurations/dev-role-assignments.bicepparam
configurations/cs-integ-msi.bicepparam
configurations/mock-identities.bicepparam
configurations/global.bicepparam
config.mk
26 changes: 23 additions & 3 deletions dev-infrastructure/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,27 @@ global.rg:
fi
.PHONY: global.rg

acr-svc: global.rg
global: global.rg
@./ensure-no-running-deployment.sh $(GLOBAL_RESOURCEGROUP) ${GLOBAL_RG_DEPLOYMENT_NAME}-acr
az deployment group create \
--name ${GLOBAL_RG_DEPLOYMENT_NAME}-acr \
--resource-group $(GLOBAL_RESOURCEGROUP) \
--template-file templates/global.bicep \
$(PROMPT_TO_CONFIRM) \
--parameters \
configurations/global.bicepparam

global.what-if: global.rg
az deployment group what-if \
--name ${GLOBAL_RG_DEPLOYMENT_NAME}-acr \
--resource-group $(GLOBAL_RESOURCEGROUP) \
--template-file templates/global.bicep \
--parameters \
configurations/global.bicepparam
--parameters \
location=westus3

acr-svc: global
@./ensure-no-running-deployment.sh $(GLOBAL_RESOURCEGROUP) ${GLOBAL_RG_DEPLOYMENT_NAME}-acr-svc
az deployment group create \
--name ${GLOBAL_RG_DEPLOYMENT_NAME}-acr-svc \
Expand All @@ -387,7 +407,7 @@ acr-svc.what-if: global.rg
configurations/acr-svc.bicepparam
.PHONY: acr-svc.what-if

acr-ocp: global.rg
acr-ocp: global
@./ensure-no-running-deployment.sh $(GLOBAL_RESOURCEGROUP) ${GLOBAL_RG_DEPLOYMENT_NAME}-acr-ocp
az deployment group create \
--name ${GLOBAL_RG_DEPLOYMENT_NAME}-acr-ocp \
Expand Down Expand Up @@ -493,7 +513,7 @@ operator-roles.what-if:
# Common
#

what-if: acr-svc.what-if acr-ocp.what-if region.what-if svc.what-if mgmt.what-if metrics-infra.what-if imagesync.what-if operator-roles.what-if
what-if: global.what-if acr-svc.what-if acr-ocp.what-if region.what-if svc.what-if mgmt.what-if metrics-infra.what-if imagesync.what-if operator-roles.what-if
.PHONY: what-if

infra: region svc.init mgmt.init
Expand Down
2 changes: 0 additions & 2 deletions dev-infrastructure/configurations/acr-ocp.tmpl.bicepparam
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using '../templates/dev-acr.bicep'

param acrName = '{{ .ocpAcrName }}'
param acrSku = 'Premium'
param location = '{{ .region }}'

param quayRepositoriesToCache = [
{
Expand Down
2 changes: 0 additions & 2 deletions dev-infrastructure/configurations/acr-svc.tmpl.bicepparam
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using '../templates/dev-acr.bicep'

param acrName = '{{ .svcAcrName }}'
param acrSku = 'Premium'
param location = '{{ .region }}'

param quayRepositoriesToCache = [
{
Expand Down
11 changes: 11 additions & 0 deletions dev-infrastructure/configurations/global.tmpl.bicepparam
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using '../templates/global.bicep'

param svcAcrName = '{{ .svcAcrName }}'
param svcAcrSku = 'Premium'

param ocpAcrName = '{{ .ocpAcrName }}'
param ocpAcrSku = 'Premium'

param location = '{{ .global.region }}'

param manageTokenRole = {{ .global.manageTokenCustomRole }}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ param externalDNSServiceAccountName = '{{ .hypershift.externalDNSServiceAccountN
param regionalDNSZoneName = '{{ .regionalDNSSubdomain}}.{{ .baseDnsZoneName }}'

// ACR
param acrPullResourceGroups = ['{{ .serviceComponentAcrResourceGroups }}']
param acrPullResourceGroups = ['{{ .global.rg }}']

// Region
param regionalResourceGroup = '{{ .regionRG }}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ param serviceKeyVaultLocation = '{{ .serviceKeyVault.region }}'
param serviceKeyVaultSoftDelete = {{ .serviceKeyVault.softDelete }}
param serviceKeyVaultPrivate = {{ .serviceKeyVault.private }}

param acrPullResourceGroups = ['{{ .serviceComponentAcrResourceGroups }}']
param acrPullResourceGroups = ['{{ .global.rg }}']
param clustersServiceAcrResourceGroupNames = ['{{ .clusterService.acrRG }}']

param oidcStorageAccountName = '{{ .oidcStorageAccountName }}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ resource acrDeleteRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = if
}
}

import * as tmr from 'token-mgmt-role.bicep'

resource tokenManagementRole 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = if (grantManageTokenAccess) {
name: guid(acrResourceGroupid, 'token-creation-role')
name: guid(tmr.tokenManagementRoleName)
}

resource acrContributorRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = if (grantManageTokenAccess) {
Expand Down
5 changes: 0 additions & 5 deletions dev-infrastructure/modules/acr/acr.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,3 @@ resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', acrPullRoleId)
}
}

module tokenMgmtRole 'token-mgmt-role.bicep' = {
name: 'acr-token-mgmt-role'
scope: subscription()
}
7 changes: 5 additions & 2 deletions dev-infrastructure/modules/acr/token-mgmt-role.bicep
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
targetScope = 'subscription'

@export()
var tokenManagementRoleName = 'token-mgmt-role'

resource tokenManagementRole 'Microsoft.Authorization/roleDefinitions@2022-04-01' = {
name: guid('token-mgmt-role')
name: guid(tokenManagementRoleName)
properties: {
roleName: 'ACR Manage Tokens'
roleName: 'ARO HCP ACR Token Management'
type: 'customRole'
assignableScopes: [
subscription().id
Expand Down
2 changes: 1 addition & 1 deletion dev-infrastructure/modules/aks-cluster-base.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ resource acrRg 'Microsoft.Resources/resourceGroups@2023-07-01' existing = [
}
]

module acrPullRole 'acr-permissions.bicep' = [
module acrPullRole 'acr/acr-permissions.bicep' = [
for (_, i) in acrPullResourceGroups: {
name: guid(acrRg[i].id, aksCluster.id, acrPullRoleDefinitionId)
scope: acrRg[i]
Expand Down
2 changes: 1 addition & 1 deletion dev-infrastructure/modules/cluster-service.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ resource clustersServiceAcrResourceGroups 'Microsoft.Resources/resourceGroups@20
}
]

module acrManageTokenRole '../modules/acr-permissions.bicep' = [
module acrManageTokenRole '../modules/acr/acr-permissions.bicep' = [
for (_, i) in acrResourceGroupNames: if (acrResourceGroupNames[i] != '') {
// temp hack for MSFT pipelines
name: guid(clustersServiceAcrResourceGroups[i].id, resourceGroup().name, 'clusters-service', 'manage-tokens')
Expand Down
Loading

0 comments on commit c545548

Please sign in to comment.