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

Mark (some ?) Nautobot variables/inputs as unsafe #114

Open
u1735067 opened this issue Nov 18, 2021 · 0 comments
Open

Mark (some ?) Nautobot variables/inputs as unsafe #114

u1735067 opened this issue Nov 18, 2021 · 0 comments

Comments

@u1735067
Copy link
Contributor

ISSUE TYPE
  • Bug Report
  • Feature Idea
SOFTWARE VERSIONS
pynautobot

1.0.3

Ansible:

2.11.6

Nautobot:

1.1.4

Collection:

v3.1.0

SUMMARY

When using Jinja2 tags in some fields imported from Nautobot (like a config context), Ansible will try to template the string which is likely to fail (and may have security implications if you put something like a lookup).

Maybe this is an Ansible bug (or feature, it seems Ansible' inventory plugins are not doing any value sanitization, but I'm not sure this should be the default). in that case maybe this could be an option (enabled by default) in this plugin?

STEPS TO REPRODUCE
  • Create a config context like:
{"my_var": "{{ hi_ansible }}"}
  • Use this config context in some playbook like below
- hosts: all
  tasks:
    # Ok for some reason ..
    - ansible.builtin.debug:
        msg: "{{ hostvars[inventory_hostname].config_context.my_var }}"
      run_once: true
      delegate_to: localhost

    # All of them will fail
    - ansible.builtin.debug:
        msg: "{{ config_context.my_var }}"
        # msg: "{{ lookup('list', [config_context.my_var]) }}"
        # msg: "{{ lookup('list', [hostvars[inventory_hostname].config_context.my_var]) }}"
      run_once: true
      delegate_to: localhost
    
    # ->"The task includes an option with an undefined variable. The error was: {[..]}: 'hi_ansible' is undefined"
EXPECTED RESULTS
ok: [my_host -> localhost] => {
    "msg": "{{ hi_ansible }}"
}
ACTUAL RESULTS
"The task includes an option with an undefined variable. The error was: {[..]}: 'hi_ansible' is undefined"
Additional informations

This can be patched by importing from ansible.utils.unsafe_proxy import wrap_var and wrapping values at https://github.com/nautobot/nautobot-ansible/blob/v3.1.0/plugins/inventory/inventory.py#L1409-L1412.

While I checked the changelog before posting this, I couldn't test with a newer version, sorry.

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

No branches or pull requests

2 participants