Skip to content

Commit 31e0445

Browse files
committed
fix(ci): address review quick wins
- Quote/env-ize shell expansions in helm-publish and release-assets (script-injection hardening for github.ref_name/github.actor; shellcheck-clean). - Require serviceAccount.name when serviceAccount.create=false instead of falling back to the namespace default SA (avoids binding the operator ClusterRole to default). - Add least-privilege 'permissions: contents: read' to the CI workflow. - Pin release-drafter to its v6.0.0 commit SHA (runs under pull_request_target). - Check the fmt.Fprintln error in etcd-migrate's version command (errcheck). Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
1 parent 27ff90d commit 31e0445

7 files changed

Lines changed: 33 additions & 14 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ on:
66
push:
77
branches: [ main ]
88

9+
# CI only builds and tests — no writes to the repo, releases, or packages.
10+
permissions:
11+
contents: read
12+
913
jobs:
1014
image-multiarch:
1115
# Build-only assertion that the operator image builds for every published

.github/workflows/helm-publish.yml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,28 @@ jobs:
4343
run: make manifests
4444

4545
- name: Resolve chart versions from tag
46+
env:
47+
REF_NAME: ${{ github.ref_name }}
4648
run: |
47-
TAG=${{ github.ref_name }}
48-
echo "RELEASE_TAG=${TAG}" >> $GITHUB_ENV
49+
TAG="$REF_NAME"
50+
echo "RELEASE_TAG=${TAG}" >> "$GITHUB_ENV"
4951
# Chart version is semver without the leading v; appVersion keeps it.
50-
echo "RELEASE_TAG_TRIMMED_V=${TAG#v}" >> $GITHUB_ENV
52+
echo "RELEASE_TAG_TRIMMED_V=${TAG#v}" >> "$GITHUB_ENV"
5153
5254
- name: Helm registry login
55+
env:
56+
ACTOR: ${{ github.actor }}
57+
TOKEN: ${{ secrets.GITHUB_TOKEN }}
5358
run: |
5459
helm registry login \
55-
--username ${{ github.actor }} \
56-
--password ${{ secrets.GITHUB_TOKEN }} \
57-
${{ env.REGISTRY }}
60+
--username "$ACTOR" \
61+
--password "$TOKEN" \
62+
"${{ env.REGISTRY }}"
5863
5964
- name: Package chart
6065
working-directory: charts
6166
run: |
62-
helm package ${{ env.CHART_NAME }} \
67+
helm package "${{ env.CHART_NAME }}" \
6368
--version "${RELEASE_TAG_TRIMMED_V}" \
6469
--app-version "${RELEASE_TAG}"
6570

.github/workflows/release-assets.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ jobs:
3636
version: 'v3.16.4'
3737

3838
- name: Resolve release tag
39-
run: echo "RELEASE_TAG=${{ github.ref_name }}" >> $GITHUB_ENV
39+
env:
40+
REF_NAME: ${{ github.ref_name }}
41+
run: echo "RELEASE_TAG=$REF_NAME" >> "$GITHUB_ENV"
4042

4143
- name: Render install manifests
42-
run: make build-dist-manifests IMG=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${RELEASE_TAG}
44+
run: make build-dist-manifests IMG="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${RELEASE_TAG}"
4345

4446
- uses: svenstaro/upload-release-action@2.9.0
4547
with:
@@ -82,10 +84,12 @@ jobs:
8284
cache: true
8385

8486
- name: Resolve release tag
85-
run: echo "RELEASE_TAG=${{ github.ref_name }}" >> $GITHUB_ENV
87+
env:
88+
REF_NAME: ${{ github.ref_name }}
89+
run: echo "RELEASE_TAG=$REF_NAME" >> "$GITHUB_ENV"
8690

8791
- name: Cross-compile CLIs
88-
run: make dist-cli VERSION=${RELEASE_TAG}
92+
run: make dist-cli VERSION="${RELEASE_TAG}"
8993

9094
- name: Upload etcd-migrate binaries
9195
uses: svenstaro/upload-release-action@2.9.0

.github/workflows/release-drafter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
# code under it is the canonical fork-to-RCE pattern. release-drafter
2828
# touches no repo code, so this job stays safe as long as nothing here
2929
# checks out untrusted refs.
30-
- uses: release-drafter/release-drafter@v6.0.0
30+
- uses: release-drafter/release-drafter@3f0f87098bd6b5c5b9a36d49c41d998ea58f9348 # v6.0.0
3131
with:
3232
disable-releaser: ${{ github.ref != 'refs/heads/main' }}
3333
config-name: release-drafter.yml

charts/etcd-operator/templates/_helpers.tpl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ app.kubernetes.io/instance: {{ .Release.Name }}
4242
{{- if .Values.serviceAccount.create -}}
4343
{{- include "etcd-operator.fullname" . -}}
4444
{{- else -}}
45-
default
45+
{{- /* Don't silently fall back to the namespace "default" SA: rbac.yaml binds
46+
the operator's broad ClusterRole to this name, and binding it to "default"
47+
would hand those permissions to every workload using the default SA. */ -}}
48+
{{- required "serviceAccount.name is required when serviceAccount.create is false" .Values.serviceAccount.name -}}
4649
{{- end -}}
4750
{{- end -}}
4851

charts/etcd-operator/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ fullnameOverride: ""
4343
serviceAccount:
4444
# -- Create the operator ServiceAccount.
4545
create: true
46+
# -- Name of an existing ServiceAccount to use when create is false. Required
47+
# in that case — the operator's ClusterRole is bound to this name.
48+
name: ""
4649
# -- Extra annotations for the ServiceAccount.
4750
annotations: {}
4851

cmd/etcd-migrate/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ explicit --skip-backup.`,
7777
Short: "Print the etcd-migrate binary version",
7878
Args: cobra.NoArgs,
7979
Run: func(cmd *cobra.Command, _ []string) {
80-
fmt.Fprintln(cmd.OutOrStdout(), version)
80+
_, _ = fmt.Fprintln(cmd.OutOrStdout(), version)
8181
},
8282
})
8383
if err := rootCmd.Execute(); err != nil {

0 commit comments

Comments
 (0)