Skip to content

podman container clone fails with secret_env type mismatch when container uses --secret name,type=env #28130

@ozgur-as

Description

@ozgur-as

Issue Description

podman container clone fails with a JSON unmarshaling error when the source container has secrets injected as environment variables (--secret name,type=env).

The root cause is a type mismatch between two Go structs sharing the same "secret_env" JSON tag:

  • ContainerMiscConfig.EnvSecrets in libpod/container_config.go is map[string]*secrets.Secret (object)
  • ContainerBasicConfig.EnvSecrets in pkg/specgen/specgen.go is map[string]string

ConfigToSpec() in pkg/specgen/generate/container.go serializes the container config to JSON and deserializes it into a SpecGenerator. The secret_env field serializes as a JSON object but the target expects a string value, causing the unmarshal to fail.

Steps to reproduce the issue

  1. Create a podman secret
    echo "my-secret-value" | podman secret create MY_SECRET -

  2. Run a container with the secret as an env var
    podman run -d --name test_container --secret MY_SECRET,type=env docker.io/library/alpine:latest sleep 3600

  3. Try to clone it
    podman container clone test_container test_clone docker.io/library/alpine:latest

Describe the results you received

Error: json: cannot unmarshal object into Go struct field SpecGenerator.ContainerBasicConfig.secret_env of type string

Describe the results you expected

The container should be cloned successfully, preserving the secret environment variable configuration.

podman info output

Ubuntu 24.04 amd64 5.4.1

Podman in a container

No

Privileged Or Rootless

Rootless

Upstream Latest Release

No

Additional environment details

No response

Additional information

No response

Metadata

Metadata

Assignees

Labels

Good First IssueThis issue would be a good issue for a first time contributor to undertake.bugweekkind/bugCategorizes issue or PR as related to a bug.triagedIssue has been triagedvolunteers-wantedIssues good for community/volunteer contributions

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions