Skip to content

Commit 76c8f4d

Browse files
committed
test: TEMPORARY BUILD_SECRETS test (not to be merged)
1 parent 1d5c2ae commit 76c8f4d

4 files changed

Lines changed: 89 additions & 0 deletions

File tree

‎.github/workflows/docker-image.yml‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ on:
121121
DOCKERHUB_TOKEN:
122122
required: false
123123
description: Docker Hub access token (or password) for DOCKERHUB_USERNAME
124+
BUILD_SECRETS:
125+
required: false
126+
description: >-
127+
Secrets for the build as BuildKit secrets (`id=value`, one per line; the format of build-push-action's
128+
`secrets` input), e.g. `sentry_auth_token=<token>`. Read in the Dockerfile with
129+
`RUN --mount=type=secret,id=sentry_auth_token ...`. Masked in the logs; unset or empty passes no secret.
124130
outputs:
125131
digest:
126132
description: Digest of the built image (the multi-platform index if more than one platform was built)
@@ -141,6 +147,18 @@ jobs:
141147
digest: ${{ steps.build.outputs.digest }}
142148
tags: ${{ steps.meta.outputs.tags }}
143149
steps:
150+
- &mask-build-secrets
151+
name: Mask build secrets
152+
env:
153+
BUILD_SECRETS: ${{ secrets.BUILD_SECRETS }}
154+
run: |
155+
# Every value is masked in the logs, also if the caller composed BUILD_SECRETS (`format(...)`) from
156+
# a secret and GitHub does not know the composed value as a secret. Nothing is printed.
157+
while IFS= read -r line; do
158+
value="${line#*=}"
159+
[ -z "$value" ] || echo "::add-mask::$value"
160+
done <<< "$BUILD_SECRETS"
161+
144162
- &checkout
145163
name: Checkout repository
146164
uses: actions/checkout@v7
@@ -346,6 +364,7 @@ jobs:
346364
push: ${{ inputs.push }}
347365
tags: ${{ steps.meta.outputs.tags }}
348366
labels: ${{ steps.meta.outputs.labels }}
367+
secrets: ${{ secrets.BUILD_SECRETS }}
349368
cache-from: type=gha,scope=${{ steps.config.outputs.cache-scope }}
350369
cache-to: type=gha,mode=min,scope=${{ steps.config.outputs.cache-scope }},ignore-error=true
351370

@@ -549,6 +568,7 @@ jobs:
549568
contents: read
550569
packages: write # push to ghcr.io
551570
steps:
571+
- *mask-build-secrets
552572
- *checkout
553573
- *download-artifact
554574
- *prepare
@@ -567,6 +587,7 @@ jobs:
567587
platforms: ${{ matrix.platform }}
568588
build-args: ${{ inputs.build-args }}
569589
labels: ${{ steps.meta.outputs.labels }}
590+
secrets: ${{ secrets.BUILD_SECRETS }}
570591
outputs: ${{ inputs.push && format('type=image,"name={0}",push-by-digest=true,name-canonical=true,push=true', steps.config.outputs.image-names) || 'type=cacheonly' }}
571592
cache-from: type=gha,scope=${{ steps.config.outputs.cache-scope }}-${{ matrix.platform == 'linux/arm64' && 'arm64' || 'amd64' }}
572593
cache-to: type=gha,mode=min,scope=${{ steps.config.outputs.cache-scope }}-${{ matrix.platform == 'linux/arm64' && 'arm64' || 'amd64' }},ignore-error=true

‎.github/workflows/test-secrets.yml‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# TEMPORARY: BUILD_SECRETS test of docker-image.yml. Not to be merged.
2+
name: TEMP test secrets
3+
on:
4+
push:
5+
branches: [test/ci-secrets]
6+
permissions: {}
7+
jobs:
8+
default-with:
9+
uses: ./.github/workflows/docker-image.yml
10+
permissions:
11+
contents: read
12+
packages: write
13+
secrets:
14+
BUILD_SECRETS: |
15+
probe=s3cr3tvalue123
16+
probe2=other-value-456
17+
with:
18+
images: ghcr.io/aam-digital/ci-test
19+
context: test/ci-image
20+
file: test/ci-image/Dockerfile.secrets
21+
platforms: linux/amd64
22+
tags: pr-sec-default
23+
cache-scope: sec-a
24+
default-without:
25+
uses: ./.github/workflows/docker-image.yml
26+
permissions:
27+
contents: read
28+
packages: write
29+
with:
30+
images: ghcr.io/aam-digital/ci-test
31+
context: test/ci-image
32+
file: test/ci-image/Dockerfile.nosecrets
33+
platforms: linux/amd64
34+
tags: pr-sec-default-none
35+
cache-scope: sec-b
36+
native-with:
37+
uses: ./.github/workflows/docker-image.yml
38+
permissions:
39+
contents: read
40+
packages: write
41+
secrets:
42+
BUILD_SECRETS: |
43+
probe=s3cr3tvalue123
44+
probe2=other-value-456
45+
with:
46+
images: ghcr.io/aam-digital/ci-test
47+
context: test/ci-image
48+
file: test/ci-image/Dockerfile.secrets
49+
native-runners: true
50+
tags: pr-sec-native
51+
cache-scope: sec-c
52+
native-without:
53+
uses: ./.github/workflows/docker-image.yml
54+
permissions:
55+
contents: read
56+
packages: write
57+
with:
58+
images: ghcr.io/aam-digital/ci-test
59+
context: test/ci-image
60+
file: test/ci-image/Dockerfile.nosecrets
61+
native-runners: true
62+
tags: pr-sec-native-none
63+
cache-scope: sec-d

‎test/ci-image/Dockerfile.nosecrets‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM busybox:1.37
2+
RUN --mount=type=secret,id=probe test ! -e /run/secrets/probe

‎test/ci-image/Dockerfile.secrets‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM busybox:1.37
2+
RUN --mount=type=secret,id=probe test "$(sha256sum < /run/secrets/probe | cut -d' ' -f1)" = a8bd414a160af4094e22a273bb6b4e7df2ad1231243d6f0c341dabb2d071b1b1
3+
RUN --mount=type=secret,id=probe2 test "$(sha256sum < /run/secrets/probe2 | cut -d' ' -f1)" = 6919d417b9b961b0a7d65626fd8f1394e9307ba795830b6bf40de4d2967baad8

0 commit comments

Comments
 (0)