You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "andre-s-pedrosa-alb (via GitHub)" <gi...@apache.org> on 2025/06/03 11:04:51 UTC
[I] Airflow not using custom API authentication/auth_backends [airflow]
andre-s-pedrosa-alb opened a new issue, #51362:
URL: https://github.com/apache/airflow/issues/51362
### Apache Airflow version
3.0.1
### If "Other Airflow 2 version" selected, which one?
_No response_
### What happened?
Recently we upgraded to ariflow 3.0.1 in our dev server but we are having problems authenticating one of our API component in Airflow through keycloak.
In the logs I simply get an error:
[2025-06-03T11:02:34.484+0000] {base_auth_manager.py:105} ERROR - JWT token is not valid: The specified alg value is not allowed
### What you think should happen instead?
_No response_
### How to reproduce
I have set a custom auth_backend
AIRFLOW__FAB__AUTH_BACKENDS=user_auth,airflow.providers.fab.auth_manager.api.auth.backend.session
I also have a file user_auth.py in /opt/airflow, which is in PYTHONPATH
<details>
<summary>user_auth.py</summary>
```py
def init_app(_):
# Initializes authentication backend
pass
def auth_current_user() -> User | None:
# Authenticate and set current user if Authorization header exists
ab_security_manager = get_auth_manager().security_manager
user = None
if ab_security_manager.auth_type == AUTH_OAUTH:
if 'Authorization' not in request.headers or not request.headers['Authorization']:
return None
token = str(request.headers['Authorization']).replace("Bearer ", "")
# with signature validation. audience value was giving some problems
#me = jwt.decode(token, public_key, algorithms=['HS256', 'RS256'], audience=CLIENT_ID)
# witouth signature validation
me = jwt.decode(token, options={"verify_signature": False})
groups = me["resource_access"]["airflow"]["roles"] # unsafe
if len(groups) < 1:
groups = ["airflow_public"]
else:
groups = [group_name for group_name in groups if "airflow" in group_name]
userinfo = {
"username": me.get("preferred_username"),
"email": me.get("email"),
"first_name": me.get("given_name"),
"last_name": me.get("family_name"),
"role_keys": groups,
}
user = ab_security_manager.auth_user_oauth(userinfo)
else:
auth = request.authorization
if auth is None or not auth.username or not auth.password:
return None
if ab_security_manager.auth_type == AUTH_LDAP:
user = ab_security_manager.auth_user_ldap(auth.username, auth.password)
if ab_security_manager.auth_type == AUTH_DB:
user = ab_security_manager.auth_user_db(auth.username, auth.password)
log.info("user: {0}".format(user))
if user is not None:
login_user(user, remember=False)
return user
def requires_authentication(function: Callable):
# Decorator for functions that require authentication
@wraps(function)
def decorated(*args, **kwargs):
if auth_current_user() is not None:
return function(*args, **kwargs)
else:
return Response("Unauthorized", 401, {"WWW-Authenticate": "Basic"})
return cast(Callable, decorated)
```
</details>
I know that the file is being interpreted, because if I change the AIRFLOW__FAB__AUTH_BACKENDS variable to user_authhhh_invalid for example I get an error that the file was not found. OR if I add a syntax error in the user_auth.py file I also get an error.
However if I add a semantic error inside one of the functions (print of an undefined variable) I get no error, in other words the functions are not being executed when a API request is made.
### Operating System
Oracle linux 8
### Versions of Apache Airflow Providers
```sh
$ pip freeze | grep providers
apache-airflow-providers-apache-spark==5.2.1
apache-airflow-providers-celery==3.11.0
apache-airflow-providers-common-compat==1.6.1
apache-airflow-providers-common-io==1.5.4
apache-airflow-providers-common-sql==1.27.0
apache-airflow-providers-fab==2.0.2
apache-airflow-providers-hashicorp==4.1.1
apache-airflow-providers-postgres==6.1.3
apache-airflow-providers-redis==4.1.0
apache-airflow-providers-smtp==2.0.3
apache-airflow-providers-standard==1.1.0
```
### Deployment
Other Docker-based deployment
### Deployment details
podman with a custom image, using as base the image docker.io/apache/airflow:slim-3.0.1
### Anything else?
_No response_
### Are you willing to submit PR?
- [x] Yes I am willing to submit a PR!
### Code of Conduct
- [x] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "andre-s-pedrosa-alb (via GitHub)" <gi...@apache.org>.
andre-s-pedrosa-alb commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-2949853305
/api/v2/dags/<id>/dagRuns?...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "edsu (via GitHub)" <gi...@apache.org>.
edsu commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-2977085339
@alpeshv if you do go the route of implementing your own auth manager for Keycloak it would be super helpful to see it as I seem to have the same problem.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "alpeshv (via GitHub)" <gi...@apache.org>.
alpeshv commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-2952601738
@vincbeck Thank you for the summary and sorry to be pain but I still can't get my head around it.
Using Fab Auth Manager API makes sense when you want to generate the JWT token using username and password. As I mentioned earlier, I want to pass a token generated by keycloak which uses RS256 alg. I have tried configuring Airflow to use RS256 but its still looking for jwt_secret which is needed for a symmetric algorithm like HS512.
Also from the other closed issue, the reporter has used
```
export AIRFLOW__CORE__AUTH_MANAGER="my.custom.FabAuthManager"
export AIRFLOW__FAB__AUTH_BACKENDS="my.custom.api_backend"
```
Do I need to provide custom implementation for `AIRFLOW__CORE__AUTH_MANAGER` when I am passing a custom implementation for `AIRFLOW__FAB__AUTH_BACKENDS`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-3597554149
Auth backends have been deprecated in Airflow 3, sadly there is no other alternative. What is your custom API authentication rely on? Which authN/authZ service are you using?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk closed issue #51362: Airflow not using custom API authentication/auth_backends
URL: https://github.com/apache/airflow/issues/51362
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "zach-overflow (via GitHub)" <gi...@apache.org>.
zach-overflow commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-2949930181
> not sure how these backends and auth manager work together for api authentication. I have gone through all the documentation available but could not find anything helpful.
I'd second this point. I'd be happy to help improve the docs but I'm also running into challenges with the FAB auth manager setup, and I'm similarly not clear on what the expected behavior is here. It seems there was also a [recent closed issue](https://github.com/apache/airflow/issues/50684) about some similar confusion on the FAB auth manager docs regarding the `auth_backends` option, but I'm not sure if the details in that issue thread were clarified, or are relevant, in the later versions of the FAB provider (versions greater than `2.0.2`).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-3602605578
> Another proposal would be to create a new method in the auth manager interface like create_api_token (or any other better name). This method would basically contain the logic [here](https://github.com/apache/airflow/blob/b18c2689aae9d5e55eaf166191113143df41fa09/providers/fab/src/airflow/providers/fab/auth_manager/api_fastapi/services/login.py#L38). This logic, by default, expect username and password. Users would then be able to easily override this method and implement their own logic. What do you think?
If we can workaround this by extending the Auth Manager interface and implementing a custom auth manager with that, I think it's a reasonable approach to replace 2.x auth backend. I would favor this over a new distribution because it's mostly straight forward and people seem familiar with custom auth manager already.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-3598745356
I do not think I can do anything. Let me explain why. Auth backends are small modules which depend heavily on Flask. So auth backends only works with Flask APIs. We are currently working on migrating over all Flask based API to fastapi in order to remove the dependency `Connexion`. The only feasible option I can see is to expose a new Flask based API in fab provider to generate a JWT token using auth backends. If we do that, it will significantly block our work towards removing `Connexion` as a dependency. @potiuk what do you think? Some users are frustrated because they no longer can use their auth backends to authenticate to Airflow API which significantly block them to use Airflow 3.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-3619726190
> I see. If no objection, I'll go with my proposal, it should be fairly easy for users to override it and put their custom logic. I'll also update the doc to explain as best as I can how to override it and maybe put the snippet code in `user_auth.py` in the doc as well. What do you think?
Perfect
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "edsu (via GitHub)" <gi...@apache.org>.
edsu commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-2977370480
@alpeshv yes, exactly. The UI Auth w/ Keycloak is working, but it's just the API Auth that is failing with a 403 error. I'll give what's on main a try, and fallback to basic auth, which is what we were using previously. Thanks very much!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-2955826265
> [@vincbeck](https://github.com/vincbeck) Thank you for the summary and sorry to be pain but I still can't get my head around it.
>
> Using Fab Auth Manager API makes sense when you want to generate the JWT token using username and password. As I mentioned earlier, I want to pass a token generated by keycloak which uses RS256 alg. I have tried configuring Airflow to use RS256 but its still looking for jwt_secret which is needed for a symmetric algorithm like HS512.
>
> Also from the other closed issue, the reporter has used
>
> ```
> export AIRFLOW__CORE__AUTH_MANAGER="my.custom.FabAuthManager"
> export AIRFLOW__FAB__AUTH_BACKENDS="my.custom.api_backend"
> ```
>
> Do I need to provide custom implementation for `AIRFLOW__CORE__AUTH_MANAGER` when I am passing a custom implementation for `AIRFLOW__FAB__AUTH_BACKENDS`?
This is not supported today. If you want to use a token generated by Keycloak to access Airflow API you need to implement your own auth manager or wait for the future (but soon) Keycloak Auth manager. Keycloak auth manager implementation is currently in progress
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "melicheradam (via GitHub)" <gi...@apache.org>.
melicheradam commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-3633457582
Hey @vincbeck, to me it seems like this is adressing the issue from the other end. From my testing the API authorization flow was using `FabAuthManager.get_user_from_token`, som im not sure where this is integrated in all of that.
How is this intended to be used? Get token from IAM -> send this token as Bearer header to airflow/api/auth endpoint -> receive new "airflow token" -> use this "airflow token" for subsequent requests?
In Airflow 2, it was not about **creating** tokens, but about **processing** tokens. The thing is, when having a multi-service architecture, you usually dont want each service/app issuing its own tokens. You have a IAM/Authz provider that generates the tokens, and then each service can just validate the token from this provider.
Either way seems like this can be used, if I understood it correctly.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-2934708230
Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-2949867835
Airflow 3 no longer use auth backends to authenticate the Airflow public API. You need to use a JWT token in order to use the Rest API. Please read the [doc](https://airflow.apache.org/docs/apache-airflow/stable/security/api.html).
Auth backends are now exclusively used to call FAB auth managers API: list users, list roles, list permissions, etc.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "melicheradam (via GitHub)" <gi...@apache.org>.
melicheradam commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-3601528147
I was able to make this work by implementing methods that do not depend on Flask, they are mostly copied from the Override as stated in the gist. It is most centainly the same logic as was in Airflow2. https://gist.github.com/melicheradam/9fb5977ea21f194eefc87d4176f3fb84
@vincbeck do you see a problem with approach like this?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "cklat (via GitHub)" <gi...@apache.org>.
cklat commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-3597386994
Hello guys,
we are struggling with this as well. A fallback, even temporarily, to basic auth for triggering a DAG through the Public API or any other operation for that matter is not feasible for us.
Any help in understanding what steps need to be taken if you have rolled out your own API Authentication (see: https://airflow.apache.org/docs/apache-airflow/2.7.1/security/api.html#roll-your-own-api-authentication) for Airflow v2 would be very helpful!
Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-2949737808
Which API are you hitting to test it?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "dispensable (via GitHub)" <gi...@apache.org>.
dispensable commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-3236183149
I finally figured it out. If you wanna use api, just run `airflow users create` cli in the api pod. Then use this username/password to generate jwt token for api usage.
keycloak is not related at all in the reset api auth
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-3607864630
> I see. If no objection, I'll go with my proposal, it should be fairly easy for users to override it and put their custom logic. I'll also update the doc to explain as best as I can how to override it and maybe put the snippet code in user_auth.py in the doc as well. What do you think?
Sounds good to me!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "cklat (via GitHub)" <gi...@apache.org>.
cklat commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-3598306966
> > > Auth backends have been deprecated in Airflow 3, sadly there is no other alternative. What is your custom API authentication rely on? Which authN/authZ service are you using?
> >
> >
> > Hey [@vincbeck](https://github.com/vincbeck)
> > internally we are using keycloak but we need to have it for any OIDC provider.
> > If auth_backend is deprecated for airflow 3, so be it but is there any option to keep this kind of auth process in airflow 3 as well? What options are there as for right now for airflow 3?
> > Or is this a total breaking change for airflow 2 user's that have been using auth_backends and cannot migrate to airflow 3 at all?
>
> I understand the frustration, let me look into it and think about a solution. I might have something in mind. In the meantime, can you share your configuration? What I mean by that:
>
We'd really like to test out/migrate airflow 3 because it gives us some features that we could benefit from, therefore thanks for your effort, really appreciate that!
As for your questions:
> * Which auth backend are you using?
> * What is your authentication configuration? I guess you're using OAUTH?
Not sure if I'm completely following but let me know if something may be still unclear or insufficient.
We are using the same auth backend that @andre-s-pedrosa-alb posted with his `user_auth.py`. It's basically the exact same code. We then reference the `user_auth.py` in the [api] section of the airflow.cfg as per the docs which I posted in the link above.
For authentification we are using OAUTH (OAUTH2), correct!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-3602493461
This is what @melicheradam is currently doing
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-3633659659
Theoretically you are right, you can override `get_user_from_token` so that you can process any token, and not only the "Airflow" token. However, this works only if you use token (in general) to authenticate users. That's why I rather document officially the Fab auth manager token API way, which can work with any type of information (not only tokens).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "melicheradam (via GitHub)" <gi...@apache.org>.
melicheradam commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-3633583867
Yes I have read the doc. I was not completely sure, it this
> Get token from IAM -> send this token as Bearer header to airflow/api/auth endpoint -> receive new "airflow token" -> use this "airflow token" for subsequent requests?
is the intended/correct flow.
Where have I suggested not using JWT token to authenticate? I am just saying, in Airflow 2, you could use ANY token from ANY provider when accessing the API. Now you have to use Airflow - because you need to use the [Fab auth manager token API](https://airflow.apache.org/docs/apache-airflow-providers-fab/stable/auth-manager/token.html). And I am talking about the logic in `FabAuthManager.get_user_from_token`, since that is the one processing tokens. This was previously easily customizable, not generating JWT tokens in airflow.
Anyway thanks for the hard work, i am sure the solution you provided will be usable :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-3607827099
I see. If no objection, I'll go with my proposal, it should be fairly easy for users to override it and put their custom logic. I'll also update the doc to explain as best as I can how to override it and maybe put the snippet code in `user_auth.py` in the doc as well. What do you think?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-3598009393
> > Auth backends have been deprecated in Airflow 3, sadly there is no other alternative. What is your custom API authentication rely on? Which authN/authZ service are you using?
>
> Hey [@vincbeck](https://github.com/vincbeck)
>
> internally we are using keycloak but we need to have it for any OIDC provider.
>
> If auth_backend is deprecated for airflow 3, so be it but is there any option to keep this kind of auth process in airflow 3 as well? What options are there as for right now for airflow 3?
>
> Or is this a total breaking change for airflow 2 user's that have been using auth_backends and cannot migrate to airflow 3 at all?
I understand the frustration, let me look into it and think about a solution. I might have something in mind. In the meantime, can you share your configuration? What I mean by that:
- Which auth backend are you using?
- What is your authentication configuration? I guess you're using OAUTH?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "melicheradam (via GitHub)" <gi...@apache.org>.
melicheradam commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-3590124648
I almost have a workaround to get user from a custom token. I fetch the public key from KC in some code above, that is irrelevant.
Basically what I want to achieve is, to be able to authenticate with the FAB, but using a custom token (from KC). I want to be able to auto-register users on the API, thats why im using the configured Oauth.
```python
from jwt import InvalidTokenError
from airflow.api_fastapi.auth.managers.models.base_user import BaseUser
from airflow.providers.fab.auth_manager.fab_auth_manager import FabAuthManager
class KeycloakAuthManager(FabAuthManager):
"""Custom Auth Manager to use Keycloak as OAuth provider as a secondary method"""
async def get_user_from_keycloak_token(self, token: str) -> BaseUser:
try:
payload: dict[str, Any] = jwt.decode(token, public_key, algorithms=['HS256', 'RS256'])
except InvalidTokenError as e:
log.error("JWT Keycloak token is not valid: %s", e)
raise e
try:
scopes = payload.get("scope", "").split(" ") # unsafe
roles = []
for scope in scopes:
roles += API_AUTH_ROLES_MAPPING.get(scope, [])
if len(roles) < 1:
roles = ["airflow_public"]
userinfo = {
"username": payload.get("sub"),
"email": payload.get("email", f"{payload.get('sub')}@null"), # email must be filled and must be unique
"first_name": payload.get("given_name", "unknown-api"),
"last_name": payload.get("family_name", "unknown-api"),
"role_keys": roles,
}
with current_app.app_context():
user = self.security_manager.auth_user_oauth(userinfo)
if user is not None:
res = login_user(user, remember=False)
else:
raise InvalidTokenError("User was not retreived from auth_user_oauth!")
return user
except (ValueError, KeyError) as e:
log.error("Couldn't deserialize user from token, JWT Keycloak token is not valid: %s", e)
raise InvalidTokenError(str(e))
async def get_user_from_token(self, token: str) -> BaseUser:
"""Verify the JWT token is valid and create a user object from it if valid."""
try:
return await super().get_user_from_token(token)
except Exception as e:
log.info("Token is not valid for default auth manager, trying Keycloak...")
return await self.get_user_from_keycloak_token(token)
```
But no matter what I do, I get this error, and im feeling pretty stuck here. The `with current_app.app_context()` is there. Why im getting the error? Maybe somebody with more experience with Airflow 3 internals or Flask can help.
```python
File "/home/airflow/.local/lib/python3.11/site-packages/airflow/api_fastapi/core_api/security.py", line 99, in resolve_user_from_token
return await get_auth_manager().get_user_from_token(token_str)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/airflow/airflow_config/keycloak_auth.py", line 102, in get_user_from_token
return await self.get_user_from_keycloak_token(token)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/airflow/airflow_config/keycloak_auth.py", line 82, in get_user_from_keycloak_token
with current_app.app_context():
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/airflow/.local/lib/python3.11/site-packages/werkzeug/local.py", line 316, in __get__
obj = instance._get_current_object()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/airflow/.local/lib/python3.11/site-packages/werkzeug/local.py", line 513, in _get_current_object
raise RuntimeError(unbound_message) from None
RuntimeError: Working outside of application context.
This typically means that you attempted to use functionality that needed
the current application. To solve this, set up an application context
with app.app_context(). See the documentation for more information.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "alpeshv (via GitHub)" <gi...@apache.org>.
alpeshv commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-2977160304
@edsu Vincent has already implemented it and its part of Airflow main branch so just waiting for it to be released. You can find the code [here](https://github.com/apache/airflow/tree/main/providers/keycloak)
I guess your UI Auth is working with Keycloak (or whichever IdP you are using) and its just the api auth you are struggling with. I am using basic auth with an airflow user to get a token from FabAuthProvider and using it to trigger a DAG run for time being.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-2949718600
cc @vincbeck can you take a look?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "melicheradam (via GitHub)" <gi...@apache.org>.
melicheradam commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-3597690191
@vincbeck cannot this be done in a service-agnostic way? I just need to be able to plug-in my own way of getting user and his roles from token, like in Airflow 2.
Using basic auth and manage user/password combinations in ariflow is unreasonable.
Also what I have picked up from your implementation of Keycloak backend, it is completely replacing the Airflow (FAB) Authorization to use keycloak authz (resources/policies ...) is that correct? So the users are expected to manage permissions/roles for UI via FAB (Oauth), but for the API it has to be managed in KC?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "cklat (via GitHub)" <gi...@apache.org>.
cklat commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-3597699846
> Auth backends have been deprecated in Airflow 3, sadly there is no other alternative. What is your custom API authentication rely on? Which authN/authZ service are you using?
Hey @vincbeck
internally we are using keycloak but we need to have it for any OIDC provider.
If auth_backend is deprecated for airflow 3, so be it but is there any option to keep this of auth process in airflow 3 as well?
What options are there as for right now for airflow 3?
Or is this a total breaking change for airflow 2 user's that have been using auth_backends and cannot migrate to airflow 3 at all?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-3602500329
> Loudly thinking. MAYBE we can create and release a separate distribution with Flask and other necessary dependencies that could provide a bridge for people who used the all AuthBackends? Say `apache-airflow-auth-backend-v2-backcompat` ?
>
> I can see this can be a blocker, but I think it should be possible to extend the original JWT-only mechanism with a simple, pluggable API that could be provided by this additional package [@vincbeck](https://github.com/vincbeck) [@pierrejeambrun](https://github.com/pierrejeambrun) -> WDYT?
The think it do not really like with this solution is yet something else to maintain, release etc
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-3633297582
https://github.com/apache/airflow/pull/59245. @melicheradam @cklat @andre-s-pedrosa-alb @alpeshv @zach-overflow Could you please take a look at the PR and confirm this is what you are looking for? Or at least solve your issue. Please review the doc as well and suggest improvement if you see some.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-3633506918
Have you read the doc in the PR? If yes I think this is not clear then :) I'll try to provide more details.
In Airflow 3, the Airflow API uses JWT token to authenticate. We do NOT want to change that. This will stay as is. I understand that in Airflow 2, you could customize that, this is no longer possible in Airflow 3. In order to generate a JWT token to call Airflow API, you can use [Fab auth manager token API](https://airflow.apache.org/docs/apache-airflow-providers-fab/stable/auth-manager/token.html). Each auth manager define its own way to generate a JWT token.
To answer your question, you should:
- Override `create_token` method as described in the doc
- As a user, you should call [Fab auth manager token API](https://airflow.apache.org/docs/apache-airflow-providers-fab/stable/auth-manager/token.html) to generate a token and use this token to call Airflow API
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "alpeshv (via GitHub)" <gi...@apache.org>.
alpeshv commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-2949889113
@vincbeck thank you for picking this up. I am having the same issue so can provide some more insight.
We have been using custom auth implementation with keycloak for Airflow api v1 to make airflow api calls from other apps, mainly to trigger a specific dag.
It was working fine until we upgraded Airflow to 3.0.1 and now trying to the use same setup for Airflow api v2. My keycloak tokens use RS256, where as airflow, by default, recognises tokens with alg HS512, when jwt_secret is set as per [this](AIRFLOW__API_AUTH__JWT_ALGORITHM) and thats what causing this issue.
I have tried changing this alg to RS256 and removed jwt_secret but that was causing api-server pod to crash with error `The value api_auth/jwt_secret must be set` in api-server pod.
My problem is that I am also using `FabAirflowSecurityManagerOverride` in my api-server config to enable keycloak oauth for Airflow UI which works fine but I am not able to make the same thing work for api auth.
```
- name: AIRFLOW__API__AUTH_BACKENDS
value: 'airflow.providers.fab.auth_manager.api.auth.backend.custom_jwt_auth_backend'
- name: AIRFLOW__FAB__AUTH_BACKENDS
value: 'airflow.providers.fab.auth_manager.api.auth.backend.custom_jwt_auth_backend'
- name: AIRFLOW__CORE__AUTH_MANAGER
value: 'airflow.providers.fab.auth_manager.fab_auth_manager.FabAuthManager'
```
Its really confusing to me that how UI auth works with keycloak but api auth doesn't. I guess fab manager somehow exchanges keycloak token for a simpler jwt token which airflow can understand. Also not sure how these backends and auth manager work together for api authentication. I have gone through all the documentation available but could not find anything helpful.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-2950258585
Thanks for the feedbacks, I'll try to provide more details about the different APIs and their authentication. As a final step, I agree we should update the docs, it seems it is confusing and not easy to grasp.
## Airflow API VS FAB auth manager API VS FAB auth manager token API
Airflow API is the [Airflow public API](https://airflow.apache.org/docs/apache-airflow/stable/stable-rest-api-ref.html) used to interact with Airflow. For example, you can list DAGs, delete connections, update variables, trigger a DAG, etc ... Its endpoint is `/api/v2`
[FAB auth manager API](https://airflow.apache.org/docs/apache-airflow-providers-fab/2.0.1/api-ref/fab-public-api-ref.html) is used to manage users, roles and permissions. Its endpoint is `/auth/fab/v1/`.
[FAB auth manager token API](https://airflow.apache.org/docs/apache-airflow-providers-fab/stable/api-ref/fab-token-api-ref.html) is used to generate a JWT token using FAB auth manager. Its endpoint is `/auth/token`.
## Airflow API authentication
In order to authenticate with Airflow API, you need to use JWT token. More information in [documentation](https://airflow.apache.org/docs/apache-airflow/stable/security/api.html).
In your case, since you are using FAB auth manager, you need to generate a JWT token using FAB auth manager. This is explained in the documentation [here](https://airflow.apache.org/docs/apache-airflow-providers-fab/stable/auth-manager/token.html). Once you generate a JWT token, you can use it to authenticate with Airflow API.
## FAB auth manager authentication
In order to authenticate with FAB auth manager API, you need to use auth backends. More information in [documentation](https://airflow.apache.org/docs/apache-airflow-providers-fab/stable/auth-manager/api-authentication.html).
I hope that helps and please let me know if you're still stuck.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-3597975794
> [@vincbeck](https://github.com/vincbeck) cannot this be done in a service-agnostic way? I just need to be able to plug-in my own way of getting user and his roles from token, like in Airflow 2.
>
> Using basic auth and manage user/password combinations in ariflow is unreasonable.
>
> Also what I have picked up from your implementation of Keycloak backend, it is completely replacing the Airflow (FAB) Authorization to use keycloak authz (resources/policies ...) is that correct?
Yes
> So the users are expected to manage permissions/roles for UI via FAB (Oauth), but for the API it has to be managed in KC?
No, everything is managed in Keycloak. All the user authentication and authorization is delegated to Keycloak so all the management is done over there.
If you use Keycloak auth manager, there is no longer FAB. Fab has been removed from Airflow 3, if you use FAB auth manager this is the last piece that is using Fab in Airflow but in the future we want to get rid of it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-3600899661
Loudly thinking. MAYBE we can create and release a separate distribution with Flask and other necessary dependencies that could provide a bridge for people who used the all AuthBackends? Say `apache-airflow-auth-backend-v2-backcompat` ?
I can see this can be a blocker, but I think it should be possible to extend the original JWT-only mechanism with a simple, pluggable API that could be provided by this additional package @vincbeck @pierrejeambrun -> WDYT?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-3602598081
My understanding is this is an example of implementation but each user has their own implementation they want to use. For example, in the description of this issue there is a file `user_auth.py` that contains a logic @andre-s-pedrosa-alb
would like to use to authenticate in order to use the API. But this logic might not (and very most likely) fit everyone's needs
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "melicheradam (via GitHub)" <gi...@apache.org>.
melicheradam commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-3602626428
I think the example provided in the issue description `user_auth.py` is what most users were using for Airflow 2 (me included), I have found it somewhere on the internet long ago.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Airflow not using custom API authentication/auth_backends [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on issue #51362:
URL: https://github.com/apache/airflow/issues/51362#issuecomment-3602575230
Well. If there is a workable solutioj like in https://gist.github.com/melicheradam/9fb5977ea21f194eefc87d4176f3fb84 - we can simply make it into a possible workaround that those users who would like to use, could.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org