mirror of https://github.com/containers/podman.git
API: use no_hosts from containers.conf
The API endpoints should properly honour the `no_hosts=true` setting in containers.conf. Fixes #13719 Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
parent
1d01815c10
commit
d8a902a167
|
@ -181,6 +181,7 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, rtc *c
|
||||||
Network: nsmode,
|
Network: nsmode,
|
||||||
PublishPorts: specPorts,
|
PublishPorts: specPorts,
|
||||||
NetworkOptions: netOpts,
|
NetworkOptions: netOpts,
|
||||||
|
NoHosts: rtc.Containers.NoHosts,
|
||||||
}
|
}
|
||||||
|
|
||||||
// network names
|
// network names
|
||||||
|
|
|
@ -18,7 +18,18 @@ import (
|
||||||
// the new container ID on success along with any warnings.
|
// the new container ID on success along with any warnings.
|
||||||
func CreateContainer(w http.ResponseWriter, r *http.Request) {
|
func CreateContainer(w http.ResponseWriter, r *http.Request) {
|
||||||
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
|
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
|
||||||
var sg specgen.SpecGenerator
|
conf, err := runtime.GetConfigNoCopy()
|
||||||
|
if err != nil {
|
||||||
|
utils.InternalServerError(w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
if err := json.NewDecoder(r.Body).Decode(&sg); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&sg); err != nil {
|
||||||
utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "Decode()"))
|
utils.Error(w, http.StatusInternalServerError, errors.Wrap(err, "Decode()"))
|
||||||
|
|
|
@ -467,7 +467,13 @@ type ContainerNetworkConfig struct {
|
||||||
// UseImageHosts indicates that /etc/hosts should not be managed by
|
// UseImageHosts indicates that /etc/hosts should not be managed by
|
||||||
// Podman, and instead sourced from the image.
|
// Podman, and instead sourced from the image.
|
||||||
// Conflicts with HostAdd.
|
// Conflicts with HostAdd.
|
||||||
UseImageHosts bool `json:"use_image_hosts,omitempty"`
|
// Do not set omitempty here, if this is false it should be set to not get
|
||||||
|
// the server default.
|
||||||
|
// Ideally this would be a pointer so we could differentiate between an
|
||||||
|
// explicitly false/true and unset (containers.conf default). However
|
||||||
|
// specgen is stable so we can not change this right now.
|
||||||
|
// TODO (5.0): change to pointer
|
||||||
|
UseImageHosts bool `json:"use_image_hosts"`
|
||||||
// HostAdd is a set of hosts which will be added to the container's
|
// HostAdd is a set of hosts which will be added to the container's
|
||||||
// /etc/hosts file.
|
// /etc/hosts file.
|
||||||
// Conflicts with UseImageHosts.
|
// Conflicts with UseImageHosts.
|
||||||
|
|
|
@ -447,3 +447,46 @@ t GET images/$iid/json 200 \
|
||||||
|
|
||||||
t DELETE containers/$cid 204
|
t DELETE containers/$cid 204
|
||||||
t DELETE images/docker.io/library/newrepo:v3?force=false 200
|
t DELETE images/docker.io/library/newrepo:v3?force=false 200
|
||||||
|
|
||||||
|
# test create without default no_hosts
|
||||||
|
t POST containers/create \
|
||||||
|
Image=$IMAGE \
|
||||||
|
201 \
|
||||||
|
.Id~[0-9a-f]\\{64\\}
|
||||||
|
cid=$(jq -r '.Id' <<<"$output")
|
||||||
|
|
||||||
|
t POST libpod/containers/$cid/init 204
|
||||||
|
|
||||||
|
t GET libpod/containers/$cid/json 200
|
||||||
|
|
||||||
|
cpid_file=$(jq -r '.ConmonPidFile' <<<"$output")
|
||||||
|
userdata_path=$(dirname $cpid_file)
|
||||||
|
|
||||||
|
t GET libpod/containers/$cid/json 200 \
|
||||||
|
.HostsPath=$userdata_path/hosts
|
||||||
|
|
||||||
|
t DELETE containers/$cid 204
|
||||||
|
|
||||||
|
# test create with default no_hosts=true
|
||||||
|
stop_service
|
||||||
|
|
||||||
|
CONTAINERS_CONF=$TESTS_DIR/containers.no_hosts.conf start_service
|
||||||
|
|
||||||
|
# check docker and libpod endpoint
|
||||||
|
for endpoint in containers/create libpod/containers/create; do
|
||||||
|
t POST $endpoint \
|
||||||
|
Image=$IMAGE \
|
||||||
|
201 \
|
||||||
|
.Id~[0-9a-f]\\{64\\}
|
||||||
|
cid=$(jq -r '.Id' <<<"$output")
|
||||||
|
|
||||||
|
t POST libpod/containers/$cid/init 204
|
||||||
|
|
||||||
|
t GET libpod/containers/$cid/json 200 \
|
||||||
|
.HostsPath=""
|
||||||
|
|
||||||
|
t DELETE containers/$cid 204
|
||||||
|
done
|
||||||
|
|
||||||
|
stop_service
|
||||||
|
start_service
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
[containers]
|
||||||
|
no_hosts=true
|
Loading…
Reference in New Issue