Commit 07bd193
authored
fix(lambda): add jti claim to GitHub App JWTs to prevent concurrent collisions (#5056)
## Summary
Fixes concurrent JWT collisions that cause silent job loss during burst
workloads.
When multiple scale-up Lambda invocations generate GitHub App JWTs
within the same second, `universal-github-app-jwt` produces
byte-identical tokens (same `iat`, `exp`, `iss`, no `jti`). GitHub
rejects the duplicates, returning HTTP 404 on `POST
/app/installations/{id}/access_tokens`, which triggers silent batch
dropping.
### Root cause
`universal-github-app-jwt` generates JWTs with only `{ iat, exp, iss }`
claims. The `iat` uses seconds precision (`Math.floor(Date.now() /
1000)`). With the same App ID and private key, concurrent invocations
within the same second produce identical tokens.
### Fix
Replace `privateKey`-based auth with a custom `createJwt` callback — a
first-class API in `@octokit/auth-app` v8.x that completely bypasses
`universal-github-app-jwt`. The callback:
- Signs JWTs using `node:crypto.createSign` (zero new dependencies)
- Includes a `crypto.randomUUID()` `jti` claim, ensuring every token is
unique
- Preserves the existing `iat`/`exp` logic (30s safety margin, 10-minute
expiry)
- Properly forwards the `timeDifference` parameter for clock drift
correction
- Supports both PKCS#1 and PKCS#8 private key formats (via
`node:crypto`)
### Changes
- `lambdas/functions/control-plane/src/github/auth.ts` — replace
`privateKey` with `createJwt` callback in `createAuth()`
- `lambdas/functions/control-plane/src/github/auth.test.ts` — update
tests to assert `createJwt` instead of `privateKey`, add test verifying
unique JWTs with `jti`
### Test coverage
- Existing tests updated to verify `createJwt` callback is passed
instead of `privateKey`
- New test generates two JWTs in rapid succession and verifies they
differ (proving `jti` uniqueness)
- New test validates JWT structure (header.payload.signature) and
verifies `jti`, `iat`, `exp`, `iss` claims are present
- All 343 control-plane tests pass
Fixes #50251 parent 6dc97d5 commit 07bd193
File tree
2 files changed
+89
-49
lines changed- lambdas/functions/control-plane/src/github
2 files changed
+89
-49
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
80 | | - | |
| 81 | + | |
81 | 82 | | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
| 83 | + | |
93 | 84 | | |
94 | 85 | | |
95 | 86 | | |
96 | | - | |
97 | 87 | | |
98 | 88 | | |
99 | 89 | | |
| |||
102 | 92 | | |
103 | 93 | | |
104 | 94 | | |
105 | | - | |
| 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 | + | |
106 | 138 | | |
107 | 139 | | |
108 | 140 | | |
109 | 141 | | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | 142 | | |
116 | 143 | | |
117 | 144 | | |
118 | 145 | | |
119 | | - | |
120 | 146 | | |
121 | 147 | | |
122 | 148 | | |
| |||
128 | 154 | | |
129 | 155 | | |
130 | 156 | | |
131 | | - | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
132 | 161 | | |
133 | 162 | | |
134 | 163 | | |
| |||
142 | 171 | | |
143 | 172 | | |
144 | 173 | | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | 174 | | |
153 | 175 | | |
154 | 176 | | |
| |||
165 | 187 | | |
166 | 188 | | |
167 | 189 | | |
168 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
169 | 195 | | |
170 | 196 | | |
171 | 197 | | |
| |||
181 | 207 | | |
182 | 208 | | |
183 | 209 | | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | 210 | | |
191 | 211 | | |
192 | 212 | | |
193 | | - | |
194 | 213 | | |
195 | 214 | | |
196 | 215 | | |
| |||
202 | 221 | | |
203 | 222 | | |
204 | 223 | | |
205 | | - | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
206 | 229 | | |
207 | 230 | | |
208 | 231 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
72 | 81 | | |
73 | 82 | | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
85 | 100 | | |
| 101 | + | |
| 102 | + | |
86 | 103 | | |
87 | 104 | | |
88 | 105 | | |
| |||
0 commit comments