Skip to content

Commit 3da49bf

Browse files
committed
fix(ci): decode base64-encoded GitHub App key before minting tokens
The App private key is now stored base64-encoded in 1Password, because a raw PEM loses its newlines (they become spaces) when pasted, which made the key undecodable (ERR_OSSL_UNSUPPORTED). Decode it in each token step before passing it to create-github-app-token; base64 ignores whitespace, so it stays valid even if the stored value is re-mangled.
1 parent 45e0701 commit 3da49bf

2 files changed

Lines changed: 46 additions & 3 deletions

File tree

.github/workflows/release-plz.yml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,26 @@ jobs:
4545
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
4646
GITHUB_APP_ID: ${{ secrets.OP_GITHUB_APP_ITEM }}/GITHUB_APP_ID
4747
GITHUB_APP_PRIVATE_KEY: ${{ secrets.OP_GITHUB_APP_ITEM }}/GITHUB_APP_PRIVATE_KEY
48+
# App key is stored base64-encoded in 1Password (raw PEM newlines get
49+
# mangled to spaces on paste); decode it (base64 ignores whitespace).
50+
- name: Decode GitHub App private key
51+
id: app_key
52+
env:
53+
APP_KEY_B64: ${{ steps.load_secrets.outputs.GITHUB_APP_PRIVATE_KEY }}
54+
run: |
55+
key="$(printf '%s' "$APP_KEY_B64" | tr -d '[:space:]' | base64 -d)"
56+
{
57+
echo 'pem<<__PEM__'
58+
printf '%s\n' "$key"
59+
echo '__PEM__'
60+
} >> "$GITHUB_OUTPUT"
61+
4862
- name: Mint GitHub App token
4963
id: app-token
5064
uses: actions/create-github-app-token@v2
5165
with:
5266
app-id: ${{ steps.load_secrets.outputs.GITHUB_APP_ID }}
53-
private-key: ${{ steps.load_secrets.outputs.GITHUB_APP_PRIVATE_KEY }}
67+
private-key: ${{ steps.app_key.outputs.pem }}
5468
- name: Run release-plz (release-pr)
5569
uses: release-plz/action@v0.5
5670
with:
@@ -89,12 +103,26 @@ jobs:
89103
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
90104
GITHUB_APP_ID: ${{ secrets.OP_GITHUB_APP_ITEM }}/GITHUB_APP_ID
91105
GITHUB_APP_PRIVATE_KEY: ${{ secrets.OP_GITHUB_APP_ITEM }}/GITHUB_APP_PRIVATE_KEY
106+
# App key is stored base64-encoded in 1Password (raw PEM newlines get
107+
# mangled to spaces on paste); decode it (base64 ignores whitespace).
108+
- name: Decode GitHub App private key
109+
id: app_key
110+
env:
111+
APP_KEY_B64: ${{ steps.load_secrets.outputs.GITHUB_APP_PRIVATE_KEY }}
112+
run: |
113+
key="$(printf '%s' "$APP_KEY_B64" | tr -d '[:space:]' | base64 -d)"
114+
{
115+
echo 'pem<<__PEM__'
116+
printf '%s\n' "$key"
117+
echo '__PEM__'
118+
} >> "$GITHUB_OUTPUT"
119+
92120
- name: Mint GitHub App token
93121
id: app-token
94122
uses: actions/create-github-app-token@v2
95123
with:
96124
app-id: ${{ steps.load_secrets.outputs.GITHUB_APP_ID }}
97-
private-key: ${{ steps.load_secrets.outputs.GITHUB_APP_PRIVATE_KEY }}
125+
private-key: ${{ steps.app_key.outputs.pem }}
98126
- name: Run release-plz (release)
99127
uses: release-plz/action@v0.5
100128
with:

.github/workflows/release.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,27 @@ jobs:
158158
dist/*.dmg
159159
dist/SHA256SUMS
160160
161+
# The App private key is stored base64-encoded in 1Password (a raw PEM's
162+
# newlines get mangled to spaces on paste, which breaks key decoding).
163+
# Decode it here; base64 ignores whitespace, so it survives re-mangling.
164+
- name: Decode GitHub App private key
165+
id: app_key
166+
env:
167+
APP_KEY_B64: ${{ steps.load_secrets.outputs.GITHUB_APP_PRIVATE_KEY }}
168+
run: |
169+
key="$(printf '%s' "$APP_KEY_B64" | tr -d '[:space:]' | base64 -d)"
170+
{
171+
echo 'pem<<__PEM__'
172+
printf '%s\n' "$key"
173+
echo '__PEM__'
174+
} >> "$GITHUB_OUTPUT"
175+
161176
- name: Mint homebrew-tap token (GitHub App)
162177
id: tap_token
163178
uses: actions/create-github-app-token@v2
164179
with:
165180
app-id: ${{ steps.load_secrets.outputs.GITHUB_APP_ID }}
166-
private-key: ${{ steps.load_secrets.outputs.GITHUB_APP_PRIVATE_KEY }}
181+
private-key: ${{ steps.app_key.outputs.pem }}
167182
owner: AprilNEA
168183
repositories: homebrew-tap
169184

0 commit comments

Comments
 (0)