Skip to content

Commit 0c8af0e

Browse files
committed
RHOAIENG-21668: chore(gha): securely commit encrypted subscription-manager credentials using git-crypt
``` git-crypt init git-crypt export-key git-crypt-key base64 git-crypt-key | gh secret set GIT_CRYPT_KEY --repo red-hat-data-services/notebook ``` Implement the security check to only allow builds for project contributors
1 parent 914a826 commit 0c8af0e

File tree

6 files changed

+70
-0
lines changed

6 files changed

+70
-0
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ci/secrets/** filter=git-crypt diff=git-crypt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
"name": "Build Notebooks (pr, RHEL images)"
3+
"on":
4+
"pull_request_target":
5+
"types": ["opened", "synchronize", "reopened", "edited"]
6+
7+
# BEWARE: This GitHub Actions workflow runs on pull_request_target, meaning it has access to our secrets
8+
# see https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-secrets
9+
# and https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
10+
11+
permissions:
12+
contents: read
13+
packages: read
14+
15+
env:
16+
#language=json
17+
contributors: |
18+
["atheo89", "andyatmiami", "caponetto", "daniellutz", "dibryant", "harshad16", "jesuino", "jiridanek", "jstourac", "paulovmr"]
19+
20+
jobs:
21+
gen:
22+
name: Generate job matrix
23+
runs-on: ubuntu-latest
24+
outputs:
25+
matrix: ${{ steps.gen.outputs.matrix }}
26+
has_jobs: ${{ steps.gen.outputs.has_jobs }}
27+
steps:
28+
- name: Check permissions (this must be done FIRST, for security, before we checkout)
29+
if: ${{ !contains(fromJSON(env.contributors), github.actor) }}
30+
run: |
31+
echo "GitHub user ${{ github.actor }} is not a registered project contributor, not allowed to run actions on RHEL!"
32+
exit 1
33+
34+
- uses: actions/checkout@v4
35+
with:
36+
ref: "refs/pull/${{ github.event.number }}/merge"
37+
38+
- name: Unlock encrypted secrets with git-crypt
39+
run: |
40+
echo "${GIT_CRYPT_KEY}" | base64 --decode > ./git-crypt-key
41+
git-crypt unlock ./git-crypt-key
42+
rm ./git-crypt-key
43+
44+
- name: Determine targets to build based on changed files
45+
run: |
46+
set -x
47+
git fetch --no-tags origin 'pull/${{ github.event.pull_request.number }}/head:${{ github.event.pull_request.head.ref }}'
48+
git fetch --no-tags origin '+refs/heads/${{ github.event.pull_request.base.ref }}:refs/remotes/origin/${{ github.event.pull_request.base.ref }}'
49+
python3 ci/cached-builds/gen_gha_matrix_jobs.py \
50+
--from-ref 'origin/${{ github.event.pull_request.base.ref }}' \
51+
--to-ref '${{ github.event.pull_request.head.ref }}'
52+
--only-rhel
53+
id: gen
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
shell: bash
57+
58+
build:
59+
needs: ["gen"]
60+
strategy:
61+
fail-fast: false
62+
matrix: "${{ fromJson(needs.gen.outputs.matrix) }}"
63+
uses: ./.github/workflows/build-notebooks-TEMPLATE.yaml
64+
if: ${{ fromJson(needs.gen.outputs.has_jobs) }}
65+
with:
66+
target: "${{ matrix.target }}"
67+
github: "${{ toJSON(github) }}"
68+
subscription: true
69+
secrets: inherit

ci/secrets/pki/consumer/cert.pem

2.23 KB
Binary file not shown.

ci/secrets/pki/consumer/key.pem

3.22 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)