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

Wrong Podman Secret Creation Behavior #741

Open
j0hann3s opened this issue May 6, 2024 · 3 comments
Open

Wrong Podman Secret Creation Behavior #741

j0hann3s opened this issue May 6, 2024 · 3 comments

Comments

@j0hann3s
Copy link

j0hann3s commented May 6, 2024

Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)

/kind bug

Description

The containers.podman.podman_secret module does not use the default driver file correctly. The passed data value is not being used as a path to the secret file, as expected, but as a literal string. This means that Podman registers the secret as "/path/to/secret" instead of "some-password" (contents of the file). According to the Podman documentation (https://docs.podman.io/en/latest/markdown/podman-secret-create.1.html) the behavior should be: "...Create accepts a path to a file, or -, which tells podman to read the secret from stdin...". It looks like the stdin '-' option is hardcoded in this module.

Steps to reproduce the issue:

  1. Create a text file with some data inside:
echo "super_secret_password" > /tmp/some_password.secret
  1. Use the following Task:
- name: Setup Podman Secret.
  containers.podman.podman_secret:
    name: "Some_Password"
    state: present
    driver: file
    data: "/tmp/some_password.secret"
  1. Check the contents of the Podman secret:
podman secret inspect --showsecret Some_Password
  1. The output from the above command will show "SecretData": "/tmp/some_password.secret" (but should instead show "SecretData": "super_secret_password").

  2. Execute the command natively with Podman Secret:

podman secret create --replace Some_Password /tmp/some_password.secret
  1. Execute step 3 again and observe the correct SecretData value (as described at the end of step 4).

Version of the containers.podman collection:
Either git commit if installed from git: git show --summary
Or version from ansible-galaxy if installed from galaxy: ansible-galaxy collection list | grep containers.podman

containers.podman                        1.12.0

Output of ansible --version:

ansible [core 2.16.5]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.12/site-packages/ansible
  ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.12.2 (main, Feb 21 2024, 00:00:00) [GCC 13.2.1 20231205 (Red Hat 13.2.1-6)] (/usr/bin/python3)
  jinja version = 3.1.3
  libyaml = True

Output of podman version:

Client:       Podman Engine
Version:      4.9.4
API Version:  4.9.4
Go Version:   go1.21.8
Built:        Tue Mar 26 10:39:52 2024
OS/Arch:      linux/amd64
@sshnaidm
Copy link
Member

sshnaidm commented May 6, 2024

I'm not sure I understand what is the problem, the docs says:

  data:
    description:
      - The value of the secret. Required when C(state) is C(present).
    type: str

It should be value, not the file path. If you want to use file path it will be a feature request, but currently everything works as designed and documented.

@j0hann3s
Copy link
Author

j0hann3s commented May 6, 2024

@sshnaidm Yes, the documentation inside this repo does mention what you cited above, but I am referring to Podman's documentation of the secret subcommand and how it is intended to be used.

As I understand it, Ansible modules are wrappers for the actual underlying program (in this case Podman with the secret subcommand) and are supposed to mimic the original functionality as closely as possible with some extra checks (exit status, etc.). But this module says that it uses the driver file by default (like Podman) which Podman originally refers to as an actual file containing the secret. This module, however, does not honor the option driver with the file value in the same sense as Podman originally.

The documentation on both containers.github.io and docs.ansible.com mentions:

driver Override default secrets driver, currently podman uses file which is unencrypted.

But using this option explicitly (driver: file) does still use a literal string provided in the actual Yaml/Playbook which partially defeats the Podman secret functionality which tries to separate sensitive data from configuration files (be it podman-compose files, Containerfiles, or Ansible Playbook's which easily can wind up committed into repos). In other words, the option driver with the value file should read from the passed file. Otherwise, I do not see any meaning in having the option if everything is going to be passed as stdin.

I would even consider this somewhat of a security risk due to how one transitioning from writing podman secret create <NAME> <PATH> to a task in an Ansible play could unintentionally set a certain service access token/password to the secret's file path and not content. So that one's, for example, reverse-proxy web interface is accessible when typing in the path to the secret file (a lot easier to brute force or attack with a dictionary attack). Here one has to hope that the respective service would throw an error and mention some formatting error with the secret data which in the worst case would just be used as a seed or token as mentioned above without throwing any errors.

I see two ways this could be tackled:

  1. (Breaking changes) The usage of the option driver with the value file (which is the current default affecting everyone) results in using the value in the option data as input for the in podman secret create <NAME> <PATH>. Using a new value, for example, stdin in the option driver results in using the literal string provided in the value of the option data.

  2. Add the option, for example, file with the value being a file path, which ignores the data option and is used as input for the in podman secret create <NAME> <PATH>. Also, adding a warning in the documentation that using the data option without the file option will use the literal string and not a file's contents (as might expected by still having driver being the value file by default).

Alternative 1 does add an extra driver value (stdin) and encompasses breaking changes but makes it clear that either the file contents are being used as a secret or the literal string value in the data option.

Alternative 2 adds an extra option for file content usage and warns users in the documentation of the deviation from the original subcommand.

I would, even though it encompasses breaking changes, recommend the first alternative just because it makes this sensitive topic more "idiot-proof" from misconfigurations.

@sshnaidm
Copy link
Member

sshnaidm commented May 6, 2024

I strongly object to the first option, it's totally clear parameter name data which means secret data. If we want to add a path option to pass file, I'm only for it.
Would you like to submit a patch?
cc @amenzhinsky

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

No branches or pull requests

2 participants