161 lines (150 loc) · 6.19 KB
/
initialize.yml
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
#
# Copyright 2022 The Sigstore Authors.
#
# 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.
name: Stage a new root and targets on a new branch
permissions: read-all
# Execute this ONLY as workflow dispatch.
on:
workflow_dispatch:
inputs:
branch:
description: 'The branch to stage changes against, generally ceremony/YYYY-MM-DD'
required: true
type: string
revoke_key:
description: 'If provided, revokes the given HSM key, identified by the serial number'
required: false
type: string
repo:
description: 'The repository in which to stage a new root and targets'
required: false
default: repository
type: string
draft:
description: 'Use for testing; creates a draft pull request'
required: false
default: false
type: boolean
jobs:
check_branch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
with:
fetch-depth: 0
- name: Check if remote branch exists
env:
BRANCH: ${{ inputs.branch }}
run: |
branch_exists=$(git ls-remote --heads origin ${BRANCH})
if [[ -z ${branch_exists} ]]; then
echo "Staging root branch ${BRANCH} does not exist: has a maintainer created one?"
exit 1
fi
init_root:
runs-on: ubuntu-latest
needs: check_branch
permissions:
id-token: 'write'
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
with:
fetch-depth: 0
# TODO(https://github.com/sigstore/root-signing/issues/98): Use a common configuration checked into source control
- name: setup environment
run: |
echo "GITHUB_USER=${{ github.actor }}" >> $GITHUB_ENV
echo "SNAPSHOT_KEY=gcpkms://projects/sigstore-root-signing/locations/global/keyRings/root/cryptoKeys/snapshot" >> $GITHUB_ENV
echo "TIMESTAMP_KEY=gcpkms://projects/sigstore-root-signing/locations/global/keyRings/root/cryptoKeys/timestamp" >> $GITHUB_ENV
echo "REPO=${{ inputs.repo }}" >> $GITHUB_ENV
echo "BRANCH=${{ inputs.branch }}" >> $GITHUB_ENV
# Note: we set LOCAL=1 because we manually push the changes in the next job.
echo "LOCAL=1" >> $GITHUB_ENV
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: './go.mod'
check-latest: true
# Setup OIDC->SA auth for signing with KMS
- uses: google-github-actions/auth@55bd3a7c6e2ae7cf1877fd1ccb9d54c0503c457c # v2.1.2
id: auth
with:
token_format: 'access_token'
workload_identity_provider: 'projects/163070369698/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider'
service_account: 'github-actions@sigstore-root-signing.iam.gserviceaccount.com'
create_credentials_file: true
- uses: google-github-actions/setup-gcloud@98ddc00a17442e89a24bbf282954a3b65ce6d200 # v2.1.0
with:
project_id: sigstore-root-signing
- name: Login
run: |
gcloud auth login --brief --cred-file="${{ steps.auth.outputs.credentials_file_path }}"
gcloud auth list
# Initialize the new root and targets layout
- name: step 0
# Note that we are already in a git repository and are manually pushing changes with the job below
# so we can simply build the TUF binary and bypass git setup in step 0.
run: |
sudo apt-get install libpcsclite-dev
go build -o tuf -tags=pivkey ./cmd/tuf
- name: step 1.5
run: |
./scripts/step-1.5.sh ${{ inputs.revoke_key }}
- name: Upload new repository
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: ${{ inputs.repo }}
path: ${{ inputs.repo }}
retention-days: 5
push:
needs: init_root
runs-on: ubuntu-latest
permissions:
pull-requests: 'write'
contents: 'write'
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
with:
ref: ${{ inputs.branch }}
fetch-depth: 0
- uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4
with:
name: ${{ inputs.repo }}
path: ${{ inputs.repo }}
# Detect new version and expiration to add to the PR description.
- name: Detect new version
env:
REPO: ${{ inputs.repo }}
run: |
# Detects the new root version.
VERSION=$(cat ${REPO}/staged/root.json | jq -r '.signed.version')
echo "VERSION=$VERSION" >> $GITHUB_ENV
# Create commits
- name: Create commits
env:
REPO: ${{ inputs.repo }}
run: |
# Set identity.
git config --global user.email "noreply@github.com"
git config --global user.name "GitHub"
git checkout -b init-root-targets
# Commit the REPO changes
git add ${REPO}
git commit -s -m "Add staged repository metadata"
git push origin HEAD
# Open pull request changes. Use the fine-grained PAT in order to trigger presubmits.
- name: create pull request
env:
DRAFT: ${{ inputs.draft && '-d' || '' }}
run:
GH_TOKEN=${{ secrets.SIGSTORE_ROOT_SIGNING_FINE_GRAINED_PAT }} gh pr create -B ${{ inputs.branch }} -H init-root-targets -t "Update Root and Targets to version ${{ env.VERSION }}" -b "Initializes a new root and targets to version ${{ env.VERSION }}" ${DRAFT} -r bobcallaway -r haydentherapper -r kommendorkapten