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

secretsmanager_secret module should not overwrite an existing Secret #1626

Closed
1 task done
brsolomon-deloitte opened this issue Dec 21, 2022 · 2 comments · Fixed by #1628
Closed
1 task done

secretsmanager_secret module should not overwrite an existing Secret #1626

brsolomon-deloitte opened this issue Dec 21, 2022 · 2 comments · Fixed by #1628
Labels
feature This issue/PR relates to a feature request has_pr module module plugins plugin (any type)

Comments

@brsolomon-deloitte
Copy link
Contributor

Summary

The community.aws.secretsmanager_secret module currently offers no option to not overwrite a Secret if it exists with the same name but a different value. This forces the user to first try to check if the Secret exists and then skip the task if it does. It will simply call secrets_mgr.update_secret(secret) and overwrite the existing one. If the intended Secret value itself is, for example, a random password, the option to only lookup that the Secret exists (but not that its values match) would be a nice feature.

Relevant code:

Issue Type

Feature Idea

Component Name

secretsmanager_secret

Additional Information

- name: Try to retrive existing elastic secrets from AWS Secrets Manager
  ansible.builtin.set_fact:
    elastic_user_password: "{{ lookup('amazon.aws.aws_secret', clustername + '/' + elastic_namespace + '.elastic-user-password', nested=true, region=region, on_missing='error') }}"
    kibana_client_secret: "{{ lookup('amazon.aws.aws_secret', clustername + '/' + elastic_namespace + '.keycloak-secret', nested=true, region=region, on_missing='error') }}"
  register: secrets_found
  ignore_errors: true

- name: Create elastic user password and Keycloak AWS secrets if necessary
  community.aws.secretsmanager_secret:
    name: "{{ clustername }}/{{ elastic_namespace }}"
    description: Elastic secrets for {{ elastic_namespace }}
    state: present
    secret_type: "string"
    json_secret: {
      "elastic-user-password": "{{ lookup('community.general.random_string', length=16, special=false) }}",
      "keycloak-secret": "{{ lookup('community.general.random_string', length=16, special=false) }}"
    }
    region: "{{ region }}"
  when: secrets_found is failed

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibullbot
Copy link

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot
Copy link

@ansibullbot ansibullbot added feature This issue/PR relates to a feature request module module needs_triage plugins plugin (any type) labels Dec 21, 2022
brsolomon-deloitte added a commit to brsolomon-deloitte/community.aws that referenced this issue Dec 21, 2022
Adds an 'overwrite' parameter

    - If set to True, an existing secret with the same name will be overwritten.
    - If set to False, a secret with the given name will only be created if none exists.

Closes ansible-collections#1626
Signed-off-by: Brad Solomon <[email protected]>
tremble pushed a commit to brsolomon-deloitte/community.aws that referenced this issue Feb 8, 2023
Adds an 'overwrite' parameter

    - If set to True, an existing secret with the same name will be overwritten.
    - If set to False, a secret with the given name will only be created if none exists.

Closes ansible-collections#1626
Signed-off-by: Brad Solomon <[email protected]>
tremble pushed a commit to brsolomon-deloitte/community.aws that referenced this issue Feb 8, 2023
Adds an 'overwrite' parameter

    - If set to True, an existing secret with the same name will be overwritten.
    - If set to False, a secret with the given name will only be created if none exists.

Closes ansible-collections#1626
Signed-off-by: Brad Solomon <[email protected]>
softwarefactory-project-zuul bot pushed a commit that referenced this issue Feb 8, 2023
secretsmanager_secret: add 'overwrite' parameter

SUMMARY
Adds an 'overwrite' parameter to secretsmanager_secret
- If set to True, an existing secret with the same name will be overwritten.
- If set to False, a secret with the given name will only be created if none exists.

Fixes #1626
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
secretsmanager_secret
ADDITIONAL INFORMATION

Reviewed-by: Mark Chappell <None>
Reviewed-by: Markus Bergholz <[email protected]>
patchback bot pushed a commit that referenced this issue Feb 8, 2023
secretsmanager_secret: add 'overwrite' parameter

SUMMARY
Adds an 'overwrite' parameter to secretsmanager_secret
- If set to True, an existing secret with the same name will be overwritten.
- If set to False, a secret with the given name will only be created if none exists.

Fixes #1626
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
secretsmanager_secret
ADDITIONAL INFORMATION

Reviewed-by: Mark Chappell <None>
Reviewed-by: Markus Bergholz <[email protected]>
(cherry picked from commit 4bfcb0c)
softwarefactory-project-zuul bot pushed a commit that referenced this issue Feb 8, 2023
[PR #1628/4bfcb0c8 backport][stable-5] secretsmanager_secret: add 'overwrite' parameter

This is a backport of PR #1628 as merged into main (4bfcb0c).
SUMMARY
Adds an 'overwrite' parameter to secretsmanager_secret
- If set to True, an existing secret with the same name will be overwritten.
- If set to False, a secret with the given name will only be created if none exists.

Fixes #1626
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
secretsmanager_secret
ADDITIONAL INFORMATION

Reviewed-by: Mark Chappell <None>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue/PR relates to a feature request has_pr module module plugins plugin (any type)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants