Skip to content

Commit e34280b

Browse files
committed
ci: harden checkout credential handling for INC-7027
1 parent 214d743 commit e34280b

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

.github/workflows/chart-chores.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ jobs:
4646
ref: ${{ github.event.pull_request.head.ref }}
4747
fetch-depth: 0
4848
token: "${{ steps.generate-github-token.outputs.token }}"
49+
# Credentials are re-introduced only in the final push step.
50+
persist-credentials: false
4951
- name: Configure curl and wget
5052
uses: ./.github/actions/setup-curl
5153
#
@@ -96,7 +98,23 @@ jobs:
9698
- name: Git pull
9799
run: git pull --rebase --autostash .
98100
- uses: EndBug/add-and-commit@290ea2c423ad77ca9c62ae0f5b224379612c0321 # v10.0.0
101+
id: commit
99102
with:
100103
author_name: "distro-ci[bot]"
101104
author_email: "122795778+distro-ci[bot]@users.noreply.github.com"
102105
message: "chore: chart chores"
106+
# Pushing is done by the next step; checkout does not persist credentials.
107+
push: false
108+
- name: Push changes
109+
if: steps.commit.outputs.committed == 'true'
110+
env:
111+
GH_APP_TOKEN: ${{ steps.generate-github-token.outputs.token }}
112+
TARGET_REPO: ${{ github.event.pull_request.head.repo.full_name }}
113+
TARGET_REF: ${{ github.event.pull_request.head.ref }}
114+
run: |
115+
set -euo pipefail
116+
# Credential is supplied per-command via a helper reading the step env, so the token is
117+
# neither written to .git/config nor visible in the process arguments.
118+
git -c credential.helper= \
119+
-c credential.helper='!f() { echo username=x-access-token; echo "password=${GH_APP_TOKEN}"; }; f' \
120+
push origin "HEAD:refs/heads/${TARGET_REF}"

.github/workflows/renovate-post-upgrade.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ jobs:
5555
repository: ${{ github.event.pull_request.head.repo.full_name }}
5656
ref: ${{ github.event.pull_request.head.ref }}
5757
fetch-depth: 0
58+
# Credentials are re-introduced only in the final push step.
59+
persist-credentials: false
5860
- name: Configure curl and wget
5961
uses: ./.github/actions/setup-curl
6062
#
@@ -134,7 +136,24 @@ jobs:
134136
- name: Git pull
135137
run: git pull --rebase --autostash .
136138
- uses: EndBug/add-and-commit@290ea2c423ad77ca9c62ae0f5b224379612c0321 # v10.0.0
139+
id: commit
137140
with:
138141
author_name: "renovate[bot]"
139142
author_email: "29139614+renovate[bot]@users.noreply.github.com"
140143
message: "chore(deps): post upgrade tasks - go mod tidy, update golden files, readme, and schema"
144+
# Pushing is done by the next step; checkout does not persist credentials.
145+
push: false
146+
- name: Push changes
147+
if: steps.commit.outputs.committed == 'true'
148+
env:
149+
GH_APP_TOKEN: ${{ steps.generate-github-token.outputs.token }}
150+
# Mirrors how actions/checkout resolved its own repository/ref inputs.
151+
TARGET_REPO: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
152+
TARGET_REF: ${{ github.event.pull_request.head.ref || github.ref_name }}
153+
run: |
154+
set -euo pipefail
155+
# Credential is supplied per-command via a helper reading the step env, so the token is
156+
# neither written to .git/config nor visible in the process arguments.
157+
git -c credential.helper= \
158+
-c credential.helper='!f() { echo username=x-access-token; echo "password=${GH_APP_TOKEN}"; }; f' \
159+
push origin "HEAD:refs/heads/${TARGET_REF}"

0 commit comments

Comments
 (0)