mirror of https://github.com/containers/podman.git
Merge pull request #16739 from giuseppe/no-chown-idmap
runtime: do not chown idmapped volumes
This commit is contained in:
commit
41af424cd8
|
@ -495,16 +495,21 @@ func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (_ *Contai
|
||||||
logrus.Debugf("Creating new volume %s for container", vol.Name)
|
logrus.Debugf("Creating new volume %s for container", vol.Name)
|
||||||
|
|
||||||
// The volume does not exist, so we need to create it.
|
// The volume does not exist, so we need to create it.
|
||||||
volOptions := []VolumeCreateOption{WithVolumeName(vol.Name), WithVolumeUID(ctr.RootUID()), WithVolumeGID(ctr.RootGID())}
|
volOptions := []VolumeCreateOption{WithVolumeName(vol.Name)}
|
||||||
if isAnonymous {
|
if isAnonymous {
|
||||||
volOptions = append(volOptions, withSetAnon())
|
volOptions = append(volOptions, withSetAnon())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
needsChown := true
|
||||||
|
|
||||||
// If volume-opts are set parse and add driver opts.
|
// If volume-opts are set parse and add driver opts.
|
||||||
if len(vol.Options) > 0 {
|
if len(vol.Options) > 0 {
|
||||||
isDriverOpts := false
|
isDriverOpts := false
|
||||||
driverOpts := make(map[string]string)
|
driverOpts := make(map[string]string)
|
||||||
for _, opts := range vol.Options {
|
for _, opts := range vol.Options {
|
||||||
|
if opts == "idmap" {
|
||||||
|
needsChown = false
|
||||||
|
}
|
||||||
if strings.HasPrefix(opts, "volume-opt") {
|
if strings.HasPrefix(opts, "volume-opt") {
|
||||||
isDriverOpts = true
|
isDriverOpts = true
|
||||||
driverOptKey, driverOptValue, err := util.ParseDriverOpts(opts)
|
driverOptKey, driverOptValue, err := util.ParseDriverOpts(opts)
|
||||||
|
@ -519,6 +524,13 @@ func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (_ *Contai
|
||||||
volOptions = append(volOptions, parsedOptions...)
|
volOptions = append(volOptions, parsedOptions...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if needsChown {
|
||||||
|
volOptions = append(volOptions, WithVolumeUID(ctr.RootUID()), WithVolumeGID(ctr.RootGID()))
|
||||||
|
} else {
|
||||||
|
volOptions = append(volOptions, WithVolumeNoChown())
|
||||||
|
}
|
||||||
|
|
||||||
newVol, err := r.newVolume(ctx, false, volOptions...)
|
newVol, err := r.newVolume(ctx, false, volOptions...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("creating named volume %q: %w", vol.Name, err)
|
return nil, fmt.Errorf("creating named volume %q: %w", vol.Name, err)
|
||||||
|
|
|
@ -109,13 +109,13 @@ var _ = Describe("Podman UserNS support", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman uidmapping and gidmapping with an idmapped volume", func() {
|
It("podman uidmapping and gidmapping with an idmapped volume", func() {
|
||||||
session := podmanTest.Podman([]string{"run", "--uidmap=0:1:500", "--gidmap=0:200:5000", "-v", "my-foo-volume:/foo:Z,idmap", "alpine", "echo", "hello"})
|
session := podmanTest.Podman([]string{"run", "--uidmap=0:1:500", "--gidmap=0:200:5000", "-v", "my-foo-volume:/foo:Z,idmap", "alpine", "stat", "-c", "#%u:%g#", "/foo"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
if strings.Contains(session.ErrorToString(), "Operation not permitted") {
|
if strings.Contains(session.ErrorToString(), "Operation not permitted") {
|
||||||
Skip("not sufficiently privileged")
|
Skip("not sufficiently privileged")
|
||||||
}
|
}
|
||||||
Expect(session).Should(Exit(0))
|
Expect(session).Should(Exit(0))
|
||||||
Expect(session.OutputToString()).To(ContainSubstring("hello"))
|
Expect(session.OutputToString()).To(ContainSubstring("#0:0#"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman uidmapping and gidmapping --net=host", func() {
|
It("podman uidmapping and gidmapping --net=host", func() {
|
||||||
|
|
Loading…
Reference in New Issue