Merge pull request #23428 from Luap99/config-clone

pkg/api: do not leak config pointers into specgen
This commit is contained in:
openshift-merge-bot[bot] 2024-07-29 19:09:01 +00:00 committed by GitHub
commit 2316d914b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 2 deletions

View File

@ -27,14 +27,18 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) {
return
}
// copy vars here and not leak config pointers into specgen
noHosts := conf.Containers.NoHosts
privileged := conf.Containers.Privileged
// we have to set the default before we decode to make sure the correct default is set when the field is unset
sg := specgen.SpecGenerator{
ContainerNetworkConfig: specgen.ContainerNetworkConfig{
UseImageHosts: &conf.Containers.NoHosts,
UseImageHosts: &noHosts,
},
ContainerSecurityConfig: specgen.ContainerSecurityConfig{
Umask: conf.Containers.Umask,
Privileged: &conf.Containers.Privileged,
Privileged: &privileged,
},
}

View File

@ -86,4 +86,17 @@ podman run $IMAGE true
t POST libpod/containers/prune 200
t GET libpod/containers/json 200 \
length=0
# check the config options are not overwritten by acceident
t POST libpod/containers/create name=test1 image=$IMAGE privileged=true 201
t GET libpod/containers/test1/json 200 \
.HostConfig.Annotations.'"io.podman.annotations.privileged"'="TRUE"
# now the same without privileged it should not inhert the privileged from before
t POST libpod/containers/create name=test2 image=$IMAGE 201
t GET libpod/containers/test2/json 200 \
.HostConfig.Annotations=null
podman rm test1 test2
# vim: filetype=sh