-
Notifications
You must be signed in to change notification settings - Fork 16.3k
Add secrets backend for microsoft azure key vault #9639
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
Add secrets backend for microsoft azure key vault #9639
Conversation
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst)
|
1b55972 to
e9f6a0b
Compare
tests/providers/microsoft/azure/secrets/test_azure_key_vault_backend.py
Outdated
Show resolved
Hide resolved
tests/providers/microsoft/azure/secrets/test_azure_key_vault_backend.py
Outdated
Show resolved
Hide resolved
07e9bb6 to
fbfe3c8
Compare
kaxil
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.
CI Failed:
airflow/providers/microsoft/azure/secrets/azure_key_vault.py:42: error: Incompatible default for argument "vault_url" (default has type "None", argument has type "str")
Found 1 error in 1 file (checked 2279 source files)
There were some mypy errors. Exiting
Fix End of Files..................................................................................................................Failed
- hook id: end-of-file-fixer
- exit code: 1
- files were modified by this hook
Fixing airflow/providers/microsoft/azure/secrets/__init__.py
Run isort to sort imports.........................................................................................................Failed
- hook id: isort
- files were modified by this hook
Fixing /home/runner/work/airflow/airflow/airflow/providers/microsoft/azure/secrets/azure_key_vault.py
************* Module airflow.providers.microsoft.azure.secrets.azure_key_vault
airflow/providers/microsoft/azure/secrets/azure_key_vault.py:123:12: E1205: Too many arguments for logging format string (logging-too-many-args)
------------------------------------
EXITING /opt/airflow/scripts/ci/in_container/run_pylint_main.sh WITH STATUS CODE 1
###########################################################################################
************* Module airflow.providers.microsoft.azure.secrets.azure_key_vault
airflow/providers/microsoft/azure/secrets/azure_key_vault.py:123:12: E1205: Too many arguments for logging format string (logging-too-many-args)
fc98cb6 to
e17e26c
Compare
e17e26c to
6bc7c1f
Compare
f6a1df0 to
4a5f447
Compare
4a5f447 to
0e86265
Compare
|
@kaxil In the aws secrets manager in the docstring it says: (Variables should be Config i think) Should i add config to this backend too? |
| path = f'{path_prefix}{sep}{secret_id}' | ||
| return path.replace('_', sep) | ||
|
|
||
| def get_secret_value(self, name: str) -> Optional[str]: |
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've refactored _get_secret to get_secret_value to allow use of this backend for secrets that do not conform to the prefixes provided for connections and variables. We have a use case for this as secret names are sometimes internally created by another department that conform to different naming standards.
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.
We will have hooks for that, for example: https://github.com/apache/airflow/blob/master/airflow/providers/hashicorp/hooks/vault.py
WDYT, would that be useful for your use-case?
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 will make it a private method again and will create a hook later on.
Yes please, it would allow you to retrieve some of the Airflow configs from Secrets Backend, details here https://airflow.readthedocs.io/en/latest/howto/set-config.html |
| And if variables prefix is ``airflow-variables-hello``, this would be accessible | ||
| if you provide ``{"variables_prefix": "airflow-variables"}`` and request variable key ``hello``. | ||
|
|
||
| :param vault_url: The URL of an Azure Key Vault to use |
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.
One more: also put vault_url after variables_prefix here too
|
Do you need any help in completing this @elwinarens? |
|
@kaxil Could use help, yes. Don’t think i can work on this the coming weeks, unfortunately. Feel free to fork this and put up a new PR |
|
Not sure if anyone who uses this noticed but the module There might be a better way to stop it from spamming the info logs, but one workaround I found is to change the logging level for the Here is an example of just one request shown in the INFO-level logs: P.S. I don't really have the time either to finish this up, but I made a very similar secrets backend for Azure Key Vault that used ClientSecretCredential instead of DefaultAzureCredential, but I like this method better because instead of having to put the client_id, client_secret, and tenant_id in the kwargs you can just add them as environment variables |
|
@alexbegg After investigating the verbose logging: while i understand that the logs are verbose and annoying, i don't think the responsibility of changing the default behaviour of the azure python sdk implementation should be changed in this backend. Because changing the logging behaviour here affects other parts (there's no logger for this particular client, i think) Related Azure/azure-sdk-for-python#9422 |
|
I'm interested in this functionality. Do you need help finishing the PR? Thanks! |
|
@flolas Please feel free to create a new PR, looks like @elwinarens might be busy |
|
ping @elwinarens @flolas |
|
@kaxil If neither are able to continue the work, what is remaining to do here? Does it need a hook? has config secrets been added to this backend yet? I am already using this same backend for my own Airflow installation but as a custom secrets backend as a standalone class, not incorporated into the apache-airflow-backport-providers-microsoft-azure package. I was working on developing my own PR for this but I was still working on the hook and other parts when I left off. |
It needs rebase on Master, I tried but the PR author hasn't allowed "Edit from Maintainers" |
|
@elwinarens We are very close to merging this can you please rebase, or just checkmark "Allow Edit From Maintainers" https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/allowing-changes-to-a-pull-request-branch-created-from-a-fork |
|
@kaxil that option is not available, because this PR is not under a personal user. Feel free to cherry pick and to put up a new PR. Let me know if you need anything. |

Add secrets backend for microsoft azure key vault. Related issue #8258.
Make sure to mark the boxes below before creating PR: [x]
In case of fundamental code change, 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 UPDATING.md.
Read the Pull Request Guidelines for more information.