Skip to content

Commit

Permalink
libpod: Detect whether we have a private UTS namespace on FreeBSD
Browse files Browse the repository at this point in the history
Right now, we always use a private UTS namespace on FreeBSD. This should
be made optional but implementing that cleanly needs a FreeBSD extension
to the OCI runtime config. The process for that is starting
(opencontainers/tob#133) but in the meantime,
assume that the UTS namespace is private on FreeBSD.

This moves the Linux-specific namespace logic to
container_internal_linux.go and adds a FreeBSD stub.

[NO NEW TESTS NEEDED]

Signed-off-by: Doug Rabson <[email protected]>
  • Loading branch information
dfr authored and openshift-cherrypick-robot committed Dec 1, 2023
1 parent 4635f40 commit 6bbbfaa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
10 changes: 1 addition & 9 deletions libpod/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,15 +688,7 @@ func (c *Container) Hostname() string {

// if the container is not running in a private UTS namespace,
// return the host's hostname.
privateUTS := false
if c.config.Spec.Linux != nil {
for _, ns := range c.config.Spec.Linux.Namespaces {
if ns.Type == spec.UTSNamespace {
privateUTS = true
break
}
}
}
privateUTS := c.hasPrivateUTS()
if !privateUTS {
hostname, err := os.Hostname()
if err == nil {
Expand Down
7 changes: 7 additions & 0 deletions libpod/container_internal_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,10 @@ func (c *Container) getPlatformRunPath() (string, error) {
func (c *Container) addMaskedPaths(g *generate.Generator) {
// There are currently no FreeBSD-specific masked paths
}

func (c *Container) hasPrivateUTS() bool {
// Currently we always use a private UTS namespace on FreeBSD. This
// should be optional but needs a FreeBSD section in the OCI runtime
// specification.
return true
}
13 changes: 13 additions & 0 deletions libpod/container_internal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,3 +811,16 @@ func (c *Container) addMaskedPaths(g *generate.Generator) {
g.AddLinuxMaskedPaths("/sys/devices/virtual/powercap")
}
}

func (c *Container) hasPrivateUTS() bool {
privateUTS := false
if c.config.Spec.Linux != nil {
for _, ns := range c.config.Spec.Linux.Namespaces {
if ns.Type == spec.UTSNamespace {
privateUTS = true
break
}
}
}
return privateUTS
}

0 comments on commit 6bbbfaa

Please sign in to comment.