Skip to content

Commit fe1f7d0

Browse files
authored
[CI] add az-sync github action to handle secrets
1 parent 77170c9 commit fe1f7d0

File tree

12 files changed

+270
-153
lines changed

12 files changed

+270
-153
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
Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,23 @@
11
name: configure-goproxy
22
author: s.breen
3-
description: Sets the current Go module proxy based on the presence of a private proxy URL in secrets
4-
inputs:
5-
user:
6-
description: Artifactory username secret name
7-
required: false
8-
default: ""
9-
token:
10-
description: Artifactory token secret name
11-
required: false
12-
default: ""
13-
url:
14-
description: Artifactory URL
15-
required: false
16-
default: ""
3+
description: Sets the current Go module proxy based on the presence of a private proxy URL in environment variables.
174
runs:
185
using: 'composite'
196
steps:
207
- name: Configure Go Proxy
218
id: configure-goproxy
229
shell: bash
2310
run: |
24-
if [[ -z "${{ inputs.user }}" ]] || \
25-
[[ -z "${{ inputs.token }}" ]] || \
26-
[[ -z "${{ inputs.url }}" ]] || \
11+
if [[ -z "${{ env.artifactory-user }}" ]] || \
12+
[[ -z "${{ env.artifactory-token }}" ]] || \
13+
[[ -z "${{ env.artifactory-url-dev }}" ]] || \
2714
[[ "${{ github.event.pull_request.head.repo.fork }}" == 'true' ]] ||
2815
[[ "${{ startsWith(github.head_ref, 'dependabot-')}}" == 'true' ]] ; then
2916
echo "No Artifactory secrets available - using direct GOPROXY"
3017
GOPROXY_VALUE="direct"
3118
else
3219
echo "Development mode - using dev Artifactory"
33-
GOPROXY_VALUE="https://${{ inputs.user }}:${{ inputs.token }}@${{ inputs.url }}"
20+
GOPROXY_VALUE="https://${{ env.artifactory-user }}:${{ env.artifactory-token }}@${{ env.artifactory-url-dev }}"
3421
fi
3522
echo "GOPROXY=${GOPROXY_VALUE}" >> $GITHUB_ENV
3623

.github/workflows/assertion.yml

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,6 @@ on:
1616
type: boolean
1717
required: false
1818
default: false
19-
workflow_call:
20-
inputs:
21-
packageVersion:
22-
description: 'Agent version'
23-
type: string
24-
required: true
25-
runId:
26-
description: 'Run ID of the workflow that built the artifacts'
27-
type: string
28-
required: false
29-
signAssertion:
30-
description: 'Sign and store the assertion document'
31-
type: boolean
32-
required: false
33-
default: false
34-
secrets:
35-
ARTIFACTORY_USER:
36-
required: true
37-
ARTIFACTORY_TOKEN:
38-
required: true
39-
ARTIFACTORY_URL:
40-
required: true
4119

4220
permissions:
4321
contents: read
@@ -48,23 +26,15 @@ jobs:
4826
runs-on: ubuntu-22.04
4927
if: ${{ !github.event.pull_request.head.repo.fork }}
5028
permissions:
51-
id-token: write
52-
contents: read
53-
env:
54-
GOPROXY: "https://${{ secrets.ARTIFACTORY_USER }}:${{ secrets.ARTIFACTORY_TOKEN }}@${{ secrets.ARTIFACTORY_URL }}"
29+
id-token: write # for OIDC authentication
30+
contents: read # Needed to download artifacts
5531
strategy:
5632
matrix:
5733
osarch: [amd64, arm64]
5834
steps:
5935
- name: Checkout Repository
6036
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
6137

62-
- name: Set up Go
63-
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
64-
with:
65-
go-version-file: 'go.mod'
66-
cache: false
67-
6838
- name: Download nginx-agent binary artifacts
6939
if: ${{ inputs.runId != '' }}
7040
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # 7.0.0
@@ -97,9 +67,9 @@ jobs:
9767
builder-id: 'github.com'
9868
builder-version: '${{env.GO_VERSION}}_test'
9969
invocation-id: ${{ github.run_id }}.${{ github.run_number }}.${{ github.run_attempt }}
100-
artifactory-user: ${{ secrets.ARTIFACTORY_USER }}
101-
artifactory-api-token: ${{ secrets.ARTIFACTORY_TOKEN }}
102-
artifactory-url: ${{ secrets.ARTIFACTORY_URL }}
70+
artifactory-user: ${{ env.artifactory-user }}
71+
artifactory-api-token: ${{ env.artifactory-token }}
72+
artifactory-url: ${{ env.artifactory-url }}
10373
artifactory-repo: 'f5-nginx-go-local-approved-dependency'
10474
assertion-doc-file: assertion_nginx-agent_${{ inputs.packageVersion }}_${{ matrix.osarch }}.json
10575
build-content-path: ${{ env.goversionm }}

0 commit comments

Comments
 (0)