secret create --replace leaves a duplicate entry when the driver no longer has the old secret
Issue Description
If the driver has lost the data of an existing secret (for example the file driver with path= on a tmpfs after a reboot), podman secret create --replace doesn't remove the old entry. It adds a second secret with the same name, and the old one can't be removed with podman secret rm either (that part is #27666).
It looks like Store() in common/pkg/secrets/secrets.go ignores ErrNoSuchSecret from driver.Delete() but then also skips s.delete(), so the old ID stays in the metadata.
Steps to reproduce the issue
With a throwaway store:
W=$(mktemp -d); mkdir "$W/run"
pm() { podman --root "$W/root" --runroot "$W/runroot" --tmpdir "$W/tmp" "$@"; }
echo one | pm secret create --driver file --driver-opts path="$W/run" app.token -
rm "$W/run/secretsdata.json" # driver data gone, like a tmpfs after a reboot
echo two | pm secret create --replace --driver file --driver-opts path="$W/run" app.token -
pm secret ls
Describe the results you received
Two secrets named app.token:
ID NAME DRIVER
1a6ace66bd6aeba56013c636a app.token file
e3ef853e98d6a2e1fbec10a95 app.token file
pm secret rm e3ef853e98d6a2e1fbec10a95 fails with no such secret and the entry stays. Each further --replace adds one more.
Describe the results you expected
One app.token entry. When the driver says the old data is already gone, --replace should still drop the old metadata. Other driver errors should still fail as they do today.
podman info output
podman 6.2.0 (podman-6.2.0-1.fc45, containers-common-0.70.0-1.fc45), Fedora 45, amd64
Also reproduced with podman 5.7.0 on Ubuntu 26.04.
Podman in a container
Yes
Privileged Or Rootless
Rootless
Upstream Latest Release
Yes
Additional environment details
6.2.0 ran inside a Fedora 45 container, 5.7.0 directly on the host.
Additional information
podman-container-tools/container-libs#558 fixes the rm side of #27666 but doesn't touch --replace. #27130 covers --replace on a name that doesn't exist yet.
Hi! I'd like to work on this issue.
I looked through the issue description, and the problem seems to be in Store() in common/pkg/secrets/secrets.go. When driver.Delete() returns ErrNoSuchSecret, the error is ignored, but the old entry is not removed from the metadata store. As a result, --replace creates a new secret while leaving the old one behind.
I'd like to look into the existing deletion logic and fix it so that the old metadata is removed even when the driver has already lost the secret data. At the same time, other driver errors should still be handled as before.
I'll also add a regression test covering this scenario and check that the existing --replace behavior is not affected.
I'd be happy to work on this and submit a PR to container-libs (i' ve already read CONTRIBUTING.md btw). Could you assign it to me?
/assign