-
Notifications
You must be signed in to change notification settings - Fork 2
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
[New Feature]: Airflow Cognito integration #126
Comments
Dependency: CS setup Cognito user pool in each target shared services venue, also provide connection information and whatever instuctions are needed for integration. Risks: Cannot be accomplished with current Airflow version, will need to wait for next Airflow version and support for AuthManager in Airflow 3.0.X???? Tests: |
Cognito/Airflow InformationThe Airflow web UI uses Flask App Builder (FAB).
Authentication for the API is handled separately to the Web Authentication.
An Amazon Cognito user pool is an OpenID Connect (OIDC) identity provider (IdP). Documentation on implementation options:
Proposed architecture
Info needed from Cognito
|
Here are the general steps that are required for OAuth2.0 authentication with Cognito user pool. From: https://aws.amazon.com/blogs/security/how-to-use-oauth-2-0-in-amazon-cognito-learn-about-the-different-oauth-2-0-grants/
So far it looks like the traffic is passing steps 1 though 3 but the redirect may not be working on step 4. I can't quite isolate where in the Airflow |
Solutions tried,
Documentation on OAuth 2.0 grants in Cognito: https://aws.amazon.com/blogs/security/how-to-use-oauth-2-0-in-amazon-cognito-learn-about-the-different-oauth-2-0-grants/ It looks like Airflow may be moving away from FAB in the future and it may make the most sense to implement our own auth manager following the AWS auth manager architecture (Note: this does not use cognito for authentication and authorization). |
We made some progress by exploring the Flask AppBuilder and authlib library classes. The error seems to occur with the POST request to the Cognito token issuer endpoint. The POST request seems to be formed correctly but the Airflow web server hangs when making the request and does not return any error messages. Solutions tried,
It seems like the Flask AppBuilder may be interfering with the request somehow. I am not sure if it has to do with async operations and event loops or if I am missing some other aspect of the web server. |
A tentative solution can be found here: https://github.com/unity-sds/unity-sps/blob/126-airflow-cognito/airflow/config/webserver_config.py
Considerations
|
Next Nikki is going to try to merge Brad's changes to make the full stack Proxies-Cognito-Airflow work together. This might imbolve removing the SSL certificates on the SPS ALBs if the proxies stop working. |
@jpl-btlunsfo and I were able to route the shared services proxy for I added a callback URL to our Airflow app client: And tested it, after logging in with Cognito, the URL is routed to: https://www.dev.mdps.mcp.nasa.gov:4443/unity-nikki-1/dev/sps/authorize
?response_type=code
&client_id=xxxxx
&redirect_uri=http%3A%2F%2Fwww.dev.mdps.mcp.nasa.gov%3A5000%2Foauth-authorized%2FCognito
&scope=email+openid+profile
&state=xxxxx
&nonce=xxxxxx I set the webserver log level to DEBUG and see the following in the logs: x.x.x.x - - [28/Oct/2024:20:20:04 +0000] "GET /login/Cognito?next=http%3A//www.dev.mdps.mcp.nasa.gov%3A5000/home HTTP/1.1" 302 1063 "https://www.dev.mdps.mcp.nasa.gov:4443/unity-nikki-1/dev/sps/login/?next=http%3A%2F%2Fwww.dev.mdps.mcp.nasa.gov%3A5000%2Fhome" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36"
x.x.x.x - - [28/Oct/2024:20:20:05 +0000] "GET /authorize?response_type=code&client_id=xxxx&redirect_uri=http%3A%2F%2Fwww.dev.mdps.mcp.nasa.gov%3A5000%2Foauth-authorized%2FCognito&scope=email+openid+profile&state=xxxxx&nonce=xxxxx HTTP/1.1" 404 456 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36" I can find two issues related to the callback URL:
I am thinking that this is an issue with the Airflow webserver pointing to the wrong protocol and port. I will have to dig deeper to see if this can be changed in the webserver code. |
@nikki-t Could you merge in the changes from the |
@jpl-btlunsfo - Sorry about that, I had not pushed the branch I created up to GitHub. I did merge in the |
I completed a deeper dive into the various redirects that are happening and unfortunately could not get much further. I read through this page on "Running Airflow behind a reverse proxy" and noticed that you can specify a I also tried to investigate how the redirect URL was specified in the Airflow Flask AppBuilder code but kept running into that same Helm chart modification issue as above and could not push any changes to the I did capture the routes that are taken when trying to log into Cognito using the proxy URL:
a. Returns "Airflow 404 Page cannot be found."
@jpl-btlunsfo - Do you think this has anything to do with how the proxy is configured? I am not quite sure how those redirects are pulling in the incorrect port and protocol. |
I agree, step 4's in step 6, that URL looks extra funky
Is that "F" a typo? if it's not, I wonder how that Regarding
That's something you can specify in the helm configuration- however, up until now we hadn't been using that. Instead that pathing fix has been occurring in the venue-services proxy (specifically in the |
The step 6 URL does have a typo, the "F" shouldn't be there. I did try testing the Maybe I can try digging back into the webserver config and code to see why it might be able to pull the right hostname but not port or protocol. |
No description provided.
The text was updated successfully, but these errors were encountered: