-
Notifications
You must be signed in to change notification settings - Fork 3.3k
223 lines (208 loc) · 8.6 KB
/
Copy pathsigstore-updater.yml
File metadata and controls
223 lines (208 loc) · 8.6 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
## %CopyrightBegin%
##
## SPDX-License-Identifier: Apache-2.0
##
## Copyright Ericsson AB 2024-2026. All Rights Reserved.
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
## %CopyrightEnd%
##
## This workflow has two jobs:
## 1. update-release-sigstore: Regenerates Sigstore attestation files
## when an existing GitHub release is edited.
## 2. attest-vex: Creates Sigstore attestations for modified OpenVEX
## files in PRs targeting the master branch.
##
name: Update Sigstore Files
on:
release:
types: [edited]
pull_request:
branches: [openvex]
paths:
- '*.openvex.json'
permissions:
contents: read
jobs:
update-release-sigstore:
if: github.event_name == 'release'
permissions:
contents: write
attestations: write
id-token: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Download release artifacts
env:
GH_TOKEN: "${{ github.token }}"
TAG: "${{ github.event.release.tag_name }}"
run: gh release download "${TAG}"
- name: Copy artifacts
run: mkdir artifacts; cp *.tar.gz artifacts/
- name: Attest Distribution Assets with SBoM
id: attest-sbom
uses: actions/attest@59d89421af93a897026c735860bf21b6eb4f7b26 # ratchet:actions/attest@v4.10
with:
subject-path: |
artifacts/*.tar.gz
sbom-path: bom.spdx.json
- name: Copy SBoM provenance
id: sbom-provenance
shell: bash
env:
ATTESTATION: "${{ steps.attest-sbom.outputs.bundle-path }}"
run: |
shopt -s nullglob
mkdir attestations
for FILE in artifacts/*.tar.gz bom.*.json; do
cp "$ATTESTATION" "attestations/$(basename "$FILE").sigstore"
done
- name: Update release
env:
GH_TOKEN: "${{ github.token }}"
TAG: "${{ github.event.release.tag_name }}"
run: gh release upload "${TAG}" attestations/*.sigstore --clobber
attest-vex:
if: >
github.event_name == 'pull_request' &&
github.repository == 'erlang/otp'
permissions:
contents: write
attestations: write
id-token: write
runs-on: ubuntu-latest
steps:
- name: Checkout PR branch
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: "${{ github.head_ref }}"
fetch-depth: 0
persist-credentials: false
- name: Find modified OpenVEX files
id: changed
run: |
git diff --name-only --diff-filter=AM HEAD~1 HEAD -- '*.openvex.json' > /tmp/changed-vex.txt
echo "Modified OpenVEX files:"
cat /tmp/changed-vex.txt
if [ -s /tmp/changed-vex.txt ]; then
echo "found=true" >> "$GITHUB_OUTPUT"
else
echo "found=false" >> "$GITHUB_OUTPUT"
fi
- name: Add license files for new OpenVEX files
if: steps.changed.outputs.found == 'true'
shell: bash
run: |
curl -sL https://raw.githubusercontent.com/erlang/otp/master/.github/scripts/add-vex-license.sh
chmod +x .github/scripts/add-vex-license.sh
.github/scripts/add-vex-license.sh /tmp/changed-vex.txt
- name: Check PR author permission
env:
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
PR_AUTHOR: "${{ github.event.pull_request.user.login }}"
PR_AUTHOR_ID: "${{ github.event.pull_request.user.id }}"
REPOSITORY: "${{ github.repository }}"
run: |
# Check permissions for modifying vex files
# erlang-bot-app[bot] user ID: 232538940
if [[ "$PR_AUTHOR_ID" == "232538940" ]]; then
echo "PR opened by erlang-bot-app[bot] (id=$PR_AUTHOR_ID), allowed"
exit 0
fi
PERMISSION=$(gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/$REPOSITORY/collaborators/$PR_AUTHOR/permission --jq '.role_name')
if [[ "$PERMISSION" != "admin" && "$PERMISSION" != "maintain" && "$PERMISSION" != "Security Master" ]]; then
echo "::error::Only maintainers or erlang-bot-app can trigger VEX attestations"
exit 1
fi
- name: Checkout PR branch
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: "${{ github.event.pull_request.head.repo.full_name }}"
ref: "${{ github.event.pull_request.head.ref }}"
fetch-depth: 0
persist-credentials: false
- name: Find modified OpenVEX files
id: changed
run: |
git diff --name-only --diff-filter=AM HEAD~1 HEAD -- 'vex/*.openvex.json' > /tmp/changed-vex.txt
echo "Modified OpenVEX files:"
cat /tmp/changed-vex.txt
if [ -s /tmp/changed-vex.txt ]; then
echo "found=true" >> "$GITHUB_OUTPUT"
else
echo "found=false" >> "$GITHUB_OUTPUT"
fi
- name: Add license files for new OpenVEX files
if: steps.changed.outputs.found == 'true'
run: bash .github/scripts/add-vex-license.sh /tmp/changed-vex.txt
- name: Attest OpenVEX files
if: steps.changed.outputs.found == 'true'
id: attest
uses: actions/attest@59d89421af93a897026c735860bf21b6eb4f7b26 # ratchet:actions/attest@v4.10
with:
subject-path: '*.openvex.json'
- uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
if: steps.changed.outputs.found == 'true'
id: app-token
with:
app-id: ${{ vars.ERLANG_BOT_APP_ID }}
private-key: ${{ secrets.ERLANG_BOT_PRIVATE_KEY }}
- name: Authenticate gh
if: steps.changed.outputs.found == 'true'
env:
STEPS_APP_TOKEN_OUTPUTS_TOKEN: "${{ steps.app-token.outputs.token }}"
run: |
echo "${STEPS_APP_TOKEN_OUTPUTS_TOKEN}" | gh auth login --with-token
# register `gh` as git credential helper => git push in otp-compliance
# uses the token from `gh`. otherwise, `persist-credentials` should not be `false`.
# changing `persist-credentials` is not a good option
- name: Configure git to use gh as credential helper
if: steps.changed.outputs.found == 'true'
run: gh auth setup-git
- name: Get GitHub App User ID
if: steps.changed.outputs.found == 'true'
id: get-user-id
env:
GH_TOKEN: "${{ steps.app-token.outputs.token }}"
STEPS_APP_TOKEN_OUTPUTS_APP_SLUG: "${{ steps.app-token.outputs.app-slug }}"
run: echo "user-id=$(gh api "/users/${STEPS_APP_TOKEN_OUTPUTS_APP_SLUG}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
- name: Commit attestations to PR
if: steps.changed.outputs.found == 'true'
shell: bash
env:
ATTESTATION: "${{ steps.attest.outputs.bundle-path }}"
STEPS_APP_TOKEN_OUTPUTS_APP_SLUG: "${{ steps.app-token.outputs.app-slug }}"
STEPS_APP_TOKEN_OUTPUTS_TOKEN: "${{ steps.app-token.outputs.token }}"
STEPS_GET_USER_ID_OUTPUTS_USER_ID: "${{ steps.get-user-id.outputs.user-id }}"
PR_HEAD_REPO: "${{ github.event.pull_request.head.repo.full_name }}"
PR_HEAD_REF: "${{ github.event.pull_request.head.ref }}"
run: |
while IFS= read -r FILE; do
[ -z "$FILE" ] && continue
BASENAME=$(basename "$FILE")
cp "$ATTESTATION" "${BASENAME}.sigstore"
done < /tmp/changed-vex.txt
git config user.name "${STEPS_APP_TOKEN_OUTPUTS_APP_SLUG}[bot]"
git config user.email "${STEPS_GET_USER_ID_OUTPUTS_USER_ID}+${STEPS_APP_TOKEN_OUTPUTS_APP_SLUG}[bot]@users.noreply.github.com"
git remote set-url origin "https://x-access-token:${STEPS_APP_TOKEN_OUTPUTS_TOKEN}@github.com/${PR_HEAD_REPO}.git"
git add *.sigstore *.sigstore.license
git commit -m "Update sigstore attestations for OpenVEX files" || true
git push origin "HEAD:${PR_HEAD_REF}"