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

fix(azure): ensure key vault url is correct and add keyvault readerrole for migration job #597

Merged
merged 1 commit into from
Apr 9, 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
31 changes: 29 additions & 2 deletions .azure/applications/web-api-migration-job/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ param location string
param containerAppEnvironmentName string
@minLength(3)
@secure()
param adoConnectionStringSecretUri string
param environmentKeyVaultName string

var namePrefix = 'dp-be-${environment}'
var baseImageUrl = 'ghcr.io/digdir/dialogporten-'
Expand All @@ -23,14 +23,41 @@ resource containerAppEnvironment 'Microsoft.App/managedEnvironments@2023-05-01'
name: containerAppEnvironmentName
}

var containerAppEnvVars = [
{
name: 'Infrastructure__DialogDbConnectionString'
secretRef: 'dbconnectionstring'
}
]

// https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/bicep-functions-deployment#example-1
var keyVaultUrl = 'https://${environmentKeyVaultName}${az.environment().suffixes.keyvaultDns}/secrets/dialogportenAdoConnectionString'

var secrets = [
{
name: 'dbconnectionstring'
keyVaultUrl: keyVaultUrl
identity: 'System'
}
]

module migrationJob '../../modules/containerAppJob/main.bicep' = {
name: name
params: {
name: name
location: location
image: '${baseImageUrl}migration-bundle:${imageTag}'
containerAppEnvId: containerAppEnvironment.id
adoConnectionStringSecretUri: adoConnectionStringSecretUri
environmentVariables: containerAppEnvVars
secrets: secrets
}
}

module keyVaultReaderAccessPolicy '../../modules/keyvault/addReaderRoles.bicep' = {
name: 'keyVaultReaderAccessPolicy-${name}'
params: {
keyvaultName: environmentKeyVaultName
principalIds: [migrationJob.outputs.identityPrincipalId]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ param imageTag = readEnvironmentVariable('IMAGE_TAG')

//secrets
param containerAppEnvironmentName = readEnvironmentVariable('CONTAINER_APP_ENVIRONMENT_NAME')
param adoConnectionStringSecretUri = readEnvironmentVariable('ADO_CONNECTION_STRING_SECRET_URI')
param environmentKeyVaultName = readEnvironmentVariable('ENVIRONMENT_KEY_VAULT_NAME')
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ param imageTag = readEnvironmentVariable('IMAGE_TAG')

//secrets
param containerAppEnvironmentName = readEnvironmentVariable('CONTAINER_APP_ENVIRONMENT_NAME')
param adoConnectionStringSecretUri = readEnvironmentVariable('ADO_CONNECTION_STRING_SECRET_URI')
param environmentKeyVaultName = readEnvironmentVariable('ENVIRONMENT_KEY_VAULT_NAME')
20 changes: 4 additions & 16 deletions .azure/modules/containerAppJob/main.bicep
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
param location string
param name string
param image string
param adoConnectionStringSecretUri string

param containerAppEnvId string
param environmentVariables { name: string, value: string?, secretRef: string? }[] = []
param secrets { name: string, keyVaultUrl: string, identity: 'System' }[] = []

resource job 'Microsoft.App/jobs@2023-05-01' = {
name: name
Expand All @@ -13,14 +13,7 @@ resource job 'Microsoft.App/jobs@2023-05-01' = {
}
properties: {
configuration: {
secrets: [
{
// todo: move this and refactor into adding this somewhere else
name: 'dbconnectionstring'
keyVaultUrl: adoConnectionStringSecretUri
identity: 'System'
}
]
secrets: secrets
manualTriggerConfig: {
parallelism: 1
replicaCompletionCount: 1
Expand All @@ -33,12 +26,7 @@ resource job 'Microsoft.App/jobs@2023-05-01' = {
template: {
containers: [
{
env: [
{
name: 'Infrastructure__DialogDbConnectionString'
secretRef: 'dbconnectionstring'
}
]
env: environmentVariables
image: image
name: name
}
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/action-deploy-apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ on:
required: true
AZURE_APP_CONFIGURATION_NAME:
required: true
AZURE_ADO_CONNECTION_STRING_SECRET_URI:
required: true

inputs:
region:
Expand Down Expand Up @@ -73,8 +71,8 @@ jobs:
# # parameters
# IMAGE_TAG: ${{ inputs.gitShortSha }}
# # secrets
# ADO_CONNECTION_STRING_SECRET_URI: ${{ secrets.AZURE_ADO_CONNECTION_STRING_SECRET_URI }}
# CONTAINER_APP_ENVIRONMENT_NAME: ${{ secrets.AZURE_CONTAINER_APP_ENVIRONMENT_NAME }}
# ENVIRONMENT_KEY_VAULT_NAME: ${{ secrets.AZURE_ENVIRONMENT_KEY_VAULT_NAME }}
# with:
# scope: resourcegroup
# template: ./.azure/applications/web-api-migration-job/main.bicep
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/ci-cd-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ jobs:
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# todo: consider resolving these in another way since they are created in the infra-step
AZURE_RESOURCE_GROUP_NAME: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }}
AZURE_ADO_CONNECTION_STRING_SECRET_URI: ${{ secrets.AZURE_ADO_CONNECTION_STRING_SECRET_URI }}
AZURE_ENVIRONMENT_KEY_VAULT_NAME: ${{ secrets.AZURE_ENVIRONMENT_KEY_VAULT_NAME }}
AZURE_CONTAINER_APP_ENVIRONMENT_NAME: ${{ secrets.AZURE_CONTAINER_APP_ENVIRONMENT_NAME }}
AZURE_APP_INSIGHTS_CONNECTION_STRING: ${{ secrets.AZURE_APP_INSIGHTS_CONNECTION_STRING }}
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/ci-cd-pull-request-release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ jobs:
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# todo: consider resolving these in another way since they are created in the infra-step
AZURE_RESOURCE_GROUP_NAME: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }}
AZURE_ADO_CONNECTION_STRING_SECRET_URI: ${{ secrets.AZURE_ADO_CONNECTION_STRING_SECRET_URI }}
AZURE_ENVIRONMENT_KEY_VAULT_NAME: ${{ secrets.AZURE_ENVIRONMENT_KEY_VAULT_NAME }}
AZURE_CONTAINER_APP_ENVIRONMENT_NAME: ${{ secrets.AZURE_CONTAINER_APP_ENVIRONMENT_NAME }}
AZURE_APP_INSIGHTS_CONNECTION_STRING: ${{ secrets.AZURE_APP_INSIGHTS_CONNECTION_STRING }}
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/ci-cd-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ jobs:
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# todo: consider resolving these in another way since they are created in the infra-step
AZURE_RESOURCE_GROUP_NAME: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }}
AZURE_ADO_CONNECTION_STRING_SECRET_URI: ${{ secrets.AZURE_ADO_CONNECTION_STRING_SECRET_URI }}
AZURE_ENVIRONMENT_KEY_VAULT_NAME: ${{ secrets.AZURE_ENVIRONMENT_KEY_VAULT_NAME }}
AZURE_CONTAINER_APP_ENVIRONMENT_NAME: ${{ secrets.AZURE_CONTAINER_APP_ENVIRONMENT_NAME }}
AZURE_APP_INSIGHTS_CONNECTION_STRING: ${{ secrets.AZURE_APP_INSIGHTS_CONNECTION_STRING }}
Expand Down
Loading