Skip to content

Commit 129ceed

Browse files
authored
az-sync by s.breen (#60)
The proposal includes already implemented az-sync action. The existing functionality stays intact
1 parent 54da3ca commit 129ceed

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed

.github/actions/az-sync/action.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Sync Secrets from Azure Key Vault
2+
author: s.breen
3+
description: az-sync
4+
inputs:
5+
az_client_id:
6+
description: 'Azure Client ID'
7+
required: true
8+
az_tenant_id:
9+
description: 'Azure Tenant ID'
10+
required: true
11+
az_subscription_id:
12+
description: 'Azure Subscription ID'
13+
required: true
14+
keyvault:
15+
description: 'Azure Key Vault name'
16+
required: true
17+
secrets-filter:
18+
description: 'Filter for secrets to sync (comma-separated patterns)'
19+
required: true
20+
default: '*'
21+
runs:
22+
using: "composite"
23+
steps:
24+
- name: Azure login
25+
uses: azure/login@a457da9ea143d694b1b9c7c869ebb04ebe844ef5 # v2.3.0
26+
with:
27+
client-id: ${{ inputs.az_client_id }}
28+
tenant-id: ${{ inputs.az_tenant_id }}
29+
subscription-id: ${{ inputs.az_subscription_id }}
30+
31+
- name: Sync
32+
shell: bash
33+
run: |
34+
IFS=',' read -r -a array <<< "${{ inputs.secrets-filter }}"
35+
for pattern in "${array[@]}"; do
36+
echo "Processing pattern: $pattern"
37+
for secret_name in $(az keyvault secret list --vault-name "${{ inputs.keyvault }}" --query "[?contains(name, '$pattern')].name" -o tsv); do
38+
secret_value=$(az keyvault secret show --name "$secret_name" --vault-name "${{ inputs.keyvault }}" --query value -o tsv)
39+
# check if value is multiline
40+
if [[ "$secret_value" == *$'\n'* ]]; then
41+
# Mask each line for multiline secrets
42+
while IFS= read -r line; do
43+
[[ -n "$line" ]] && echo "::add-mask::${line}"
44+
done <<< "$secret_value"
45+
46+
# Use heredoc syntax for multiline environment variables
47+
delimiter="EOF_${secret_name}_$(date +%s)"
48+
{
49+
echo "${secret_name}<<${delimiter}"
50+
echo "$secret_value"
51+
echo "$delimiter"
52+
} >> $GITHUB_ENV
53+
else
54+
echo "::add-mask::${secret_value}"
55+
echo "$secret_name=$secret_value" >> $GITHUB_ENV
56+
fi
57+
echo "Synced secret: env.$secret_name"
58+
done
59+
done
60+
61+
- name: Azure logout
62+
shell: bash
63+
run: |
64+
az logout

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Table of contents
2+
1. [docs-actions](#docs-actions)
3+
1. [Hugo theme version](#hugo-theme-version)
4+
1. [az-sync-action](#az-sync-action)
5+
6+
17
# docs-actions
28

39
This repo contains actions for building and deploying, hugo and sphinx based documentation websites for NGINX.
@@ -140,3 +146,52 @@ on:
140146
paths:
141147
- docsDirectory/**
142148
.......
149+
```
150+
151+
# az-sync action
152+
153+
**Path:** `.github/actions/az-sync/action.yml`
154+
155+
A reusable composite action written by s.breen that logs into Azure, retrieves secrets from an Azure Key Vault, and exports them as environment variables for use in subsequent workflow steps. After all secrets are synced, it logs out of Azure automatically.
156+
157+
## Inputs
158+
159+
| Input | Description | Required | Default |
160+
|---|---|---|---|
161+
| `az_client_id` | Azure Client ID (for OIDC federated login) | Yes | — |
162+
| `az_tenant_id` | Azure Tenant ID | Yes | — |
163+
| `az_subscription_id` | Azure Subscription ID | Yes | — |
164+
| `keyvault` | Name of the Azure Key Vault to read secrets from | Yes | — |
165+
| `secrets-filter` | Comma-separated list (no spaces) of secret name patterns to sync | Yes | `*` |
166+
167+
## Usage example
168+
169+
```yml
170+
- name: Get Secrets from Azure Key Vault
171+
# Always use full path while adding into called workflow
172+
uses: nginxinc/docs-actions/.github/actions/az-sync
173+
with:
174+
az_client_id: ${{ secrets.AZURE_VAULT_CLIENT_ID }}
175+
az_tenant_id: ${{ secrets.AZURE_VAULT_TENANT_ID }}
176+
az_subscription_id: ${{ secrets.AZURE_VAULT_SUBSCRIPTION_ID }}
177+
keyvault: ${{ secrets.DOCS_VAULTNAME }}
178+
secrets-filter: 'MySecret1,MySecret2'
179+
180+
- name: Using secrets
181+
env:
182+
MySecret1: ${{ env.MySecret1 }}
183+
MySecret2: ${{ env.MySecret2 }}
184+
run: |
185+
...
186+
187+
- name: Configure AWS credentials via OIDC (assume role)
188+
uses: aws-actions/configure-aws-credentials@v4
189+
with:
190+
role-to-assume: arn:aws:iam::${{ env.MySecret1 }}:role/${{ env.MySecret1 }}
191+
aws-region: eu-central-1
192+
```
193+
194+
Each matched secret is exported as an environment variable named after the secret (e.g. `MySecret1`). Multiline secret values are handled using the heredoc syntax supported by `$GITHUB_ENV`.
195+
196+
---
197+

0 commit comments

Comments
 (0)