-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Fix connection test API to restore masked password/extra from existing connections #59643
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
Conversation
airflow-core/src/airflow/api_fastapi/core_api/routes/public/connections.py
Outdated
Show resolved
Hide resolved
|
It seems to be a CI failure unrelated to my changes🤔 |
jason810496
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix!
Not sure will option 2 be a more compatible approach, as current patch might result in breaking change behavior for the scenario I described.
Since we don't need to ensure the Frontend compatibility ( UI is out of scope of public interface ), but we have to ensure the Public API compatibility.
airflow-core/src/airflow/api_fastapi/core_api/routes/public/connections.py
Outdated
Show resolved
Hide resolved
airflow-core/src/airflow/api_fastapi/core_api/openapi/v2-rest-api-generated.yaml
Outdated
Show resolved
Hide resolved
|
considered a couple of options:
When testing the API, there is a scenario where users want to test the connection using a newly provided password, rather than the credential stored in the database. To support this, I added a
If, in the future, the UI adds functionality similar to the API test, where connections can be tested using user-provided input this parameter can be switched to |
|
It seem a bit complex, but I think this is the better option. |
jason810496
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To support this, I added a use_existing_credentials query parameter, with the default value set to false.
Yes, that make sense to me.
However, we still required test for the corresponding change for public API, thanks!
Thanks for review! |
|
Actually - the best way to fix it is to do it properly - i.e. run "test_connection" from workers - not from the "api-server" component. This is not the question of only the connection password masking but also execution environment. A bit more context.Running "test_connection" in the api_server context has several problems:
This is a functional problem with "test connection" run from api-server
https://airflow.apache.org/blog/airflow-2.7.0/
This is a security problem with running "Test-connection" from the api-server. The conditions of triggering the vulnerability and dangers have not changed a bit since 2.7.0 - even with task isolation - those are exactly the same dangers that were in 2.7.0 when test-connection was disabled by default. Users are exactly in the same - dangerous - place where they enable it back today. What can we do about with it ?Build on generic workflow feature introduced in Deadline alerts and instead of running "Test-connection" in the api-server, schedule workflow to be executed to actually do this in "worker" or "triggerer". This is what I was sceptical about when test-connection was introduced: #15795 (comment) and further discussions. What HAS changed since then is the argument of runing "api-server" and "workers" together does not stand any more (soon). We do everything possible now to enable the case where workers have not only different dependencies but simply - different airflow distribiutions ("airflow-task-sdk" rather than "airflow-core") - so the main argument in that discusison that running Airflow in such isolated environments is an edge case - but in Airflow 3.2 hopefully - this will become essentially "reocmmended" way of running airflow. Also we have something more thna we had 4 year ago - we finally are clearing the path of being able to run more generic workloads and run them through wokers/triggerer and provide feedback from those workloads (with deadline feature) - and we could follow the suite and implement it in similar way. This does not solve all the security issues but it makes our isolation way more consistent. With test connection on api_server you basically make UI users capable of running arbitrary code in api_server, and arbitrary modification of the database. If you move it's execution to workers- those components of airflow are way more isolated and are supposed to run dangerous code already, and usually is done in ephemeral (say k8s pods in k8s executor) - rather than long running environment of api_server. Which has IMHO acceptable security properties to even enable it by default with some security model description changes. My recommendation would be - not to "fix" this feature - but declare it "broken" and fix it properly by moving test-connection workflows to "workers". |
|
Wow! Thanks for the detailed background. I agree that instead of incrementally fixing test_connection, it makes more sense to remove it and re-implement it on the worker side. That said, I don’t yet have a enough understanding of backend architecture, and this doesn’t look like a small change, so it’s hard for me to implement it right away. |
pierrejeambrun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Jarek on the long term fix, but that's a much bigger effort.
In the meantime I think we should still fix the feature for sensitive value. We can just use update_orm_from_pydantic and test the connection on the mutated orm_conn, and then discard the updated orm_conn object to not mutate the db.
No need for an extra param, update_orm_from_pydantic takes care of everything. (if sensitive values were updated take those new sensitive values, if they were not restore them from db)
airflow-core/src/airflow/api_fastapi/core_api/routes/public/connections.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Thanks for the update.
One final nit: Could we assert the existed connection is not modified after calling test connection API? Since we called the update_orm_from_pydantic after change. Thanks!
pierrejeambrun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good.
Test need adjustments I believe.
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_connections.py
Outdated
Show resolved
Hide resolved
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_connections.py
Show resolved
Hide resolved
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_connections.py
Show resolved
Hide resolved
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_connections.py
Show resolved
Hide resolved
pierrejeambrun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGMT, I rebased it to solve a merge conflict (and adjusted a really small nit).
Should be good to go, thanks 🎉
2a77151 to
49d5e13
Compare
Backport failed to create: v3-1-test. View the failure log Run details
You can attempt to backport this manually by running: cherry_picker efb27dc v3-1-testThis should apply the commit to the v3-1-test branch and leave the commit in conflict state marking After you have resolved the conflicts, you can continue the backport process by running: cherry_picker --continueIf you don't have cherry-picker installed, see the installation guide. |
…g connections (apache#59643) * Fix connection test API to restore masked password/extra from existing connections * Use get_connection_from_secrets in test endpoint * Remove unused session parameter * Add use_existing_credentials flag to test connections * fix api-gen description * Standardize docstring format * Add use_existing_credentials flag to test connections * Refactor connection test logic using update_orm_from_pydantic * Remove useExistingCredentials flag from TestConnectionButton mutation * Add proper assertions for test connection merge tests * Small test adjustment --------- Co-authored-by: pierrejeambrun <pierrejbrun@gmail.com> (cherry picked from commit efb27dc)
|
Manual backport #60873 |
…g connections (#59643) (#60873) * Fix connection test API to restore masked password/extra from existing connections * Use get_connection_from_secrets in test endpoint * Remove unused session parameter * Add use_existing_credentials flag to test connections * fix api-gen description * Standardize docstring format * Add use_existing_credentials flag to test connections * Refactor connection test logic using update_orm_from_pydantic * Remove useExistingCredentials flag from TestConnectionButton mutation * Add proper assertions for test connection merge tests * Small test adjustment --------- (cherry picked from commit efb27dc) Co-authored-by: Yeonguk Choo <choo121600@gmail.com>
…g connections (apache#59643) * Fix connection test API to restore masked password/extra from existing connections * Use get_connection_from_secrets in test endpoint * Remove unused session parameter * Add use_existing_credentials flag to test connections * fix api-gen description * Standardize docstring format * Add use_existing_credentials flag to test connections * Refactor connection test logic using update_orm_from_pydantic * Remove useExistingCredentials flag from TestConnectionButton mutation * Add proper assertions for test connection merge tests * Small test adjustment --------- Co-authored-by: pierrejeambrun <pierrejbrun@gmail.com>
…g connections (apache#59643) * Fix connection test API to restore masked password/extra from existing connections * Use get_connection_from_secrets in test endpoint * Remove unused session parameter * Add use_existing_credentials flag to test connections * fix api-gen description * Standardize docstring format * Add use_existing_credentials flag to test connections * Refactor connection test logic using update_orm_from_pydantic * Remove useExistingCredentials flag from TestConnectionButton mutation * Add proper assertions for test connection merge tests * Small test adjustment --------- Co-authored-by: pierrejeambrun <pierrejbrun@gmail.com>
…g connections (apache#59643) * Fix connection test API to restore masked password/extra from existing connections * Use get_connection_from_secrets in test endpoint * Remove unused session parameter * Add use_existing_credentials flag to test connections * fix api-gen description * Standardize docstring format * Add use_existing_credentials flag to test connections * Refactor connection test logic using update_orm_from_pydantic * Remove useExistingCredentials flag from TestConnectionButton mutation * Add proper assertions for test connection merge tests * Small test adjustment --------- Co-authored-by: pierrejeambrun <pierrejbrun@gmail.com>
…g connections (apache#59643) * Fix connection test API to restore masked password/extra from existing connections * Use get_connection_from_secrets in test endpoint * Remove unused session parameter * Add use_existing_credentials flag to test connections * fix api-gen description * Standardize docstring format * Add use_existing_credentials flag to test connections * Refactor connection test logic using update_orm_from_pydantic * Remove useExistingCredentials flag from TestConnectionButton mutation * Add proper assertions for test connection merge tests * Small test adjustment --------- Co-authored-by: pierrejeambrun <pierrejbrun@gmail.com>

This PR fixes an issue where the connection test API (/connections/test) fails when testing existing connections that have masked sensitive fields (password, extra).
Previously, when a user tried to test an existing connection, the API would receive masked values like "***" for password and extra fields, causing the connection test to fail because the actual credentials were not available.
Before
After
closes: #59298
^ 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.rstor{issue_number}.significant.rst, in airflow-core/newsfragments.