Skip to content

Commit

Permalink
libpod: hides env secrets from container inspect
Browse files Browse the repository at this point in the history
Replaces env values supplied from podman secrets,
returns ******* instead

Fixes: containers#23788

Signed-off-by: Rafael Passos <rafael@rcpassos.me>
  • Loading branch information
auyer committed Sep 17, 2024
1 parent fdb8b1c commit a5e9b4d
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 + "=*******")))
})
})

0 comments on commit a5e9b4d

Please sign in to comment.