Skip to content

Commit

Permalink
Merge pull request #23959 from auyer/hide-secrets-from-container-inspect
Browse files Browse the repository at this point in the history
Hide secrets from container inspect command
  • Loading branch information
openshift-merge-bot[bot] committed Sep 17, 2024
2 parents 9781a26 + a5e9b4d commit f4a08f4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
14 changes: 14 additions & 0 deletions libpod/container_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,20 @@ func (c *Container) generateInspectContainerConfig(spec *spec.Spec) *define.Insp
if spec.Process != nil {
ctrConfig.Tty = spec.Process.Terminal
ctrConfig.Env = append([]string{}, spec.Process.Env...)

// finds all secrets mounted as env variables and hides the value
// the inspect command should not display it
envSecrets := c.config.EnvSecrets
for envIndex, envValue := range ctrConfig.Env {
// env variables come in the style `name=value`
envName := strings.Split(envValue, "=")[0]

envSecret, ok := envSecrets[envName]
if ok {
ctrConfig.Env[envIndex] = envSecret.Name + "=*******"
}
}

ctrConfig.WorkingDir = spec.Process.Cwd
}

Expand Down
22 changes: 22 additions & 0 deletions test/e2e/container_inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package integration

import (
"fmt"
"os"
"path/filepath"

Expand Down Expand Up @@ -82,4 +83,25 @@ var _ = Describe("Podman container inspect", func() {
Expect(data[0].HostConfig.VolumesFrom).To(Equal([]string{volsctr}))
Expect(data[0].Config.Annotations[define.VolumesFromAnnotation]).To(Equal(volsctr))
})

It("podman inspect hides secrets mounted to env", func() {
secretName := "mysecret"

secretFilePath := filepath.Join(podmanTest.TempDir, "secret")
err := os.WriteFile(secretFilePath, []byte("mySecretValue"), 0755)
Expect(err).ToNot(HaveOccurred())

session := podmanTest.Podman([]string{"secret", "create", secretName, secretFilePath})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())

name := "testcon"
session = podmanTest.Podman([]string{"run", "--secret", fmt.Sprintf("%s,type=env", secretName), "--name", name, CITEST_IMAGE})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())

data := podmanTest.InspectContainer(name)
Expect(data).To(HaveLen(1))
Expect(data[0].Config.Env).To(ContainElement(Equal(secretName + "=*******")))
})
})

1 comment on commit f4a08f4

@packit-as-a-service
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

podman-next COPR build failed. @containers/packit-build please check.

Please sign in to comment.