Skip to content

Various issues with shell driver of podman secret #27130

@coolwanglu

Description

@coolwanglu

Issue Description

I'm been experimenting the shell driver of podman secrets. It's not really working well.

Steps to reproduce the issue

Setup

I created a simple shell script test.sh

podman secret create \
  --driver=shell \
  --driver-opts=list=/bin/true \
  --driver-opts=lookup="cat $2" \
  --driver-opts=store=/bin/true \
  --driver-opts=delete=/bin/true \
  --replace=true \
  "$1" - <<<SECRET

The idea is, test.sh name filename will allow me to register the content of filename as secret name. This is similar to LoadCredential= in systemd.

Test Cases

Test Case 1

  1. Make sure podman secret ls is empty, make sure /var/lib/containers/storage/secrets is empty (or does not exist).
  2. Run as root (same below) echo SECRET | podman secret create test1 -
  3. podman secret ls should show test1
  4. test.sh test2 /test2
  5. podman secret ls shows only test2. test1 disappeared
  6. /var/lib/containers/storage/secrets/filedriver/secretsdata.json still contains test1.

Test Case 2

  1. Make sure podman secret ls is empty, make sure /var/lib/containers/storage/secrets is empty (or does not exist).
  2. Run as root (same below) echo SECRET | podman secret create test1 -
  3. echo SECRET | podman secret create test2 -
  4. podman secret ls should show test1 and test2
  5. test.sh test3 /test3 got error Error: deleting secret : more than one result secret with prefix : secret is ambiguous

Issue 1: Bug with --replace for new secret

When --replace is specified, podman tries to delete the old secret, however, the ID field is not set for new secrets.

This means we are deleting a secret with an empty string. The file driver will throw an "no such secret" error, which is muted, that's why the file driver works.

However, if the driver does not throw an error, podman will go ahead and try to delete the metadata. Because an empty ID does not exist, it is now interpreted as a prefix (which is even worse in my opinion).

This explains both test cases: if there is only one entry in the store, it is matched with the empty prefix and deleted. If there are multiple entries, podman will complain the prefix is ambigiuous.

Proposal

A workaround is to check SECRET_ID is not empty in the shell script. But I think this is hacky, because the shell driver treats any error as "no such secret" error.

The correct solution should be avoid deleting anything, when adding a new secret.

Issue 2: Incorrect logic with multiple drivers

Let's say I run the following:

  • podman secret create --driver=DRIVER1 --replace secret ...
  • podman secret create --driver=DRIVER2 --replace secret ...

Currently podman asks DRIVER2 to delete the secret, which doesn't make sense to me. We should use DRIVER1.

Issue 3: Quoting/Escaping issues with shell scripts

It seems that if a script (e.g. lookup/delete/store/list) ends with ", it will be removed. Examples:

  • --driver-opts=list="echo \"SECRET\"" will produce "list": "echo \"SECRET" in podman secret inspect
  • --driver-opts=list="echo \"SECRET\" " works as expected, note the trialing whitespace.

Issue 4: list command for shell driver

Throughout the codebase I cannot find where it is used, nor can I trigger it.
Is it expected?

Describe the results you received

See above

Describe the results you expected

See above

podman info output

podman version 5.4.2 on Debian.

Podman in a container

No

Privileged Or Rootless

Privileged

Upstream Latest Release

No

Additional environment details

No response

Additional information

No response

Metadata

Metadata

Labels

kind/bugCategorizes issue or PR as related to a bug.stale-issuetriagedIssue has been triaged

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions