The GitHub Actions job "Tests" on airflow.git has failed.
Run started by GitHub user brouberol (triggered by vincbeck).

Head commit for run:
416fa1a9272408922ce39f8761c513b3a32a2c99 / Balthazar Rouberol 
<[email protected]>
fab_auth_manager: allow get_user method to return the user authenticated via 
Kerberos

The issue this PR fixes was initially discussed in 
https://github.com/apache/airflow/discussions/39683.

@jijoj-hmetrix and I noticed that, starting from Airflow 2.8.0, Kerberos
authentication does not seem to work with the stable API. Even when a
user provides a valid Kerberos ticket, and that the whole gssapi
authentication dance is successful, and that the user has the required
permissions, the API returns a 403 response.

```console
$ curl --negotiate -u: -s --service-name airflow 
https://airflow-test.xxxx.com/api/v1/pools  | jq .
{
  "detail": null,
  "status": 403,
  "title": "Forbidden",
  "type": 
"https://airflow.apache.org/docs/apache-airflow/2.10.2/stable-rest-api-ref.html#section/Errors/PermissionDenied";
}
```

I found that 
[`airflow.providers.fab.auth_manager.fab_auth_manager.FabAuthManager.get_user`](https://github.com/apache/airflow/blob/baf2b3cb4453d44ff00598a3b0c42d432a7203f9/providers/src/airflow/providers/fab/auth_manager/fab_auth_manager.py#L185-L189)
 relies on flask-login's 
[current_user](https://github.com/maxcountryman/flask-login/blob/main/src/flask_login/utils.py#L25)
 to get the currently logged in user from the session.

However, the Kerberos auth backend stores the authenticated user 
[in:wq`g`](https://github.com/brouberol/airflow/blob/main/providers/src/airflow/providers/fab/auth_manager/api/auth/backend/kerberos_auth.py#L136)
and not in the session.

This patch allows the current user to be pulled either from `g` or the session,
which allows the API to detect the user authenticated via Kerberos, and
then link it to Fab permissions.

Here's an examle from an instance running with the patch, with a admin
user associated with a User account with Admin permissions:

```console
$ curl --negotiate -u: -s --service-name airflow 
https://airflow-test.xxx.com/api/v1/pools
{
  "pools": [
    {
      "deferred_slots": 0,
      "description": "Default pool",
      "include_deferred": false,
      "name": "default_pool",
      "occupied_slots": 0,
      "open_slots": 128,
      "queued_slots": 0,
      "running_slots": 0,
      "scheduled_slots": 0,
      "slots": 128
    }
  ],
  "total_entries": 1
}
```

I accompany the change with a small unit test.

Signed-off-by: Balthazar Rouberol <[email protected]>

Report URL: https://github.com/apache/airflow/actions/runs/11672689404

With regards,
GitHub Actions via GitBox


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to