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

Added option for disabling MSI autodiscover feature in azure_keyvault_secret lookup plugin #1353

Conversation

nalle
Copy link
Contributor

@nalle nalle commented Dec 1, 2023

SUMMARY

Added an option to be able to disable MSI autodiscover feature.

The default for the module is to assume that the MSI metadata URL is available, which slows down the module considerably when not being able to access that IP.

This way the original intended functionality is preserved and we who want to use it without MSI available can do so without an almost 30s penalty.

Some things had to be moved around due to where the options kwarg is available.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

azure.azcollection.azure_keyvault_secret

ADDITIONAL INFORMATION

Below follows a paste from running with and without MSI autodiscover enabled
With MSI autodiscovery without MSI metadata host:

PLAY [localhost] ***************************************************************************************************************************************************************************

TASK [debug] *******************************************************************************************************************************************************************************
Friday 19 August 2022  09:35:14 +0200 (0:00:00.016)       0:00:00.016 *********
Your credentials class does not support session injection. Performance will not be at the maximum.
ok: [localhost] => {
    "msg": "the value of this secret is <redacted>"
}

PLAY RECAP *********************************************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Friday 19 August 2022  09:35:42 +0200 (0:00:28.608)       0:00:28.624 *********
===============================================================================
debug ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 28.61s
Playbook run took 0 days, 0 hours, 0 minutes, 28 seconds

Without MSI autodiscovery enabled:

PLAY [localhost] ***************************************************************************************************************************************************************************

TASK [debug] *******************************************************************************************************************************************************************************
Friday 19 August 2022  09:35:06 +0200 (0:00:00.019)       0:00:00.019 *********
Your credentials class does not support session injection. Performance will not be at the maximum.
ok: [localhost] => {
    "msg": "the value of this secret is <redacted>"
}

PLAY RECAP *********************************************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Friday 19 August 2022  09:35:07 +0200 (0:00:00.920)       0:00:00.939 *********
===============================================================================
debug ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 0.92s
Playbook run took 0 days, 0 hours, 0 minutes, 0 seconds

And some examples that were in the previous pull request

Using MSI autodiscovery

  connection: local
  vars:
    azure_keyvault_url: https://something.vault.azure.net
    azure_client_id: xxxxxx-xxxx-xxxxx-xxxxx
    azure_secret: xxxxxx-xxx-xxxxx-xxxxxx
    azure_tenant_id: xxxxxxx-xxxx-xxxxx-xxxxx-
  tasks:
    - debug:
        msg: "{{ lookup('azure.azcollection.azure_keyvault_secret','secretname',vault_url=azure_keyvault_url, client_id=azure_client_id, secret=azure_secret, tenant_id=azure_tenant_id) }}

Without MSI autodiscovery

  connection: local
  vars:
    azure_keyvault_url: https://something.vault.azure.net
    azure_client_id: xxxxxx-xxxx-xxxxx-xxxxx
    azure_secret: xxxxxx-xxx-xxxxx-xxxxxx
    azure_tenant_id: xxxxxxx-xxxx-xxxxx-xxxxx-
  tasks:
    - debug:
        msg: "{{ lookup('azure.azcollection.azure_keyvault_secret','secretname',vault_url=azure_keyvault_url, client_id=azure_client_id, secret=azure_secret, tenant_id=azure_tenant_id, use_msi=False) }}

@nalle
Copy link
Contributor Author

nalle commented Dec 1, 2023

@Fred-sun ok, new pull request that looks a lot better than #956 and should be free from conflicts

Copy link
Collaborator

@Fred-sun Fred-sun left a comment

Choose a reason for hiding this comment

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

Small change request!

plugins/lookup/azure_keyvault_secret.py Outdated Show resolved Hide resolved
plugins/lookup/azure_keyvault_secret.py Outdated Show resolved Hide resolved
plugins/lookup/azure_keyvault_secret.py Outdated Show resolved Hide resolved
@Fred-sun Fred-sun added ready_for_review The PR has been modified and can be reviewed and merged medium_priority Medium priority labels Dec 5, 2023
@xuzhang3 xuzhang3 merged commit 498bb04 into ansible-collections:dev Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
medium_priority Medium priority ready_for_review The PR has been modified and can be reviewed and merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants