-
Notifications
You must be signed in to change notification settings - Fork 0
/
secret-rotation-template.yaml
72 lines (69 loc) · 2.42 KB
/
secret-rotation-template.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# In order to have a unique variable to call on for both the secret name and the actual value
# I've split the single parameter into two. The theory being that the value should be populated
# By the declared variableGroup.
parameters:
- name: libraryVariables
type: object
default:
- variableName: var1
variableValue: $(var1)
- variableName: var2
variableValue: $(var2)
- variableName: var3
variableValue: $(var3)
# template specific parameters
# If these are not included, the pipeline will give an error on main.yaml saying that they're unexpected parameters.
- name: variableGroup
default: ''
- name: stageName
default: ''
- name: stageDisplayName
default: ''
- name: vaultName
default: ''
- name: serviceConnectionName
default: ''
- name: adoEnvironment
default: ''
stages:
- stage: ${{ parameters.stageName }}
displayName: ${{ parameters.stageDisplayName }}
variables:
- group: ${{ parameters.variableGroup }}
jobs:
- deployment: 'approvalGate'
displayName: 'Approval Gate'
environment: ${{ parameters.adoEnvironment }}
strategy:
runOnce:
deploy:
steps:
- script: echo 'Approval Granted, continuing'
- job: rotateSecrets
displayName: ${{ parameters.stageDisplayName }}
steps:
- ${{ each libraryVariables in parameters.libraryVariables }}:
- task: AzureCLI@2
displayName: 'Rotate Secrets'
enabled: true
inputs:
azureSubscription: ${{ parameters.serviceConnectionName }}
failOnStandardError: true
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
if [[ -n "${{ libraryVariables.variableValue }}" ]]; then
az keyvault secret set --vault-name "${{ parameters.vaultName }}" --name "${{ libraryVariables.variableName }}" --value "${{ libraryVariables.variableValue }}" --output none
fi
- job: getSecretNames
displayName: 'Get Secret Names'
steps:
- task: AzureCLI@2
displayName: 'Get Secret Names'
inputs:
azureSubscription: ${{ parameters.serviceConnectionName }}
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
secrets=$(az keyvault secret list --vault-name "${{ parameters.vaultName }}" --query "[].name" -o tsv)
echo "Secret Names: $secrets"