Skip to content

Commit 8f42818

Browse files
authored
fix(security): allow release tag build signatures (#446)
Signed-off-by: Roel de Cort <roel.decort@adfinis.com>
1 parent f7b2327 commit 8f42818

4 files changed

Lines changed: 50 additions & 7 deletions

File tree

.github/workflows/release-tag.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ on:
1111
- '.release-please-manifest.json'
1212
- 'charts/openbao-operator/Chart.yaml'
1313
workflow_dispatch:
14+
inputs:
15+
tag_target:
16+
description: "Commit to tag. Use branch-head only to retry a failed draft release after a release-branch fix."
17+
required: false
18+
default: release-pr-merge
19+
type: choice
20+
options:
21+
- release-pr-merge
22+
- branch-head
1423

1524
permissions:
1625
contents: read
@@ -97,6 +106,7 @@ jobs:
97106
env:
98107
REPO: ${{ github.repository }}
99108
BASE_BRANCH: ${{ github.ref_name }}
109+
TAG_TARGET: ${{ github.event_name == 'workflow_dispatch' && inputs.tag_target || 'release-pr-merge' }}
100110
GH_READ_TOKEN: ${{ github.token }}
101111
GH_WRITE_TOKEN: ${{ steps.app-token.outputs.token }}
102112
OPENBAO_OPERATOR_RELEASE_TAG_GPG_PASSPHRASE: ${{ secrets.OPENBAO_OPERATOR_RELEASE_TAG_GPG_PASSPHRASE }}

hack/ci/create-release-tag-and-draft.sh

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ MANIFEST_FILE="${MANIFEST_FILE:-.release-please-manifest.json}"
99
CHART_FILE="${CHART_FILE:-charts/openbao-operator/Chart.yaml}"
1010
RELEASE_NOTES_DIR="${RELEASE_NOTES_DIR:-release-notes}"
1111
DRY_RUN="${DRY_RUN:-0}"
12+
TAG_TARGET="${TAG_TARGET:-release-pr-merge}"
1213

1314
GH_READ_TOKEN="${GH_READ_TOKEN:-${GH_TOKEN:-}}"
1415
GH_WRITE_TOKEN="${GH_WRITE_TOKEN:-${GH_TOKEN:-}}"
@@ -23,6 +24,14 @@ if [[ "${DRY_RUN}" != "1" && -z "${GH_WRITE_TOKEN}" ]]; then
2324
exit 1
2425
fi
2526

27+
case "${TAG_TARGET}" in
28+
release-pr-merge | branch-head) ;;
29+
*)
30+
echo "TAG_TARGET must be either 'release-pr-merge' or 'branch-head', got '${TAG_TARGET}'" >&2
31+
exit 1
32+
;;
33+
esac
34+
2635
require_file() {
2736
local path="$1"
2837
if [[ ! -f "${path}" ]]; then
@@ -203,6 +212,29 @@ if [[ "${manifest_at_merge}" != "${version}" || "${chart_version_at_merge}" != "
203212
exit 1
204213
fi
205214

215+
tag_oid="${merge_oid}"
216+
217+
if [[ "${TAG_TARGET}" == "branch-head" ]]; then
218+
tag_oid="$(git rev-parse HEAD)"
219+
220+
if ! git merge-base --is-ancestor "${merge_oid}" "${tag_oid}"; then
221+
echo "branch-head tag target ${tag_oid} does not descend from release PR merge commit ${merge_oid}" >&2
222+
exit 1
223+
fi
224+
225+
manifest_at_target="$(git show "${tag_oid}:${MANIFEST_FILE}" | jq -er '."."')"
226+
chart_version_at_target="$(git show "${tag_oid}:${CHART_FILE}" | chart_value /dev/stdin "version")"
227+
chart_app_version_at_target="$(git show "${tag_oid}:${CHART_FILE}" | chart_value /dev/stdin "appVersion")"
228+
229+
if [[ "${manifest_at_target}" != "${version}" || "${chart_version_at_target}" != "${version}" || "${chart_app_version_at_target}" != "${version}" ]]; then
230+
echo "release files at branch-head tag target ${tag_oid} do not match ${version}" >&2
231+
echo " manifest@target: ${manifest_at_target}" >&2
232+
echo " chart@target: ${chart_version_at_target}" >&2
233+
echo " appVersion@target: ${chart_app_version_at_target}" >&2
234+
exit 1
235+
fi
236+
fi
237+
206238
notes_file="$(mktemp)"
207239
generated_notes_file="$(mktemp)"
208240
trap 'rm -f "${notes_file}" "${generated_notes_file}"' EXIT
@@ -231,23 +263,23 @@ fi
231263

232264
if git rev-parse -q --verify "refs/tags/${version}" >/dev/null 2>&1; then
233265
local_tag_commit="$(git rev-list -n1 "${version}")"
234-
if [[ "${local_tag_commit}" != "${merge_oid}" ]]; then
235-
echo "local tag ${version} points at ${local_tag_commit}, expected ${merge_oid}" >&2
266+
if [[ "${local_tag_commit}" != "${tag_oid}" ]]; then
267+
echo "local tag ${version} points at ${local_tag_commit}, expected ${tag_oid}" >&2
236268
exit 1
237269
fi
238270
elif git ls-remote --exit-code --tags origin "refs/tags/${version}" >/dev/null 2>&1; then
239271
git fetch --no-tags origin "refs/tags/${version}:refs/tags/${version}" >/dev/null 2>&1
240272
remote_tag_commit="$(git rev-list -n1 "${version}")"
241-
if [[ "${remote_tag_commit}" != "${merge_oid}" ]]; then
242-
echo "remote tag ${version} points at ${remote_tag_commit}, expected ${merge_oid}" >&2
273+
if [[ "${remote_tag_commit}" != "${tag_oid}" ]]; then
274+
echo "remote tag ${version} points at ${remote_tag_commit}, expected ${tag_oid}" >&2
243275
exit 1
244276
fi
245277
else
246278
if [[ "${DRY_RUN}" == "1" ]]; then
247-
echo "[dry-run] would create signed annotated tag ${version} at ${merge_oid}"
279+
echo "[dry-run] would create signed annotated tag ${version} at ${tag_oid} (${TAG_TARGET})"
248280
else
249281
require_git_tag_signing
250-
git tag -s "${version}" "${merge_oid}" -m "Release ${version}"
282+
git tag -s "${version}" "${tag_oid}" -m "Release ${version}"
251283
git push origin "refs/tags/${version}"
252284
fi
253285
fi

internal/adapter/security/cluster_image_verification_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func assertOperatorSubjectRegExp(t *testing.T, expr string) {
7171
"https://github.com/dc-tec/openbao-operator/.github/workflows/publish-edge.yml@refs/heads/main",
7272
"https://github.com/dc-tec/openbao-operator/.github/workflows/publish-nightly.yml@refs/heads/main",
7373
"https://github.com/dc-tec/openbao-operator/.github/workflows/reusable-build.yml@refs/heads/main",
74+
"https://github.com/dc-tec/openbao-operator/.github/workflows/reusable-build.yml@refs/tags/0.2.1",
7475
}
7576
for _, subject := range trusted {
7677
if !re.MatchString(subject) {

internal/port/security/image_verification.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const (
1616
defaultGitHubOIDCIssuerRegExp = "^https://token\\.actions\\.githubusercontent\\.com$"
1717

1818
openBaoReleaseSubjectRegExp = "^https://github\\.com/openbao/openbao/\\.github/workflows/release\\.yml@refs/tags/v?[0-9A-Za-z][0-9A-Za-z._+-]*$"
19-
operatorSubjectRegExp = "^https://github\\.com/dc-tec/openbao-operator/\\.github/workflows/(release\\.yml@refs/tags/.+|publish-edge\\.yml@refs/heads/main|publish-nightly\\.yml@refs/heads/main|reusable-build\\.yml@refs/heads/main)$"
19+
operatorSubjectRegExp = "^https://github\\.com/dc-tec/openbao-operator/\\.github/workflows/(release\\.yml@refs/tags/.+|publish-edge\\.yml@refs/heads/main|publish-nightly\\.yml@refs/heads/main|reusable-build\\.yml@(refs/heads/main|refs/tags/.+))$"
2020

2121
operatorInitOfficialRepository = "ghcr.io/dc-tec/openbao-init"
2222
operatorBackupOfficialRepository = "ghcr.io/dc-tec/openbao-backup"

0 commit comments

Comments
 (0)