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

Configurable API response (CORS) headers #13620

Merged

Conversation

ryanahamilton
Copy link
Contributor

Employing the newly improved REST API from an independent web application is currently prohibited by browsers due to the lack of CORS (Cross-Origin Resource Sharing) headers in the API response.

This PR adds 3 configuration options to add the following headers:

  • Access-Control-Allow-Headers via AIRFLOW__API__ACCESS_CONTROL_ALLOW_HEADERS
  • Access-Control-Allow-Methods via AIRFLOW__API__ACCESS_CONTROL_ALLOW_METHODS
  • Access-Control-Allow-Origin via AIRFLOW__API__ACCESS_CONTROL_ALLOW_ORIGIN

This only covers a minimum of all potential headers that could be utilized, but the added set_cors_headers_on_response function establishes an obvious place for it to be further extended in the future if needed.

We did look into utilizing Flask-CORS to add this functionality, but ultimately found it to be overkill given we only want to add this to the API endpoint and not the entire Webserver application.

I've added documentation of this feature to Security/API and also cross-linked to that documentation from within the API documentation as well.

@boring-cyborg boring-cyborg bot added area:API Airflow's REST/HTTP API area:webserver Webserver related Issues kind:documentation labels Jan 11, 2021
@mik-laj
Copy link
Member

mik-laj commented Jan 11, 2021

@github-actions
Copy link

The Workflow run is cancelling this PR. Building images for the PR has failed. Follow the the workflow link to check the reason.

@ryanahamilton
Copy link
Contributor Author

Thanks for the input @mik-laj! Ash helped me work out the handler registration.

re: Access-Control-Allow-Credentials I don't have a strong opinion on this as I haven't yet encountered a use-case that requires it. I'm happy to add it if you think it would be prudent? Otherwise, this will establish an obvious place to do so if the need arises in the future.

@ashb
Copy link
Member

ashb commented Jan 12, 2021

Thanks for the input @mik-laj! Ash helped me work out the handler registration.

re: Access-Control-Allow-Credentials I don't have a strong opinion on this as I haven't yet encountered a use-case that requires it. I'm happy to add it if you think it would be prudent? Otherwise, this will establish an obvious place to do so if the need arises in the future.

Probably add it when we/someone have a use case for it then

Copy link
Member

@ashb ashb left a comment

Choose a reason for hiding this comment

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

CI just failed with a backfill job 137-error, unrelated.

@github-actions github-actions bot added the full tests needed We need to run full set of tests for this PR to merge label Jan 13, 2021
@github-actions
Copy link

The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest master at your convenience, or amend the last commit of the PR, and push it with --force-with-lease.

@ryanahamilton ryanahamilton merged commit 87645b3 into apache:master Jan 14, 2021
@ryanahamilton ryanahamilton deleted the api_response_cors_headers_config branch January 14, 2021 20:17
@mik-laj mik-laj mentioned this pull request Sep 9, 2021
2 tasks
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 area:webserver Webserver related Issues full tests needed We need to run full set of tests for this PR to merge kind:documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants