Skip to content

Commit

Permalink
Make secrets configurable
Browse files Browse the repository at this point in the history
Secrets are passed as files into componentsync.
  • Loading branch information
janboll committed Dec 12, 2024
1 parent 3405133 commit ebaa619
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 42 deletions.
1 change: 1 addition & 0 deletions config/config.msft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ defaults:
enabled: true
imageRepo: image-sync/component-sync
repositories: quay.io/acm-d/rhtap-hypershift-operator,quay.io/app-sre/uhc-clusters-service,quay.io/package-operator/package-operator-package
secrets: '{"secrets":[{"registry": "quay.io", "secretfile": "/auth/${pullSecretFile}"}]}'
ocMirror:
enabled: true
imageRepo: image-sync/oc-mirror
Expand Down
6 changes: 5 additions & 1 deletion config/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,18 @@
},
"repositories": {
"type": "string"
},
"secrets": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"enabled",
"imageRepo",
"imageTag",
"repositories"
"repositories",
"secrets"
]
},
"ocMirror": {
Expand Down
1 change: 1 addition & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ defaults:
imageRepo: image-sync/component-sync
imageTag: latest
repositories: quay.io/acm-d/rhtap-hypershift-operator,quay.io/app-sre/uhc-clusters-service,quay.io/package-operator/package-operator-package
secrets: '{"secrets":[{"registry": "quay.io", "secretfile": "/auth/${pullSecretFile}"}]}'
ocMirror:
enabled: true
imageRepo: image-sync/oc-mirror
Expand Down
5 changes: 4 additions & 1 deletion dev-infrastructure/configurations/image-sync.tmpl.bicepparam
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ param keyVaultName = '{{ .imageSync.keyVault.name}}'
param keyVaultPrivate = {{ .imageSync.keyVault.private }}
param keyVaultSoftDelete = {{ .imageSync.keyVault.softDelete }}

param bearerSecretName = 'bearer-secret'
param bearerSecretNames = ['bearer-secret']
param componentSyncPullSecretName = 'component-sync-pull-secret'
param componentSyncImage = '{{ .svcAcrName }}.azurecr.io/{{ .imageSync.componentSync.imageRepo }}:{{ .imageSync.componentSync.imageTag }}'
param componentSyncEnabed = {{ .imageSync.componentSync.enabled }}

param componentSyncSecrets = '{{ .imageSync.componentSync.secrets }}'
param svcAcrName = '{{ .svcAcrName }}'

param ocpAcrName = '{{ .ocpAcrName }}'
param ocpPullSecretName = 'pull-secret'
param repositoriesToSync = '{{ .imageSync.componentSync.repositories }}'
param ocMirrorImage = '{{ .svcAcrName }}.azurecr.io/{{ .imageSync.ocMirror.imageRepo }}:{{ .imageSync.ocMirror.imageTag }}'
param ocMirrorEnabled = {{ .imageSync.ocMirror.enabled }}

param numberOfTags = 10
92 changes: 52 additions & 40 deletions dev-infrastructure/templates/image-sync.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ param keyVaultSoftDelete bool
@description('The name of the pull secret for the component sync job')
param componentSyncPullSecretName string

@description('The name of the Quay API bearer token secret')
param bearerSecretName string
@description('The names of the bearer token secrets')
param bearerSecretNames array

@description('The image to use for the component sync job')
param componentSyncImage string
Expand All @@ -55,6 +55,9 @@ param ocMirrorEnabled bool
@description('The name of the pull secret for the oc-mirror job')
param ocpPullSecretName string

@description('Secret configuration to pass into component sync')
param componentSyncSecrets string

//
// Container App Infra
//
Expand Down Expand Up @@ -123,7 +126,7 @@ module acrPullRole '../modules/acr/acr-permissions.bicep' = {
}

module pullSecretPermission '../modules/keyvault/keyvault-secret-access.bicep' = [
for secretName in [componentSyncPullSecretName, bearerSecretName, ocpPullSecretName]: {
for secretName in union([componentSyncPullSecretName, ocpPullSecretName], bearerSecretNames): {
name: guid(imageSyncManagedIdentity, location, keyVaultName, secretName, 'secret-user')
params: {
keyVaultName: keyVaultName
Expand All @@ -144,6 +147,24 @@ module pullSecretPermission '../modules/keyvault/keyvault-secret-access.bicep' =
var componentSyncJobName = 'component-sync'
var pullSecretFile = 'quayio-auth.json'

var componentSecretsArray = [
for bearerSecretName in bearerSecretNames: {
name: 'bearer-secret'
keyVaultUrl: 'https://${keyVaultName}${environment().suffixes.keyvaultDns}/secrets/${bearerSecretName}'
identity: uami.id
}
]

var componentSecretVolumesArray = [
for bearerSecretName in bearerSecretNames: {
name: bearerSecretName
storageType: 'Secret'
secrets: [
{ secretRef: bearerSecretName }
]
}
]

resource componentSyncJob 'Microsoft.App/jobs@2024-03-01' = if (componentSyncEnabed) {
name: componentSyncJobName
location: location
Expand Down Expand Up @@ -171,18 +192,16 @@ resource componentSyncJob 'Microsoft.App/jobs@2024-03-01' = if (componentSyncEna
server: '${svcAcrName}${environment().suffixes.acrLoginServer}'
}
]
secrets: [
{
name: 'pull-secrets'
keyVaultUrl: 'https://${keyVaultName}${environment().suffixes.keyvaultDns}/secrets/${componentSyncPullSecretName}'
identity: uami.id
}
{
name: 'bearer-secret'
keyVaultUrl: 'https://${keyVaultName}${environment().suffixes.keyvaultDns}/secrets/${bearerSecretName}'
identity: uami.id
}
]
secrets: union(
[
{
name: 'pull-secrets'
keyVaultUrl: 'https://${keyVaultName}${environment().suffixes.keyvaultDns}/secrets/${componentSyncPullSecretName}'
identity: uami.id
}
],
componentSecretsArray
)
}
template: {
containers: [
Expand All @@ -199,10 +218,7 @@ resource componentSyncJob 'Microsoft.App/jobs@2024-03-01' = if (componentSyncEna
{ name: 'TENANT_ID', value: tenant().tenantId }
{ name: 'DOCKER_CONFIG', value: '/auth' }
{ name: 'MANAGED_IDENTITY_CLIENT_ID', value: uami.properties.clientId }
{
name: 'SECRETS'
value: '{"secrets":[{"registry": "quay.io", "secretfile": "/auth/${pullSecretFile}"}]}'
}
{ name: 'SECRETS', value: componentSyncSecrets }
]
}
]
Expand All @@ -215,7 +231,7 @@ resource componentSyncJob 'Microsoft.App/jobs@2024-03-01' = if (componentSyncEna
]
args: [
'-c'
'cat /tmp/secret-orig/pull-secrets |base64 -d > /etc/containers/config.json && cat /tmp/bearer-secret/bearer-secret | base64 -d > /etc/containers/${pullSecretFile}'
'cat /tmp/secret-orig/pull-secrets |base64 -d > /etc/containers/config.json && for file in $(find . -type f); do; export fn=$(basename $file); cat $file | base64 -d > /etc/containers/$fn; done;'
]
volumeMounts: [
{ volumeName: 'pull-secrets-updated', mountPath: '/etc/containers' }
Expand All @@ -224,26 +240,22 @@ resource componentSyncJob 'Microsoft.App/jobs@2024-03-01' = if (componentSyncEna
]
}
]
volumes: [
{
name: 'pull-secrets-updated'
storageType: 'EmptyDir'
}
{
name: 'pull-secrets'
storageType: 'Secret'
secrets: [
{ secretRef: 'pull-secrets' }
]
}
{
name: 'bearer-secret'
storageType: 'Secret'
secrets: [
{ secretRef: 'bearer-secret' }
]
}
]
volumes: union(
[
{
name: 'pull-secrets-updated'
storageType: 'EmptyDir'
}
{
name: 'pull-secrets'
storageType: 'Secret'
secrets: [
{ secretRef: 'pull-secrets' }
]
}
],
componentSecretVolumesArray
)
}
}
dependsOn: [
Expand Down

0 comments on commit ebaa619

Please sign in to comment.