Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix kerberos authentication for the REST API. #29054

Merged
merged 1 commit into from Jan 20, 2023

Conversation

potiuk
Copy link
Member

@potiuk potiuk commented Jan 20, 2023

Previously we assigned kerberos user name directly to the flask user,
but this had no chance to work because we expect FAB user there and
our security code crash with 'str' has no attribute 'perms'.

This PR uses Kerberos username (including the Kerberos realm) to
retrieve the user from the security manager. This means that
the user name has to have the form of user_name@KERBEROS_REALM.

The reason why we are not using email (despite similarities of
the realm and domain name is that those are often different. Email
domain names have often nothing to do the with the realms within
organisations, and it seems safer to put fully qualified names
including the realm in order to uniquely identify the users in
case the organisation uses more than one REALM.

Fixes: #28919


^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

@boring-cyborg boring-cyborg bot added the area:API Airflow's REST/HTTP API label Jan 20, 2023
@@ -141,7 +143,7 @@ def decorated(*args, **kwargs):
token = "".join(header.split()[1:])
return_code = _gssapi_authenticate(token)
if return_code == kerberos.AUTH_GSS_COMPLETE:
g.user = ctx.kerberos_user
g.user = get_airflow_app().appbuilder.sm.find_user(email=ctx.kerberos_user)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works. In case when email domain not equal kerberos realm I suggest to look user by username field. It works too.

@potiuk potiuk force-pushed the check-email-use-in-kerberos-auth branch from 2232a93 to f159080 Compare January 20, 2023 12:19
@potiuk potiuk changed the title [Experimental] Treat kerberos identity as email in authentication Fix kerberos authentication for the REST API. Jan 20, 2023
@potiuk potiuk marked this pull request as ready for review January 20, 2023 12:20
@potiuk potiuk requested a review from mik-laj January 20, 2023 12:20
Previously we assigned kerberos user name directly to the flask user,
but this had no chance to work because we expect FAB user there and
our security code crash with 'str' has no attribute 'perms'.

This PR uses Kerberos username (including the Kerberos realm) to
retrieve the user from the security manager. This means that
the user name has to have the form of `user_name@KERBEROS_REALM`.

The reason why we are not using email (despite similarities of
the realm and domain name is that those are often different. Email
domain names have often nothing to do the with the realms within
organisations, and it seems safer to put fully qualified names
including the realm in order to uniquely identify the users in
case the organisation uses more than one REALM.

Fixes: apache#28919

Co-authored-by: BMFH <bogner85@mail.ru>
@potiuk potiuk force-pushed the check-email-use-in-kerberos-auth branch from f159080 to b364ee7 Compare January 20, 2023 12:22
@potiuk potiuk merged commit 135aef3 into apache:main Jan 20, 2023
@potiuk potiuk deleted the check-email-use-in-kerberos-auth branch January 20, 2023 16:05
maggesssss pushed a commit to maggesssss/airflow that referenced this pull request Jan 21, 2023
Previously we assigned kerberos user name directly to the flask user,
but this had no chance to work because we expect FAB user there and
our security code crash with 'str' has no attribute 'perms'.

This PR uses Kerberos username (including the Kerberos realm) to
retrieve the user from the security manager. This means that
the user name has to have the form of `user_name@KERBEROS_REALM`.

The reason why we are not using email (despite similarities of
the realm and domain name is that those are often different. Email
domain names have often nothing to do the with the realms within
organisations, and it seems safer to put fully qualified names
including the realm in order to uniquely identify the users in
case the organisation uses more than one REALM.

Fixes: apache#28919

Co-authored-by: BMFH <bogner85@mail.ru>

Co-authored-by: BMFH <bogner85@mail.ru>
@potiuk potiuk added this to the Airflow 2.5.2 milestone Feb 8, 2023
@pierrejeambrun pierrejeambrun added the type:bug-fix Changelog: Bug Fixes label Feb 27, 2023
pierrejeambrun pushed a commit that referenced this pull request Mar 7, 2023
Previously we assigned kerberos user name directly to the flask user,
but this had no chance to work because we expect FAB user there and
our security code crash with 'str' has no attribute 'perms'.

This PR uses Kerberos username (including the Kerberos realm) to
retrieve the user from the security manager. This means that
the user name has to have the form of `user_name@KERBEROS_REALM`.

The reason why we are not using email (despite similarities of
the realm and domain name is that those are often different. Email
domain names have often nothing to do the with the realms within
organisations, and it seems safer to put fully qualified names
including the realm in order to uniquely identify the users in
case the organisation uses more than one REALM.

Fixes: #28919

Co-authored-by: BMFH <bogner85@mail.ru>

Co-authored-by: BMFH <bogner85@mail.ru>
(cherry picked from commit 135aef3)
pierrejeambrun pushed a commit that referenced this pull request Mar 8, 2023
Previously we assigned kerberos user name directly to the flask user,
but this had no chance to work because we expect FAB user there and
our security code crash with 'str' has no attribute 'perms'.

This PR uses Kerberos username (including the Kerberos realm) to
retrieve the user from the security manager. This means that
the user name has to have the form of `user_name@KERBEROS_REALM`.

The reason why we are not using email (despite similarities of
the realm and domain name is that those are often different. Email
domain names have often nothing to do the with the realms within
organisations, and it seems safer to put fully qualified names
including the realm in order to uniquely identify the users in
case the organisation uses more than one REALM.

Fixes: #28919

Co-authored-by: BMFH <bogner85@mail.ru>

Co-authored-by: BMFH <bogner85@mail.ru>
(cherry picked from commit 135aef3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:API Airflow's REST/HTTP API type:bug-fix Changelog: Bug Fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Airflow API kerberos authentication error
4 participants