Skip to content

Commit 088935d

Browse files
committed
Add a user and rg to box in ASO
1 parent 6a9a405 commit 088935d

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

Cluster.bicep

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,28 @@ module iam_flux_crypto 'modules/resourceRoleAssignment.bicep' = {
381381
}
382382
}
383383

384+
module rg 'modules/resourceGroup.bicep' = {
385+
scope: subscription()
386+
params: {
387+
name: '${resourceGroup().name}-aso'
388+
location: location
389+
tags: tags
390+
}
391+
}
392+
393+
module aso 'modules/azureServiceOperator.bicep' = {
394+
name: '${deploymentName}_aso'
395+
scope: resourceGroup('${resourceGroup().name}-aso')
396+
params: {
397+
deploymentNamePrefix: take(deploymentName, 47)
398+
baseName: 'aso'
399+
location: rg.outputs.location
400+
tags: tags
401+
oidcIssuerUrl: aks.outputs.oidcIssuerUrl
402+
}
403+
}
404+
405+
384406
// @description('Flux release namespace')
385407
// output fluxReleaseNamespace string = flux.outputs.fluxReleaseNamespace
386408

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ This repo has a full bicep deployment for a Kubernetes Cluster, including a gith
44

55
I've written my own templates for deploying AKS in [Azure Bicep](https://docs.microsoft.com/en-us/azure/azure-resource-manager/bicep/overview), and I've been maintaining them for a number of years at this point. They are relatively opinionated as to what features I use, and I last overhauled them completely in early 2024. I'm still maintaining them, and doing clean deploys as of March 2024. If you're not interested in my infrastructure code, but want to deploy Kubernetes to Azure, you should consider the [AKS Construction](https://azure.github.io/AKS-Construction/) as an alternative. There are also AKS templates in the [Azure Quickstart Templates](https://learn.microsoft.com/en-us/samples/azure/azure-quickstart-templates/aks/), although those are relatively simplistic -- fine for a test case or demo, but perhaps not for your production cluster.
66

7+
## NOTE
8+
9+
I'm testing some things with the Azure Service Operator, and for right now, this bicep creates a third resource group (i.e. if you create 'rg-poshcode' in Azure, AKS will create 'rg-poshcode-aks' and the bicep will create 'rg-poshcode-aso' to _contain_ the Azure Service Operator). That way it's creating a user assigned identity for the Azure Service Operator to use which has `Contributor` access just to the -aso resource group.
10+
711
## Azure Prerequisites
812

913
These pre-requisites are not part of the CI/CD build, because they only have to be done once, but the [Initialize-Azure](./Initialize-Azure.ps1) script is essentially idempotent and re-runnable.

modules/azureServiceOperator.bicep

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
targetScope = 'resourceGroup'
2+
3+
// *** This template deploys the cluster for poshcode.org. See README.md before making changes ***
4+
@description('Required. The AKS OIDC IssuerUrl')
5+
param oidcIssuerUrl string
6+
7+
@description('Optional. This template deploys the cluster for poshcode.org. See README.md before making changes')
8+
param baseName string = 'aso'
9+
10+
@description('Optional. The location to deploy. Defaults to resourceGroup().location')
11+
param location string = resourceGroup().location
12+
13+
@description('Optional. Tags for the resource. Defaults to resourceGroup().tags')
14+
param tags object = resourceGroup().tags
15+
16+
// 64 is the max deployment name, and the longest name in our sub-deployments is 17 characters, 64-17 = 47
17+
@description('Optional. Provide unique deployment name prefix for the module references. Defaults to take(deploymentName().name, 47)')
18+
@maxLength(47)
19+
param deploymentNamePrefix string = take(deployment().name, 64-17)
20+
21+
22+
module asoId 'userAssignedIdentity.bicep' = {
23+
name: '${deploymentNamePrefix}_uai_asoId'
24+
params: {
25+
baseName: baseName
26+
location: location
27+
tags: tags
28+
federatedIdentitySubjectIssuerDictionary: {
29+
// For creating Azure resources
30+
'system:serviceaccount:azure:operator': oidcIssuerUrl
31+
}
32+
}
33+
}
34+
35+
36+
module iam_azure_owner 'resourceRoleAssignment.bicep' = {
37+
name: '${deploymentNamePrefix}_iam_aso_operator'
38+
params: {
39+
principalIds: [ asoId.outputs.principalId ]
40+
resourceId: asoId.outputs.id
41+
roleName: 'Contributor'
42+
}
43+
}

modules/resourceGroup.bicep

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
targetScope = 'subscription'
2+
3+
@description('Required. The base name of the resource group (will be prefixed with "rg-")')
4+
param name string
5+
6+
@description('The location to deploy')
7+
param location string
8+
9+
@description('Tags for the resource')
10+
param tags object
11+
12+
resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = {
13+
name: name
14+
location: location
15+
tags: tags
16+
}
17+
18+
@description('The resource ID of the resource group')
19+
output id string = rg.id
20+
21+
@description('The name of the resource group')
22+
output name string = rg.name
23+
24+
@description('The location of the resource group')
25+
output location string = rg.location

0 commit comments

Comments
 (0)