Conversation
3013d04 to
db5fef3
Compare
9c0c8d6 to
3da1786
Compare
|
Hi @vincbeck We have defined the scope of Task 1 in the PR description. Thank you for your previous comments and suggestions to complete this task. There is a part of the proposed solution that we are still unclear.
In a recent comment RobbeSneyders commented 2 days ago suggested
So, should we still consider moving |
31301cd to
1900ffc
Compare
Yes |
1900ffc to
46630eb
Compare
Refinement: Returning
|
f66f6d9 to
de01bb4
Compare
ProblemDue to the upgrade of connextion v3, we cannot access blueprints( they moved the blueprint registration code inside their codebase). We used the returned blueprint to make exemptions to accept HTTP(S) requests without "csrf token" in the header. When the auth-token is in the header, the client doesn't include a csrf token. That's why we get csrf token missing error with @RobbeSneyders suggested utilizing the middleware library asgi-csrf to do the same without using blueprints. This is a sample code to make csrf-token exemption.
|
I assume the scope :) ?. I believe the scope is the base URL of Airflow webserver (not 100% sure how asg-csrf does it but that's what I understand it should be. The CSRF tokens we have are generated in the webserver views - and those are generated at the "base URL" (and anything that's deeper in the path) - and those csrf tokens are then used by the browser to make the calls to the API.
We should use https://airflow.apache.org/docs/apache-airflow/stable/configurations-ref.html#secret-key - this is done usually by: conf.get_mandatory_value("webserver", "secret_key") |
|
Yes, it's scope. I have this now. After using asgi_csrf, I get a different error. I hope I'm in the right direction to solve the issue. Here is my pull request to Sudipto's forked repo. |
It is possible to avoid this error using the following tweak for the time being. asgi-csrf looks for # asgi-csrf skip_if_scope
flask_app.config['SECRET_KEY'] = conf.get_mandatory_value("webserver", "secret_key")
def skip_api_paths(scope):
return scope["path"].startswith("/api/v1")
asgi_csrf(
flask_app,
signing_secret=conf.get_mandatory_value("webserver", "secret_key"),
skip_if_scope=skip_api_paths,
)@potiuk |
|
We might be able to handle @connexion_app.app.before_request
def before_request():
"""Exempts the view function associated with '/api/v1' requests from CSRF protection."""
if request.path.startswith("/api/v1"): # TODO: make sure this path is correct
view_function = flask_app.view_functions.get(request.endpoint)
if view_function:
# Exempt the view function from CSRF protection
connexion_app.app.extensions["csrf"].exempt(view_function)I implemented it here, asking for a review @vincbeck @potiuk @Satoshi-Sh |
de01bb4 to
f261cf5
Compare
|
Nicely done, @sudiptob2 . I checked it with Once todo about the scope is done, we can go ahead to the second bug. |
|
cc: @VladaZakharova - just adding you for awareness :) |
Once I do a bit of homework on it myself :) |
Hi @Satoshi-Sh, breeze start-airflow --dev-mode --load-example-dags --backend postgres
This has to be handled in subtask 1 so that reviewers can easily review it. |
The problem here was that some sessions should be committed/closed but also in order to run it standalone we wanted to create log templates in the database - as it relied implcitly on log templates created by other tests. Also handling of the response without conteent type had to be fixed. Remaining issue is 401 vs 403 forbidden returned. To be looked at later.
Signed-off-by: sudipto baral <sudiptobaral.me@gmail.com>
Signed-off-by: sudipto baral <sudiptobaral.me@gmail.com>
Signed-off-by: sudipto baral <sudiptobaral.me@gmail.com>
Signed-off-by: sudipto baral <sudiptobaral.me@gmail.com>
Signed-off-by: sudipto baral <sudiptobaral.me@gmail.com>
Signed-off-by: sudipto baral <sudiptobaral.me@gmail.com>
Switching to flask client rather than starlette, helped to fix the issue.
The fix checks for the 429 HTTP exception that should be returned in this case. This also reverts commit a9aa27d.
Fixed by switching to use flask client for testing rather than starlette. Starlette client in this case has some side effects that are also impacting Sqlite's session being created in a different thread and deleted with close_all_sessions fixture.
Fixed by switching to use flask client for testing rather than starlette. Starlette client in this case has some side effects that are also impacting Sqlite's session being created in a different thread and deleted with close_all_sessions fixture.
Fixed by switching the test to flask_admin_client. Removes sqlalchemy session creted from a different thread.
Signed-off-by: sudipto baral <sudiptobaral.me@gmail.com>
Signed-off-by: sudipto baral <sudiptobaral.me@gmail.com>
Signed-off-by: sudipto baral <sudiptobaral.me@gmail.com>
It was enough to use flask test client
Hey @RobbeSneyders Thanks for the offer. We got the PR green finally (HURRAY!). What - I think, you could help with is to validate some of our assumptions. Due to the length of this PR and comments and number of commits in that, I will open a new PR and ask some concrete questions and explain our decisions there and ask you for comments - and I will involve other maintainers as well. |
|
Continued in #39055 |
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions. |


This PR is created based on #36052
Todo
blueprintin connexion v3Taks 1 - Refactor get_api_endpoints()
Problem Definiton
Ref: Github Pull Request #36052 VladaZakharova commented on Jan 18
In the
init_api_auth_providermethod, we update the base path as follows:However, the
blueprintobject obtained fromauth_mgr.get_api_endpoints(connexion_app)will always beNoneif we are using ConnexionV3.Proposed solution
Ref vincbeck commented on Jan 18
get_api_endpointstoset_api_endpoints. The return type should be updated toNone. Documentation should be updated as well to something like "Set API endpoint(s) definition for the auth manager.". This is a breaking change but nobody uses this interface yet, so it is a good time to do it.This piece of codeRef: Migrate to connexion v3 #37638 (comment)flask_app.extensions["csrf"].exempt(blueprint)should be moved in theset_api_endpointsmethod usingappbuilder.app.extensions["csrf"].exempt(api.blueprint)How to test
python ./clients/python/test_python_client.pySubtasks
base_paths.append(blueprint.url_prefix if blueprint.url_prefix else "")CSRFexemption is correct. Ref: Migrate to connexion v3 #37638 (comment)swagger-uiinstallation, Ref: Migrate to connexion v3 #37638 (comment)favicon.icoproblem in the swagger UI.Task 2 - Replace envrion_overrides argument
Problem Definition
Ref: Github Pull Request #36052 commented on Feb 6
Solution
{'REMOTE_USER:"user"}instead of using environ_overirdes argument inside testclient.method. Accordinly update the authentication part intests/test_utils/remote_user_api_auth_backend.pytouser_id = request.headers.get("REMOTE_USER")