Repository navigation
Description
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
user_auth.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)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
$ 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.0Deployment
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?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
boring-cyborg commentedon Jun 3, 2025
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.
eladkal commentedon Jun 6, 2025
cc @vincbeck can you take a look?
vincbeck commentedon Jun 6, 2025
Which API are you hitting to test it?
andre-s-pedrosa-alb commentedon Jun 6, 2025
/api/v2/dags/:id/dagRuns?...
vincbeck commentedon Jun 6, 2025
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.
Auth backends are now exclusively used to call FAB auth managers API: list users, list roles, list permissions, etc.
alpeshv commentedon Jun 6, 2025
@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 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 setin api-server pod.My problem is that I am also using
FabAirflowSecurityManagerOverridein 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.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.
zach-overflow commentedon Jun 6, 2025
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 about some similar confusion on the FAB auth manager docs regarding the
auth_backendsoption, 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 than2.0.2).vincbeck commentedon Jun 6, 2025
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 used to interact with Airflow. For example, you can list DAGs, delete connections, update variables, trigger a DAG, etc ... Its endpoint is
/api/v2FAB auth manager API is used to manage users, roles and permissions. Its endpoint is
/auth/fab/v1/.FAB auth manager token API 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.
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. 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.
I hope that helps and please let me know if you're still stuck.
alpeshv commentedon Jun 7, 2025
@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
Do I need to provide custom implementation for
AIRFLOW__CORE__AUTH_MANAGERwhen I am passing a custom implementation forAIRFLOW__FAB__AUTH_BACKENDS?vincbeck commentedon Jun 9, 2025
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
edsu commentedon Jun 16, 2025
@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.
16 remaining items
vincbeck commentedon Dec 2, 2025
This is what @melicheradam is currently doing
vincbeck commentedon Dec 2, 2025
The think it do not really like with this solution is yet something else to maintain, release etc
potiuk commentedon Dec 2, 2025
Well. If there is a workable solution 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.
vincbeck commentedon Dec 2, 2025
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.pythat contains a logic @andre-s-pedrosa-albwould like to use to authenticate in order to use the API. But this logic might not (and very most likely) fit everyone's needs
pierrejeambrun commentedon Dec 2, 2025
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. A piece of doc explaining how to convert your custom auth backend to custom auth manager for a happy path upgrade to airflow 3 would be cool too!
melicheradam commentedon Dec 2, 2025
I think the example provided in the issue description
user_auth.pyis what most users were using for Airflow 2 (me included), I have found it somewhere on the internet long ago.edit: some examples
vincbeck commentedon Dec 3, 2025
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.pyin the doc as well. What do you think?pierrejeambrun commentedon Dec 3, 2025
Sounds good to me!
potiuk commentedon Dec 6, 2025
Perfect
vincbeck commentedon Dec 9, 2025
#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.
melicheradam commentedon Dec 9, 2025
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.
vincbeck commentedon Dec 9, 2025
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. Each auth manager define its own way to generate a JWT token.
To answer your question, you should:
create_tokenmethod as described in the docmelicheradam commentedon Dec 9, 2025
Yes I have read the doc. I was not completely sure, it this
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. 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 :)
vincbeck commentedon Dec 9, 2025
Theoretically you are right, you can override
get_user_from_tokenso 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).