Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/api: do not leak config pointers into specgen #23428

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions pkg/api/handlers/libpod/containers_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

Expand Down
13 changes: 13 additions & 0 deletions test/apiv2/25-containersMore.at
Original file line number Diff line number Diff line change
Expand Up @@ -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