E4FE Merge pull request #14281 from vrothberg/fix-14251 · containers/podman@7d00b0e · GitHub
[go: up one dir, main page]

Skip to content

Commit 7d00b0e

Browse files
Merge pull request #14281 from vrothberg/fix-14251
fix --init with /dev bind mount
2 parents be25528 + 633d5f1 commit 7d00b0e

File tree

7 files changed

+26
-19
lines changed

7 files changed

+26
-19
lines changed

docs/source/markdown/podman-create.1.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,8 @@ content that disappears when the container is stopped.
460460
#### **--init**
461461

462462
Run an init inside the container that forwards signals and reaps processes.
463+
The container-init binary is mounted at `/run/podman-init`.
464+
Mounting over `/run` will hence break container execution.
463465

464466
#### **--init-ctr**=*type* (pods only)
465467

docs/source/markdown/podman-run.1.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,8 @@ content that disappears when the container is stopped.
498498
#### **--init**
499499

500500
Run an init inside the container that forwards signals and reaps processes.
501+
The container-init binary is mounted at `/run/podman-init`.
502+
Mounting over `/run` will hence break container execution.
501503

502504
#### **--init-path**=*path*
503505

libpod/define/container.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,6 @@ const (
3535
// OneShotInitContainer is a container that only runs as init once
3636
// and is then deleted.
3737
OneShotInitContainer = "once"
38+
// ContainerInitPath is the default path of the mounted container init.
39+
ContainerInitPath = "/run/podman-init"
3840
)

libpod/diff.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ import (
88
)
99

1010
var initInodes = map[string]bool{
11-
"/dev": true,
12-
"/etc/hostname": true,
13-
"/etc/hosts": true,
14-
"/etc/resolv.conf": true,
15-
"/proc": true,
16-
"/run": true,
17-
"/run/notify": true,
18-
"/run/.containerenv": true,
19-
"/run/secrets": true,
20-
"/sys": true,
21-
"/etc/mtab": true,
11+
"/dev": true,
12+
"/etc/hostname": true,
13+
"/etc/hosts": true,
14+
"/etc/resolv.conf": true,
15+
"/proc": true,
16+
"/run": true,
17+
"/run/notify": true,
18+
"/run/.containerenv": true,
19+
"/run/secrets": true,
20+
define.ContainerInitPath: true,
21+
"/sys": true,
22+
"/etc/mtab": true,
2223
}
2324

2425
// GetDiff returns the differences between the two images, layers, or containers

pkg/specgen/generate/oci.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func makeCommand(s *specgen.SpecGenerator, imageData *libimage.ImageData, rtc *c
128128
if initPath == "" {
129129
return nil, errors.Errorf("no path to init binary found but container requested an init")
130130
}
131-
finalCommand = append([]string{"/dev/init", "--"}, finalCommand...)
131+
finalCommand = append([]string{define.ContainerInitPath, "--"}, finalCommand...)
132132
}
133133

134134
return finalCommand, nil

pkg/specgen/generate/storage.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ import (
2020
"github.com/sirupsen/logrus"
2121
)
2222

23-
var (
24-
errDuplicateDest = errors.Errorf("duplicate mount destination")
25-
)
23+
var errDuplicateDest = errors.Errorf("duplicate mount destination")
2624

2725
// Produce final mounts and named volumes for a container
2826
func finalizeMounts(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runtime, rtc *config.Config, img *libimage.Image) ([]spec.Mount, []*specgen.NamedVolume, []*specgen.OverlayVolume, error) {
@@ -359,7 +357,7 @@ func getVolumesFrom(volumesFrom []string, runtime *libpod.Runtime) (map[string]s
359357
// This does *NOT* modify the container command - that must be done elsewhere.
360358
func addContainerInitBinary(s *specgen.SpecGenerator, path string) (spec.Mount, error) {
361359
mount := spec.Mount{
362-
Destination: "/dev/init",
360+
Destination: define.ContainerInitPath,
363361
Type: define.TypeBind,
364362
Source: path,
365363
Options: []string{define.TypeBind, "ro"},

test/e2e/run_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"time"
1414

1515
"github.com/containers/common/pkg/cgroups"
16+
"github.com/containers/podman/v4/libpod/define"
1617
"github.com/containers/podman/v4/pkg/rootless"
1718
. "github.com/containers/podman/v4/test/utils"
1819
"github.com/containers/storage/pkg/stringid"
@@ -286,19 +287,20 @@ var _ = Describe("Podman run", func() {
286287
result.WaitWithDefaultTimeout()
287288
Expect(result).Should(Exit(0))
288289
conData := result.InspectContainerToJSON()
289-
Expect(conData[0]).To(HaveField("Path", "/dev/init"))
290+
Expect(conData[0]).To(HaveField("Path", define.ContainerInitPath))
290291
Expect(conData[0].Config.Annotations).To(HaveKeyWithValue("io.podman.annotations.init", "TRUE"))
291292
})
292293

293294
It("podman run a container with --init and --init-path", func() {
294-
session := podmanTest.Podman([]string{"run", "--name", "test", "--init", "--init-path", "/usr/libexec/podman/catatonit", ALPINE, "ls"})
295+
// Also bind-mount /dev (#14251).
296+
session := podmanTest.Podman([]string{"run", "-v", "/dev:/dev", "--name", "test", "--init", "--init-path", "/usr/libexec/podman/catatonit", ALPINE, "ls"})
295297
session.WaitWithDefaultTimeout()
296298
Expect(session).Should(Exit(0))
297299
result := podmanTest.Podman([]string{"inspect", "test"})
298300
result.WaitWithDefaultTimeout()
299301
Expect(result).Should(Exit(0))
300302
conData := result.InspectContainerToJSON()
301-
Expect(conData[0]).To(HaveField("Path", "/dev/init"))
303+
Expect(conData[0]).To(HaveField("Path", define.ContainerInitPath))
302304
Expect(conData[0].Config.Annotations).To(HaveKeyWithValue("io.podman.annotations.init", "TRUE"))
303305
})
304306

0 commit comments

Comments
 (0)
0