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

Decrypt ansible-vault strings in nb_inventory #1114

Merged
merged 1 commit into from Dec 10, 2023

Conversation

jetomit
Copy link
Contributor

@jetomit jetomit commented Nov 8, 2023

This allows storing secrets in config context data.

Related Issue

#551

New Behavior

This allows storing ansible-vault secrets in a NetBox config context, like this:

{
    "plain_var": "value",
    "secret_var": {
        "__ansible_vault": "$ANSIBLE_VAULT;1.1;AES256\n123456…"
    }
}

Contrast to Current Behavior

Currently encrypted values are returned as is, and cannot be used directly in Ansible playbooks or templates without the workaround described in #551.

Discussion: Benefits and Drawbacks

The change should have no effect on existing installations; the workaround in #551 will still work but do nothing, as the values are now decrpyted earlier. Other possible workarounds (e.g. decrypting values in a playbook) might break if they expect an ansible-vault string.

Replacing json.loads with self.loader.load makes nb_inventory work more like the builtin script plugin, so I believe it is a better solution. If additional functionality is added to the DataLoader class in Ansible, it should work with nb_inventory with no changes to the plugin.

Changes to the Documentation

No changes. Please let me know if I should add a note somewhere.

Proposed Release Note Entry

Support ansible-vault encrypted values in NetBox config contexts

Double Check

  • I have read the comments and followed the CONTRIBUTING.md.
  • I have explained my PR according to the information in the comments or in a linked issue.
  • My PR targets the devel branch.

This allows storing secrets in config context data.
@sc68cal
Copy link
Contributor

sc68cal commented Nov 9, 2023

Can you add a test that exercises this? Creat a device and a config context with an encrypted string, and successfully decrypt?

@rodvand rodvand merged commit ca2fc6a into netbox-community:devel Dec 10, 2023
8 checks passed
@jetomit
Copy link
Contributor Author

jetomit commented Dec 12, 2023

Thanks for merging this! I did try to write a test case but had some problems. One issue is that it cannot be an inventory test since the values are only decrypted when running a playbook (I think). I might give it another try at some point, but for what it’s worth we’ve been using the patched version without issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants