Commit 1f51acb
authored
Bind Keycloak cookie tokens to the Airflow session identity (#72207)
* Bind Keycloak cookie tokens to the Airflow session identity
For Airflow 3.3+ the Keycloak access and refresh tokens are no longer carried in
the signed Airflow JWT; they travel in separate _access_token and _refresh_token
cookies. get_user_from_token validated the Airflow JWT and then attached whatever
those cookies contained, without checking that they described the same subject.
A caller could therefore pair their own Airflow session with another subject's
Keycloak token. Every authorization decision goes to Keycloak carrying that
token, so the effective privileges were the token's, while get_id() and
get_name() - used for the session identity, audit records and logging - stayed
those of the Airflow JWT.
The access token's sub is now compared against the user id the signed JWT
established before the token is attached. Both are the Keycloak subject: every
place a KeycloakAuthManagerUser is constructed sets user_id from userinfo[sub],
in the interactive login, the password grant and the client_credentials grant
alike. A token whose payload cannot be read yields no subject and so matches
nothing.
The subject is read without signature verification, which is sufficient here:
the value is only ever compared against an identity the signed Airflow JWT has
already established, a forged token is refused by Keycloak when presented, and a
genuine token belonging to somebody else is what the comparison exists to catch.
The two existing tests passed the literal string "access_token" as a cookie
value; they now build a JWT-shaped token naming the same subject. Adds coverage
for a token naming another subject and for one that cannot be parsed.
* Refuse malformed Keycloak access-token cookies with 403, not 500
A Keycloak access-token cookie whose payload decodes to valid JSON that is
not an object reached the subject lookup as a non-mapping, so reading the
claim raised an error the middleware does not translate. The cookie is
attacker-supplied, so any shape it can take has to end in the same refusal
as a token naming the wrong subject.
* Drop the Keycloak changelog note about token-to-session binding
Every place a session is established sets the Airflow user id from the
Keycloak subject, so the two can only disagree in a request whose cookies
were assembled by hand. No deployment reaches the new refusal by ordinary
use, which leaves the note describing a change nobody observes.1 parent f8957f6 commit 1f51acb
2 files changed
Lines changed: 94 additions & 4 deletions
File tree
- providers/keycloak
- src/airflow/providers/keycloak/auth_manager
- tests/unit/keycloak/auth_manager
Lines changed: 32 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
174 | 175 | | |
175 | 176 | | |
176 | 177 | | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
177 | 186 | | |
178 | 187 | | |
179 | 188 | | |
| |||
818 | 827 | | |
819 | 828 | | |
820 | 829 | | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
821 | 853 | | |
822 | 854 | | |
823 | 855 | | |
| |||
Lines changed: 62 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
135 | 151 | | |
136 | 152 | | |
137 | 153 | | |
| |||
207 | 223 | | |
208 | 224 | | |
209 | 225 | | |
210 | | - | |
| 226 | + | |
| 227 | + | |
211 | 228 | | |
212 | 229 | | |
213 | 230 | | |
214 | | - | |
| 231 | + | |
215 | 232 | | |
216 | 233 | | |
217 | 234 | | |
| |||
270 | 287 | | |
271 | 288 | | |
272 | 289 | | |
273 | | - | |
| 290 | + | |
| 291 | + | |
274 | 292 | | |
275 | 293 | | |
276 | 294 | | |
277 | | - | |
| 295 | + | |
278 | 296 | | |
279 | 297 | | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
280 | 338 | | |
281 | 339 | | |
282 | 340 | | |
| |||
0 commit comments