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

KeyVault refactor #320

Merged
merged 6 commits into from
Jul 20, 2022
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
6 changes: 3 additions & 3 deletions .github/workflows/ByoVnetCI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ jobs:
} else { Write-Output "-- Looks like $feature is registered properly" }
}

if($params.parameters.azureKeyvaultSecretsProvider.value -eq $true) {
if($params.parameters.keyVaultAksCSI.value -eq $true) {
$feature='AKS-AzureKeyVaultSecretsProvider'
write-output "-- $feature"
$featureCsi = $aksfeatures | Where-Object {$_.name -like "*$feature"}
Expand Down Expand Up @@ -336,7 +336,7 @@ jobs:
$paramFileContent=Get-Content $paramFilePath
$params=$paramFileContent|ConvertFrom-Json

if($params.parameters.createKV.value -eq $true) {
if($params.parameters.keyVaultCreate.value -eq $true) {
Write-Output "Checking for already existing soft deleted KV"

#lets do this properly and interrogate the whatif file for the KVNAME
Expand Down Expand Up @@ -641,7 +641,7 @@ jobs:
}

Write-Output "Checking for CSI Secrets driver"
if($params.parameters.azureKeyvaultSecretsProvider.value -eq $true) {
if($params.parameters.keyVaultAksCSI.value -eq $true) {
$csiEnabled=az aks show -n $AKSNAME -g $RG --query "addonProfiles.omsagent.enabled" -o tsv
write-output $csiEnabled

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows_dep/AksDeploy-ByoVnet.parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@
"SystemPoolType" : {
"value" : "Standard"
},
"createKV" : {
"keyVaultCreate" : {
"value" : true
},
"azureKeyvaultSecretsProvider" : {
"keyVaultAksCSI" : {
"value" : true
},
"appgwKVIntegration" : {
Expand All @@ -87,10 +87,10 @@
"guard"
]
},
"KeyVaultSoftDelete" : {
"keyVaultSoftDelete" : {
"value" : false
},
"KeyVaultPurgeProtection" : {
"keyVaultPurgeProtection" : {
"value" : false
},
"dnsZoneId" : {
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows_dep/AksDeploy-Private.parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@
"appgwKVIntegration": {
"value": true
},
"azureKeyvaultSecretsProvider": {
"keyVaultAksCSI": {
"value": true
},
"createKV": {
"keyVaultCreate": {
"value": true
},
"upgradeChannel": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
"networkPlugin": {
"value": "azure"
},
"KeyVaultSoftDelete" : {
"keyVaultSoftDelete" : {
"value" : false
},
"KeyVaultPurgeProtection" : {
"keyVaultPurgeProtection" : {
"value" : false
}
}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows_dep/regressionparams/key-vault.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
"appgwKVIntegration": {
"value": true
},
"azureKeyvaultSecretsProvider": {
"keyVaultAksCSI": {
"value": true
},
"createKV": {
"keyVaultCreate": {
"value": true
},
"kvIPAllowlist": {
"keyVaultIPAllowlist": {
"value": [
"1.2.3.4/32"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@
"appgwKVIntegration": {
"value": true
},
"azureKeyvaultSecretsProvider": {
"keyVaultAksCSI": {
"value": true
},
"createKV": {
"keyVaultCreate": {
"value": true
},
"upgradeChannel": {
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows_dep/regressionparams/managed-private.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@
"appgwKVIntegration": {
"value": true
},
"createKV": {
"keyVaultCreate": {
"value": true
},
"azureKeyvaultSecretsProvider": {
"keyVaultAksCSI": {
"value": true
},
"upgradeChannel": {
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows_dep/regressionparams/managed-public.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
"appgwKVIntegration": {
"value": true
},
"createKV": {
"keyVaultCreate": {
"value": true
},
"azureKeyvaultSecretsProvider": {
"keyVaultAksCSI": {
"value": true
},
"upgradeChannel": {
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows_dep/regressionparams/open-secure.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
"azurepolicy": {
"value": "audit"
},
"azureKeyvaultSecretsProvider": {
"keyVaultAksCSI": {
"value": true
},
"createKV": {
"keyVaultCreate": {
"value": true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@
"appgwKVIntegration": {
"value": true
},
"azureKeyvaultSecretsProvider": {
"keyVaultAksCSI": {
"value": true
},
"createKV": {
"keyVaultCreate": {
"value": true
},
"upgradeChannel": {
Expand Down
80 changes: 80 additions & 0 deletions bicep/keyvault.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
@minLength(2)
@description('The location to use for the deployment. defaults to Resource Groups location.')
param location string = resourceGroup().location

@minLength(3)
@maxLength(20)
@description('Used to name all resources')
param resourceName string

@description('Enable support for private links')
param privateLinks bool = false

@description('If soft delete protection is enabled')
param keyVaultSoftDelete bool = true

@description('If purge protection is enabled')
param keyVaultPurgeProtection bool = true

@description('Add IP to KV firewall allow-list')
param keyVaultIPAllowlist array = []

param logAnalyticsWorkspaceId string = ''

var akvRawName = 'kv-${replace(resourceName, '-', '')}${uniqueString(resourceGroup().id, resourceName)}'
var akvName = length(akvRawName) > 24 ? substring(akvRawName, 0, 24) : akvRawName

var kvIPRules = [for kvIp in keyVaultIPAllowlist: {
value: kvIp
}]

resource kv 'Microsoft.KeyVault/vaults@2021-11-01-preview' = {
name: akvName
location: location
properties: {
tenantId: subscription().tenantId
sku: {
family: 'A'
name: 'standard'
}
// publicNetworkAccess: whether the vault will accept traffic from public internet. If set to 'disabled' all traffic except private endpoint traffic and that that originates from trusted services will be blocked.
publicNetworkAccess: privateLinks && empty(keyVaultIPAllowlist) ? 'disabled' : 'enabled'

networkAcls: privateLinks && !empty(keyVaultIPAllowlist) ? {
bypass: 'AzureServices'
defaultAction: 'Deny'
ipRules: kvIPRules
virtualNetworkRules: []
} : {}

enableRbacAuthorization: true
enabledForDeployment: false
enabledForDiskEncryption: false
enabledForTemplateDeployment: false
enableSoftDelete: keyVaultSoftDelete
enablePurgeProtection: keyVaultPurgeProtection ? true : json('null')
}
}

resource kvDiags 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = if (!empty(logAnalyticsWorkspaceId)) {
name: 'kvDiags'
scope: kv
properties: {
workspaceId: logAnalyticsWorkspaceId
logs: [
{
category: 'AuditEvent'
enabled: true
}
]
metrics: [
{
category: 'AllMetrics'
enabled: true
}
]
}
}

output keyVaultName string = kv.name
output keyVaultId string = kv.id
74 changes: 74 additions & 0 deletions bicep/keyvaultrbac.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
param keyVaultName string

@description('An array of Service Principal IDs')
param rbacSecretUserSps array = []

@description('An array of Service Principal IDs')
param rbacSecretOfficerSps array = []

@description('An array of Service Principal IDs')
param rbacCertOfficerSps array = []

@description('An array of User IDs')
param rbacSecretOfficerUsers array = []

@description('An array of User IDs')
param rbacCertOfficerUsers array = []

var keyVaultSecretsUserRole = resourceId('Microsoft.Authorization/roleDefinitions', '4633458b-17de-408a-b874-0445c86b69e6')
var keyVaultSecretsOfficerRole = resourceId('Microsoft.Authorization/roleDefinitions', 'b86a8fe4-44ce-4948-aee5-eccb2c155cd7')
var keyVaultCertsOfficerRole = resourceId('Microsoft.Authorization/roleDefinitions', 'a4417e6f-fecd-4de8-b567-7b0420556985')

resource kv 'Microsoft.KeyVault/vaults@2021-11-01-preview' existing = {
name: keyVaultName
}

resource rbacSecretUserSp 'Microsoft.Authorization/roleAssignments@2021-04-01-preview' = [for rbacSp in rbacSecretUserSps : if(!empty(rbacSp)) {
scope: kv
name: guid(kv.id, rbacSp, keyVaultSecretsUserRole)
properties: {
roleDefinitionId: keyVaultSecretsUserRole
principalType: 'ServicePrincipal'
principalId: rbacSp
}
}]

resource rbacSecretOfficerSp 'Microsoft.Authorization/roleAssignments@2021-04-01-preview' = [for rbacSp in rbacSecretOfficerSps : if(!empty(rbacSp)) {
scope: kv
name: guid(kv.id, rbacSp, keyVaultSecretsOfficerRole)
properties: {
roleDefinitionId: keyVaultSecretsOfficerRole
principalType: 'ServicePrincipal'
principalId: rbacSp
}
}]

resource rbacCertsOfficerSp 'Microsoft.Authorization/roleAssignments@2021-04-01-preview' = [for rbacSp in rbacCertOfficerSps : if(!empty(rbacSp)) {
scope: kv
name: guid(kv.id, rbacSp, keyVaultCertsOfficerRole)
properties: {
roleDefinitionId: keyVaultCertsOfficerRole
principalType: 'ServicePrincipal'
principalId: rbacSp
}
}]

resource rbacSecretOfficerUser 'Microsoft.Authorization/roleAssignments@2021-04-01-preview' = [for rbacSp in rbacSecretOfficerUsers : if(!empty(rbacSp)) {
scope: kv
name: guid(kv.id, rbacSp, keyVaultSecretsOfficerRole)
properties: {
roleDefinitionId: keyVaultSecretsOfficerRole
principalType: 'User'
principalId: rbacSp
}
}]

resource rbacCertsOfficerUser 'Microsoft.Authorization/roleAssignments@2021-04-01-preview' = [for rbacSp in rbacCertOfficerUsers : if(!empty(rbacSp)) {
scope: kv
name: guid(kv.id, rbacSp, keyVaultCertsOfficerRole)
properties: {
roleDefinitionId: keyVaultCertsOfficerRole
principalType: 'User'
principalId: rbacSp
}
}]
Loading