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

Update Simple auth manager to define its UI (login form) using fastapi #45696

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

vincbeck
Copy link
Contributor

@vincbeck vincbeck commented Jan 15, 2025

SimpleAuthManager is a minimalist auth manager in core Airflow. It defines its own login form in order for users to log in. Example below:

Screenshot 2025-01-15 at 5 06 01 PM

Simple auth manager has its UI defined using Flask, you can then use it with Airflow 2 UI. But the goal is to use simple auth manager in Airflow 3. In order to use simple auth manager with Airflow 3 UI, we need to implement its views in the fastapi application. This is the goal of this PR.

After this PR is merged, I'll remove the UI/views definitions of simple auth manager in Flask. We do not need the simple auth manager to be compatible with Airflow 2 UI (although that was necessary for testing it).

As a result of this PR, multiple endpoints are added:

  • <env_endpoint>/auth/webapp/login: the login form
  • <env_endpoint>/auth/static/assets/index-......js: the JS/React artifact defining the login form
  • POST <env_endpoint>/auth/token: to create a JWT token given username and password

(Sorry for the massive PR).

Testing

To test this PR and play around with the simple auth manager login form:

  • Set export AIRFLOW__CORE__AUTH_MANAGER="airflow.auth.managers.simple.simple_auth_manager.SimpleAuthManager"
  • In airflow/auth/managers/simple/ui/, run npm run build. I need to update the pre-commit script to do that automatically
  • Run Airflow and go to /auth/webapp/login

^ 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.

Copy link
Contributor

@bbovenzi bbovenzi left a comment

Choose a reason for hiding this comment

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

Tested locally. It works!

I'd like us to match the main UI's setup a bit more. Use pnpm instead of npm and I want to see if we can share the same linting/prettier rules.

airflow/auth/managers/simple/ui/src/login/Controller.tsx Outdated Show resolved Hide resolved
export const Login = () => {
const onSuccess = (data: LoginResponse) => {
// Redirect to index page with the token
globalThis.location.replace(`/webapp/?token=${data.jwt_token}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll need to remember to change this whenever we drop the /webapp. Or better, have one source of truth on the UI base route

airflow/auth/managers/simple/ui/src/login/Form.tsx Outdated Show resolved Hide resolved
airflow/auth/managers/simple/ui/src/login/Form.tsx Outdated Show resolved Hide resolved
airflow/auth/managers/simple/ui/src/login/index.test.tsx Outdated Show resolved Hide resolved
airflow/auth/managers/simple/ui/src/queryClient.ts Outdated Show resolved Hide resolved
airflow/auth/managers/simple/ui/src/login/Controller.tsx Outdated Show resolved Hide resolved
airflow/auth/managers/simple/ui/src/login/Form.tsx Outdated Show resolved Hide resolved
airflow/auth/managers/simple/ui/src/login/index.test.tsx Outdated Show resolved Hide resolved
@vincbeck
Copy link
Contributor Author

Tested locally. It works!

I'd like us to match the main UI's setup a bit more. Use pnpm instead of npm and I want to see if we can share the same linting/prettier rules.

I agree that would be great. I made multiple tries but could not come up with something working. Typescript could not recognize types defined in the simple auth manager UI directory. We could give it another try later. I dont think this is a must have for now

Copy link
Member

@pierrejeambrun pierrejeambrun left a comment

Choose a reason for hiding this comment

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

That's a little unclear for me where we're at and what we want to do for auth managers.

For other auth managers, especially FAB one, do we plan to use the flask middleware to be able to render all of those flask views into fastapi ? (avoiding the flask <-> fastapi convertion, I think this is what was suggested by Jed.)

Then we only do this work for the simple auth manager because we do not need backward compat and because it's more convenient to have that in native FastAPI ?

@vincbeck
Copy link
Contributor Author

That's a little unclear for me where we're at and what we want to do for auth managers.

For other auth managers, especially FAB one, do we plan to use the flask middleware to be able to render all of those flask views into fastapi ? (avoiding the flask <-> fastapi convertion, I think this is what was suggested by Jed.)

Then we only do this work for the simple auth manager because we do not need backward compat and because it's more convenient to have that in native FastAPI ?

Yes to everything :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants