aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.cirrus.yml2
-rw-r--r--cmd/podman/generate/systemd.go13
-rw-r--r--cmd/podman/system/events.go4
-rw-r--r--docs/source/markdown/options/device.md14
-rw-r--r--docs/source/markdown/podman-attach.1.md2
-rw-r--r--docs/source/markdown/podman-auto-update.1.md.in2
-rw-r--r--docs/source/markdown/podman-build.1.md.in36
-rw-r--r--docs/source/markdown/podman-commit.1.md2
-rw-r--r--docs/source/markdown/podman-completion.1.md2
-rw-r--r--docs/source/markdown/podman-container-checkpoint.1.md2
-rw-r--r--docs/source/markdown/podman-container-cleanup.1.md2
-rw-r--r--docs/source/markdown/podman-container-clone.1.md.in27
-rw-r--r--docs/source/markdown/podman-container-diff.1.md2
-rw-r--r--docs/source/markdown/podman-container-exists.1.md2
-rw-r--r--docs/source/markdown/podman-container-inspect.1.md2
-rw-r--r--docs/source/markdown/podman-container-prune.1.md2
-rw-r--r--docs/source/markdown/podman-container-restore.1.md2
-rw-r--r--docs/source/markdown/podman-container-runlabel.1.md.in2
-rw-r--r--docs/source/markdown/podman-container.1.md2
-rw-r--r--docs/source/markdown/podman-cp.1.md2
-rw-r--r--docs/source/markdown/podman-create.1.md.in17
-rw-r--r--docs/source/markdown/podman-diff.1.md2
-rw-r--r--docs/source/markdown/podman-events.1.md2
-rw-r--r--docs/source/markdown/podman-exec.1.md.in2
-rw-r--r--docs/source/markdown/podman-export.1.md2
-rw-r--r--docs/source/markdown/podman-generate-spec.1.md2
-rw-r--r--docs/source/markdown/podman-generate-systemd.1.md8
-rw-r--r--docs/source/markdown/podman-generate.1.md2
-rw-r--r--docs/source/markdown/podman-healthcheck-run.1.md2
-rw-r--r--docs/source/markdown/podman-healthcheck.1.md2
-rw-r--r--docs/source/markdown/podman-history.1.md2
-rw-r--r--docs/source/markdown/podman-image-diff.1.md2
-rw-r--r--docs/source/markdown/podman-image-exists.1.md2
-rw-r--r--docs/source/markdown/podman-image-inspect.1.md2
-rw-r--r--docs/source/markdown/podman-image-mount.1.md2
-rw-r--r--docs/source/markdown/podman-image-prune.1.md2
-rw-r--r--docs/source/markdown/podman-image-scp.1.md2
-rw-r--r--docs/source/markdown/podman-image-sign.1.md.in2
-rw-r--r--docs/source/markdown/podman-image-tree.1.md2
-rw-r--r--docs/source/markdown/podman-image-trust.1.md2
-rw-r--r--docs/source/markdown/podman-image-unmount.1.md2
-rw-r--r--docs/source/markdown/podman-image.1.md2
-rw-r--r--docs/source/markdown/podman-images.1.md2
-rw-r--r--docs/source/markdown/podman-import.1.md2
-rw-r--r--docs/source/markdown/podman-info.1.md2
-rw-r--r--docs/source/markdown/podman-init.1.md2
-rw-r--r--docs/source/markdown/podman-inspect.1.md2
-rw-r--r--docs/source/markdown/podman-kill.1.md.in2
-rw-r--r--docs/source/markdown/podman-kube-down.1.md2
-rw-r--r--docs/source/markdown/podman-kube-play.1.md.in2
-rw-r--r--docs/source/markdown/podman-kube.1.md2
-rw-r--r--docs/source/markdown/podman-load.1.md2
-rw-r--r--docs/source/markdown/podman-login.1.md.in2
-rw-r--r--docs/source/markdown/podman-logout.1.md.in2
-rw-r--r--docs/source/markdown/podman-logs.1.md.in2
-rw-r--r--docs/source/markdown/podman-machine-info.1.md2
-rw-r--r--docs/source/markdown/podman-machine-init.1.md2
-rw-r--r--docs/source/markdown/podman-machine-inspect.1.md2
-rw-r--r--docs/source/markdown/podman-machine-list.1.md2
-rw-r--r--docs/source/markdown/podman-machine-rm.1.md2
-rw-r--r--docs/source/markdown/podman-machine-set.1.md2
-rw-r--r--docs/source/markdown/podman-machine-ssh.1.md2
-rw-r--r--docs/source/markdown/podman-machine-start.1.md2
-rw-r--r--docs/source/markdown/podman-machine-stop.1.md2
-rw-r--r--docs/source/markdown/podman-machine.1.md2
-rw-r--r--docs/source/markdown/podman-manifest-add.1.md.in2
-rw-r--r--docs/source/markdown/podman-manifest-annotate.1.md2
-rw-r--r--docs/source/markdown/podman-manifest-create.1.md2
-rw-r--r--docs/source/markdown/podman-manifest-exists.1.md2
-rw-r--r--docs/source/markdown/podman-manifest-inspect.1.md2
-rw-r--r--docs/source/markdown/podman-manifest-push.1.md.in2
-rw-r--r--docs/source/markdown/podman-manifest-remove.1.md2
-rw-r--r--docs/source/markdown/podman-manifest.1.md2
-rw-r--r--docs/source/markdown/podman-mount.1.md2
-rw-r--r--docs/source/markdown/podman-network-connect.1.md2
-rw-r--r--docs/source/markdown/podman-network-create.1.md2
-rw-r--r--docs/source/markdown/podman-network-disconnect.1.md2
-rw-r--r--docs/source/markdown/podman-network-exists.1.md2
-rw-r--r--docs/source/markdown/podman-network-inspect.1.md2
-rw-r--r--docs/source/markdown/podman-network-ls.1.md2
-rw-r--r--docs/source/markdown/podman-network-prune.1.md2
-rw-r--r--docs/source/markdown/podman-network-reload.1.md2
-rw-r--r--docs/source/markdown/podman-network-rm.1.md2
-rw-r--r--docs/source/markdown/podman-network.1.md2
-rw-r--r--docs/source/markdown/podman-pause.1.md.in2
-rw-r--r--docs/source/markdown/podman-pod-clone.1.md.in38
-rw-r--r--docs/source/markdown/podman-pod-create.1.md.in38
-rw-r--r--docs/source/markdown/podman-pod-exists.1.md2
-rw-r--r--docs/source/markdown/podman-pod-inspect.1.md2
-rw-r--r--docs/source/markdown/podman-pod-kill.1.md.in2
-rw-r--r--docs/source/markdown/podman-pod-logs.1.md.in2
-rw-r--r--docs/source/markdown/podman-pod-pause.1.md2
-rw-r--r--docs/source/markdown/podman-pod-prune.1.md2
-rw-r--r--docs/source/markdown/podman-pod-ps.1.md2
-rw-r--r--docs/source/markdown/podman-pod-restart.1.md2
-rw-r--r--docs/source/markdown/podman-pod-rm.1.md.in2
-rw-r--r--docs/source/markdown/podman-pod-start.1.md.in2
-rw-r--r--docs/source/markdown/podman-pod-stats.1.md2
-rw-r--r--docs/source/markdown/podman-pod-stop.1.md.in2
-rw-r--r--docs/source/markdown/podman-pod-top.1.md2
-rw-r--r--docs/source/markdown/podman-pod-unpause.1.md2
-rw-r--r--docs/source/markdown/podman-pod.1.md2
-rw-r--r--docs/source/markdown/podman-port.1.md2
-rw-r--r--docs/source/markdown/podman-ps.1.md2
-rw-r--r--docs/source/markdown/podman-pull.1.md.in2
-rw-r--r--docs/source/markdown/podman-push.1.md.in2
-rw-r--r--docs/source/markdown/podman-remote.1.md2
-rw-r--r--docs/source/markdown/podman-rename.1.md2
-rw-r--r--docs/source/markdown/podman-restart.1.md2
-rw-r--r--docs/source/markdown/podman-rm.1.md.in2
-rw-r--r--docs/source/markdown/podman-rmi.1.md2
-rw-r--r--docs/source/markdown/podman-run.1.md.in27
-rw-r--r--docs/source/markdown/podman-save.1.md2
-rw-r--r--docs/source/markdown/podman-search.1.md.in2
-rw-r--r--docs/source/markdown/podman-secret-create.1.md2
-rw-r--r--docs/source/markdown/podman-secret-inspect.1.md2
-rw-r--r--docs/source/markdown/podman-secret-ls.1.md2
-rw-r--r--docs/source/markdown/podman-secret-rm.1.md2
-rw-r--r--docs/source/markdown/podman-secret.1.md2
-rw-r--r--docs/source/markdown/podman-start.1.md2
-rw-r--r--docs/source/markdown/podman-stats.1.md2
-rw-r--r--docs/source/markdown/podman-stop.1.md.in2
-rw-r--r--docs/source/markdown/podman-system-connection-add.1.md2
-rw-r--r--docs/source/markdown/podman-system-connection-default.1.md2
-rw-r--r--docs/source/markdown/podman-system-connection-list.1.md2
-rw-r--r--docs/source/markdown/podman-system-connection-remove.1.md2
-rw-r--r--docs/source/markdown/podman-system-connection-rename.1.md2
-rw-r--r--docs/source/markdown/podman-system-connection.1.md2
-rw-r--r--docs/source/markdown/podman-system-df.1.md2
-rw-r--r--docs/source/markdown/podman-system-migrate.1.md2
-rw-r--r--docs/source/markdown/podman-system-prune.1.md2
-rw-r--r--docs/source/markdown/podman-system-renumber.1.md2
-rw-r--r--docs/source/markdown/podman-system-reset.1.md2
-rw-r--r--docs/source/markdown/podman-system-service.1.md2
-rw-r--r--docs/source/markdown/podman-system.1.md2
-rw-r--r--docs/source/markdown/podman-tag.1.md2
-rw-r--r--docs/source/markdown/podman-top.1.md2
-rw-r--r--docs/source/markdown/podman-unmount.1.md2
-rw-r--r--docs/source/markdown/podman-unpause.1.md.in2
-rw-r--r--docs/source/markdown/podman-unshare.1.md2
-rw-r--r--docs/source/markdown/podman-untag.1.md2
-rw-r--r--docs/source/markdown/podman-update.1.md.in2
-rw-r--r--docs/source/markdown/podman-version.1.md2
-rw-r--r--docs/source/markdown/podman-volume-create.1.md2
-rw-r--r--docs/source/markdown/podman-volume-exists.1.md2
-rw-r--r--docs/source/markdown/podman-volume-export.1.md2
-rw-r--r--docs/source/markdown/podman-volume-import.1.md2
-rw-r--r--docs/source/markdown/podman-volume-inspect.1.md2
-rw-r--r--docs/source/markdown/podman-volume-ls.1.md2
-rw-r--r--docs/source/markdown/podman-volume-mount.1.md2
-rw-r--r--docs/source/markdown/podman-volume-prune.1.md2
-rw-r--r--docs/source/markdown/podman-volume-reload.1.md2
-rw-r--r--docs/source/markdown/podman-volume-rm.1.md2
-rw-r--r--docs/source/markdown/podman-volume-unmount.1.md2
-rw-r--r--docs/source/markdown/podman-volume.1.md2
-rw-r--r--docs/source/markdown/podman-wait.1.md2
-rw-r--r--docs/source/markdown/podman.1.md2
-rw-r--r--go.mod2
-rw-r--r--go.sum4
-rw-r--r--libpod/container.go14
-rw-r--r--libpod/container_freebsd.go10
-rw-r--r--libpod/container_internal_common.go2699
-rw-r--r--libpod/container_internal_freebsd.go285
-rw-r--r--libpod/container_internal_linux.go3014
-rw-r--r--libpod/container_internal_unsupported.go4
-rw-r--r--libpod/container_linux.go15
-rw-r--r--libpod/networking_unsupported.go5
-rw-r--r--libpod/runtime_ctr.go17
-rw-r--r--libpod/runtime_ctr_freebsd.go5
-rw-r--r--libpod/runtime_ctr_linux.go5
-rw-r--r--pkg/api/handlers/libpod/generate.go58
-rw-r--r--pkg/api/server/register_generate.go7
-rw-r--r--pkg/bindings/generate/types.go2
-rw-r--r--pkg/bindings/generate/types_systemd_options.go15
-rw-r--r--pkg/domain/entities/generate.go43
-rw-r--r--pkg/domain/infra/tunnel/generate.go3
-rw-r--r--pkg/machine/wsl/machine.go1
-rw-r--r--pkg/systemd/generate/containers.go147
-rw-r--r--pkg/systemd/generate/containers_test.go48
-rw-r--r--pkg/util/utils_freebsd.go6
-rw-r--r--test/e2e/events_test.go16
-rw-r--r--test/e2e/generate_systemd_test.go71
-rw-r--r--test/system/255-auto-update.bats6
-rw-r--r--test/system/500-networking.bats4
-rw-r--r--vendor/github.com/container-orchestrated-devices/container-device-interface/pkg/cdi/cache.go6
-rw-r--r--vendor/github.com/container-orchestrated-devices/container-device-interface/pkg/cdi/spec-dirs.go7
-rw-r--r--vendor/modules.txt2
187 files changed, 3724 insertions, 3313 deletions
diff --git a/.cirrus.yml b/.cirrus.yml
index 628b74f72..dc0735836 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -61,7 +61,7 @@ env:
# Curl-command prefix for downloading task artifacts, simply add the
# the url-encoded task name, artifact name, and path as a suffix.
ARTCURL: >-
- curl --fail --location -O
+ curl --retry 5 --retry-delay 8 --fail --location -O
--url https://api.cirrus-ci.com/v1/artifact/build/${CIRRUS_BUILD_ID}
diff --git a/cmd/podman/generate/systemd.go b/cmd/podman/generate/systemd.go
index e40416534..a7cdd9bfe 100644
--- a/cmd/podman/generate/systemd.go
+++ b/cmd/podman/generate/systemd.go
@@ -13,6 +13,7 @@ import (
"github.com/containers/podman/v4/cmd/podman/registry"
"github.com/containers/podman/v4/cmd/podman/utils"
"github.com/containers/podman/v4/pkg/domain/entities"
+ envLib "github.com/containers/podman/v4/pkg/env"
systemDefine "github.com/containers/podman/v4/pkg/systemd/define"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
@@ -28,9 +29,11 @@ const (
wantsFlagName = "wants"
afterFlagName = "after"
requiresFlagName = "requires"
+ envFlagName = "env"
)
var (
+ envInput []string
files bool
format string
systemdRestart string
@@ -109,6 +112,9 @@ func init() {
flags.StringArrayVar(&systemdOptions.Requires, requiresFlagName, nil, "Similar to wants, but declares stronger requirement dependencies")
_ = systemdCmd.RegisterFlagCompletionFunc(requiresFlagName, completion.AutocompleteNone)
+ flags.StringArrayVarP(&envInput, envFlagName, "e", nil, "Set environment variables to the systemd unit files")
+ _ = systemdCmd.RegisterFlagCompletionFunc(envFlagName, completion.AutocompleteNone)
+
flags.SetNormalizeFunc(utils.TimeoutAliasFlags)
}
@@ -141,6 +147,13 @@ func systemd(cmd *cobra.Command, args []string) error {
if cmd.Flags().Changed(stopTimeoutCompatFlagName) {
setStopTimeout++
}
+ if cmd.Flags().Changed(envFlagName) {
+ cliEnv, err := envLib.ParseSlice(envInput)
+ if err != nil {
+ return fmt.Errorf("error parsing environment variables: %w", err)
+ }
+ systemdOptions.AdditionalEnvVariables = envLib.Slice(cliEnv)
+ }
switch setStopTimeout {
case 1:
systemdOptions.StopTimeout = &stopTimeout
diff --git a/cmd/podman/system/events.go b/cmd/podman/system/events.go
index b04668f86..3c6a35e83 100644
--- a/cmd/podman/system/events.go
+++ b/cmd/podman/system/events.go
@@ -85,7 +85,9 @@ func eventsCmd(cmd *cobra.Command, _ []string) error {
doJSON = report.IsJSON(eventFormat)
if !doJSON {
var err error
- rpt, err = report.New(os.Stdout, cmd.Name()).Parse(report.OriginUser, eventFormat)
+ // Use OriginUnknown so it does not add an extra range since it
+ // will only be called for each single element and not a slice.
+ rpt, err = report.New(os.Stdout, cmd.Name()).Parse(report.OriginUnknown, eventFormat)
if err != nil {
return err
}
diff --git a/docs/source/markdown/options/device.md b/docs/source/markdown/options/device.md
new file mode 100644
index 000000000..619c70a9b
--- /dev/null
+++ b/docs/source/markdown/options/device.md
@@ -0,0 +1,14 @@
+#### **--device**=*host-device[:container-device][:permissions]*
+
+Add a host device to the <<container|pod>>. Optional *permissions* parameter
+can be used to specify device permissions by combining
+**r** for read, **w** for write, and **m** for **mknod**(2).
+
+Example: **--device=/dev/sdc:/dev/xvdc:rwm**.
+
+Note: if *host-device* is a symbolic link then it will be resolved first.
+The <<container|pod>> will only store the major and minor numbers of the host device.
+
+Podman may load kernel modules required for using the specified
+device. The devices that Podman will load modules for when necessary are:
+/dev/fuse.
diff --git a/docs/source/markdown/podman-attach.1.md b/docs/source/markdown/podman-attach.1.md
index 985cfa0e8..c073fccf8 100644
--- a/docs/source/markdown/podman-attach.1.md
+++ b/docs/source/markdown/podman-attach.1.md
@@ -1,4 +1,4 @@
-% podman-attach(1)
+% podman-attach 1
## NAME
podman\-attach - Attach to a running container
diff --git a/docs/source/markdown/podman-auto-update.1.md.in b/docs/source/markdown/podman-auto-update.1.md.in
index b724f1157..cd9a08a78 100644
--- a/docs/source/markdown/podman-auto-update.1.md.in
+++ b/docs/source/markdown/podman-auto-update.1.md.in
@@ -1,4 +1,4 @@
-% podman-auto-update(1)
+% podman-auto-update 1
## NAME
podman\-auto-update - Auto update containers according to their auto-update policy
diff --git a/docs/source/markdown/podman-build.1.md.in b/docs/source/markdown/podman-build.1.md.in
index 5b05cc5c9..63b587687 100644
--- a/docs/source/markdown/podman-build.1.md.in
+++ b/docs/source/markdown/podman-build.1.md.in
@@ -1,4 +1,4 @@
-% podman-build(1)
+% podman-build 1
## NAME
podman\-build - Build a container image using a Containerfile
@@ -205,16 +205,7 @@ keys and/or certificates. Decryption will be tried with all keys. If the key is
protected by a passphrase, it is required to be passed in the argument and
omitted otherwise.
-#### **--device**=*host-device[:container-device][:permissions]*
-
-Add a host device to the container. Optional *permissions* parameter
-can be used to specify device permissions, it is combination of
-**r** for read, **w** for write, and **m** for **mknod**(2).
-
-Example: **--device=/dev/sdc:/dev/xvdc:rwm**.
-
-Note: if *host-device* is a symbolic link then it will be resolved first.
-The container will only store the major and minor numbers of the host device.
+@@option device
Note: if the user only has access rights via a group, accessing the device
from inside a rootless container will fail. The **[crun(1)](https://github.com/containers/crun/tree/main/crun.1.md)** runtime offers a
@@ -391,28 +382,9 @@ This option is not supported on the remote client, including Mac and Windows
Name of the manifest list to which the image will be added. Creates the manifest list
if it does not exist. This option is useful for building multi architecture images.
-#### **--memory**, **-m**=*LIMIT*
-
-Memory limit (format: `<number>[<unit>]`, where unit = b (bytes), k (kibibytes),
-m (mebibytes), or g (gibibytes))
-
-Allows you to constrain the memory available to a container. If the host
-supports swap memory, then the **-m** memory setting can be larger than physical
-RAM. If a limit of 0 is specified (not using **-m**), the container's memory is
-not limited. The actual limit may be rounded up to a multiple of the operating
-system's page size (the value would be very large, that's millions of
-trillions).
-
-#### **--memory-swap**=*LIMIT*
-
-A limit value equal to memory plus swap. Must be used with the **-m**
-(**--memory**) option. The swap `LIMIT` should always be larger than **-m**
-(**--memory**) value. By default, the swap `LIMIT` will be set to double
-the value of --memory.
+@@option memory
-The format of `LIMIT` is `<number>[<unit>]`. Unit can be `b` (bytes),
-`k` (kibibytes), `m` (mebibytes), or `g` (gibibytes). If you don't specify a
-unit, `b` is used. Set LIMIT to `-1` to enable unlimited swap.
+@@option memory-swap
#### **--network**=*mode*, **--net**
diff --git a/docs/source/markdown/podman-commit.1.md b/docs/source/markdown/podman-commit.1.md
index b7b52e3a7..82243c557 100644
--- a/docs/source/markdown/podman-commit.1.md
+++ b/docs/source/markdown/podman-commit.1.md
@@ -1,4 +1,4 @@
-% podman-commit(1)
+% podman-commit 1
## NAME
podman\-commit - Create new image based on the changed container
diff --git a/docs/source/markdown/podman-completion.1.md b/docs/source/markdown/podman-completion.1.md
index 538bb9e60..14e196587 100644
--- a/docs/source/markdown/podman-completion.1.md
+++ b/docs/source/markdown/podman-completion.1.md
@@ -1,4 +1,4 @@
-% podman-completion(1)
+% podman-completion 1
## NAME
podman\-completion - Generate shell completion scripts
diff --git a/docs/source/markdown/podman-container-checkpoint.1.md b/docs/source/markdown/podman-container-checkpoint.1.md
index a11897081..b68dffc8a 100644
--- a/docs/source/markdown/podman-container-checkpoint.1.md
+++ b/docs/source/markdown/podman-container-checkpoint.1.md
@@ -1,4 +1,4 @@
-% podman-container-checkpoint(1)
+% podman-container-checkpoint 1
## NAME
podman\-container\-checkpoint - Checkpoints one or more running containers
diff --git a/docs/source/markdown/podman-container-cleanup.1.md b/docs/source/markdown/podman-container-cleanup.1.md
index 0ad09efd3..744f7b41b 100644
--- a/docs/source/markdown/podman-container-cleanup.1.md
+++ b/docs/source/markdown/podman-container-cleanup.1.md
@@ -1,4 +1,4 @@
-% podman-container-cleanup(1)
+% podman-container-cleanup 1
## NAME
podman\-container\-cleanup - Clean up the container's network and mountpoints
diff --git a/docs/source/markdown/podman-container-clone.1.md.in b/docs/source/markdown/podman-container-clone.1.md.in
index 3e31389d2..d4add19fd 100644
--- a/docs/source/markdown/podman-container-clone.1.md.in
+++ b/docs/source/markdown/podman-container-clone.1.md.in
@@ -1,4 +1,4 @@
-% podman-container-clone(1)
+% podman-container-clone 1
## NAME
podman\-container\-clone - Creates a copy of an existing container
@@ -64,28 +64,15 @@ Force removal of the original container that we are cloning. Can only be used in
If no memory limits are specified, the original container's will be used.
-#### **--memory-reservation**=*limit*
+@@option memory-reservation
-Memory soft limit (format: `<number>[<unit>]`, where unit = b (bytes), k (kibibytes), m (mebibytes), or g (gibibytes))
+If unspecified, memory reservation will be the same as memory limit from the
+container being cloned.
-After setting memory reservation, when the system detects memory contention
-or low memory, containers are forced to restrict their consumption to their
-reservation. So you should always set the value below **--memory**, otherwise the
-hard limit will take precedence. By default, memory reservation will be the same
-as memory limit from the container being cloned.
+@@option memory-swap
-#### **--memory-swap**=*limit*
-
-A limit value equal to memory plus swap. Must be used with the **-m**
-(**--memory**) flag. The swap `LIMIT` should always be larger than **-m**
-(**--memory**) value. By default, the swap `LIMIT` will be set to double
-the value of --memory if specified. Otherwise, the container being cloned will be used to derive the swap value.
-
-The format of `LIMIT` is `<number>[<unit>]`. Unit can be `b` (bytes),
-`k` (kibibytes), `m` (mebibytes), or `g` (gibibytes). If you don't specify a
-unit, `b` is used. Set LIMIT to `-1` to enable unlimited swap.
-
-This option is not supported on cgroups V1 rootless systems.
+If unspecified, the container being cloned will be used to derive
+the swap value.
@@option memory-swappiness
diff --git a/docs/source/markdown/podman-container-diff.1.md b/docs/source/markdown/podman-container-diff.1.md
index f09bc4896..261c6f878 100644
--- a/docs/source/markdown/podman-container-diff.1.md
+++ b/docs/source/markdown/podman-container-diff.1.md
@@ -1,4 +1,4 @@
-% podman-container-diff(1)
+% podman-container-diff 1
## NAME
podman\-container\-diff - Inspect changes on a container's filesystem
diff --git a/docs/source/markdown/podman-container-exists.1.md b/docs/source/markdown/podman-container-exists.1.md
index cc5defe6b..49b74f1ee 100644
--- a/docs/source/markdown/podman-container-exists.1.md
+++ b/docs/source/markdown/podman-container-exists.1.md
@@ -1,4 +1,4 @@
-% podman-container-exists(1)
+% podman-container-exists 1
## NAME
podman\-container\-exists - Check if a container exists in local storage
diff --git a/docs/source/markdown/podman-container-inspect.1.md b/docs/source/markdown/podman-container-inspect.1.md
index 4e45bcc40..f92eea7bd 100644
--- a/docs/source/markdown/podman-container-inspect.1.md
+++ b/docs/source/markdown/podman-container-inspect.1.md
@@ -1,4 +1,4 @@
-% podman-container-inspect(1)
+% podman-container-inspect 1
## NAME
podman\-container\-inspect - Display a container's configuration
diff --git a/docs/source/markdown/podman-container-prune.1.md b/docs/source/markdown/podman-container-prune.1.md
index b20936c15..66519b96d 100644
--- a/docs/source/markdown/podman-container-prune.1.md
+++ b/docs/source/markdown/podman-container-prune.1.md
@@ -1,4 +1,4 @@
-% podman-container-prune(1)
+% podman-container-prune 1
## NAME
podman\-container\-prune - Remove all stopped containers from local storage
diff --git a/docs/source/markdown/podman-container-restore.1.md b/docs/source/markdown/podman-container-restore.1.md
index a70cc30d1..a5347fa48 100644
--- a/docs/source/markdown/podman-container-restore.1.md
+++ b/docs/source/markdown/podman-container-restore.1.md
@@ -1,4 +1,4 @@
-% podman-container-restore(1)
+% podman-container-restore 1
## NAME
podman\-container\-restore - Restores one or more containers from a checkpoint
diff --git a/docs/source/markdown/podman-container-runlabel.1.md.in b/docs/source/markdown/podman-container-runlabel.1.md.in
index f5fb8ca60..36e021ce4 100644
--- a/docs/source/markdown/podman-container-runlabel.1.md.in
+++ b/docs/source/markdown/podman-container-runlabel.1.md.in
@@ -1,4 +1,4 @@
-% podman-container-runlabel(1)
+% podman-container-runlabel 1
## NAME
podman-container-runlabel - Executes a command as described by a container-image label
diff --git a/docs/source/markdown/podman-container.1.md b/docs/source/markdown/podman-container.1.md
index 593cd3c42..1662000ed 100644
--- a/docs/source/markdown/podman-container.1.md
+++ b/docs/source/markdown/podman-container.1.md
@@ -1,4 +1,4 @@
-% podman-container(1)
+% podman-container 1
## NAME
podman\-container - Manage containers
diff --git a/docs/source/markdown/podman-cp.1.md b/docs/source/markdown/podman-cp.1.md
index bb86e3f13..49a3a8cd8 100644
--- a/docs/source/markdown/podman-cp.1.md
+++ b/docs/source/markdown/podman-cp.1.md
@@ -1,4 +1,4 @@
-% podman-cp(1)
+% podman-cp 1
## NAME
podman\-cp - Copy files/folders between a container and the local filesystem
diff --git a/docs/source/markdown/podman-create.1.md.in b/docs/source/markdown/podman-create.1.md.in
index 25726af8c..ac45fa61d 100644
--- a/docs/source/markdown/podman-create.1.md.in
+++ b/docs/source/markdown/podman-create.1.md.in
@@ -1,4 +1,4 @@
-% podman-create(1)
+% podman-create 1
## NAME
podman\-create - Create a new container
@@ -123,25 +123,12 @@ each of stdin, stdout, and stderr.
@@option cpuset-mems
-#### **--device**=*host-device[:container-device][:permissions]*
-
-Add a host device to the container. Optional *permissions* parameter
-can be used to specify device permissions, it is combination of
-**r** for read, **w** for write, and **m** for **mknod**(2).
-
-Example: **--device=/dev/sdc:/dev/xvdc:rwm**.
-
-Note: if *host-device* is a symbolic link then it will be resolved first.
-The container will only store the major and minor numbers of the host device.
+@@option device
Note: if the user only has access rights via a group, accessing the device
from inside a rootless container will fail. Use the `--group-add keep-groups`
flag to pass the user's supplementary group access into the container.
-Podman may load kernel modules required for using the specified
-device. The devices that podman will load modules when necessary are:
-/dev/fuse.
-
@@option device-cgroup-rule
@@option device-read-bps
diff --git a/docs/source/markdown/podman-diff.1.md b/docs/source/markdown/podman-diff.1.md
index 66675de93..0a086c20e 100644
--- a/docs/source/markdown/podman-diff.1.md
+++ b/docs/source/markdown/podman-diff.1.md
@@ -1,4 +1,4 @@
-% podman-diff(1)
+% podman-diff 1
## NAME
podman\-diff - Inspect changes on a container or image's filesystem
diff --git a/docs/source/markdown/podman-events.1.md b/docs/source/markdown/podman-events.1.md
index 526a7fa10..d0c95fe06 100644
--- a/docs/source/markdown/podman-events.1.md
+++ b/docs/source/markdown/podman-events.1.md
@@ -1,4 +1,4 @@
-% podman-events(1)
+% podman-events 1
## NAME
podman\-events - Monitor Podman events
diff --git a/docs/source/markdown/podman-exec.1.md.in b/docs/source/markdown/podman-exec.1.md.in
index 4f78f1c31..3202159c9 100644
--- a/docs/source/markdown/podman-exec.1.md.in
+++ b/docs/source/markdown/podman-exec.1.md.in
@@ -1,4 +1,4 @@
-% podman-exec(1)
+% podman-exec 1
## NAME
podman\-exec - Execute a command in a running container
diff --git a/docs/source/markdown/podman-export.1.md b/docs/source/markdown/podman-export.1.md
index 53d7e425e..d024d0256 100644
--- a/docs/source/markdown/podman-export.1.md
+++ b/docs/source/markdown/podman-export.1.md
@@ -1,4 +1,4 @@
-% podman-export(1)
+% podman-export 1
## NAME
podman\-export - Export a container's filesystem contents as a tar archive
diff --git a/docs/source/markdown/podman-generate-spec.1.md b/docs/source/markdown/podman-generate-spec.1.md
index 08c939698..73924df6c 100644
--- a/docs/source/markdown/podman-generate-spec.1.md
+++ b/docs/source/markdown/podman-generate-spec.1.md
@@ -1,4 +1,4 @@
-% podman-generate-spec(1)
+% podman-generate-spec 1
## NAME
podman\-generate\-spec - Generate Specgen JSON based on containers or pods
diff --git a/docs/source/markdown/podman-generate-systemd.1.md b/docs/source/markdown/podman-generate-systemd.1.md
index 88dff2a45..ee649c95b 100644
--- a/docs/source/markdown/podman-generate-systemd.1.md
+++ b/docs/source/markdown/podman-generate-systemd.1.md
@@ -1,4 +1,4 @@
-% podman-generate-systemd(1)
+% podman-generate-systemd 1
## NAME
podman\-generate\-systemd - Generate systemd unit file(s) for a container or pod
@@ -44,6 +44,12 @@ User-defined dependencies will be appended to the generated unit file, but any e
Set the systemd unit name prefix for containers. The default is *container*.
+#### **--env**, **-e**=*env*
+
+Set environment variables to the systemd unit files.
+
+If an environment variable is specified without a value, Podman will check the host environment for a value and set the variable only if it is set on the host. As a special case, if an environment variable ending in __*__ is specified without a value, Podman will search the host environment for variables starting with the prefix and will add those variables to the systemd unit files.
+
#### **--files**, **-f**
Generate files instead of printing to stdout. The generated files are named {container,pod}-{ID,name}.service and will be placed in the current working directory.
diff --git a/docs/source/markdown/podman-generate.1.md b/docs/source/markdown/podman-generate.1.md
index d84a9e098..dab9a866b 100644
--- a/docs/source/markdown/podman-generate.1.md
+++ b/docs/source/markdown/podman-generate.1.md
@@ -1,4 +1,4 @@
-% podman-generate(1)
+% podman-generate 1
## NAME
podman\-generate - Generate structured data based on containers, pods or volumes
diff --git a/docs/source/markdown/podman-healthcheck-run.1.md b/docs/source/markdown/podman-healthcheck-run.1.md
index dbaf87a0b..b2ef3110b 100644
--- a/docs/source/markdown/podman-healthcheck-run.1.md
+++ b/docs/source/markdown/podman-healthcheck-run.1.md
@@ -1,4 +1,4 @@
-% podman-healthcheck-run(1)
+% podman-healthcheck-run 1
## NAME
podman\-healthcheck\-run - Run a container healthcheck
diff --git a/docs/source/markdown/podman-healthcheck.1.md b/docs/source/markdown/podman-healthcheck.1.md
index eae71eba9..4caf65501 100644
--- a/docs/source/markdown/podman-healthcheck.1.md
+++ b/docs/source/markdown/podman-healthcheck.1.md
@@ -1,4 +1,4 @@
-% podman-healthcheck(1)
+% podman-healthcheck 1
## NAME
podman\-healthcheck - Manage healthchecks for containers
diff --git a/docs/source/markdown/podman-history.1.md b/docs/source/markdown/podman-history.1.md
index d114e0523..fb186127a 100644
--- a/docs/source/markdown/podman-history.1.md
+++ b/docs/source/markdown/podman-history.1.md
@@ -1,4 +1,4 @@
-% podman-history(1)
+% podman-history 1
## NAME
podman\-history - Show the history of an image
diff --git a/docs/source/markdown/podman-image-diff.1.md b/docs/source/markdown/podman-image-diff.1.md
index c5c62c751..0e6747ee0 100644
--- a/docs/source/markdown/podman-image-diff.1.md
+++ b/docs/source/markdown/podman-image-diff.1.md
@@ -1,4 +1,4 @@
-% podman-image-diff(1)
+% podman-image-diff 1
## NAME
podman-image-diff - Inspect changes on an image's filesystem
diff --git a/docs/source/markdown/podman-image-exists.1.md b/docs/source/markdown/podman-image-exists.1.md
index b585d16f1..7c08205bf 100644
--- a/docs/source/markdown/podman-image-exists.1.md
+++ b/docs/source/markdown/podman-image-exists.1.md
@@ -1,4 +1,4 @@
-% podman-image-exists(1)
+% podman-image-exists 1
## NAME
podman-image-exists - Check if an image exists in local storage
diff --git a/docs/source/markdown/podman-image-inspect.1.md b/docs/source/markdown/podman-image-inspect.1.md
index eb8d75786..7297b136f 100644
--- a/docs/source/markdown/podman-image-inspect.1.md
+++ b/docs/source/markdown/podman-image-inspect.1.md
@@ -1,4 +1,4 @@
-% podman-image-inspect(1)
+% podman-image-inspect 1
## NAME
podman\-image\-inspect - Display an image's configuration
diff --git a/docs/source/markdown/podman-image-mount.1.md b/docs/source/markdown/podman-image-mount.1.md
index 453266f8c..3808a4c9a 100644
--- a/docs/source/markdown/podman-image-mount.1.md
+++ b/docs/source/markdown/podman-image-mount.1.md
@@ -1,4 +1,4 @@
-% podman-image-mount(1)
+% podman-image-mount 1
## NAME
podman\-image\-mount - Mount an image's root filesystem
diff --git a/docs/source/markdown/podman-image-prune.1.md b/docs/source/markdown/podman-image-prune.1.md
index db17f97fb..2a9d215a3 100644
--- a/docs/source/markdown/podman-image-prune.1.md
+++ b/docs/source/markdown/podman-image-prune.1.md
@@ -1,4 +1,4 @@
-% podman-image-prune(1)
+% podman-image-prune 1
## NAME
podman-image-prune - Remove all unused images from the local store
diff --git a/docs/source/markdown/podman-image-scp.1.md b/docs/source/markdown/podman-image-scp.1.md
index b6b610a7d..b6a55bef2 100644
--- a/docs/source/markdown/podman-image-scp.1.md
+++ b/docs/source/markdown/podman-image-scp.1.md
@@ -1,4 +1,4 @@
-% podman-image-scp(1)
+% podman-image-scp 1
## NAME
podman-image-scp - Securely copy an image from one host to another
diff --git a/docs/source/markdown/podman-image-sign.1.md.in b/docs/source/markdown/podman-image-sign.1.md.in
index d5efabc1a..580f7e6dc 100644
--- a/docs/source/markdown/podman-image-sign.1.md.in
+++ b/docs/source/markdown/podman-image-sign.1.md.in
@@ -1,4 +1,4 @@
-% podman-image-sign(1)
+% podman-image-sign 1
## NAME
podman-image-sign - Create a signature for an image
diff --git a/docs/source/markdown/podman-image-tree.1.md b/docs/source/markdown/podman-image-tree.1.md
index 78f1b1004..28eaf0609 100644
--- a/docs/source/markdown/podman-image-tree.1.md
+++ b/docs/source/markdown/podman-image-tree.1.md
@@ -1,4 +1,4 @@
-% podman-image-tree(1)
+% podman-image-tree 1
## NAME
podman\-image\-tree - Prints layer hierarchy of an image in a tree format
diff --git a/docs/source/markdown/podman-image-trust.1.md b/docs/source/markdown/podman-image-trust.1.md
index 2a7da82cc..9dce3d890 100644
--- a/docs/source/markdown/podman-image-trust.1.md
+++ b/docs/source/markdown/podman-image-trust.1.md
@@ -1,4 +1,4 @@
-% podman-image-trust(1)
+% podman-image-trust 1
## NAME
podman\-image\-trust - Manage container registry image trust policy
diff --git a/docs/source/markdown/podman-image-unmount.1.md b/docs/source/markdown/podman-image-unmount.1.md
index 394811bd4..bffb5ff1d 100644
--- a/docs/source/markdown/podman-image-unmount.1.md
+++ b/docs/source/markdown/podman-image-unmount.1.md
@@ -1,4 +1,4 @@
-% podman-image-unmount(1)
+% podman-image-unmount 1
## NAME
podman\-image\-unmount - Unmount an image's root filesystem
diff --git a/docs/source/markdown/podman-image.1.md b/docs/source/markdown/podman-image.1.md
index 356369007..a74890cf2 100644
--- a/docs/source/markdown/podman-image.1.md
+++ b/docs/source/markdown/podman-image.1.md
@@ -1,4 +1,4 @@
-% podman-image(1)
+% podman-image 1
## NAME
podman\-image - Manage images
diff --git a/docs/source/markdown/podman-images.1.md b/docs/source/markdown/podman-images.1.md
index d005db23d..63e447960 100644
--- a/docs/source/markdown/podman-images.1.md
+++ b/docs/source/markdown/podman-images.1.md
@@ -1,4 +1,4 @@
-% podman-images(1)
+% podman-images 1
## NAME
podman\-images - List images in local storage
diff --git a/docs/source/markdown/podman-import.1.md b/docs/source/markdown/podman-import.1.md
index 8d482b961..60b34013c 100644
--- a/docs/source/markdown/podman-import.1.md
+++ b/docs/source/markdown/podman-import.1.md
@@ -1,4 +1,4 @@
-% podman-import(1)
+% podman-import 1
## NAME
podman\-import - Import a tarball and save it as a filesystem image
diff --git a/docs/source/markdown/podman-info.1.md b/docs/source/markdown/podman-info.1.md
index fc7e1f0e2..b0e4d68c0 100644
--- a/docs/source/markdown/podman-info.1.md
+++ b/docs/source/markdown/podman-info.1.md
@@ -1,4 +1,4 @@
-% podman-info(1)
+% podman-info 1
## NAME
podman\-info - Displays Podman related system information
diff --git a/docs/source/markdown/podman-init.1.md b/docs/source/markdown/podman-init.1.md
index 9525f610c..019e3d4a7 100644
--- a/docs/source/markdown/podman-init.1.md
+++ b/docs/source/markdown/podman-init.1.md
@@ -1,4 +1,4 @@
-% podman-init(1)
+% podman-init 1
## NAME
podman\-init - Initialize one or more containers
diff --git a/docs/source/markdown/podman-inspect.1.md b/docs/source/markdown/podman-inspect.1.md
index a67604ab5..ddd7ec972 100644
--- a/docs/source/markdown/podman-inspect.1.md
+++ b/docs/source/markdown/podman-inspect.1.md
@@ -1,4 +1,4 @@
-% podman-inspect(1)
+% podman-inspect 1
## NAME
podman\-inspect - Display a container, image, volume, network, or pod's configuration
diff --git a/docs/source/markdown/podman-kill.1.md.in b/docs/source/markdown/podman-kill.1.md.in
index 46d7f5c6b..852784caf 100644
--- a/docs/source/markdown/podman-kill.1.md.in
+++ b/docs/source/markdown/podman-kill.1.md.in
@@ -1,4 +1,4 @@
-% podman-kill(1)
+% podman-kill 1
## NAME
podman\-kill - Kill the main process in one or more containers
diff --git a/docs/source/markdown/podman-kube-down.1.md b/docs/source/markdown/podman-kube-down.1.md
index c345abbd1..898188d2b 100644
--- a/docs/source/markdown/podman-kube-down.1.md
+++ b/docs/source/markdown/podman-kube-down.1.md
@@ -1,4 +1,4 @@
-% podman-kube-down(1)
+% podman-kube-down 1
## NAME
podman-kube-down - Remove containers and pods based on Kubernetes YAML
diff --git a/docs/source/markdown/podman-kube-play.1.md.in b/docs/source/markdown/podman-kube-play.1.md.in
index bcd5687ca..6bf3acc9b 100644
--- a/docs/source/markdown/podman-kube-play.1.md.in
+++ b/docs/source/markdown/podman-kube-play.1.md.in
@@ -1,4 +1,4 @@
-% podman-kube-play(1)
+% podman-kube-play 1
## NAME
podman-kube-play - Create containers, pods and volumes based on Kubernetes YAML
diff --git a/docs/source/markdown/podman-kube.1.md b/docs/source/markdown/podman-kube.1.md
index 0d3654011..f70a61f47 100644
--- a/docs/source/markdown/podman-kube.1.md
+++ b/docs/source/markdown/podman-kube.1.md
@@ -1,4 +1,4 @@
-% podman-kube(1)
+% podman-kube 1
## NAME
podman\-kube - Play containers, pods or volumes based on a structured input file
diff --git a/docs/source/markdown/podman-load.1.md b/docs/source/markdown/podman-load.1.md
index ad32df854..8d0efb1a4 100644
--- a/docs/source/markdown/podman-load.1.md
+++ b/docs/source/markdown/podman-load.1.md
@@ -1,4 +1,4 @@
-% podman-load(1)
+% podman-load 1
## NAME
podman\-load - Load image(s) from a tar archive into container storage
diff --git a/docs/source/markdown/podman-login.1.md.in b/docs/source/markdown/podman-login.1.md.in
index 4537988eb..c309395fb 100644
--- a/docs/source/markdown/podman-login.1.md.in
+++ b/docs/source/markdown/podman-login.1.md.in
@@ -1,4 +1,4 @@
-% podman-login(1)
+% podman-login 1
## NAME
podman\-login - Login to a container registry
diff --git a/docs/source/markdown/podman-logout.1.md.in b/docs/source/markdown/podman-logout.1.md.in
index 6997bb36e..0f4180416 100644
--- a/docs/source/markdown/podman-logout.1.md.in
+++ b/docs/source/markdown/podman-logout.1.md.in
@@ -1,4 +1,4 @@
-% podman-logout(1)
+% podman-logout 1
## NAME
podman\-logout - Logout of a container registry
diff --git a/docs/source/markdown/podman-logs.1.md.in b/docs/source/markdown/podman-logs.1.md.in
index 7b0c45cf0..63144bec3 100644
--- a/docs/source/markdown/podman-logs.1.md.in
+++ b/docs/source/markdown/podman-logs.1.md.in
@@ -1,4 +1,4 @@
-% podman-logs(1)
+% podman-logs 1
## NAME
podman\-logs - Display the logs of one or more containers
diff --git a/docs/source/markdown/podman-machine-info.1.md b/docs/source/markdown/podman-machine-info.1.md
index 926d3d8b3..cdb8c7295 100644
--- a/docs/source/markdown/podman-machine-info.1.md
+++ b/docs/source/markdown/podman-machine-info.1.md
@@ -1,4 +1,4 @@
-% podman-machine-info(1)
+% podman-machine-info 1
## NAME
podman\-machine\-info - Display machine host info
diff --git a/docs/source/markdown/podman-machine-init.1.md b/docs/source/markdown/podman-machine-init.1.md
index cf2eeca0b..7a23faf59 100644
--- a/docs/source/markdown/podman-machine-init.1.md
+++ b/docs/source/markdown/podman-machine-init.1.md
@@ -1,4 +1,4 @@
-% podman-machine-init(1)
+% podman-machine-init 1
## NAME
podman\-machine\-init - Initialize a new virtual machine
diff --git a/docs/source/markdown/podman-machine-inspect.1.md b/docs/source/markdown/podman-machine-inspect.1.md
index 29cd775c2..79611f65d 100644
--- a/docs/source/markdown/podman-machine-inspect.1.md
+++ b/docs/source/markdown/podman-machine-inspect.1.md
@@ -1,4 +1,4 @@
-% podman-machine-inspect(1)
+% podman-machine-inspect 1
## NAME
podman\-machine\-inspect - Inspect one or more virtual machines
diff --git a/docs/source/markdown/podman-machine-list.1.md b/docs/source/markdown/podman-machine-list.1.md
index a25aae090..351e8cf1b 100644
--- a/docs/source/markdown/podman-machine-list.1.md
+++ b/docs/source/markdown/podman-machine-list.1.md
@@ -1,4 +1,4 @@
-% podman-machine-ls(1)
+% podman-machine-ls 1
## NAME
podman\-machine\-list - List virtual machines
diff --git a/docs/source/markdown/podman-machine-rm.1.md b/docs/source/markdown/podman-machine-rm.1.md
index d90b615ce..43c9d5813 100644
--- a/docs/source/markdown/podman-machine-rm.1.md
+++ b/docs/source/markdown/podman-machine-rm.1.md
@@ -1,4 +1,4 @@
-% podman-machine-rm(1)
+% podman-machine-rm 1
## NAME
podman\-machine\-rm - Remove a virtual machine
diff --git a/docs/source/markdown/podman-machine-set.1.md b/docs/source/markdown/podman-machine-set.1.md
index 52338cedb..a5ca5033e 100644
--- a/docs/source/markdown/podman-machine-set.1.md
+++ b/docs/source/markdown/podman-machine-set.1.md
@@ -1,4 +1,4 @@
-% podman-machine-set(1)
+% podman-machine-set 1
## NAME
podman\-machine\-set - Sets a virtual machine setting
diff --git a/docs/source/markdown/podman-machine-ssh.1.md b/docs/source/markdown/podman-machine-ssh.1.md
index 5432f0e9f..2d827df3d 100644
--- a/docs/source/markdown/podman-machine-ssh.1.md
+++ b/docs/source/markdown/podman-machine-ssh.1.md
@@ -1,4 +1,4 @@
-% podman-machine-ssh(1)
+% podman-machine-ssh 1
## NAME
podman\-machine\-ssh - SSH into a virtual machine
diff --git a/docs/source/markdown/podman-machine-start.1.md b/docs/source/markdown/podman-machine-start.1.md
index b92494dda..aa356a374 100644
--- a/docs/source/markdown/podman-machine-start.1.md
+++ b/docs/source/markdown/podman-machine-start.1.md
@@ -1,4 +1,4 @@
-% podman-machine-start(1)
+% podman-machine-start 1
## NAME
podman\-machine\-start - Start a virtual machine
diff --git a/docs/source/markdown/podman-machine-stop.1.md b/docs/source/markdown/podman-machine-stop.1.md
index 29f3e81f4..6ec4ba989 100644
--- a/docs/source/markdown/podman-machine-stop.1.md
+++ b/docs/source/markdown/podman-machine-stop.1.md
@@ -1,4 +1,4 @@
-% podman-machine-stop(1)
+% podman-machine-stop 1
## NAME
podman\-machine\-stop - Stop a virtual machine
diff --git a/docs/source/markdown/podman-machine.1.md b/docs/source/markdown/podman-machine.1.md
index 6197b8d4e..a3d04c776 100644
--- a/docs/source/markdown/podman-machine.1.md
+++ b/docs/source/markdown/podman-machine.1.md
@@ -1,4 +1,4 @@
-% podman-machine(1)
+% podman-machine 1
## NAME
podman\-machine - Manage Podman's virtual machine
diff --git a/docs/source/markdown/podman-manifest-add.1.md.in b/docs/source/markdown/podman-manifest-add.1.md.in
index e82c04985..0d957cd1e 100644
--- a/docs/source/markdown/podman-manifest-add.1.md.in
+++ b/docs/source/markdown/podman-manifest-add.1.md.in
@@ -1,4 +1,4 @@
-% podman-manifest-add(1)
+% podman-manifest-add 1
## NAME
podman\-manifest\-add - Add an image to a manifest list or image index
diff --git a/docs/source/markdown/podman-manifest-annotate.1.md b/docs/source/markdown/podman-manifest-annotate.1.md
index 36c35c7c8..a6f82aa9a 100644
--- a/docs/source/markdown/podman-manifest-annotate.1.md
+++ b/docs/source/markdown/podman-manifest-annotate.1.md
@@ -1,4 +1,4 @@
-% podman-manifest-annotate(1)
+% podman-manifest-annotate 1
## NAME
podman\-manifest\-annotate - Add or update information about an entry in a manifest list or image index
diff --git a/docs/source/markdown/podman-manifest-create.1.md b/docs/source/markdown/podman-manifest-create.1.md
index 06a24da2b..cb8ad41fb 100644
--- a/docs/source/markdown/podman-manifest-create.1.md
+++ b/docs/source/markdown/podman-manifest-create.1.md
@@ -1,4 +1,4 @@
-% podman-manifest-create(1)
+% podman-manifest-create 1
## NAME
podman\-manifest\-create - Create a manifest list or image index
diff --git a/docs/source/markdown/podman-manifest-exists.1.md b/docs/source/markdown/podman-manifest-exists.1.md
index dd344046d..b87559f8b 100644
--- a/docs/source/markdown/podman-manifest-exists.1.md
+++ b/docs/source/markdown/podman-manifest-exists.1.md
@@ -1,4 +1,4 @@
-% podman-manifest-exists(1)
+% podman-manifest-exists 1
## NAME
podman\-manifest\-exists - Check if the given manifest list exists in local storage
diff --git a/docs/source/markdown/podman-manifest-inspect.1.md b/docs/source/markdown/podman-manifest-inspect.1.md
index b2c6b1935..4b7fc3a40 100644
--- a/docs/source/markdown/podman-manifest-inspect.1.md
+++ b/docs/source/markdown/podman-manifest-inspect.1.md
@@ -1,4 +1,4 @@
-% podman-manifest-inspect(1)
+% podman-manifest-inspect 1
## NAME
podman\-manifest\-inspect - Display a manifest list or image index
diff --git a/docs/source/markdown/podman-manifest-push.1.md.in b/docs/source/markdown/podman-manifest-push.1.md.in
index b27fbee8d..e3d578d10 100644
--- a/docs/source/markdown/podman-manifest-push.1.md.in
+++ b/docs/source/markdown/podman-manifest-push.1.md.in
@@ -1,4 +1,4 @@
-% podman-manifest-push(1)
+% podman-manifest-push 1
## NAME
podman\-manifest\-push - Push a manifest list or image index to a registry
diff --git a/docs/source/markdown/podman-manifest-remove.1.md b/docs/source/markdown/podman-manifest-remove.1.md
index 256d5a5b5..32fc5892e 100644
--- a/docs/source/markdown/podman-manifest-remove.1.md
+++ b/docs/source/markdown/podman-manifest-remove.1.md
@@ -1,4 +1,4 @@
-% podman-manifest-remove(1)
+% podman-manifest-remove 1
## NAME
podman\-manifest\-remove - Remove an image from a manifest list or image index
diff --git a/docs/source/markdown/podman-manifest.1.md b/docs/source/markdown/podman-manifest.1.md
index cc716b2a0..74c59b657 100644
--- a/docs/source/markdown/podman-manifest.1.md
+++ b/docs/source/markdown/podman-manifest.1.md
@@ -1,4 +1,4 @@
-% podman-manifest(1)
+% podman-manifest 1
## NAME
podman\-manifest - Create and manipulate manifest lists and image indexes
diff --git a/docs/source/markdown/podman-mount.1.md b/docs/source/markdown/podman-mount.1.md
index 82c7fe804..8229b1390 100644
--- a/docs/source/markdown/podman-mount.1.md
+++ b/docs/source/markdown/podman-mount.1.md
@@ -1,4 +1,4 @@
-% podman-mount(1)
+% podman-mount 1
## NAME
podman\-mount - Mount a working container's root filesystem
diff --git a/docs/source/markdown/podman-network-connect.1.md b/docs/source/markdown/podman-network-connect.1.md
index d1718b812..dc238fced 100644
--- a/docs/source/markdown/podman-network-connect.1.md
+++ b/docs/source/markdown/podman-network-connect.1.md
@@ -1,4 +1,4 @@
-% podman-network-connect(1)
+% podman-network-connect 1
## NAME
podman\-network\-connect - Connect a container to a network
diff --git a/docs/source/markdown/podman-network-create.1.md b/docs/source/markdown/podman-network-create.1.md
index 3836ea05c..6fd31dd4d 100644
--- a/docs/source/markdown/podman-network-create.1.md
+++ b/docs/source/markdown/podman-network-create.1.md
@@ -1,4 +1,4 @@
-% podman-network-create(1)
+% podman-network-create 1
## NAME
podman\-network-create - Create a Podman network
diff --git a/docs/source/markdown/podman-network-disconnect.1.md b/docs/source/markdown/podman-network-disconnect.1.md
index f3ca059a1..9685cf400 100644
--- a/docs/source/markdown/podman-network-disconnect.1.md
+++ b/docs/source/markdown/podman-network-disconnect.1.md
@@ -1,4 +1,4 @@
-% podman-network-disconnect(1)
+% podman-network-disconnect 1
## NAME
podman\-network\-disconnect - Disconnect a container from a network
diff --git a/docs/source/markdown/podman-network-exists.1.md b/docs/source/markdown/podman-network-exists.1.md
index 44c145cd9..f014b14ef 100644
--- a/docs/source/markdown/podman-network-exists.1.md
+++ b/docs/source/markdown/podman-network-exists.1.md
@@ -1,4 +1,4 @@
-% podman-network-exists(1)
+% podman-network-exists 1
## NAME
podman\-network\-exists - Check if the given network exists
diff --git a/docs/source/markdown/podman-network-inspect.1.md b/docs/source/markdown/podman-network-inspect.1.md
index 2ba4a63cb..f812542db 100644
--- a/docs/source/markdown/podman-network-inspect.1.md
+++ b/docs/source/markdown/podman-network-inspect.1.md
@@ -1,4 +1,4 @@
-% podman-network-inspect(1)
+% podman-network-inspect 1
## NAME
podman\-network\-inspect - Displays the network configuration for one or more networks
diff --git a/docs/source/markdown/podman-network-ls.1.md b/docs/source/markdown/podman-network-ls.1.md
index c7ea24b9b..83d1365ec 100644
--- a/docs/source/markdown/podman-network-ls.1.md
+++ b/docs/source/markdown/podman-network-ls.1.md
@@ -1,4 +1,4 @@
-% podman-network-ls(1)
+% podman-network-ls 1
## NAME
podman\-network\-ls - Display a summary of networks
diff --git a/docs/source/markdown/podman-network-prune.1.md b/docs/source/markdown/podman-network-prune.1.md
index b0a81646d..806f5c8a1 100644
--- a/docs/source/markdown/podman-network-prune.1.md
+++ b/docs/source/markdown/podman-network-prune.1.md
@@ -1,4 +1,4 @@
-% podman-network-prune(1)
+% podman-network-prune 1
## NAME
podman\-network\-prune - Remove all unused networks
diff --git a/docs/source/markdown/podman-network-reload.1.md b/docs/source/markdown/podman-network-reload.1.md
index 31d10829e..4ecce17f8 100644
--- a/docs/source/markdown/podman-network-reload.1.md
+++ b/docs/source/markdown/podman-network-reload.1.md
@@ -1,4 +1,4 @@
-% podman-network-reload(1)
+% podman-network-reload 1
## NAME
podman\-network\-reload - Reload network configuration for containers
diff --git a/docs/source/markdown/podman-network-rm.1.md b/docs/source/markdown/podman-network-rm.1.md
index 880f1d0c7..714fea8fb 100644
--- a/docs/source/markdown/podman-network-rm.1.md
+++ b/docs/source/markdown/podman-network-rm.1.md
@@ -1,4 +1,4 @@
-% podman-network-rm(1)
+% podman-network-rm 1
## NAME
podman\-network\-rm - Remove one or more networks
diff --git a/docs/source/markdown/podman-network.1.md b/docs/source/markdown/podman-network.1.md
index f58bd5d5c..6ab7013e1 100644
--- a/docs/source/markdown/podman-network.1.md
+++ b/docs/source/markdown/podman-network.1.md
@@ -1,4 +1,4 @@
-% podman-network(1)
+% podman-network 1
## NAME
podman\-network - Manage Podman networks
diff --git a/docs/source/markdown/podman-pause.1.md.in b/docs/source/markdown/podman-pause.1.md.in
index af308f034..a228f7107 100644
--- a/docs/source/markdown/podman-pause.1.md.in
+++ b/docs/source/markdown/podman-pause.1.md.in
@@ -1,4 +1,4 @@
-% podman-pause(1)
+% podman-pause 1
## NAME
podman\-pause - Pause one or more containers
diff --git a/docs/source/markdown/podman-pod-clone.1.md.in b/docs/source/markdown/podman-pod-clone.1.md.in
index e2e08d2a6..32183d778 100644
--- a/docs/source/markdown/podman-pod-clone.1.md.in
+++ b/docs/source/markdown/podman-pod-clone.1.md.in
@@ -1,4 +1,4 @@
-% podman-pod-clone(1)
+% podman-pod-clone 1
## NAME
podman\-pod\-clone - Creates a copy of an existing pod
@@ -31,23 +31,10 @@ If none are specified, the original pod's CPUset is used.
@@option destroy
-#### **--device**=*host-device[:container-device][:permissions]*
-
-Add a host device to the pod. Optional *permissions* parameter
-can be used to specify device permissions. It is a combination of
-**r** for read, **w** for write, and **m** for **mknod**(2).
-
-Example: **--device=/dev/sdc:/dev/xvdc:rwm**.
-
-Note: if _host_device_ is a symbolic link then it will be resolved first.
-The pod will only store the major and minor numbers of the host device.
+@@option device
Note: the pod implements devices by storing the initial configuration passed by the user and recreating the device on each container added to the pod.
-Podman may load kernel modules required for using the specified
-device. The devices that Podman will load modules for when necessary are:
-/dev/fuse.
-
@@option device-read-bps
@@option device-write-bps
@@ -70,26 +57,9 @@ Print usage statement.
@@option label-file
-#### **--memory**, **-m**=*limit*
-
-Memory limit (format: `<number>[<unit>]`, where unit = b (bytes), k (kibibytes), m (mebibytes), or g (gibibytes))
-
-Constrains the memory available to a container. If the host
-supports swap memory, then the **-m** memory setting can be larger than physical
-RAM. If a limit of 0 is specified (not using **-m**), the container's memory is
-not limited. The actual limit may be rounded up to a multiple of the operating
-system's page size (the value would be very large, that's millions of trillions).
-
-#### **--memory-swap**=*limit*
-
-A limit value equal to memory plus swap. Must be used with the **-m**
-(**--memory**) flag. The swap `LIMIT` should always be larger than **-m**
-(**--memory**) value. By default, the swap `LIMIT` will be set to double
-the value of --memory.
+@@option memory
-The format of `LIMIT` is `<number>[<unit>]`. Unit can be `b` (bytes),
-`k` (kibibytes), `m` (mebibytes), or `g` (gibibytes). If you don't specify a
-unit, `b` is used. Set LIMIT to `-1` to enable unlimited swap.
+@@option memory-swap
#### **--name**, **-n**
diff --git a/docs/source/markdown/podman-pod-create.1.md.in b/docs/source/markdown/podman-pod-create.1.md.in
index f3d6884c5..b747022eb 100644
--- a/docs/source/markdown/podman-pod-create.1.md.in
+++ b/docs/source/markdown/podman-pod-create.1.md.in
@@ -1,4 +1,4 @@
-% podman-pod-create(1)
+% podman-pod-create 1
## NAME
podman\-pod\-create - Create a new pod
@@ -48,23 +48,10 @@ Set the total number of CPUs delegated to the pod. Default is 0.000 which indica
@@option cpuset-mems
-#### **--device**=_host-device_[**:**_container-device_][**:**_permissions_]
-
-Add a host device to the pod. Optional *permissions* parameter
-can be used to specify device permissions. It is a combination of
-**r** for read, **w** for write, and **m** for **mknod**(2).
-
-Example: **--device=/dev/sdc:/dev/xvdc:rwm**.
-
-Note: if *host-device* is a symbolic link then it will be resolved first.
-The pod will only store the major and minor numbers of the host device.
+@@option device
Note: the pod implements devices by storing the initial configuration passed by the user and recreating the device on each container added to the pod.
-Podman may load kernel modules required for using the specified
-device. The devices that Podman will load modules for when necessary are:
-/dev/fuse.
-
@@option device-read-bps
@@option device-write-bps
@@ -136,26 +123,9 @@ To specify multiple static IPv6 addresses per pod, set multiple networks using t
@@option mac-address
-#### **--memory**, **-m**=*limit*
-
-Memory limit (format: `<number>[<unit>]`, where unit = b (bytes), k (kibibytes), m (mebibytes), or g (gibibytes))
-
-Constrains the memory available to a container. If the host
-supports swap memory, then the **-m** memory setting can be larger than physical
-RAM. If a limit of 0 is specified (not using **-m**), the container's memory is
-not limited. The actual limit may be rounded up to a multiple of the operating
-system's page size (the value would be very large, that's millions of trillions).
-
-#### **--memory-swap**=*limit*
-
-A limit value equal to memory plus swap. Must be used with the **-m**
-(**--memory**) flag. The swap `LIMIT` should always be larger than **-m**
-(**--memory**) value. By default, the swap `LIMIT` will be set to double
-the value of --memory.
+@@option memory
-The format of `LIMIT` is `<number>[<unit>]`. Unit can be `b` (bytes),
-`k` (kibibytes), `m` (mebibytes), or `g` (gibibytes). If you don't specify a
-unit, `b` is used. Set LIMIT to `-1` to enable unlimited swap.
+@@option memory-swap
#### **--name**, **-n**=*name*
diff --git a/docs/source/markdown/podman-pod-exists.1.md b/docs/source/markdown/podman-pod-exists.1.md
index 201dfbefd..eea4633d7 100644
--- a/docs/source/markdown/podman-pod-exists.1.md
+++ b/docs/source/markdown/podman-pod-exists.1.md
@@ -1,4 +1,4 @@
-% podman-pod-exists(1)
+% podman-pod-exists 1
## NAME
podman-pod-exists - Check if a pod exists in local storage
diff --git a/docs/source/markdown/podman-pod-inspect.1.md b/docs/source/markdown/podman-pod-inspect.1.md
index d0a165b05..e100256af 100644
--- a/docs/source/markdown/podman-pod-inspect.1.md
+++ b/docs/source/markdown/podman-pod-inspect.1.md
@@ -1,4 +1,4 @@
-% podman-pod-inspect(1)
+% podman-pod-inspect 1
## NAME
podman\-pod\-inspect - Displays information describing a pod
diff --git a/docs/source/markdown/podman-pod-kill.1.md.in b/docs/source/markdown/podman-pod-kill.1.md.in
index 7f37661b0..64425bb4d 100644
--- a/docs/source/markdown/podman-pod-kill.1.md.in
+++ b/docs/source/markdown/podman-pod-kill.1.md.in
@@ -1,4 +1,4 @@
-% podman-pod-kill(1)
+% podman-pod-kill 1
## NAME
podman\-pod\-kill - Kill the main process of each container in one or more pods
diff --git a/docs/source/markdown/podman-pod-logs.1.md.in b/docs/source/markdown/podman-pod-logs.1.md.in
index 391f620f8..cc224eee3 100644
--- a/docs/source/markdown/podman-pod-logs.1.md.in
+++ b/docs/source/markdown/podman-pod-logs.1.md.in
@@ -1,4 +1,4 @@
-% podman-pod-logs(1)
+% podman-pod-logs 1
## NAME
podman\-pod\-logs - Displays logs for pod with one or more containers
diff --git a/docs/source/markdown/podman-pod-pause.1.md b/docs/source/markdown/podman-pod-pause.1.md
index 2d2fac00d..6519ae2e7 100644
--- a/docs/source/markdown/podman-pod-pause.1.md
+++ b/docs/source/markdown/podman-pod-pause.1.md
@@ -1,4 +1,4 @@
-% podman-pod-pause(1)
+% podman-pod-pause 1
## NAME
podman\-pod\-pause - Pause one or more pods
diff --git a/docs/source/markdown/podman-pod-prune.1.md b/docs/source/markdown/podman-pod-prune.1.md
index 6cc9babf1..5dfb14517 100644
--- a/docs/source/markdown/podman-pod-prune.1.md
+++ b/docs/source/markdown/podman-pod-prune.1.md
@@ -1,4 +1,4 @@
-% podman-pod-prune(1)
+% podman-pod-prune 1
## NAME
podman-pod-prune - Remove all stopped pods and their containers
diff --git a/docs/source/markdown/podman-pod-ps.1.md b/docs/source/markdown/podman-pod-ps.1.md
index 34f49173a..ae249ecf0 100644
--- a/docs/source/markdown/podman-pod-ps.1.md
+++ b/docs/source/markdown/podman-pod-ps.1.md
@@ -1,4 +1,4 @@
-% podman-pod-ps(1)
+% podman-pod-ps 1
## NAME
podman\-pod\-ps - Prints out information about pods
diff --git a/docs/source/markdown/podman-pod-restart.1.md b/docs/source/markdown/podman-pod-restart.1.md
index 51f13dbf8..1e309be9f 100644
--- a/docs/source/markdown/podman-pod-restart.1.md
+++ b/docs/source/markdown/podman-pod-restart.1.md
@@ -1,4 +1,4 @@
-% podman-pod-restart(1)
+% podman-pod-restart 1
## NAME
podman\-pod\-restart - Restart one or more pods
diff --git a/docs/source/markdown/podman-pod-rm.1.md.in b/docs/source/markdown/podman-pod-rm.1.md.in
index 82e28acb1..5d708b65c 100644
--- a/docs/source/markdown/podman-pod-rm.1.md.in
+++ b/docs/source/markdown/podman-pod-rm.1.md.in
@@ -1,4 +1,4 @@
-% podman-pod-rm(1)
+% podman-pod-rm 1
## NAME
podman\-pod\-rm - Remove one or more stopped pods and containers
diff --git a/docs/source/markdown/podman-pod-start.1.md.in b/docs/source/markdown/podman-pod-start.1.md.in
index 6a47ce1b9..aec67b009 100644
--- a/docs/source/markdown/podman-pod-start.1.md.in
+++ b/docs/source/markdown/podman-pod-start.1.md.in
@@ -1,4 +1,4 @@
-% podman-pod-start(1)
+% podman-pod-start 1
## NAME
podman\-pod\-start - Start one or more pods
diff --git a/docs/source/markdown/podman-pod-stats.1.md b/docs/source/markdown/podman-pod-stats.1.md
index 389540fdf..c71159f09 100644
--- a/docs/source/markdown/podman-pod-stats.1.md
+++ b/docs/source/markdown/podman-pod-stats.1.md
@@ -1,4 +1,4 @@
-% podman-pod-stats(1)
+% podman-pod-stats 1
## NAME
podman\-pod\-stats - Display a live stream of resource usage stats for containers in one or more pods
diff --git a/docs/source/markdown/podman-pod-stop.1.md.in b/docs/source/markdown/podman-pod-stop.1.md.in
index abcc69e9e..575a5fa30 100644
--- a/docs/source/markdown/podman-pod-stop.1.md.in
+++ b/docs/source/markdown/podman-pod-stop.1.md.in
@@ -1,4 +1,4 @@
-% podman-pod-stop(1)
+% podman-pod-stop 1
## NAME
podman\-pod\-stop - Stop one or more pods
diff --git a/docs/source/markdown/podman-pod-top.1.md b/docs/source/markdown/podman-pod-top.1.md
index 3f4c24117..6a2077656 100644
--- a/docs/source/markdown/podman-pod-top.1.md
+++ b/docs/source/markdown/podman-pod-top.1.md
@@ -1,4 +1,4 @@
-% podman-pod-top(1)
+% podman-pod-top 1
## NAME
podman\-pod\-top - Display the running processes of containers in a pod
diff --git a/docs/source/markdown/podman-pod-unpause.1.md b/docs/source/markdown/podman-pod-unpause.1.md
index d6645d69c..f4b50275e 100644
--- a/docs/source/markdown/podman-pod-unpause.1.md
+++ b/docs/source/markdown/podman-pod-unpause.1.md
@@ -1,4 +1,4 @@
-% podman-pod-unpause(1)
+% podman-pod-unpause 1
## NAME
podman\-pod\-unpause - Unpause one or more pods
diff --git a/docs/source/markdown/podman-pod.1.md b/docs/source/markdown/podman-pod.1.md
index c38235e89..680324316 100644
--- a/docs/source/markdown/podman-pod.1.md
+++ b/docs/source/markdown/podman-pod.1.md
@@ -1,4 +1,4 @@
-% podman-pod(1)
+% podman-pod 1
## NAME
podman\-pod - Management tool for groups of containers, called pods
diff --git a/docs/source/markdown/podman-port.1.md b/docs/source/markdown/podman-port.1.md
index ebfeeccd7..c1c67a28d 100644
--- a/docs/source/markdown/podman-port.1.md
+++ b/docs/source/markdown/podman-port.1.md
@@ -1,4 +1,4 @@
-% podman-port(1)
+% podman-port 1
## NAME
podman\-port - List port mappings for a container
diff --git a/docs/source/markdown/podman-ps.1.md b/docs/source/markdown/podman-ps.1.md
index 6e2a8616c..3b5a2a508 100644
--- a/docs/source/markdown/podman-ps.1.md
+++ b/docs/source/markdown/podman-ps.1.md
@@ -1,4 +1,4 @@
-% podman-ps(1)
+% podman-ps 1
## NAME
podman\-ps - Prints out information about containers
diff --git a/docs/source/markdown/podman-pull.1.md.in b/docs/source/markdown/podman-pull.1.md.in
index 03f9b8fd7..5405d7a45 100644
--- a/docs/source/markdown/podman-pull.1.md.in
+++ b/docs/source/markdown/podman-pull.1.md.in
@@ -1,4 +1,4 @@
-% podman-pull(1)
+% podman-pull 1
## NAME
podman\-pull - Pull an image from a registry
diff --git a/docs/source/markdown/podman-push.1.md.in b/docs/source/markdown/podman-push.1.md.in
index 408fdb43c..6e6eecfa2 100644
--- a/docs/source/markdown/podman-push.1.md.in
+++ b/docs/source/markdown/podman-push.1.md.in
@@ -1,4 +1,4 @@
-% podman-push(1)
+% podman-push 1
## NAME
podman\-push - Push an image, manifest list or image index from local storage to elsewhere
diff --git a/docs/source/markdown/podman-remote.1.md b/docs/source/markdown/podman-remote.1.md
index e87129e38..6369eea56 100644
--- a/docs/source/markdown/podman-remote.1.md
+++ b/docs/source/markdown/podman-remote.1.md
@@ -1,4 +1,4 @@
-% podman-remote(1)
+% podman-remote 1
## NAME
podman-remote - A remote CLI for Podman: A Simple management tool for pods, containers and images.
diff --git a/docs/source/markdown/podman-rename.1.md b/docs/source/markdown/podman-rename.1.md
index 0a807e6de..a91ac2666 100644
--- a/docs/source/markdown/podman-rename.1.md
+++ b/docs/source/markdown/podman-rename.1.md
@@ -1,4 +1,4 @@
-% podman-rename(1)
+% podman-rename 1
## NAME
podman\-rename - Rename an existing container
diff --git a/docs/source/markdown/podman-restart.1.md b/docs/source/markdown/podman-restart.1.md
index b9da413f7..513b9a1bf 100644
--- a/docs/source/markdown/podman-restart.1.md
+++ b/docs/source/markdown/podman-restart.1.md
@@ -1,4 +1,4 @@
-% podman-restart(1)
+% podman-restart 1
## NAME
podman\-restart - Restart one or more containers
diff --git a/docs/source/markdown/podman-rm.1.md.in b/docs/source/markdown/podman-rm.1.md.in
index 9eb44dcc1..6f4366ce9 100644
--- a/docs/source/markdown/podman-rm.1.md.in
+++ b/docs/source/markdown/podman-rm.1.md.in
@@ -1,4 +1,4 @@
-% podman-rm(1)
+% podman-rm 1
## NAME
podman\-rm - Remove one or more containers
diff --git a/docs/source/markdown/podman-rmi.1.md b/docs/source/markdown/podman-rmi.1.md
index 93658daaf..08e6742c9 100644
--- a/docs/source/markdown/podman-rmi.1.md
+++ b/docs/source/markdown/podman-rmi.1.md
@@ -1,4 +1,4 @@
-% podman-rmi(1)
+% podman-rmi 1
## NAME
podman\-rmi - Removes one or more locally stored images
diff --git a/docs/source/markdown/podman-run.1.md.in b/docs/source/markdown/podman-run.1.md.in
index a32bf4781..d9b4fe5c3 100644
--- a/docs/source/markdown/podman-run.1.md.in
+++ b/docs/source/markdown/podman-run.1.md.in
@@ -1,4 +1,4 @@
-% podman-run(1)
+% podman-run 1
## NAME
podman\-run - Run a command in a new container
@@ -159,25 +159,12 @@ Specify the key sequence for detaching a container. Format is a single character
This option can also be set in **containers.conf**(5) file.
-#### **--device**=*host-device[:container-device][:permissions]*
-
-Add a host device to the container. Optional *permissions* parameter
-can be used to specify device permissions by combining
-**r** for read, **w** for write, and **m** for **mknod**(2).
-
-Example: **--device=/dev/sdc:/dev/xvdc:rwm**.
-
-Note: if _host_device_ is a symbolic link then it will be resolved first.
-The container will only store the major and minor numbers of the host device.
+@@option device
Note: if the user only has access rights via a group, accessing the device
from inside a rootless container will fail. Use the `--group-add keep-groups`
flag to pass the user's supplementary group access into the container.
-Podman may load kernel modules required for using the specified
-device. The devices that Podman will load modules when necessary are:
-/dev/fuse.
-
@@option device-cgroup-rule
@@option device-read-bps
@@ -307,15 +294,7 @@ This option is currently supported only by the **journald** log driver.
@@option mac-address
-#### **--memory**, **-m**=*number[unit]*
-
-Memory limit. A _unit_ can be **b** (bytes), **k** (kibibytes), **m** (mebibytes), or **g** (gibibytes).
-
-Allows you to constrain the memory available to a container. If the host
-supports swap memory, then the **-m** memory setting can be larger than physical
-RAM. If a limit of 0 is specified (not using **-m**), the container's memory is
-not limited. The actual limit may be rounded up to a multiple of the operating
-system's page size (the value would be very large, that's millions of trillions).
+@@option memory
@@option memory-reservation
diff --git a/docs/source/markdown/podman-save.1.md b/docs/source/markdown/podman-save.1.md
index aa4900e25..088d9dc21 100644
--- a/docs/source/markdown/podman-save.1.md
+++ b/docs/source/markdown/podman-save.1.md
@@ -1,4 +1,4 @@
-% podman-save(1)
+% podman-save 1
## NAME
podman\-save - Save image(s) to an archive
diff --git a/docs/source/markdown/podman-search.1.md.in b/docs/source/markdown/podman-search.1.md.in
index 9dd8cebf8..102cf7ad7 100644
--- a/docs/source/markdown/podman-search.1.md.in
+++ b/docs/source/markdown/podman-search.1.md.in
@@ -1,4 +1,4 @@
-% podman-search(1)
+% podman-search 1
## NAME
podman\-search - Search a registry for an image
diff --git a/docs/source/markdown/podman-secret-create.1.md b/docs/source/markdown/podman-secret-create.1.md
index 39e0c6843..1aafc6c11 100644
--- a/docs/source/markdown/podman-secret-create.1.md
+++ b/docs/source/markdown/podman-secret-create.1.md
@@ -1,4 +1,4 @@
-% podman-secret-create(1)
+% podman-secret-create 1
## NAME
podman\-secret\-create - Create a new secret
diff --git a/docs/source/markdown/podman-secret-inspect.1.md b/docs/source/markdown/podman-secret-inspect.1.md
index 1a7115f63..0e0d16120 100644
--- a/docs/source/markdown/podman-secret-inspect.1.md
+++ b/docs/source/markdown/podman-secret-inspect.1.md
@@ -1,4 +1,4 @@
-% podman-secret-inspect(1)
+% podman-secret-inspect 1
## NAME
podman\-secret\-inspect - Display detailed information on one or more secrets
diff --git a/docs/source/markdown/podman-secret-ls.1.md b/docs/source/markdown/podman-secret-ls.1.md
index dcd10c9cf..6f82f562b 100644
--- a/docs/source/markdown/podman-secret-ls.1.md
+++ b/docs/source/markdown/podman-secret-ls.1.md
@@ -1,4 +1,4 @@
-% podman-secret-ls(1)
+% podman-secret-ls 1
## NAME
podman\-secret\-ls - List all available secrets
diff --git a/docs/source/markdown/podman-secret-rm.1.md b/docs/source/markdown/podman-secret-rm.1.md
index ceab3df60..820c8515c 100644
--- a/docs/source/markdown/podman-secret-rm.1.md
+++ b/docs/source/markdown/podman-secret-rm.1.md
@@ -1,4 +1,4 @@
-% podman-secret-rm(1)
+% podman-secret-rm 1
## NAME
podman\-secret\-rm - Remove one or more secrets
diff --git a/docs/source/markdown/podman-secret.1.md b/docs/source/markdown/podman-secret.1.md
index 671a0c43b..f6c0a945f 100644
--- a/docs/source/markdown/podman-secret.1.md
+++ b/docs/source/markdown/podman-secret.1.md
@@ -1,4 +1,4 @@
-% podman-secret(1)
+% podman-secret 1
## NAME
podman\-secret - Manage podman secrets
diff --git a/docs/source/markdown/podman-start.1.md b/docs/source/markdown/podman-start.1.md
index 6b0433483..fd24c6bf4 100644
--- a/docs/source/markdown/podman-start.1.md
+++ b/docs/source/markdown/podman-start.1.md
@@ -1,4 +1,4 @@
-% podman-start(1)
+% podman-start 1
## NAME
podman\-start - Start one or more containers
diff --git a/docs/source/markdown/podman-stats.1.md b/docs/source/markdown/podman-stats.1.md
index 8d07be1a0..a1a0f6a93 100644
--- a/docs/source/markdown/podman-stats.1.md
+++ b/docs/source/markdown/podman-stats.1.md
@@ -1,4 +1,4 @@
-% podman-stats(1)
+% podman-stats 1
## NAME
podman\-stats - Display a live stream of one or more container's resource usage statistics
diff --git a/docs/source/markdown/podman-stop.1.md.in b/docs/source/markdown/podman-stop.1.md.in
index 9aaccdfaa..7b32ca4b0 100644
--- a/docs/source/markdown/podman-stop.1.md.in
+++ b/docs/source/markdown/podman-stop.1.md.in
@@ -1,4 +1,4 @@
-% podman-stop(1)
+% podman-stop 1
## NAME
podman\-stop - Stop one or more running containers
diff --git a/docs/source/markdown/podman-system-connection-add.1.md b/docs/source/markdown/podman-system-connection-add.1.md
index d608ab7a7..f06cd2780 100644
--- a/docs/source/markdown/podman-system-connection-add.1.md
+++ b/docs/source/markdown/podman-system-connection-add.1.md
@@ -1,4 +1,4 @@
-% podman-system-connection-add(1)
+% podman-system-connection-add 1
## NAME
podman\-system\-connection\-add - Record destination for the Podman service
diff --git a/docs/source/markdown/podman-system-connection-default.1.md b/docs/source/markdown/podman-system-connection-default.1.md
index 49f165e81..574625cef 100644
--- a/docs/source/markdown/podman-system-connection-default.1.md
+++ b/docs/source/markdown/podman-system-connection-default.1.md
@@ -1,4 +1,4 @@
-% podman-system-connection-default(1)
+% podman-system-connection-default 1
## NAME
podman\-system\-connection\-default - Set named destination as default for the Podman service
diff --git a/docs/source/markdown/podman-system-connection-list.1.md b/docs/source/markdown/podman-system-connection-list.1.md
index 23784a319..325c78a5c 100644
--- a/docs/source/markdown/podman-system-connection-list.1.md
+++ b/docs/source/markdown/podman-system-connection-list.1.md
@@ -1,4 +1,4 @@
-% podman-system-connection-list(1)
+% podman-system-connection-list 1
## NAME
podman\-system\-connection\-list - List the destination for the Podman service(s)
diff --git a/docs/source/markdown/podman-system-connection-remove.1.md b/docs/source/markdown/podman-system-connection-remove.1.md
index 348b49876..45fede021 100644
--- a/docs/source/markdown/podman-system-connection-remove.1.md
+++ b/docs/source/markdown/podman-system-connection-remove.1.md
@@ -1,4 +1,4 @@
-% podman-system-connection-remove(1)
+% podman-system-connection-remove 1
## NAME
podman\-system\-connection\-remove - Delete named destination
diff --git a/docs/source/markdown/podman-system-connection-rename.1.md b/docs/source/markdown/podman-system-connection-rename.1.md
index 5b5930738..ed10c1cd6 100644
--- a/docs/source/markdown/podman-system-connection-rename.1.md
+++ b/docs/source/markdown/podman-system-connection-rename.1.md
@@ -1,4 +1,4 @@
-% podman-system-connection-rename(1)
+% podman-system-connection-rename 1
## NAME
podman\-system\-connection\-rename - Rename the destination for Podman service
diff --git a/docs/source/markdown/podman-system-connection.1.md b/docs/source/markdown/podman-system-connection.1.md
index df9d8d248..007fb0d22 100644
--- a/docs/source/markdown/podman-system-connection.1.md
+++ b/docs/source/markdown/podman-system-connection.1.md
@@ -1,4 +1,4 @@
-% podman-system-connection(1)
+% podman-system-connection 1
## NAME
podman\-system\-connection - Manage the destination(s) for Podman service(s)
diff --git a/docs/source/markdown/podman-system-df.1.md b/docs/source/markdown/podman-system-df.1.md
index eb2c79b96..ac37d5e4d 100644
--- a/docs/source/markdown/podman-system-df.1.md
+++ b/docs/source/markdown/podman-system-df.1.md
@@ -1,4 +1,4 @@
-% podman-system-df(1)
+% podman-system-df 1
## NAME
podman\-system\-df - Show podman disk usage
diff --git a/docs/source/markdown/podman-system-migrate.1.md b/docs/source/markdown/podman-system-migrate.1.md
index dbdd24132..2e9cf02e3 100644
--- a/docs/source/markdown/podman-system-migrate.1.md
+++ b/docs/source/markdown/podman-system-migrate.1.md
@@ -1,4 +1,4 @@
-% podman-system-migrate(1)
+% podman-system-migrate 1
## NAME
podman\-system\-migrate - Migrate existing containers to a new podman version
diff --git a/docs/source/markdown/podman-system-prune.1.md b/docs/source/markdown/podman-system-prune.1.md
index c4c17fbe5..cb6603791 100644
--- a/docs/source/markdown/podman-system-prune.1.md
+++ b/docs/source/markdown/podman-system-prune.1.md
@@ -1,4 +1,4 @@
-% podman-system-prune(1)
+% podman-system-prune 1
## NAME
podman\-system\-prune - Remove all unused pods, containers, images, networks, and volume data
diff --git a/docs/source/markdown/podman-system-renumber.1.md b/docs/source/markdown/podman-system-renumber.1.md
index 61e26242b..845fc2c53 100644
--- a/docs/source/markdown/podman-system-renumber.1.md
+++ b/docs/source/markdown/podman-system-renumber.1.md
@@ -1,4 +1,4 @@
-% podman-system-renumber(1)
+% podman-system-renumber 1
## NAME
podman\-system\-renumber - Migrate lock numbers to handle a change in maximum number of locks
diff --git a/docs/source/markdown/podman-system-reset.1.md b/docs/source/markdown/podman-system-reset.1.md
index 11ce11d07..a36e597f7 100644
--- a/docs/source/markdown/podman-system-reset.1.md
+++ b/docs/source/markdown/podman-system-reset.1.md
@@ -1,4 +1,4 @@
-% podman-system-reset(1)
+% podman-system-reset 1
## NAME
podman\-system\-reset - Reset storage back to initial state
diff --git a/docs/source/markdown/podman-system-service.1.md b/docs/source/markdown/podman-system-service.1.md
index 3e7a00362..2ec48aeb4 100644
--- a/docs/source/markdown/podman-system-service.1.md
+++ b/docs/source/markdown/podman-system-service.1.md
@@ -1,4 +1,4 @@
-% podman-service(1)
+% podman-service 1
## NAME
podman\-system\-service - Run an API service
diff --git a/docs/source/markdown/podman-system.1.md b/docs/source/markdown/podman-system.1.md
index 7469eb79d..0a9ef4f49 100644
--- a/docs/source/markdown/podman-system.1.md
+++ b/docs/source/markdown/podman-system.1.md
@@ -1,4 +1,4 @@
-% podman-system(1)
+% podman-system 1
## NAME
podman\-system - Manage podman
diff --git a/docs/source/markdown/podman-tag.1.md b/docs/source/markdown/podman-tag.1.md
index 23dd3b60b..38ccfaec8 100644
--- a/docs/source/markdown/podman-tag.1.md
+++ b/docs/source/markdown/podman-tag.1.md
@@ -1,4 +1,4 @@
-% podman-tag(1)
+% podman-tag 1
## NAME
podman\-tag - Add an additional name to a local image
diff --git a/docs/source/markdown/podman-top.1.md b/docs/source/markdown/podman-top.1.md
index 6b9433b89..ceefe84e9 100644
--- a/docs/source/markdown/podman-top.1.md
+++ b/docs/source/markdown/podman-top.1.md
@@ -1,4 +1,4 @@
-% podman-top(1)
+% podman-top 1
## NAME
podman\-top - Display the running processes of a container
diff --git a/docs/source/markdown/podman-unmount.1.md b/docs/source/markdown/podman-unmount.1.md
index 3f45e8114..5493f3c1e 100644
--- a/docs/source/markdown/podman-unmount.1.md
+++ b/docs/source/markdown/podman-unmount.1.md
@@ -1,4 +1,4 @@
-% podman-unmount(1)
+% podman-unmount 1
## NAME
podman\-unmount - Unmount a working container's root filesystem
diff --git a/docs/source/markdown/podman-unpause.1.md.in b/docs/source/markdown/podman-unpause.1.md.in
index 7bd46e171..85852708a 100644
--- a/docs/source/markdown/podman-unpause.1.md.in
+++ b/docs/source/markdown/podman-unpause.1.md.in
@@ -1,4 +1,4 @@
-% podman-unpause(1)
+% podman-unpause 1
## NAME
podman\-unpause - Unpause one or more containers
diff --git a/docs/source/markdown/podman-unshare.1.md b/docs/source/markdown/podman-unshare.1.md
index db1bc5387..a88e514d3 100644
--- a/docs/source/markdown/podman-unshare.1.md
+++ b/docs/source/markdown/podman-unshare.1.md
@@ -1,4 +1,4 @@
-% podman-unshare(1)
+% podman-unshare 1
## NAME
podman\-unshare - Run a command inside of a modified user namespace
diff --git a/docs/source/markdown/podman-untag.1.md b/docs/source/markdown/podman-untag.1.md
index 0dd882a92..f9ea2b644 100644
--- a/docs/source/markdown/podman-untag.1.md
+++ b/docs/source/markdown/podman-untag.1.md
@@ -1,4 +1,4 @@
-% podman-untag(1)
+% podman-untag 1
## NAME
podman\-untag - Removes one or more names from a locally-stored image
diff --git a/docs/source/markdown/podman-update.1.md.in b/docs/source/markdown/podman-update.1.md.in
index 2928379f3..49f356d25 100644
--- a/docs/source/markdown/podman-update.1.md.in
+++ b/docs/source/markdown/podman-update.1.md.in
@@ -1,4 +1,4 @@
-% podman-update(1)
+% podman-update 1
## NAME
podman\-update - Updates the cgroup configuration of a given container
diff --git a/docs/source/markdown/podman-version.1.md b/docs/source/markdown/podman-version.1.md
index 94fa0fb21..3062d10ab 100644
--- a/docs/source/markdown/podman-version.1.md
+++ b/docs/source/markdown/podman-version.1.md
@@ -1,4 +1,4 @@
-% podman-version(1)
+% podman-version 1
## NAME
podman\-version - Display the Podman version information
diff --git a/docs/source/markdown/podman-volume-create.1.md b/docs/source/markdown/podman-volume-create.1.md
index 65b788851..934488111 100644
--- a/docs/source/markdown/podman-volume-create.1.md
+++ b/docs/source/markdown/podman-volume-create.1.md
@@ -1,4 +1,4 @@
-% podman-volume-create(1)
+% podman-volume-create 1
## NAME
podman\-volume\-create - Create a new volume
diff --git a/docs/source/markdown/podman-volume-exists.1.md b/docs/source/markdown/podman-volume-exists.1.md
index 28d42e987..37aa2b61a 100644
--- a/docs/source/markdown/podman-volume-exists.1.md
+++ b/docs/source/markdown/podman-volume-exists.1.md
@@ -1,4 +1,4 @@
-% podman-volume-exists(1)
+% podman-volume-exists 1
## NAME
podman\-volume\-exists - Check if the given volume exists
diff --git a/docs/source/markdown/podman-volume-export.1.md b/docs/source/markdown/podman-volume-export.1.md
index 57b707ae5..8b2959036 100644
--- a/docs/source/markdown/podman-volume-export.1.md
+++ b/docs/source/markdown/podman-volume-export.1.md
@@ -1,4 +1,4 @@
-% podman-volume-export(1)
+% podman-volume-export 1
## NAME
podman\-volume\-export - Exports volume to external tar
diff --git a/docs/source/markdown/podman-volume-import.1.md b/docs/source/markdown/podman-volume-import.1.md
index ec5d5ebfc..a69ac991b 100644
--- a/docs/source/markdown/podman-volume-import.1.md
+++ b/docs/source/markdown/podman-volume-import.1.md
@@ -1,4 +1,4 @@
-% podman-volume-import(1)
+% podman-volume-import 1
## NAME
podman\-volume\-import - Import tarball contents into an existing podman volume
diff --git a/docs/source/markdown/podman-volume-inspect.1.md b/docs/source/markdown/podman-volume-inspect.1.md
index 9be0f9c2d..45c39c23a 100644
--- a/docs/source/markdown/podman-volume-inspect.1.md
+++ b/docs/source/markdown/podman-volume-inspect.1.md
@@ -1,4 +1,4 @@
-% podman-volume-inspect(1)
+% podman-volume-inspect 1
## NAME
podman\-volume\-inspect - Get detailed information on one or more volumes
diff --git a/docs/source/markdown/podman-volume-ls.1.md b/docs/source/markdown/podman-volume-ls.1.md
index 86896b0a2..69e999251 100644
--- a/docs/source/markdown/podman-volume-ls.1.md
+++ b/docs/source/markdown/podman-volume-ls.1.md
@@ -1,4 +1,4 @@
-% podman-volume-ls(1)
+% podman-volume-ls 1
## NAME
podman\-volume\-ls - List all the available volumes
diff --git a/docs/source/markdown/podman-volume-mount.1.md b/docs/source/markdown/podman-volume-mount.1.md
index a5f35a34d..2066ec19f 100644
--- a/docs/source/markdown/podman-volume-mount.1.md
+++ b/docs/source/markdown/podman-volume-mount.1.md
@@ -1,4 +1,4 @@
-% podman-volume-mount(1)
+% podman-volume-mount 1
## NAME
podman\-volume\-mount - Mount a volume filesystem
diff --git a/docs/source/markdown/podman-volume-prune.1.md b/docs/source/markdown/podman-volume-prune.1.md
index 0127cc12a..ab0479b84 100644
--- a/docs/source/markdown/podman-volume-prune.1.md
+++ b/docs/source/markdown/podman-volume-prune.1.md
@@ -1,4 +1,4 @@
-% podman-volume-prune(1)
+% podman-volume-prune 1
## NAME
podman\-volume\-prune - Remove all unused volumes
diff --git a/docs/source/markdown/podman-volume-reload.1.md b/docs/source/markdown/podman-volume-reload.1.md
index 5b9e9b9ac..4e2d97b91 100644
--- a/docs/source/markdown/podman-volume-reload.1.md
+++ b/docs/source/markdown/podman-volume-reload.1.md
@@ -1,4 +1,4 @@
-% podman-volume-reload(1)
+% podman-volume-reload 1
## NAME
podman\-volume\-reload - Reload all volumes from volumes plugins
diff --git a/docs/source/markdown/podman-volume-rm.1.md b/docs/source/markdown/podman-volume-rm.1.md
index 8274eaaf3..744b322b1 100644
--- a/docs/source/markdown/podman-volume-rm.1.md
+++ b/docs/source/markdown/podman-volume-rm.1.md
@@ -1,4 +1,4 @@
-% podman-volume-rm(1)
+% podman-volume-rm 1
## NAME
podman\-volume\-rm - Remove one or more volumes
diff --git a/docs/source/markdown/podman-volume-unmount.1.md b/docs/source/markdown/podman-volume-unmount.1.md
index c489af6c9..3c4634835 100644
--- a/docs/source/markdown/podman-volume-unmount.1.md
+++ b/docs/source/markdown/podman-volume-unmount.1.md
@@ -1,4 +1,4 @@
-% podman-volume-unmount(1)
+% podman-volume-unmount 1
## NAME
podman\-volume\-unmount - Unmount a volume
diff --git a/docs/source/markdown/podman-volume.1.md b/docs/source/markdown/podman-volume.1.md
index a437590b3..3971b485d 100644
--- a/docs/source/markdown/podman-volume.1.md
+++ b/docs/source/markdown/podman-volume.1.md
@@ -1,4 +1,4 @@
-% podman-volume(1)
+% podman-volume 1
## NAME
podman\-volume - Simple management tool for volumes
diff --git a/docs/source/markdown/podman-wait.1.md b/docs/source/markdown/podman-wait.1.md
index e307e4528..a6aadf28c 100644
--- a/docs/source/markdown/podman-wait.1.md
+++ b/docs/source/markdown/podman-wait.1.md
@@ -1,4 +1,4 @@
-% podman-wait(1)
+% podman-wait 1
## NAME
podman\-wait - Wait on one or more containers to stop and print their exit codes
diff --git a/docs/source/markdown/podman.1.md b/docs/source/markdown/podman.1.md
index 8c3af2561..3b3974dcc 100644
--- a/docs/source/markdown/podman.1.md
+++ b/docs/source/markdown/podman.1.md
@@ -1,4 +1,4 @@
-% podman(1)
+% podman 1
## NAME
podman - Simple management tool for pods, containers and images
diff --git a/go.mod b/go.mod
index e6fb5a8f1..1c2b86b9a 100644
--- a/go.mod
+++ b/go.mod
@@ -8,7 +8,7 @@ require (
github.com/buger/goterm v1.0.4
github.com/checkpoint-restore/checkpointctl v0.0.0-20220321135231-33f4a66335f0
github.com/checkpoint-restore/go-criu/v5 v5.3.0
- github.com/container-orchestrated-devices/container-device-interface v0.5.0
+ github.com/container-orchestrated-devices/container-device-interface v0.5.1
github.com/containernetworking/cni v1.1.2
github.com/containernetworking/plugins v1.1.1
github.com/containers/buildah v1.27.0
diff --git a/go.sum b/go.sum
index b2a311fbf..5815deb72 100644
--- a/go.sum
+++ b/go.sum
@@ -281,8 +281,8 @@ github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h
github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA=
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb/go.mod h1:ZjrT6AXHbDs86ZSdt/osfBi5qfexBrKUdONk989Wnk4=
-github.com/container-orchestrated-devices/container-device-interface v0.5.0 h1:BPFG0J1R8bW7z69DtG98K+/l8jsVYXD/o2fmgKXby2s=
-github.com/container-orchestrated-devices/container-device-interface v0.5.0/go.mod h1:ZToWfSyUH5l9Rk7/bjkUUkNLz4b1mE+CVUVafuikDPY=
+github.com/container-orchestrated-devices/container-device-interface v0.5.1 h1:nXIUTrlEgGcA/n2geY3J7yyaGGhkocSlMkKPS4Qp4c0=
+github.com/container-orchestrated-devices/container-device-interface v0.5.1/go.mod h1:ZToWfSyUH5l9Rk7/bjkUUkNLz4b1mE+CVUVafuikDPY=
github.com/containerd/aufs v0.0.0-20200908144142-dab0cbea06f4/go.mod h1:nukgQABAEopAHvB6j7cnP5zJ+/3aVcE7hCYqvIwAHyE=
github.com/containerd/aufs v0.0.0-20201003224125-76a6863f2989/go.mod h1:AkGGQs9NM2vtYHaUen+NljV0/baGCAPELGm2q9ZXpWU=
github.com/containerd/aufs v0.0.0-20210316121734-20793ff83c97/go.mod h1:kL5kd6KM5TzQjR79jljyi4olc1Vrx6XBlcyj3gNv2PU=
diff --git a/libpod/container.go b/libpod/container.go
index 44a8669fd..1891b124f 100644
--- a/libpod/container.go
+++ b/libpod/container.go
@@ -1133,20 +1133,6 @@ func (c *Container) NetworkDisabled() (bool, error) {
return networkDisabled(c)
}
-func networkDisabled(c *Container) (bool, error) {
- if c.config.CreateNetNS {
- return false, nil
- }
- if !c.config.PostConfigureNetNS {
- for _, ns := range c.config.Spec.Linux.Namespaces {
- if ns.Type == spec.NetworkNamespace {
- return ns.Path == "", nil
- }
- }
- }
- return false, nil
-}
-
func (c *Container) HostNetwork() bool {
if c.config.CreateNetNS || c.config.NetNsCtr != "" {
return false
diff --git a/libpod/container_freebsd.go b/libpod/container_freebsd.go
index f9fbc4daa..7292ba37a 100644
--- a/libpod/container_freebsd.go
+++ b/libpod/container_freebsd.go
@@ -10,3 +10,13 @@ type containerPlatformState struct {
// namespace.
NetworkJail string `json:"-"`
}
+
+func networkDisabled(c *Container) (bool, error) {
+ if c.config.CreateNetNS {
+ return false, nil
+ }
+ if !c.config.PostConfigureNetNS {
+ return c.state.NetworkJail == "", nil
+ }
+ return false, nil
+}
diff --git a/libpod/container_internal_common.go b/libpod/container_internal_common.go
new file mode 100644
index 000000000..192a86b6a
--- /dev/null
+++ b/libpod/container_internal_common.go
@@ -0,0 +1,2699 @@
+//go:build linux || freebsd
+// +build linux freebsd
+
+package libpod
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "io"
+ "io/ioutil"
+ "math"
+ "os"
+ "os/user"
+ "path"
+ "path/filepath"
+ "strconv"
+ "strings"
+ "syscall"
+ "time"
+
+ metadata "github.com/checkpoint-restore/checkpointctl/lib"
+ "github.com/checkpoint-restore/go-criu/v5/stats"
+ cdi "github.com/container-orchestrated-devices/container-device-interface/pkg/cdi"
+ "github.com/containers/buildah"
+ "github.com/containers/buildah/pkg/chrootuser"
+ "github.com/containers/buildah/pkg/overlay"
+ butil "github.com/containers/buildah/util"
+ "github.com/containers/common/libnetwork/etchosts"
+ "github.com/containers/common/libnetwork/resolvconf"
+ "github.com/containers/common/libnetwork/types"
+ "github.com/containers/common/pkg/apparmor"
+ "github.com/containers/common/pkg/chown"
+ "github.com/containers/common/pkg/config"
+ "github.com/containers/common/pkg/subscriptions"
+ "github.com/containers/common/pkg/umask"
+ cutil "github.com/containers/common/pkg/util"
+ is "github.com/containers/image/v5/storage"
+ "github.com/containers/podman/v4/libpod/define"
+ "github.com/containers/podman/v4/libpod/events"
+ "github.com/containers/podman/v4/pkg/annotations"
+ "github.com/containers/podman/v4/pkg/checkpoint/crutils"
+ "github.com/containers/podman/v4/pkg/criu"
+ "github.com/containers/podman/v4/pkg/lookup"
+ "github.com/containers/podman/v4/pkg/rootless"
+ "github.com/containers/podman/v4/pkg/util"
+ "github.com/containers/podman/v4/version"
+ "github.com/containers/storage/pkg/archive"
+ "github.com/containers/storage/pkg/idtools"
+ "github.com/containers/storage/pkg/lockfile"
+ securejoin "github.com/cyphar/filepath-securejoin"
+ runcuser "github.com/opencontainers/runc/libcontainer/user"
+ spec "github.com/opencontainers/runtime-spec/specs-go"
+ "github.com/opencontainers/runtime-tools/generate"
+ "github.com/opencontainers/selinux/go-selinux"
+ "github.com/opencontainers/selinux/go-selinux/label"
+ "github.com/sirupsen/logrus"
+)
+
+// Internal only function which returns upper and work dir from
+// overlay options.
+func getOverlayUpperAndWorkDir(options []string) (string, string, error) {
+ upperDir := ""
+ workDir := ""
+ for _, o := range options {
+ if strings.HasPrefix(o, "upperdir") {
+ splitOpt := strings.SplitN(o, "=", 2)
+ if len(splitOpt) > 1 {
+ upperDir = splitOpt[1]
+ if upperDir == "" {
+ return "", "", errors.New("cannot accept empty value for upperdir")
+ }
+ }
+ }
+ if strings.HasPrefix(o, "workdir") {
+ splitOpt := strings.SplitN(o, "=", 2)
+ if len(splitOpt) > 1 {
+ workDir = splitOpt[1]
+ if workDir == "" {
+ return "", "", errors.New("cannot accept empty value for workdir")
+ }
+ }
+ }
+ }
+ if (upperDir != "" && workDir == "") || (upperDir == "" && workDir != "") {
+ return "", "", errors.New("must specify both upperdir and workdir")
+ }
+ return upperDir, workDir, nil
+}
+
+// Generate spec for a container
+// Accepts a map of the container's dependencies
+func (c *Container) generateSpec(ctx context.Context) (*spec.Spec, error) {
+ overrides := c.getUserOverrides()
+ execUser, err := lookup.GetUserGroupInfo(c.state.Mountpoint, c.config.User, overrides)
+ if err != nil {
+ if cutil.StringInSlice(c.config.User, c.config.HostUsers) {
+ execUser, err = lookupHostUser(c.config.User)
+ }
+ if err != nil {
+ return nil, err
+ }
+ }
+
+ // NewFromSpec() is deprecated according to its comment
+ // however the recommended replace just causes a nil map panic
+ //nolint:staticcheck
+ g := generate.NewFromSpec(c.config.Spec)
+
+ // If the flag to mount all devices is set for a privileged container, add
+ // all the devices from the host's machine into the container
+ if c.config.MountAllDevices {
+ if err := util.AddPrivilegedDevices(&g); err != nil {
+ return nil, err
+ }
+ }
+
+ // If network namespace was requested, add it now
+ if err := c.addNetworkNamespace(&g); err != nil {
+ return nil, err
+ }
+
+ // Apply AppArmor checks and load the default profile if needed.
+ if len(c.config.Spec.Process.ApparmorProfile) > 0 {
+ updatedProfile, err := apparmor.CheckProfileAndLoadDefault(c.config.Spec.Process.ApparmorProfile)
+ if err != nil {
+ return nil, err
+ }
+ g.SetProcessApparmorProfile(updatedProfile)
+ }
+
+ if err := c.makeBindMounts(); err != nil {
+ return nil, err
+ }
+
+ if err := c.mountNotifySocket(g); err != nil {
+ return nil, err
+ }
+
+ // Get host UID and GID based on the container process UID and GID.
+ hostUID, hostGID, err := butil.GetHostIDs(util.IDtoolsToRuntimeSpec(c.config.IDMappings.UIDMap), util.IDtoolsToRuntimeSpec(c.config.IDMappings.GIDMap), uint32(execUser.Uid), uint32(execUser.Gid))
+ if err != nil {
+ return nil, err
+ }
+
+ // Add named volumes
+ for _, namedVol := range c.config.NamedVolumes {
+ volume, err := c.runtime.GetVolume(namedVol.Name)
+ if err != nil {
+ return nil, fmt.Errorf("error retrieving volume %s to add to container %s: %w", namedVol.Name, c.ID(), err)
+ }
+ mountPoint, err := volume.MountPoint()
+ if err != nil {
+ return nil, err
+ }
+
+ overlayFlag := false
+ upperDir := ""
+ workDir := ""
+ for _, o := range namedVol.Options {
+ if o == "O" {
+ overlayFlag = true
+ upperDir, workDir, err = getOverlayUpperAndWorkDir(namedVol.Options)
+ if err != nil {
+ return nil, err
+ }
+ }
+ }
+
+ if overlayFlag {
+ var overlayMount spec.Mount
+ var overlayOpts *overlay.Options
+ contentDir, err := overlay.TempDir(c.config.StaticDir, c.RootUID(), c.RootGID())
+ if err != nil {
+ return nil, err
+ }
+
+ overlayOpts = &overlay.Options{RootUID: c.RootUID(),
+ RootGID: c.RootGID(),
+ UpperDirOptionFragment: upperDir,
+ WorkDirOptionFragment: workDir,
+ GraphOpts: c.runtime.store.GraphOptions(),
+ }
+
+ overlayMount, err = overlay.MountWithOptions(contentDir, mountPoint, namedVol.Dest, overlayOpts)
+ if err != nil {
+ return nil, fmt.Errorf("mounting overlay failed %q: %w", mountPoint, err)
+ }
+
+ for _, o := range namedVol.Options {
+ if o == "U" {
+ if err := c.ChangeHostPathOwnership(mountPoint, true, int(hostUID), int(hostGID)); err != nil {
+ return nil, err
+ }
+
+ if err := c.ChangeHostPathOwnership(contentDir, true, int(hostUID), int(hostGID)); err != nil {
+ return nil, err
+ }
+ }
+ }
+ g.AddMount(overlayMount)
+ } else {
+ volMount := spec.Mount{
+ Type: define.TypeBind,
+ Source: mountPoint,
+ Destination: namedVol.Dest,
+ Options: namedVol.Options,
+ }
+ g.AddMount(volMount)
+ }
+ }
+
+ // Check if the spec file mounts contain the options z, Z or U.
+ // If they have z or Z, relabel the source directory and then remove the option.
+ // If they have U, chown the source directory and them remove the option.
+ for i := range g.Config.Mounts {
+ m := &g.Config.Mounts[i]
+ var options []string
+ for _, o := range m.Options {
+ switch o {
+ case "U":
+ if m.Type == "tmpfs" {
+ options = append(options, []string{fmt.Sprintf("uid=%d", execUser.Uid), fmt.Sprintf("gid=%d", execUser.Gid)}...)
+ } else {
+ // only chown on initial creation of container
+ if err := c.ChangeHostPathOwnership(m.Source, true, int(hostUID), int(hostGID)); err != nil {
+ return nil, err
+ }
+ }
+ case "z":
+ fallthrough
+ case "Z":
+ if err := c.relabel(m.Source, c.MountLabel(), label.IsShared(o)); err != nil {
+ return nil, err
+ }
+
+ default:
+ options = append(options, o)
+ }
+ }
+ m.Options = options
+ }
+
+ c.setProcessLabel(&g)
+ c.setMountLabel(&g)
+
+ // Add bind mounts to container
+ for dstPath, srcPath := range c.state.BindMounts {
+ newMount := spec.Mount{
+ Type: define.TypeBind,
+ Source: srcPath,
+ Destination: dstPath,
+ Options: bindOptions,
+ }
+ if c.IsReadOnly() && dstPath != "/dev/shm" {
+ newMount.Options = append(newMount.Options, "ro", "nosuid", "noexec", "nodev")
+ }
+ if dstPath == "/dev/shm" && c.state.BindMounts["/dev/shm"] == c.config.ShmDir {
+ newMount.Options = append(newMount.Options, "nosuid", "noexec", "nodev")
+ }
+ if !MountExists(g.Mounts(), dstPath) {
+ g.AddMount(newMount)
+ } else {
+ logrus.Infof("User mount overriding libpod mount at %q", dstPath)
+ }
+ }
+
+ // Add overlay volumes
+ for _, overlayVol := range c.config.OverlayVolumes {
+ upperDir, workDir, err := getOverlayUpperAndWorkDir(overlayVol.Options)
+ if err != nil {
+ return nil, err
+ }
+ contentDir, err := overlay.TempDir(c.config.StaticDir, c.RootUID(), c.RootGID())
+ if err != nil {
+ return nil, err
+ }
+ overlayOpts := &overlay.Options{RootUID: c.RootUID(),
+ RootGID: c.RootGID(),
+ UpperDirOptionFragment: upperDir,
+ WorkDirOptionFragment: workDir,
+ GraphOpts: c.runtime.store.GraphOptions(),
+ }
+
+ overlayMount, err := overlay.MountWithOptions(contentDir, overlayVol.Source, overlayVol.Dest, overlayOpts)
+ if err != nil {
+ return nil, fmt.Errorf("mounting overlay failed %q: %w", overlayVol.Source, err)
+ }
+
+ // Check overlay volume options
+ for _, o := range overlayVol.Options {
+ if o == "U" {
+ if err := c.ChangeHostPathOwnership(overlayVol.Source, true, int(hostUID), int(hostGID)); err != nil {
+ return nil, err
+ }
+
+ if err := c.ChangeHostPathOwnership(contentDir, true, int(hostUID), int(hostGID)); err != nil {
+ return nil, err
+ }
+ }
+ }
+
+ g.AddMount(overlayMount)
+ }
+
+ // Add image volumes as overlay mounts
+ for _, volume := range c.config.ImageVolumes {
+ // Mount the specified image.
+ img, _, err := c.runtime.LibimageRuntime().LookupImage(volume.Source, nil)
+ if err != nil {
+ return nil, fmt.Errorf("error creating image volume %q:%q: %w", volume.Source, volume.Dest, err)
+ }
+ mountPoint, err := img.Mount(ctx, nil, "")
+ if err != nil {
+ return nil, fmt.Errorf("error mounting image volume %q:%q: %w", volume.Source, volume.Dest, err)
+ }
+
+ contentDir, err := overlay.TempDir(c.config.StaticDir, c.RootUID(), c.RootGID())
+ if err != nil {
+ return nil, fmt.Errorf("failed to create TempDir in the %s directory: %w", c.config.StaticDir, err)
+ }
+
+ var overlayMount spec.Mount
+ if volume.ReadWrite {
+ overlayMount, err = overlay.Mount(contentDir, mountPoint, volume.Dest, c.RootUID(), c.RootGID(), c.runtime.store.GraphOptions())
+ } else {
+ overlayMount, err = overlay.MountReadOnly(contentDir, mountPoint, volume.Dest, c.RootUID(), c.RootGID(), c.runtime.store.GraphOptions())
+ }
+ if err != nil {
+ return nil, fmt.Errorf("creating overlay mount for image %q failed: %w", volume.Source, err)
+ }
+ g.AddMount(overlayMount)
+ }
+
+ hasHomeSet := false
+ for _, s := range c.config.Spec.Process.Env {
+ if strings.HasPrefix(s, "HOME=") {
+ hasHomeSet = true
+ break
+ }
+ }
+ if !hasHomeSet && execUser.Home != "" {
+ c.config.Spec.Process.Env = append(c.config.Spec.Process.Env, fmt.Sprintf("HOME=%s", execUser.Home))
+ }
+
+ if c.config.User != "" {
+ // User and Group must go together
+ g.SetProcessUID(uint32(execUser.Uid))
+ g.SetProcessGID(uint32(execUser.Gid))
+ g.AddProcessAdditionalGid(uint32(execUser.Gid))
+ }
+
+ if c.config.Umask != "" {
+ decVal, err := strconv.ParseUint(c.config.Umask, 8, 32)
+ if err != nil {
+ return nil, fmt.Errorf("invalid Umask Value: %w", err)
+ }
+ umask := uint32(decVal)
+ g.Config.Process.User.Umask = &umask
+ }
+
+ // Add addition groups if c.config.GroupAdd is not empty
+ if len(c.config.Groups) > 0 {
+ gids, err := lookup.GetContainerGroups(c.config.Groups, c.state.Mountpoint, overrides)
+ if err != nil {
+ return nil, fmt.Errorf("error looking up supplemental groups for container %s: %w", c.ID(), err)
+ }
+ for _, gid := range gids {
+ g.AddProcessAdditionalGid(gid)
+ }
+ }
+
+ if err := c.addSystemdMounts(&g); err != nil {
+ return nil, err
+ }
+
+ // Look up and add groups the user belongs to, if a group wasn't directly specified
+ if !strings.Contains(c.config.User, ":") {
+ // the gidMappings that are present inside the container user namespace
+ var gidMappings []idtools.IDMap
+
+ switch {
+ case len(c.config.IDMappings.GIDMap) > 0:
+ gidMappings = c.config.IDMappings.GIDMap
+ case rootless.IsRootless():
+ // Check whether the current user namespace has enough gids available.
+ availableGids, err := rootless.GetAvailableGids()
+ if err != nil {
+ return nil, fmt.Errorf("cannot read number of available GIDs: %w", err)
+ }
+ gidMappings = []idtools.IDMap{{
+ ContainerID: 0,
+ HostID: 0,
+ Size: int(availableGids),
+ }}
+ default:
+ gidMappings = []idtools.IDMap{{
+ ContainerID: 0,
+ HostID: 0,
+ Size: math.MaxInt32,
+ }}
+ }
+ for _, gid := range execUser.Sgids {
+ isGIDAvailable := false
+ for _, m := range gidMappings {
+ if gid >= m.ContainerID && gid < m.ContainerID+m.Size {
+ isGIDAvailable = true
+ break
+ }
+ }
+ if isGIDAvailable {
+ g.AddProcessAdditionalGid(uint32(gid))
+ } else {
+ logrus.Warnf("Additional gid=%d is not present in the user namespace, skip setting it", gid)
+ }
+ }
+ }
+
+ // Add shared namespaces from other containers
+ if err := c.addSharedNamespaces(&g); err != nil {
+ return nil, err
+ }
+
+ g.SetRootPath(c.state.Mountpoint)
+ g.AddAnnotation(annotations.Created, c.config.CreatedTime.Format(time.RFC3339Nano))
+ g.AddAnnotation("org.opencontainers.image.stopSignal", fmt.Sprintf("%d", c.config.StopSignal))
+
+ if _, exists := g.Config.Annotations[annotations.ContainerManager]; !exists {
+ g.AddAnnotation(annotations.ContainerManager, annotations.ContainerManagerLibpod)
+ }
+
+ if err := c.setCgroupsPath(&g); err != nil {
+ return nil, err
+ }
+
+ // Warning: CDI may alter g.Config in place.
+ if len(c.config.CDIDevices) > 0 {
+ registry := cdi.GetRegistry(
+ cdi.WithAutoRefresh(false),
+ )
+ if err := registry.Refresh(); err != nil {
+ logrus.Debugf("The following error was triggered when refreshing the CDI registry: %v", err)
+ }
+ _, err := registry.InjectDevices(g.Config, c.config.CDIDevices...)
+ if err != nil {
+ return nil, fmt.Errorf("error setting up CDI devices: %w", err)
+ }
+ }
+
+ // Mounts need to be sorted so paths will not cover other paths
+ mounts := sortMounts(g.Mounts())
+ g.ClearMounts()
+
+ for _, m := range mounts {
+ // We need to remove all symlinks from tmpfs mounts.
+ // Runc and other runtimes may choke on them.
+ // Easy solution: use securejoin to do a scoped evaluation of
+ // the links, then trim off the mount prefix.
+ if m.Type == "tmpfs" {
+ finalPath, err := securejoin.SecureJoin(c.state.Mountpoint, m.Destination)
+ if err != nil {
+ return nil, fmt.Errorf("error resolving symlinks for mount destination %s: %w", m.Destination, err)
+ }
+ trimmedPath := strings.TrimPrefix(finalPath, strings.TrimSuffix(c.state.Mountpoint, "/"))
+ m.Destination = trimmedPath
+ }
+ g.AddMount(m)
+ }
+
+ if err := c.addRootPropagation(&g, mounts); err != nil {
+ return nil, err
+ }
+
+ // Warning: precreate hooks may alter g.Config in place.
+ if c.state.ExtensionStageHooks, err = c.setupOCIHooks(ctx, g.Config); err != nil {
+ return nil, fmt.Errorf("error setting up OCI Hooks: %w", err)
+ }
+ if len(c.config.EnvSecrets) > 0 {
+ manager, err := c.runtime.SecretsManager()
+ if err != nil {
+ return nil, err
+ }
+ if err != nil {
+ return nil, err
+ }
+ for name, secr := range c.config.EnvSecrets {
+ _, data, err := manager.LookupSecretData(secr.Name)
+ if err != nil {
+ return nil, err
+ }
+ g.AddProcessEnv(name, string(data))
+ }
+ }
+
+ // Pass down the LISTEN_* environment (see #10443).
+ for _, key := range []string{"LISTEN_PID", "LISTEN_FDS", "LISTEN_FDNAMES"} {
+ if val, ok := os.LookupEnv(key); ok {
+ // Force the PID to `1` since we cannot rely on (all
+ // versions of) all runtimes to do it for us.
+ if key == "LISTEN_PID" {
+ val = "1"
+ }
+ g.AddProcessEnv(key, val)
+ }
+ }
+
+ return g.Config, nil
+}
+
+// isWorkDirSymlink returns true if resolved workdir is symlink or a chain of symlinks,
+// and final resolved target is present either on volume, mount or inside of container
+// otherwise it returns false. Following function is meant for internal use only and
+// can change at any point of time.
+func (c *Container) isWorkDirSymlink(resolvedPath string) bool {
+ // We cannot create workdir since explicit --workdir is
+ // set in config but workdir could also be a symlink.
+ // If it's a symlink, check if the resolved target is present in the container.
+ // If so, that's a valid use case: return nil.
+
+ maxSymLinks := 0
+ for {
+ // Linux only supports a chain of 40 links.
+ // Reference: https://github.com/torvalds/linux/blob/master/include/linux/namei.h#L13
+ if maxSymLinks > 40 {
+ break
+ }
+ resolvedSymlink, err := os.Readlink(resolvedPath)
+ if err != nil {
+ // End sym-link resolution loop.
+ break
+ }
+ if resolvedSymlink != "" {
+ _, resolvedSymlinkWorkdir, err := c.resolvePath(c.state.Mountpoint, resolvedSymlink)
+ if isPathOnVolume(c, resolvedSymlinkWorkdir) || isPathOnBindMount(c, resolvedSymlinkWorkdir) {
+ // Resolved symlink exists on external volume or mount
+ return true
+ }
+ if err != nil {
+ // Could not resolve path so end sym-link resolution loop.
+ break
+ }
+ if resolvedSymlinkWorkdir != "" {
+ resolvedPath = resolvedSymlinkWorkdir
+ _, err := os.Stat(resolvedSymlinkWorkdir)
+ if err == nil {
+ // Symlink resolved successfully and resolved path exists on container,
+ // this is a valid use-case so return nil.
+ logrus.Debugf("Workdir is a symlink with target to %q and resolved symlink exists on container", resolvedSymlink)
+ return true
+ }
+ }
+ }
+ maxSymLinks++
+ }
+ return false
+}
+
+// resolveWorkDir resolves the container's workdir and, depending on the
+// configuration, will create it, or error out if it does not exist.
+// Note that the container must be mounted before.
+func (c *Container) resolveWorkDir() error {
+ workdir := c.WorkingDir()
+
+ // If the specified workdir is a subdir of a volume or mount,
+ // we don't need to do anything. The runtime is taking care of
+ // that.
+ if isPathOnVolume(c, workdir) || isPathOnBindMount(c, workdir) {
+ logrus.Debugf("Workdir %q resolved to a volume or mount", workdir)
+ return nil
+ }
+
+ _, resolvedWorkdir, err := c.resolvePath(c.state.Mountpoint, workdir)
+ if err != nil {
+ return err
+ }
+ logrus.Debugf("Workdir %q resolved to host path %q", workdir, resolvedWorkdir)
+
+ st, err := os.Stat(resolvedWorkdir)
+ if err == nil {
+ if !st.IsDir() {
+ return fmt.Errorf("workdir %q exists on container %s, but is not a directory", workdir, c.ID())
+ }
+ return nil
+ }
+ if !c.config.CreateWorkingDir {
+ // No need to create it (e.g., `--workdir=/foo`), so let's make sure
+ // the path exists on the container.
+ if err != nil {
+ if os.IsNotExist(err) {
+ // If resolved Workdir path gets marked as a valid symlink,
+ // return nil cause this is valid use-case.
+ if c.isWorkDirSymlink(resolvedWorkdir) {
+ return nil
+ }
+ return fmt.Errorf("workdir %q does not exist on container %s", workdir, c.ID())
+ }
+ // This might be a serious error (e.g., permission), so
+ // we need to return the full error.
+ return fmt.Errorf("error detecting workdir %q on container %s: %w", workdir, c.ID(), err)
+ }
+ return nil
+ }
+ if err := os.MkdirAll(resolvedWorkdir, 0755); err != nil {
+ if os.IsExist(err) {
+ return nil
+ }
+ return fmt.Errorf("error creating container %s workdir: %w", c.ID(), err)
+ }
+
+ // Ensure container entrypoint is created (if required).
+ uid, gid, _, err := chrootuser.GetUser(c.state.Mountpoint, c.User())
+ if err != nil {
+ return fmt.Errorf("error looking up %s inside of the container %s: %w", c.User(), c.ID(), err)
+ }
+ if err := os.Chown(resolvedWorkdir, int(uid), int(gid)); err != nil {
+ return fmt.Errorf("error chowning container %s workdir to container root: %w", c.ID(), err)
+ }
+
+ return nil
+}
+
+func (c *Container) getUserOverrides() *lookup.Overrides {
+ var hasPasswdFile, hasGroupFile bool
+ overrides := lookup.Overrides{}
+ for _, m := range c.config.Spec.Mounts {
+ if m.Destination == "/etc/passwd" {
+ overrides.ContainerEtcPasswdPath = m.Source
+ hasPasswdFile = true
+ }
+ if m.Destination == "/etc/group" {
+ overrides.ContainerEtcGroupPath = m.Source
+ hasGroupFile = true
+ }
+ if m.Destination == "/etc" {
+ if !hasPasswdFile {
+ overrides.ContainerEtcPasswdPath = filepath.Join(m.Source, "passwd")
+ }
+ if !hasGroupFile {
+ overrides.ContainerEtcGroupPath = filepath.Join(m.Source, "group")
+ }
+ }
+ }
+ if path, ok := c.state.BindMounts["/etc/passwd"]; ok {
+ overrides.ContainerEtcPasswdPath = path
+ }
+ return &overrides
+}
+
+func lookupHostUser(name string) (*runcuser.ExecUser, error) {
+ var execUser runcuser.ExecUser
+ // Look up User on host
+ u, err := util.LookupUser(name)
+ if err != nil {
+ return &execUser, err
+ }
+ uid, err := strconv.ParseUint(u.Uid, 8, 32)
+ if err != nil {
+ return &execUser, err
+ }
+
+ gid, err := strconv.ParseUint(u.Gid, 8, 32)
+ if err != nil {
+ return &execUser, err
+ }
+ execUser.Uid = int(uid)
+ execUser.Gid = int(gid)
+ execUser.Home = u.HomeDir
+ return &execUser, nil
+}
+
+// mountNotifySocket mounts the NOTIFY_SOCKET into the container if it's set
+// and if the sdnotify mode is set to container. It also sets c.notifySocket
+// to avoid redundantly looking up the env variable.
+func (c *Container) mountNotifySocket(g generate.Generator) error {
+ if c.config.SdNotifySocket == "" {
+ return nil
+ }
+ if c.config.SdNotifyMode != define.SdNotifyModeContainer {
+ return nil
+ }
+
+ notifyDir := filepath.Join(c.bundlePath(), "notify")
+ logrus.Debugf("Checking notify %q dir", notifyDir)
+ if err := os.MkdirAll(notifyDir, 0755); err != nil {
+ if !os.IsExist(err) {
+ return fmt.Errorf("unable to create notify %q dir: %w", notifyDir, err)
+ }
+ }
+ if err := label.Relabel(notifyDir, c.MountLabel(), true); err != nil {
+ return fmt.Errorf("relabel failed %q: %w", notifyDir, err)
+ }
+ logrus.Debugf("Add bindmount notify %q dir", notifyDir)
+ if _, ok := c.state.BindMounts["/run/notify"]; !ok {
+ c.state.BindMounts["/run/notify"] = notifyDir
+ }
+
+ // Set the container's notify socket to the proxy socket created by conmon
+ g.AddProcessEnv("NOTIFY_SOCKET", "/run/notify/notify.sock")
+
+ return nil
+}
+
+func (c *Container) addCheckpointImageMetadata(importBuilder *buildah.Builder) error {
+ // Get information about host environment
+ hostInfo, err := c.Runtime().hostInfo()
+ if err != nil {
+ return fmt.Errorf("getting host info: %v", err)
+ }
+
+ criuVersion, err := criu.GetCriuVersion()
+ if err != nil {
+ return fmt.Errorf("getting criu version: %v", err)
+ }
+
+ rootfsImageID, rootfsImageName := c.Image()
+
+ // Add image annotations with information about the container and the host.
+ // This information is useful to check compatibility before restoring the checkpoint
+
+ checkpointImageAnnotations := map[string]string{
+ define.CheckpointAnnotationName: c.config.Name,
+ define.CheckpointAnnotationRawImageName: c.config.RawImageName,
+ define.CheckpointAnnotationRootfsImageID: rootfsImageID,
+ define.CheckpointAnnotationRootfsImageName: rootfsImageName,
+ define.CheckpointAnnotationPodmanVersion: version.Version.String(),
+ define.CheckpointAnnotationCriuVersion: strconv.Itoa(criuVersion),
+ define.CheckpointAnnotationRuntimeName: hostInfo.OCIRuntime.Name,
+ define.CheckpointAnnotationRuntimeVersion: hostInfo.OCIRuntime.Version,
+ define.CheckpointAnnotationConmonVersion: hostInfo.Conmon.Version,
+ define.CheckpointAnnotationHostArch: hostInfo.Arch,
+ define.CheckpointAnnotationHostKernel: hostInfo.Kernel,
+ define.CheckpointAnnotationCgroupVersion: hostInfo.CgroupsVersion,
+ define.CheckpointAnnotationDistributionVersion: hostInfo.Distribution.Version,
+ define.CheckpointAnnotationDistributionName: hostInfo.Distribution.Distribution,
+ }
+
+ for key, value := range checkpointImageAnnotations {
+ importBuilder.SetAnnotation(key, value)
+ }
+
+ return nil
+}
+
+func (c *Container) resolveCheckpointImageName(options *ContainerCheckpointOptions) error {
+ if options.CreateImage == "" {
+ return nil
+ }
+
+ // Resolve image name
+ resolvedImageName, err := c.runtime.LibimageRuntime().ResolveName(options.CreateImage)
+ if err != nil {
+ return err
+ }
+
+ options.CreateImage = resolvedImageName
+ return nil
+}
+
+func (c *Container) createCheckpointImage(ctx context.Context, options ContainerCheckpointOptions) error {
+ if options.CreateImage == "" {
+ return nil
+ }
+ logrus.Debugf("Create checkpoint image %s", options.CreateImage)
+
+ // Create storage reference
+ imageRef, err := is.Transport.ParseStoreReference(c.runtime.store, options.CreateImage)
+ if err != nil {
+ return errors.New("failed to parse image name")
+ }
+
+ // Build an image scratch
+ builderOptions := buildah.BuilderOptions{
+ FromImage: "scratch",
+ }
+ importBuilder, err := buildah.NewBuilder(ctx, c.runtime.store, builderOptions)
+ if err != nil {
+ return err
+ }
+ // Clean up buildah working container
+ defer func() {
+ if err := importBuilder.Delete(); err != nil {
+ logrus.Errorf("Image builder delete failed: %v", err)
+ }
+ }()
+
+ if err := c.prepareCheckpointExport(); err != nil {
+ return err
+ }
+
+ // Export checkpoint into temporary tar file
+ tmpDir, err := ioutil.TempDir("", "checkpoint_image_")
+ if err != nil {
+ return err
+ }
+ defer os.RemoveAll(tmpDir)
+
+ options.TargetFile = path.Join(tmpDir, "checkpoint.tar")
+
+ if err := c.exportCheckpoint(options); err != nil {
+ return err
+ }
+
+ // Copy checkpoint from temporary tar file in the image
+ addAndCopyOptions := buildah.AddAndCopyOptions{}
+ if err := importBuilder.Add("", true, addAndCopyOptions, options.TargetFile); err != nil {
+ return err
+ }
+
+ if err := c.addCheckpointImageMetadata(importBuilder); err != nil {
+ return err
+ }
+
+ commitOptions := buildah.CommitOptions{
+ Squash: true,
+ SystemContext: c.runtime.imageContext,
+ }
+
+ // Create checkpoint image
+ id, _, _, err := importBuilder.Commit(ctx, imageRef, commitOptions)
+ if err != nil {
+ return err
+ }
+ logrus.Debugf("Created checkpoint image: %s", id)
+ return nil
+}
+
+func (c *Container) exportCheckpoint(options ContainerCheckpointOptions) error {
+ if len(c.Dependencies()) == 1 {
+ // Check if the dependency is an infra container. If it is we can checkpoint
+ // the container out of the Pod.
+ if c.config.Pod == "" {
+ return errors.New("cannot export checkpoints of containers with dependencies")
+ }
+
+ pod, err := c.runtime.state.Pod(c.config.Pod)
+ if err != nil {
+ return fmt.Errorf("container %s is in pod %s, but pod cannot be retrieved: %w", c.ID(), c.config.Pod, err)
+ }
+ infraID, err := pod.InfraContainerID()
+ if err != nil {
+ return fmt.Errorf("cannot retrieve infra container ID for pod %s: %w", c.config.Pod, err)
+ }
+ if c.Dependencies()[0] != infraID {
+ return errors.New("cannot export checkpoints of containers with dependencies")
+ }
+ }
+ if len(c.Dependencies()) > 1 {
+ return errors.New("cannot export checkpoints of containers with dependencies")
+ }
+ logrus.Debugf("Exporting checkpoint image of container %q to %q", c.ID(), options.TargetFile)
+
+ includeFiles := []string{
+ "artifacts",
+ metadata.DevShmCheckpointTar,
+ metadata.ConfigDumpFile,
+ metadata.SpecDumpFile,
+ metadata.NetworkStatusFile,
+ stats.StatsDump,
+ }
+
+ if c.LogDriver() == define.KubernetesLogging ||
+ c.LogDriver() == define.JSONLogging {
+ includeFiles = append(includeFiles, "ctr.log")
+ }
+ if options.PreCheckPoint {
+ includeFiles = append(includeFiles, preCheckpointDir)
+ } else {
+ includeFiles = append(includeFiles, metadata.CheckpointDirectory)
+ }
+ // Get root file-system changes included in the checkpoint archive
+ var addToTarFiles []string
+ if !options.IgnoreRootfs {
+ // To correctly track deleted files, let's go through the output of 'podman diff'
+ rootFsChanges, err := c.runtime.GetDiff("", c.ID(), define.DiffContainer)
+ if err != nil {
+ return fmt.Errorf("error exporting root file-system diff for %q: %w", c.ID(), err)
+ }
+
+ addToTarFiles, err := crutils.CRCreateRootFsDiffTar(&rootFsChanges, c.state.Mountpoint, c.bundlePath())
+ if err != nil {
+ return err
+ }
+
+ includeFiles = append(includeFiles, addToTarFiles...)
+ }
+
+ // Folder containing archived volumes that will be included in the export
+ expVolDir := filepath.Join(c.bundlePath(), metadata.CheckpointVolumesDirectory)
+
+ // Create an archive for each volume associated with the container
+ if !options.IgnoreVolumes {
+ if err := os.MkdirAll(expVolDir, 0700); err != nil {
+ return fmt.Errorf("error creating volumes export directory %q: %w", expVolDir, err)
+ }
+
+ for _, v := range c.config.NamedVolumes {
+ volumeTarFilePath := filepath.Join(metadata.CheckpointVolumesDirectory, v.Name+".tar")
+ volumeTarFileFullPath := filepath.Join(c.bundlePath(), volumeTarFilePath)
+
+ volumeTarFile, err := os.Create(volumeTarFileFullPath)
+ if err != nil {
+ return fmt.Errorf("error creating %q: %w", volumeTarFileFullPath, err)
+ }
+
+ volume, err := c.runtime.GetVolume(v.Name)
+ if err != nil {
+ return err
+ }
+
+ mp, err := volume.MountPoint()
+ if err != nil {
+ return err
+ }
+ if mp == "" {
+ return fmt.Errorf("volume %s is not mounted, cannot export: %w", volume.Name(), define.ErrInternal)
+ }
+
+ input, err := archive.TarWithOptions(mp, &archive.TarOptions{
+ Compression: archive.Uncompressed,
+ IncludeSourceDir: true,
+ })
+ if err != nil {
+ return fmt.Errorf("error reading volume directory %q: %w", v.Dest, err)
+ }
+
+ _, err = io.Copy(volumeTarFile, input)
+ if err != nil {
+ return err
+ }
+ volumeTarFile.Close()
+
+ includeFiles = append(includeFiles, volumeTarFilePath)
+ }
+ }
+
+ input, err := archive.TarWithOptions(c.bundlePath(), &archive.TarOptions{
+ Compression: options.Compression,
+ IncludeSourceDir: true,
+ IncludeFiles: includeFiles,
+ })
+
+ if err != nil {
+ return fmt.Errorf("error reading checkpoint directory %q: %w", c.ID(), err)
+ }
+
+ outFile, err := os.Create(options.TargetFile)
+ if err != nil {
+ return fmt.Errorf("error creating checkpoint export file %q: %w", options.TargetFile, err)
+ }
+ defer outFile.Close()
+
+ if err := os.Chmod(options.TargetFile, 0600); err != nil {
+ return err
+ }
+
+ _, err = io.Copy(outFile, input)
+ if err != nil {
+ return err
+ }
+
+ for _, file := range addToTarFiles {
+ os.Remove(filepath.Join(c.bundlePath(), file))
+ }
+
+ if !options.IgnoreVolumes {
+ os.RemoveAll(expVolDir)
+ }
+
+ return nil
+}
+
+func (c *Container) checkpointRestoreSupported(version int) error {
+ if !criu.CheckForCriu(version) {
+ return fmt.Errorf("checkpoint/restore requires at least CRIU %d", version)
+ }
+ if !c.ociRuntime.SupportsCheckpoint() {
+ return errors.New("configured runtime does not support checkpoint/restore")
+ }
+ return nil
+}
+
+func (c *Container) checkpoint(ctx context.Context, options ContainerCheckpointOptions) (*define.CRIUCheckpointRestoreStatistics, int64, error) {
+ if err := c.checkpointRestoreSupported(criu.MinCriuVersion); err != nil {
+ return nil, 0, err
+ }
+
+ if c.state.State != define.ContainerStateRunning {
+ return nil, 0, fmt.Errorf("%q is not running, cannot checkpoint: %w", c.state.State, define.ErrCtrStateInvalid)
+ }
+
+ if c.AutoRemove() && options.TargetFile == "" {
+ return nil, 0, errors.New("cannot checkpoint containers that have been started with '--rm' unless '--export' is used")
+ }
+
+ if err := c.resolveCheckpointImageName(&options); err != nil {
+ return nil, 0, err
+ }
+
+ if err := crutils.CRCreateFileWithLabel(c.bundlePath(), "dump.log", c.MountLabel()); err != nil {
+ return nil, 0, err
+ }
+
+ // Setting CheckpointLog early in case there is a failure.
+ c.state.CheckpointLog = path.Join(c.bundlePath(), "dump.log")
+ c.state.CheckpointPath = c.CheckpointPath()
+
+ runtimeCheckpointDuration, err := c.ociRuntime.CheckpointContainer(c, options)
+ if err != nil {
+ return nil, 0, err
+ }
+
+ // Keep the content of /dev/shm directory
+ if c.config.ShmDir != "" && c.state.BindMounts["/dev/shm"] == c.config.ShmDir {
+ shmDirTarFileFullPath := filepath.Join(c.bundlePath(), metadata.DevShmCheckpointTar)
+
+ shmDirTarFile, err := os.Create(shmDirTarFileFullPath)
+ if err != nil {
+ return nil, 0, err
+ }
+ defer shmDirTarFile.Close()
+
+ input, err := archive.TarWithOptions(c.config.ShmDir, &archive.TarOptions{
+ Compression: archive.Uncompressed,
+ IncludeSourceDir: true,
+ })
+ if err != nil {
+ return nil, 0, err
+ }
+
+ if _, err = io.Copy(shmDirTarFile, input); err != nil {
+ return nil, 0, err
+ }
+ }
+
+ // Save network.status. This is needed to restore the container with
+ // the same IP. Currently limited to one IP address in a container
+ // with one interface.
+ // FIXME: will this break something?
+ if _, err := metadata.WriteJSONFile(c.getNetworkStatus(), c.bundlePath(), metadata.NetworkStatusFile); err != nil {
+ return nil, 0, err
+ }
+
+ defer c.newContainerEvent(events.Checkpoint)
+
+ // There is a bug from criu: https://github.com/checkpoint-restore/criu/issues/116
+ // We have to change the symbolic link from absolute path to relative path
+ if options.WithPrevious {
+ os.Remove(path.Join(c.CheckpointPath(), "parent"))
+ if err := os.Symlink("../pre-checkpoint", path.Join(c.CheckpointPath(), "parent")); err != nil {
+ return nil, 0, err
+ }
+ }
+
+ if options.TargetFile != "" {
+ if err := c.exportCheckpoint(options); err != nil {
+ return nil, 0, err
+ }
+ } else {
+ if err := c.createCheckpointImage(ctx, options); err != nil {
+ return nil, 0, err
+ }
+ }
+
+ logrus.Debugf("Checkpointed container %s", c.ID())
+
+ if !options.KeepRunning && !options.PreCheckPoint {
+ c.state.State = define.ContainerStateStopped
+ c.state.Checkpointed = true
+ c.state.CheckpointedTime = time.Now()
+ c.state.Restored = false
+ c.state.RestoredTime = time.Time{}
+
+ // Clean up Storage and Network
+ if err := c.cleanup(ctx); err != nil {
+ return nil, 0, err
+ }
+ }
+
+ criuStatistics, err := func() (*define.CRIUCheckpointRestoreStatistics, error) {
+ if !options.PrintStats {
+ return nil, nil
+ }
+ statsDirectory, err := os.Open(c.bundlePath())
+ if err != nil {
+ return nil, fmt.Errorf("not able to open %q: %w", c.bundlePath(), err)
+ }
+
+ dumpStatistics, err := stats.CriuGetDumpStats(statsDirectory)
+ if err != nil {
+ return nil, fmt.Errorf("displaying checkpointing statistics not possible: %w", err)
+ }
+
+ return &define.CRIUCheckpointRestoreStatistics{
+ FreezingTime: dumpStatistics.GetFreezingTime(),
+ FrozenTime: dumpStatistics.GetFrozenTime(),
+ MemdumpTime: dumpStatistics.GetMemdumpTime(),
+ MemwriteTime: dumpStatistics.GetMemwriteTime(),
+ PagesScanned: dumpStatistics.GetPagesScanned(),
+ PagesWritten: dumpStatistics.GetPagesWritten(),
+ }, nil
+ }()
+ if err != nil {
+ return nil, 0, err
+ }
+
+ if !options.Keep && !options.PreCheckPoint {
+ cleanup := []string{
+ "dump.log",
+ stats.StatsDump,
+ metadata.ConfigDumpFile,
+ metadata.SpecDumpFile,
+ }
+ for _, del := range cleanup {
+ file := filepath.Join(c.bundlePath(), del)
+ if err := os.Remove(file); err != nil {
+ logrus.Debugf("Unable to remove file %s", file)
+ }
+ }
+ // The file has been deleted. Do not mention it.
+ c.state.CheckpointLog = ""
+ }
+
+ c.state.FinishedTime = time.Now()
+ return criuStatistics, runtimeCheckpointDuration, c.save()
+}
+
+func (c *Container) generateContainerSpec() error {
+ // Make sure the newly created config.json exists on disk
+
+ // NewFromSpec() is deprecated according to its comment
+ // however the recommended replace just causes a nil map panic
+ //nolint:staticcheck
+ g := generate.NewFromSpec(c.config.Spec)
+
+ if err := c.saveSpec(g.Config); err != nil {
+ return fmt.Errorf("saving imported container specification for restore failed: %w", err)
+ }
+
+ return nil
+}
+
+func (c *Container) importCheckpointImage(ctx context.Context, imageID string) error {
+ img, _, err := c.Runtime().LibimageRuntime().LookupImage(imageID, nil)
+ if err != nil {
+ return err
+ }
+
+ mountPoint, err := img.Mount(ctx, nil, "")
+ defer func() {
+ if err := c.unmount(true); err != nil {
+ logrus.Errorf("Failed to unmount container: %v", err)
+ }
+ }()
+ if err != nil {
+ return err
+ }
+
+ // Import all checkpoint files except ConfigDumpFile and SpecDumpFile. We
+ // generate new container config files to enable to specifying a new
+ // container name.
+ checkpoint := []string{
+ "artifacts",
+ metadata.CheckpointDirectory,
+ metadata.CheckpointVolumesDirectory,
+ metadata.DevShmCheckpointTar,
+ metadata.RootFsDiffTar,
+ metadata.DeletedFilesFile,
+ metadata.PodOptionsFile,
+ metadata.PodDumpFile,
+ }
+
+ for _, name := range checkpoint {
+ src := filepath.Join(mountPoint, name)
+ dst := filepath.Join(c.bundlePath(), name)
+ if err := archive.NewDefaultArchiver().CopyWithTar(src, dst); err != nil {
+ logrus.Debugf("Can't import '%s' from checkpoint image", name)
+ }
+ }
+
+ return c.generateContainerSpec()
+}
+
+func (c *Container) importCheckpointTar(input string) error {
+ if err := crutils.CRImportCheckpointWithoutConfig(c.bundlePath(), input); err != nil {
+ return err
+ }
+
+ return c.generateContainerSpec()
+}
+
+func (c *Container) importPreCheckpoint(input string) error {
+ archiveFile, err := os.Open(input)
+ if err != nil {
+ return fmt.Errorf("failed to open pre-checkpoint archive for import: %w", err)
+ }
+
+ defer archiveFile.Close()
+
+ err = archive.Untar(archiveFile, c.bundlePath(), nil)
+ if err != nil {
+ return fmt.Errorf("unpacking of pre-checkpoint archive %s failed: %w", input, err)
+ }
+ return nil
+}
+
+func (c *Container) restore(ctx context.Context, options ContainerCheckpointOptions) (criuStatistics *define.CRIUCheckpointRestoreStatistics, runtimeRestoreDuration int64, retErr error) {
+ minCriuVersion := func() int {
+ if options.Pod == "" {
+ return criu.MinCriuVersion
+ }
+ return criu.PodCriuVersion
+ }()
+ if err := c.checkpointRestoreSupported(minCriuVersion); err != nil {
+ return nil, 0, err
+ }
+
+ if options.Pod != "" && !crutils.CRRuntimeSupportsPodCheckpointRestore(c.ociRuntime.Path()) {
+ return nil, 0, fmt.Errorf("runtime %s does not support pod restore", c.ociRuntime.Path())
+ }
+
+ if !c.ensureState(define.ContainerStateConfigured, define.ContainerStateExited) {
+ return nil, 0, fmt.Errorf("container %s is running or paused, cannot restore: %w", c.ID(), define.ErrCtrStateInvalid)
+ }
+
+ if options.ImportPrevious != "" {
+ if err := c.importPreCheckpoint(options.ImportPrevious); err != nil {
+ return nil, 0, err
+ }
+ }
+
+ if options.TargetFile != "" {
+ if err := c.importCheckpointTar(options.TargetFile); err != nil {
+ return nil, 0, err
+ }
+ } else if options.CheckpointImageID != "" {
+ if err := c.importCheckpointImage(ctx, options.CheckpointImageID); err != nil {
+ return nil, 0, err
+ }
+ }
+
+ // Let's try to stat() CRIU's inventory file. If it does not exist, it makes
+ // no sense to try a restore. This is a minimal check if a checkpoint exist.
+ if _, err := os.Stat(filepath.Join(c.CheckpointPath(), "inventory.img")); os.IsNotExist(err) {
+ return nil, 0, fmt.Errorf("a complete checkpoint for this container cannot be found, cannot restore: %w", err)
+ }
+
+ if err := crutils.CRCreateFileWithLabel(c.bundlePath(), "restore.log", c.MountLabel()); err != nil {
+ return nil, 0, err
+ }
+
+ // Setting RestoreLog early in case there is a failure.
+ c.state.RestoreLog = path.Join(c.bundlePath(), "restore.log")
+ c.state.CheckpointPath = c.CheckpointPath()
+
+ // Read network configuration from checkpoint
+ var netStatus map[string]types.StatusBlock
+ _, err := metadata.ReadJSONFile(&netStatus, c.bundlePath(), metadata.NetworkStatusFile)
+ if err != nil {
+ logrus.Infof("Failed to unmarshal network status, cannot restore the same ip/mac: %v", err)
+ }
+ // If the restored container should get a new name, the IP address of
+ // the container will not be restored. This assumes that if a new name is
+ // specified, the container is restored multiple times.
+ // TODO: This implicit restoring with or without IP depending on an
+ // unrelated restore parameter (--name) does not seem like the
+ // best solution.
+ if err == nil && options.Name == "" && (!options.IgnoreStaticIP || !options.IgnoreStaticMAC) {
+ // The file with the network.status does exist. Let's restore the
+ // container with the same networks settings as during checkpointing.
+ networkOpts, err := c.networks()
+ if err != nil {
+ return nil, 0, err
+ }
+
+ netOpts := make(map[string]types.PerNetworkOptions, len(netStatus))
+ for network, perNetOpts := range networkOpts {
+ // unset mac and ips before we start adding the ones from the status
+ perNetOpts.StaticMAC = nil
+ perNetOpts.StaticIPs = nil
+ for name, netInt := range netStatus[network].Interfaces {
+ perNetOpts.InterfaceName = name
+ if !options.IgnoreStaticIP {
+ perNetOpts.StaticMAC = netInt.MacAddress
+ }
+ if !options.IgnoreStaticIP {
+ for _, netAddress := range netInt.Subnets {
+ perNetOpts.StaticIPs = append(perNetOpts.StaticIPs, netAddress.IPNet.IP)
+ }
+ }
+ // Normally interfaces have a length of 1, only for some special cni configs we could get more.
+ // For now just use the first interface to get the ips this should be good enough for most cases.
+ break
+ }
+ netOpts[network] = perNetOpts
+ }
+ c.perNetworkOpts = netOpts
+ }
+
+ defer func() {
+ if retErr != nil {
+ if err := c.cleanup(ctx); err != nil {
+ logrus.Errorf("Cleaning up container %s: %v", c.ID(), err)
+ }
+ }
+ }()
+
+ if err := c.prepare(); err != nil {
+ return nil, 0, err
+ }
+
+ // Read config
+ jsonPath := filepath.Join(c.bundlePath(), "config.json")
+ logrus.Debugf("generate.NewFromFile at %v", jsonPath)
+ g, err := generate.NewFromFile(jsonPath)
+ if err != nil {
+ logrus.Debugf("generate.NewFromFile failed with %v", err)
+ return nil, 0, err
+ }
+
+ // Restoring from an import means that we are doing migration
+ if options.TargetFile != "" || options.CheckpointImageID != "" {
+ g.SetRootPath(c.state.Mountpoint)
+ }
+
+ // We want to have the same network namespace as before.
+ if err := c.addNetworkNamespace(&g); err != nil {
+ return nil, 0, err
+ }
+
+ if options.Pod != "" {
+ // Running in a Pod means that we have to change all namespace settings to
+ // the ones from the infrastructure container.
+ pod, err := c.runtime.LookupPod(options.Pod)
+ if err != nil {
+ return nil, 0, fmt.Errorf("pod %q cannot be retrieved: %w", options.Pod, err)
+ }
+
+ infraContainer, err := pod.InfraContainer()
+ if err != nil {
+ return nil, 0, fmt.Errorf("cannot retrieved infra container from pod %q: %w", options.Pod, err)
+ }
+
+ infraContainer.lock.Lock()
+ if err := infraContainer.syncContainer(); err != nil {
+ infraContainer.lock.Unlock()
+ return nil, 0, fmt.Errorf("error syncing infrastructure container %s status: %w", infraContainer.ID(), err)
+ }
+ if infraContainer.state.State != define.ContainerStateRunning {
+ if err := infraContainer.initAndStart(ctx); err != nil {
+ infraContainer.lock.Unlock()
+ return nil, 0, fmt.Errorf("error starting infrastructure container %s status: %w", infraContainer.ID(), err)
+ }
+ }
+ infraContainer.lock.Unlock()
+
+ if c.config.IPCNsCtr != "" {
+ nsPath, err := infraContainer.namespacePath(IPCNS)
+ if err != nil {
+ return nil, 0, fmt.Errorf("cannot retrieve IPC namespace path for Pod %q: %w", options.Pod, err)
+ }
+ if err := g.AddOrReplaceLinuxNamespace(string(spec.IPCNamespace), nsPath); err != nil {
+ return nil, 0, err
+ }
+ }
+
+ if c.config.NetNsCtr != "" {
+ nsPath, err := infraContainer.namespacePath(NetNS)
+ if err != nil {
+ return nil, 0, fmt.Errorf("cannot retrieve network namespace path for Pod %q: %w", options.Pod, err)
+ }
+ if err := g.AddOrReplaceLinuxNamespace(string(spec.NetworkNamespace), nsPath); err != nil {
+ return nil, 0, err
+ }
+ }
+
+ if c.config.PIDNsCtr != "" {
+ nsPath, err := infraContainer.namespacePath(PIDNS)
+ if err != nil {
+ return nil, 0, fmt.Errorf("cannot retrieve PID namespace path for Pod %q: %w", options.Pod, err)
+ }
+ if err := g.AddOrReplaceLinuxNamespace(string(spec.PIDNamespace), nsPath); err != nil {
+ return nil, 0, err
+ }
+ }
+
+ if c.config.UTSNsCtr != "" {
+ nsPath, err := infraContainer.namespacePath(UTSNS)
+ if err != nil {
+ return nil, 0, fmt.Errorf("cannot retrieve UTS namespace path for Pod %q: %w", options.Pod, err)
+ }
+ if err := g.AddOrReplaceLinuxNamespace(string(spec.UTSNamespace), nsPath); err != nil {
+ return nil, 0, err
+ }
+ }
+
+ if c.config.CgroupNsCtr != "" {
+ nsPath, err := infraContainer.namespacePath(CgroupNS)
+ if err != nil {
+ return nil, 0, fmt.Errorf("cannot retrieve Cgroup namespace path for Pod %q: %w", options.Pod, err)
+ }
+ if err := g.AddOrReplaceLinuxNamespace(string(spec.CgroupNamespace), nsPath); err != nil {
+ return nil, 0, err
+ }
+ }
+ }
+
+ if err := c.makeBindMounts(); err != nil {
+ return nil, 0, err
+ }
+
+ if options.TargetFile != "" || options.CheckpointImageID != "" {
+ for dstPath, srcPath := range c.state.BindMounts {
+ newMount := spec.Mount{
+ Type: "bind",
+ Source: srcPath,
+ Destination: dstPath,
+ Options: []string{"bind", "private"},
+ }
+ if c.IsReadOnly() && dstPath != "/dev/shm" {
+ newMount.Options = append(newMount.Options, "ro", "nosuid", "noexec", "nodev")
+ }
+ if dstPath == "/dev/shm" && c.state.BindMounts["/dev/shm"] == c.config.ShmDir {
+ newMount.Options = append(newMount.Options, "nosuid", "noexec", "nodev")
+ }
+ if !MountExists(g.Mounts(), dstPath) {
+ g.AddMount(newMount)
+ }
+ }
+ }
+
+ // Restore /dev/shm content
+ if c.config.ShmDir != "" && c.state.BindMounts["/dev/shm"] == c.config.ShmDir {
+ shmDirTarFileFullPath := filepath.Join(c.bundlePath(), metadata.DevShmCheckpointTar)
+ if _, err := os.Stat(shmDirTarFileFullPath); err != nil {
+ logrus.Debug("Container checkpoint doesn't contain dev/shm: ", err.Error())
+ } else {
+ shmDirTarFile, err := os.Open(shmDirTarFileFullPath)
+ if err != nil {
+ return nil, 0, err
+ }
+ defer shmDirTarFile.Close()
+
+ if err := archive.UntarUncompressed(shmDirTarFile, c.config.ShmDir, nil); err != nil {
+ return nil, 0, err
+ }
+ }
+ }
+
+ // Cleanup for a working restore.
+ if err := c.removeConmonFiles(); err != nil {
+ return nil, 0, err
+ }
+
+ // Save the OCI spec to disk
+ if err := c.saveSpec(g.Config); err != nil {
+ return nil, 0, err
+ }
+
+ // When restoring from an imported archive, allow restoring the content of volumes.
+ // Volumes are created in setupContainer()
+ if !options.IgnoreVolumes && (options.TargetFile != "" || options.CheckpointImageID != "") {
+ for _, v := range c.config.NamedVolumes {
+ volumeFilePath := filepath.Join(c.bundlePath(), metadata.CheckpointVolumesDirectory, v.Name+".tar")
+
+ volumeFile, err := os.Open(volumeFilePath)
+ if err != nil {
+ return nil, 0, fmt.Errorf("failed to open volume file %s: %w", volumeFilePath, err)
+ }
+ defer volumeFile.Close()
+
+ volume, err := c.runtime.GetVolume(v.Name)
+ if err != nil {
+ return nil, 0, fmt.Errorf("failed to retrieve volume %s: %w", v.Name, err)
+ }
+
+ mountPoint, err := volume.MountPoint()
+ if err != nil {
+ return nil, 0, err
+ }
+ if mountPoint == "" {
+ return nil, 0, fmt.Errorf("unable to import volume %s as it is not mounted: %w", volume.Name(), err)
+ }
+ if err := archive.UntarUncompressed(volumeFile, mountPoint, nil); err != nil {
+ return nil, 0, fmt.Errorf("failed to extract volume %s to %s: %w", volumeFilePath, mountPoint, err)
+ }
+ }
+ }
+
+ // Before actually restarting the container, apply the root file-system changes
+ if !options.IgnoreRootfs {
+ if err := crutils.CRApplyRootFsDiffTar(c.bundlePath(), c.state.Mountpoint); err != nil {
+ return nil, 0, err
+ }
+
+ if err := crutils.CRRemoveDeletedFiles(c.ID(), c.bundlePath(), c.state.Mountpoint); err != nil {
+ return nil, 0, err
+ }
+ }
+
+ runtimeRestoreDuration, err = c.ociRuntime.CreateContainer(c, &options)
+ if err != nil {
+ return nil, 0, err
+ }
+
+ criuStatistics, err = func() (*define.CRIUCheckpointRestoreStatistics, error) {
+ if !options.PrintStats {
+ return nil, nil
+ }
+ statsDirectory, err := os.Open(c.bundlePath())
+ if err != nil {
+ return nil, fmt.Errorf("not able to open %q: %w", c.bundlePath(), err)
+ }
+
+ restoreStatistics, err := stats.CriuGetRestoreStats(statsDirectory)
+ if err != nil {
+ return nil, fmt.Errorf("displaying restore statistics not possible: %w", err)
+ }
+
+ return &define.CRIUCheckpointRestoreStatistics{
+ PagesCompared: restoreStatistics.GetPagesCompared(),
+ PagesSkippedCow: restoreStatistics.GetPagesSkippedCow(),
+ ForkingTime: restoreStatistics.GetForkingTime(),
+ RestoreTime: restoreStatistics.GetRestoreTime(),
+ PagesRestored: restoreStatistics.GetPagesRestored(),
+ }, nil
+ }()
+ if err != nil {
+ return nil, 0, err
+ }
+
+ logrus.Debugf("Restored container %s", c.ID())
+
+ c.state.State = define.ContainerStateRunning
+ c.state.Checkpointed = false
+ c.state.Restored = true
+ c.state.CheckpointedTime = time.Time{}
+ c.state.RestoredTime = time.Now()
+
+ if !options.Keep {
+ // Delete all checkpoint related files. At this point, in theory, all files
+ // should exist. Still ignoring errors for now as the container should be
+ // restored and running. Not erroring out just because some cleanup operation
+ // failed. Starting with the checkpoint directory
+ err = os.RemoveAll(c.CheckpointPath())
+ if err != nil {
+ logrus.Debugf("Non-fatal: removal of checkpoint directory (%s) failed: %v", c.CheckpointPath(), err)
+ }
+ c.state.CheckpointPath = ""
+ err = os.RemoveAll(c.PreCheckPointPath())
+ if err != nil {
+ logrus.Debugf("Non-fatal: removal of pre-checkpoint directory (%s) failed: %v", c.PreCheckPointPath(), err)
+ }
+ err = os.RemoveAll(c.CheckpointVolumesPath())
+ if err != nil {
+ logrus.Debugf("Non-fatal: removal of checkpoint volumes directory (%s) failed: %v", c.CheckpointVolumesPath(), err)
+ }
+ cleanup := [...]string{
+ "restore.log",
+ "dump.log",
+ stats.StatsDump,
+ stats.StatsRestore,
+ metadata.DevShmCheckpointTar,
+ metadata.NetworkStatusFile,
+ metadata.RootFsDiffTar,
+ metadata.DeletedFilesFile,
+ }
+ for _, del := range cleanup {
+ file := filepath.Join(c.bundlePath(), del)
+ err = os.Remove(file)
+ if err != nil {
+ logrus.Debugf("Non-fatal: removal of checkpoint file (%s) failed: %v", file, err)
+ }
+ }
+ c.state.CheckpointLog = ""
+ c.state.RestoreLog = ""
+ }
+
+ return criuStatistics, runtimeRestoreDuration, c.save()
+}
+
+// Retrieves a container's "root" net namespace container dependency.
+func (c *Container) getRootNetNsDepCtr() (depCtr *Container, err error) {
+ containersVisited := map[string]int{c.config.ID: 1}
+ nextCtr := c.config.NetNsCtr
+ for nextCtr != "" {
+ // Make sure we aren't in a loop
+ if _, visited := containersVisited[nextCtr]; visited {
+ return nil, errors.New("loop encountered while determining net namespace container")
+ }
+ containersVisited[nextCtr] = 1
+
+ depCtr, err = c.runtime.state.Container(nextCtr)
+ if err != nil {
+ return nil, fmt.Errorf("error fetching dependency %s of container %s: %w", c.config.NetNsCtr, c.ID(), err)
+ }
+ // This should never happen without an error
+ if depCtr == nil {
+ break
+ }
+ nextCtr = depCtr.config.NetNsCtr
+ }
+
+ if depCtr == nil {
+ return nil, errors.New("unexpected error depCtr is nil without reported error from runtime state")
+ }
+ return depCtr, nil
+}
+
+// Ensure standard bind mounts are mounted into all root directories (including chroot directories)
+func (c *Container) mountIntoRootDirs(mountName string, mountPath string) error {
+ c.state.BindMounts[mountName] = mountPath
+
+ for _, chrootDir := range c.config.ChrootDirs {
+ c.state.BindMounts[filepath.Join(chrootDir, mountName)] = mountPath
+ }
+
+ return nil
+}
+
+// Make standard bind mounts to include in the container
+func (c *Container) makeBindMounts() error {
+ if err := os.Chown(c.state.RunDir, c.RootUID(), c.RootGID()); err != nil {
+ return fmt.Errorf("cannot chown run directory: %w", err)
+ }
+
+ if c.state.BindMounts == nil {
+ c.state.BindMounts = make(map[string]string)
+ }
+ netDisabled, err := c.NetworkDisabled()
+ if err != nil {
+ return err
+ }
+
+ if !netDisabled {
+ // If /etc/resolv.conf and /etc/hosts exist, delete them so we
+ // will recreate. Only do this if we aren't sharing them with
+ // another container.
+ if c.config.NetNsCtr == "" {
+ if resolvePath, ok := c.state.BindMounts["/etc/resolv.conf"]; ok {
+ if err := os.Remove(resolvePath); err != nil && !os.IsNotExist(err) {
+ return fmt.Errorf("container %s: %w", c.ID(), err)
+ }
+ delete(c.state.BindMounts, "/etc/resolv.conf")
+ }
+ if hostsPath, ok := c.state.BindMounts["/etc/hosts"]; ok {
+ if err := os.Remove(hostsPath); err != nil && !os.IsNotExist(err) {
+ return fmt.Errorf("container %s: %w", c.ID(), err)
+ }
+ delete(c.state.BindMounts, "/etc/hosts")
+ }
+ }
+
+ if c.config.NetNsCtr != "" && (!c.config.UseImageResolvConf || !c.config.UseImageHosts) {
+ // We share a net namespace.
+ // We want /etc/resolv.conf and /etc/hosts from the
+ // other container. Unless we're not creating both of
+ // them.
+ depCtr, err := c.getRootNetNsDepCtr()
+ if err != nil {
+ return fmt.Errorf("error fetching network namespace dependency container for container %s: %w", c.ID(), err)
+ }
+
+ // We need that container's bind mounts
+ bindMounts, err := depCtr.BindMounts()
+ if err != nil {
+ return fmt.Errorf("error fetching bind mounts from dependency %s of container %s: %w", depCtr.ID(), c.ID(), err)
+ }
+
+ // The other container may not have a resolv.conf or /etc/hosts
+ // If it doesn't, don't copy them
+ resolvPath, exists := bindMounts["/etc/resolv.conf"]
+ if !c.config.UseImageResolvConf && exists {
+ err := c.mountIntoRootDirs("/etc/resolv.conf", resolvPath)
+
+ if err != nil {
+ return fmt.Errorf("error assigning mounts to container %s: %w", c.ID(), err)
+ }
+ }
+
+ // check if dependency container has an /etc/hosts file.
+ // It may not have one, so only use it if it does.
+ hostsPath, exists := bindMounts[config.DefaultHostsFile]
+ if !c.config.UseImageHosts && exists {
+ // we cannot use the dependency container lock due ABBA deadlocks in cleanup()
+ lock, err := lockfile.GetLockfile(hostsPath)
+ if err != nil {
+ return fmt.Errorf("failed to lock hosts file: %w", err)
+ }
+ lock.Lock()
+
+ // add the newly added container to the hosts file
+ // we always use 127.0.0.1 as ip since they have the same netns
+ err = etchosts.Add(hostsPath, getLocalhostHostEntry(c))
+ lock.Unlock()
+ if err != nil {
+ return fmt.Errorf("error creating hosts file for container %s which depends on container %s: %w", c.ID(), depCtr.ID(), err)
+ }
+
+ // finally, save it in the new container
+ err = c.mountIntoRootDirs(config.DefaultHostsFile, hostsPath)
+ if err != nil {
+ return fmt.Errorf("error assigning mounts to container %s: %w", c.ID(), err)
+ }
+ }
+
+ if !hasCurrentUserMapped(c) {
+ if err := makeAccessible(resolvPath, c.RootUID(), c.RootGID()); err != nil {
+ return err
+ }
+ if err := makeAccessible(hostsPath, c.RootUID(), c.RootGID()); err != nil {
+ return err
+ }
+ }
+ } else {
+ if !c.config.UseImageResolvConf {
+ if err := c.generateResolvConf(); err != nil {
+ return fmt.Errorf("error creating resolv.conf for container %s: %w", c.ID(), err)
+ }
+ }
+
+ if !c.config.UseImageHosts {
+ if err := c.createHosts(); err != nil {
+ return fmt.Errorf("error creating hosts file for container %s: %w", c.ID(), err)
+ }
+ }
+ }
+
+ if c.state.BindMounts["/etc/hosts"] != "" {
+ if err := c.relabel(c.state.BindMounts["/etc/hosts"], c.config.MountLabel, true); err != nil {
+ return err
+ }
+ }
+
+ if c.state.BindMounts["/etc/resolv.conf"] != "" {
+ if err := c.relabel(c.state.BindMounts["/etc/resolv.conf"], c.config.MountLabel, true); err != nil {
+ return err
+ }
+ }
+ } else if !c.config.UseImageHosts && c.state.BindMounts["/etc/hosts"] == "" {
+ if err := c.createHosts(); err != nil {
+ return fmt.Errorf("error creating hosts file for container %s: %w", c.ID(), err)
+ }
+ }
+
+ if c.config.ShmDir != "" {
+ // If ShmDir has a value SHM is always added when we mount the container
+ c.state.BindMounts["/dev/shm"] = c.config.ShmDir
+ }
+
+ if c.config.Passwd == nil || *c.config.Passwd {
+ newPasswd, newGroup, err := c.generatePasswdAndGroup()
+ if err != nil {
+ return fmt.Errorf("error creating temporary passwd file for container %s: %w", c.ID(), err)
+ }
+ if newPasswd != "" {
+ // Make /etc/passwd
+ // If it already exists, delete so we can recreate
+ delete(c.state.BindMounts, "/etc/passwd")
+ c.state.BindMounts["/etc/passwd"] = newPasswd
+ }
+ if newGroup != "" {
+ // Make /etc/group
+ // If it already exists, delete so we can recreate
+ delete(c.state.BindMounts, "/etc/group")
+ c.state.BindMounts["/etc/group"] = newGroup
+ }
+ }
+
+ // Make /etc/hostname
+ // This should never change, so no need to recreate if it exists
+ if _, ok := c.state.BindMounts["/etc/hostname"]; !ok {
+ hostnamePath, err := c.writeStringToRundir("hostname", c.Hostname())
+ if err != nil {
+ return fmt.Errorf("error creating hostname file for container %s: %w", c.ID(), err)
+ }
+ c.state.BindMounts["/etc/hostname"] = hostnamePath
+ }
+
+ // Make /etc/localtime
+ ctrTimezone := c.Timezone()
+ if ctrTimezone != "" {
+ // validate the format of the timezone specified if it's not "local"
+ if ctrTimezone != "local" {
+ _, err = time.LoadLocation(ctrTimezone)
+ if err != nil {
+ return fmt.Errorf("error finding timezone for container %s: %w", c.ID(), err)
+ }
+ }
+ if _, ok := c.state.BindMounts["/etc/localtime"]; !ok {
+ var zonePath string
+ if ctrTimezone == "local" {
+ zonePath, err = filepath.EvalSymlinks("/etc/localtime")
+ if err != nil {
+ return fmt.Errorf("error finding local timezone for container %s: %w", c.ID(), err)
+ }
+ } else {
+ zone := filepath.Join("/usr/share/zoneinfo", ctrTimezone)
+ zonePath, err = filepath.EvalSymlinks(zone)
+ if err != nil {
+ return fmt.Errorf("error setting timezone for container %s: %w", c.ID(), err)
+ }
+ }
+ localtimePath, err := c.copyTimezoneFile(zonePath)
+ if err != nil {
+ return fmt.Errorf("error setting timezone for container %s: %w", c.ID(), err)
+ }
+ c.state.BindMounts["/etc/localtime"] = localtimePath
+ }
+ }
+
+ _, hasRunContainerenv := c.state.BindMounts["/run/.containerenv"]
+ if !hasRunContainerenv {
+ // check in the spec mounts
+ for _, m := range c.config.Spec.Mounts {
+ if m.Destination == "/run/.containerenv" || m.Destination == "/run" {
+ hasRunContainerenv = true
+ break
+ }
+ }
+ }
+
+ // Make .containerenv if it does not exist
+ if !hasRunContainerenv {
+ containerenv := c.runtime.graphRootMountedFlag(c.config.Spec.Mounts)
+ isRootless := 0
+ if rootless.IsRootless() {
+ isRootless = 1
+ }
+ imageID, imageName := c.Image()
+
+ if c.Privileged() {
+ // Populate the .containerenv with container information
+ containerenv = fmt.Sprintf(`engine="podman-%s"
+name=%q
+id=%q
+image=%q
+imageid=%q
+rootless=%d
+%s`, version.Version.String(), c.Name(), c.ID(), imageName, imageID, isRootless, containerenv)
+ }
+ containerenvPath, err := c.writeStringToRundir(".containerenv", containerenv)
+ if err != nil {
+ return fmt.Errorf("error creating containerenv file for container %s: %w", c.ID(), err)
+ }
+ c.state.BindMounts["/run/.containerenv"] = containerenvPath
+ }
+
+ // Add Subscription Mounts
+ subscriptionMounts := subscriptions.MountsWithUIDGID(c.config.MountLabel, c.state.RunDir, c.runtime.config.Containers.DefaultMountsFile, c.state.Mountpoint, c.RootUID(), c.RootGID(), rootless.IsRootless(), false)
+ for _, mount := range subscriptionMounts {
+ if _, ok := c.state.BindMounts[mount.Destination]; !ok {
+ c.state.BindMounts[mount.Destination] = mount.Source
+ }
+ }
+
+ // Secrets are mounted by getting the secret data from the secrets manager,
+ // copying the data into the container's static dir,
+ // then mounting the copied dir into /run/secrets.
+ // The secrets mounting must come after subscription mounts, since subscription mounts
+ // creates the /run/secrets dir in the container where we mount as well.
+ if len(c.Secrets()) > 0 {
+ // create /run/secrets if subscriptions did not create
+ if err := c.createSecretMountDir(); err != nil {
+ return fmt.Errorf("error creating secrets mount: %w", err)
+ }
+ for _, secret := range c.Secrets() {
+ secretFileName := secret.Name
+ base := "/run/secrets"
+ if secret.Target != "" {
+ secretFileName = secret.Target
+ // If absolute path for target given remove base.
+ if filepath.IsAbs(secretFileName) {
+ base = ""
+ }
+ }
+ src := filepath.Join(c.config.SecretsPath, secret.Name)
+ dest := filepath.Join(base, secretFileName)
+ c.state.BindMounts[dest] = src
+ }
+ }
+
+ return nil
+}
+
+// generateResolvConf generates a containers resolv.conf
+func (c *Container) generateResolvConf() error {
+ var (
+ networkNameServers []string
+ networkSearchDomains []string
+ )
+
+ netStatus := c.getNetworkStatus()
+ for _, status := range netStatus {
+ if status.DNSServerIPs != nil {
+ for _, nsIP := range status.DNSServerIPs {
+ networkNameServers = append(networkNameServers, nsIP.String())
+ }
+ logrus.Debugf("Adding nameserver(s) from network status of '%q'", status.DNSServerIPs)
+ }
+ if status.DNSSearchDomains != nil {
+ networkSearchDomains = append(networkSearchDomains, status.DNSSearchDomains...)
+ logrus.Debugf("Adding search domain(s) from network status of '%q'", status.DNSSearchDomains)
+ }
+ }
+
+ ipv6, err := c.checkForIPv6(netStatus)
+ if err != nil {
+ return err
+ }
+
+ nameservers := make([]string, 0, len(c.runtime.config.Containers.DNSServers)+len(c.config.DNSServer))
+ nameservers = append(nameservers, c.runtime.config.Containers.DNSServers...)
+ for _, ip := range c.config.DNSServer {
+ nameservers = append(nameservers, ip.String())
+ }
+ // If the user provided dns, it trumps all; then dns masq; then resolv.conf
+ var search []string
+ keepHostServers := false
+ if len(nameservers) == 0 {
+ keepHostServers = true
+ // first add the nameservers from the networks status
+ nameservers = networkNameServers
+ // when we add network dns server we also have to add the search domains
+ search = networkSearchDomains
+ // slirp4netns has a built in DNS forwarder.
+ nameservers = c.addSlirp4netnsDNS(nameservers)
+ }
+
+ if len(c.config.DNSSearch) > 0 || len(c.runtime.config.Containers.DNSSearches) > 0 {
+ customSearch := make([]string, 0, len(c.config.DNSSearch)+len(c.runtime.config.Containers.DNSSearches))
+ customSearch = append(customSearch, c.runtime.config.Containers.DNSSearches...)
+ customSearch = append(customSearch, c.config.DNSSearch...)
+ search = customSearch
+ }
+
+ options := make([]string, 0, len(c.config.DNSOption)+len(c.runtime.config.Containers.DNSOptions))
+ options = append(options, c.runtime.config.Containers.DNSOptions...)
+ options = append(options, c.config.DNSOption...)
+
+ destPath := filepath.Join(c.state.RunDir, "resolv.conf")
+
+ if err := resolvconf.New(&resolvconf.Params{
+ IPv6Enabled: ipv6,
+ KeepHostServers: keepHostServers,
+ Nameservers: nameservers,
+ Namespaces: c.config.Spec.Linux.Namespaces,
+ Options: options,
+ Path: destPath,
+ Searches: search,
+ }); err != nil {
+ return fmt.Errorf("error building resolv.conf for container %s: %w", c.ID(), err)
+ }
+
+ return c.bindMountRootFile(destPath, resolvconf.DefaultResolvConf)
+}
+
+// Check if a container uses IPv6.
+func (c *Container) checkForIPv6(netStatus map[string]types.StatusBlock) (bool, error) {
+ for _, status := range netStatus {
+ for _, netInt := range status.Interfaces {
+ for _, netAddress := range netInt.Subnets {
+ // Note: only using To16() does not work since it also returns a valid ip for ipv4
+ if netAddress.IPNet.IP.To4() == nil && netAddress.IPNet.IP.To16() != nil {
+ return true, nil
+ }
+ }
+ }
+ }
+
+ return c.isSlirp4netnsIPv6()
+}
+
+// Add a new nameserver to the container's resolv.conf, ensuring that it is the
+// first nameserver present.
+// Usable only with running containers.
+func (c *Container) addNameserver(ips []string) error {
+ // Take no action if container is not running.
+ if !c.ensureState(define.ContainerStateRunning, define.ContainerStateCreated) {
+ return nil
+ }
+
+ // Do we have a resolv.conf at all?
+ path, ok := c.state.BindMounts[resolvconf.DefaultResolvConf]
+ if !ok {
+ return nil
+ }
+
+ if err := resolvconf.Add(path, ips); err != nil {
+ return fmt.Errorf("adding new nameserver to container %s resolv.conf: %w", c.ID(), err)
+ }
+
+ return nil
+}
+
+// Remove an entry from the existing resolv.conf of the container.
+// Usable only with running containers.
+func (c *Container) removeNameserver(ips []string) error {
+ // Take no action if container is not running.
+ if !c.ensureState(define.ContainerStateRunning, define.ContainerStateCreated) {
+ return nil
+ }
+
+ // Do we have a resolv.conf at all?
+ path, ok := c.state.BindMounts[resolvconf.DefaultResolvConf]
+ if !ok {
+ return nil
+ }
+
+ if err := resolvconf.Remove(path, ips); err != nil {
+ return fmt.Errorf("removing nameservers from container %s resolv.conf: %w", c.ID(), err)
+ }
+
+ return nil
+}
+
+func getLocalhostHostEntry(c *Container) etchosts.HostEntries {
+ return etchosts.HostEntries{{IP: "127.0.0.1", Names: []string{c.Hostname(), c.config.Name}}}
+}
+
+// getHostsEntries returns the container ip host entries for the correct netmode
+func (c *Container) getHostsEntries() (etchosts.HostEntries, error) {
+ var entries etchosts.HostEntries
+ names := []string{c.Hostname(), c.config.Name}
+ switch {
+ case c.config.NetMode.IsBridge():
+ entries = etchosts.GetNetworkHostEntries(c.state.NetworkStatus, names...)
+ case c.config.NetMode.IsSlirp4netns():
+ ip, err := GetSlirp4netnsIP(c.slirp4netnsSubnet)
+ if err != nil {
+ return nil, err
+ }
+ entries = etchosts.HostEntries{{IP: ip.String(), Names: names}}
+ default:
+ if c.hasNetNone() {
+ entries = etchosts.HostEntries{{IP: "127.0.0.1", Names: names}}
+ }
+ }
+ return entries, nil
+}
+
+func (c *Container) createHosts() error {
+ var containerIPsEntries etchosts.HostEntries
+ var err error
+ // if we configure the netns after the container create we should not add
+ // the hosts here since we have no information about the actual ips
+ // instead we will add them in c.completeNetworkSetup()
+ if !c.config.PostConfigureNetNS {
+ containerIPsEntries, err = c.getHostsEntries()
+ if err != nil {
+ return fmt.Errorf("failed to get container ip host entries: %w", err)
+ }
+ }
+ baseHostFile, err := etchosts.GetBaseHostFile(c.runtime.config.Containers.BaseHostsFile, c.state.Mountpoint)
+ if err != nil {
+ return err
+ }
+
+ targetFile := filepath.Join(c.state.RunDir, "hosts")
+ err = etchosts.New(&etchosts.Params{
+ BaseFile: baseHostFile,
+ ExtraHosts: c.config.HostAdd,
+ ContainerIPs: containerIPsEntries,
+ HostContainersInternalIP: etchosts.GetHostContainersInternalIP(c.runtime.config, c.state.NetworkStatus, c.runtime.network),
+ TargetFile: targetFile,
+ })
+ if err != nil {
+ return err
+ }
+
+ return c.bindMountRootFile(targetFile, config.DefaultHostsFile)
+}
+
+// bindMountRootFile will chown and relabel the source file to make it usable in the container.
+// It will also add the path to the container bind mount map.
+// source is the path on the host, dest is the path in the container.
+func (c *Container) bindMountRootFile(source, dest string) error {
+ if err := os.Chown(source, c.RootUID(), c.RootGID()); err != nil {
+ return err
+ }
+ if err := label.Relabel(source, c.MountLabel(), false); err != nil {
+ return err
+ }
+
+ return c.mountIntoRootDirs(dest, source)
+}
+
+// generateGroupEntry generates an entry or entries into /etc/group as
+// required by container configuration.
+// Generally speaking, we will make an entry under two circumstances:
+// 1. The container is started as a specific user:group, and that group is both
+// numeric, and does not already exist in /etc/group.
+// 2. It is requested that Libpod add the group that launched Podman to
+// /etc/group via AddCurrentUserPasswdEntry (though this does not trigger if
+// the group in question already exists in /etc/passwd).
+//
+// Returns group entry (as a string that can be appended to /etc/group) and any
+// error that occurred.
+func (c *Container) generateGroupEntry() (string, error) {
+ groupString := ""
+
+ // Things we *can't* handle: adding the user we added in
+ // generatePasswdEntry to any *existing* groups.
+ addedGID := 0
+ if c.config.AddCurrentUserPasswdEntry {
+ entry, gid, err := c.generateCurrentUserGroupEntry()
+ if err != nil {
+ return "", err
+ }
+ groupString += entry
+ addedGID = gid
+ }
+ if c.config.User != "" {
+ entry, err := c.generateUserGroupEntry(addedGID)
+ if err != nil {
+ return "", err
+ }
+ groupString += entry
+ }
+
+ return groupString, nil
+}
+
+// Make an entry in /etc/group for the group of the user running podman iff we
+// are rootless.
+func (c *Container) generateCurrentUserGroupEntry() (string, int, error) {
+ gid := rootless.GetRootlessGID()
+ if gid == 0 {
+ return "", 0, nil
+ }
+
+ g, err := user.LookupGroupId(strconv.Itoa(gid))
+ if err != nil {
+ return "", 0, fmt.Errorf("failed to get current group: %w", err)
+ }
+
+ // Look up group name to see if it exists in the image.
+ _, err = lookup.GetGroup(c.state.Mountpoint, g.Name)
+ if err != runcuser.ErrNoGroupEntries {
+ return "", 0, err
+ }
+
+ // Look up GID to see if it exists in the image.
+ _, err = lookup.GetGroup(c.state.Mountpoint, g.Gid)
+ if err != runcuser.ErrNoGroupEntries {
+ return "", 0, err
+ }
+
+ // We need to get the username of the rootless user so we can add it to
+ // the group.
+ username := ""
+ uid := rootless.GetRootlessUID()
+ if uid != 0 {
+ u, err := user.LookupId(strconv.Itoa(uid))
+ if err != nil {
+ return "", 0, fmt.Errorf("failed to get current user to make group entry: %w", err)
+ }
+ username = u.Username
+ }
+
+ // Make the entry.
+ return fmt.Sprintf("%s:x:%s:%s\n", g.Name, g.Gid, username), gid, nil
+}
+
+// Make an entry in /etc/group for the group the container was specified to run
+// as.
+func (c *Container) generateUserGroupEntry(addedGID int) (string, error) {
+ if c.config.User == "" {
+ return "", nil
+ }
+
+ splitUser := strings.SplitN(c.config.User, ":", 2)
+ group := splitUser[0]
+ if len(splitUser) > 1 {
+ group = splitUser[1]
+ }
+
+ gid, err := strconv.ParseUint(group, 10, 32)
+ if err != nil {
+ return "", nil //nolint: nilerr
+ }
+
+ if addedGID != 0 && addedGID == int(gid) {
+ return "", nil
+ }
+
+ // Check if the group already exists
+ _, err = lookup.GetGroup(c.state.Mountpoint, group)
+ if err != runcuser.ErrNoGroupEntries {
+ return "", err
+ }
+
+ return fmt.Sprintf("%d:x:%d:%s\n", gid, gid, splitUser[0]), nil
+}
+
+// generatePasswdEntry generates an entry or entries into /etc/passwd as
+// required by container configuration.
+// Generally speaking, we will make an entry under two circumstances:
+// 1. The container is started as a specific user who is not in /etc/passwd.
+// This only triggers if the user is given as a *numeric* ID.
+// 2. It is requested that Libpod add the user that launched Podman to
+// /etc/passwd via AddCurrentUserPasswdEntry (though this does not trigger if
+// the user in question already exists in /etc/passwd) or the UID to be added
+// is 0).
+// 3. The user specified additional host user accounts to add the the /etc/passwd file
+//
+// Returns password entry (as a string that can be appended to /etc/passwd) and
+// any error that occurred.
+func (c *Container) generatePasswdEntry() (string, error) {
+ passwdString := ""
+
+ addedUID := 0
+ for _, userid := range c.config.HostUsers {
+ // Look up User on host
+ u, err := util.LookupUser(userid)
+ if err != nil {
+ return "", err
+ }
+ entry, err := c.userPasswdEntry(u)
+ if err != nil {
+ return "", err
+ }
+ passwdString += entry
+ }
+ if c.config.AddCurrentUserPasswdEntry {
+ entry, uid, _, err := c.generateCurrentUserPasswdEntry()
+ if err != nil {
+ return "", err
+ }
+ passwdString += entry
+ addedUID = uid
+ }
+ if c.config.User != "" {
+ entry, err := c.generateUserPasswdEntry(addedUID)
+ if err != nil {
+ return "", err
+ }
+ passwdString += entry
+ }
+
+ return passwdString, nil
+}
+
+// generateCurrentUserPasswdEntry generates an /etc/passwd entry for the user
+// running the container engine.
+// Returns a passwd entry for the user, and the UID and GID of the added entry.
+func (c *Container) generateCurrentUserPasswdEntry() (string, int, int, error) {
+ uid := rootless.GetRootlessUID()
+ if uid == 0 {
+ return "", 0, 0, nil
+ }
+
+ u, err := user.LookupId(strconv.Itoa(uid))
+ if err != nil {
+ return "", 0, 0, fmt.Errorf("failed to get current user: %w", err)
+ }
+ pwd, err := c.userPasswdEntry(u)
+ if err != nil {
+ return "", 0, 0, err
+ }
+
+ return pwd, uid, rootless.GetRootlessGID(), nil
+}
+
+func (c *Container) userPasswdEntry(u *user.User) (string, error) {
+ // Look up the user to see if it exists in the container image.
+ _, err := lookup.GetUser(c.state.Mountpoint, u.Username)
+ if err != runcuser.ErrNoPasswdEntries {
+ return "", err
+ }
+
+ // Look up the UID to see if it exists in the container image.
+ _, err = lookup.GetUser(c.state.Mountpoint, u.Uid)
+ if err != runcuser.ErrNoPasswdEntries {
+ return "", err
+ }
+
+ // If the user's actual home directory exists, or was mounted in - use
+ // that.
+ homeDir := c.WorkingDir()
+ hDir := u.HomeDir
+ for hDir != "/" {
+ if MountExists(c.config.Spec.Mounts, hDir) {
+ homeDir = u.HomeDir
+ break
+ }
+ hDir = filepath.Dir(hDir)
+ }
+ if homeDir != u.HomeDir {
+ for _, hDir := range c.UserVolumes() {
+ if hDir == u.HomeDir {
+ homeDir = u.HomeDir
+ break
+ }
+ }
+ }
+ // Set HOME environment if not already set
+ hasHomeSet := false
+ for _, s := range c.config.Spec.Process.Env {
+ if strings.HasPrefix(s, "HOME=") {
+ hasHomeSet = true
+ break
+ }
+ }
+ if !hasHomeSet {
+ c.config.Spec.Process.Env = append(c.config.Spec.Process.Env, fmt.Sprintf("HOME=%s", homeDir))
+ }
+ if c.config.PasswdEntry != "" {
+ return c.passwdEntry(u.Username, u.Uid, u.Gid, u.Name, homeDir), nil
+ }
+
+ return fmt.Sprintf("%s:*:%s:%s:%s:%s:/bin/sh\n", u.Username, u.Uid, u.Gid, u.Name, homeDir), nil
+}
+
+// generateUserPasswdEntry generates an /etc/passwd entry for the container user
+// to run in the container.
+// The UID and GID of the added entry will also be returned.
+// Accepts one argument, that being any UID that has already been added to the
+// passwd file by other functions; if it matches the UID we were given, we don't
+// need to do anything.
+func (c *Container) generateUserPasswdEntry(addedUID int) (string, error) {
+ var (
+ groupspec string
+ gid int
+ )
+ if c.config.User == "" {
+ return "", nil
+ }
+ splitSpec := strings.SplitN(c.config.User, ":", 2)
+ userspec := splitSpec[0]
+ if len(splitSpec) > 1 {
+ groupspec = splitSpec[1]
+ }
+ // If a non numeric User, then don't generate passwd
+ uid, err := strconv.ParseUint(userspec, 10, 32)
+ if err != nil {
+ return "", nil //nolint: nilerr
+ }
+
+ if addedUID != 0 && int(uid) == addedUID {
+ return "", nil
+ }
+
+ // Look up the user to see if it exists in the container image
+ _, err = lookup.GetUser(c.state.Mountpoint, userspec)
+ if err != runcuser.ErrNoPasswdEntries {
+ return "", err
+ }
+
+ if groupspec != "" {
+ ugid, err := strconv.ParseUint(groupspec, 10, 32)
+ if err == nil {
+ gid = int(ugid)
+ } else {
+ group, err := lookup.GetGroup(c.state.Mountpoint, groupspec)
+ if err != nil {
+ return "", fmt.Errorf("unable to get gid %s from group file: %w", groupspec, err)
+ }
+ gid = group.Gid
+ }
+ }
+
+ if c.config.PasswdEntry != "" {
+ entry := c.passwdEntry(fmt.Sprintf("%d", uid), fmt.Sprintf("%d", uid), fmt.Sprintf("%d", gid), "container user", c.WorkingDir())
+ return entry, nil
+ }
+
+ return fmt.Sprintf("%d:*:%d:%d:container user:%s:/bin/sh\n", uid, uid, gid, c.WorkingDir()), nil
+}
+
+func (c *Container) passwdEntry(username string, uid, gid, name, homeDir string) string {
+ s := c.config.PasswdEntry
+ s = strings.ReplaceAll(s, "$USERNAME", username)
+ s = strings.ReplaceAll(s, "$UID", uid)
+ s = strings.ReplaceAll(s, "$GID", gid)
+ s = strings.ReplaceAll(s, "$NAME", name)
+ s = strings.ReplaceAll(s, "$HOME", homeDir)
+ return s + "\n"
+}
+
+// generatePasswdAndGroup generates container-specific passwd and group files
+// iff g.config.User is a number or we are configured to make a passwd entry for
+// the current user or the user specified HostsUsers
+// Returns path to file to mount at /etc/passwd, path to file to mount at
+// /etc/group, and any error that occurred. If no passwd/group file were
+// required, the empty string will be returned for those path (this may occur
+// even if no error happened).
+// This may modify the mounted container's /etc/passwd and /etc/group instead of
+// making copies to bind-mount in, so we don't break useradd (it wants to make a
+// copy of /etc/passwd and rename the copy to /etc/passwd, which is impossible
+// with a bind mount). This is done in cases where the container is *not*
+// read-only. In this case, the function will return nothing ("", "", nil).
+func (c *Container) generatePasswdAndGroup() (string, string, error) {
+ if !c.config.AddCurrentUserPasswdEntry && c.config.User == "" &&
+ len(c.config.HostUsers) == 0 {
+ return "", "", nil
+ }
+
+ needPasswd := true
+ needGroup := true
+
+ // First, check if there's a mount at /etc/passwd or group, we don't
+ // want to interfere with user mounts.
+ if MountExists(c.config.Spec.Mounts, "/etc/passwd") {
+ needPasswd = false
+ }
+ if MountExists(c.config.Spec.Mounts, "/etc/group") {
+ needGroup = false
+ }
+
+ // Next, check if we already made the files. If we didn't, don't need to
+ // do anything more.
+ if needPasswd {
+ passwdPath := filepath.Join(c.config.StaticDir, "passwd")
+ if _, err := os.Stat(passwdPath); err == nil {
+ needPasswd = false
+ }
+ }
+ if needGroup {
+ groupPath := filepath.Join(c.config.StaticDir, "group")
+ if _, err := os.Stat(groupPath); err == nil {
+ needGroup = false
+ }
+ }
+
+ // If we don't need a /etc/passwd or /etc/group at this point we can
+ // just return.
+ if !needPasswd && !needGroup {
+ return "", "", nil
+ }
+
+ passwdPath := ""
+ groupPath := ""
+
+ ro := c.IsReadOnly()
+
+ if needPasswd {
+ passwdEntry, err := c.generatePasswdEntry()
+ if err != nil {
+ return "", "", err
+ }
+
+ needsWrite := passwdEntry != ""
+ switch {
+ case ro && needsWrite:
+ logrus.Debugf("Making /etc/passwd for container %s", c.ID())
+ originPasswdFile, err := securejoin.SecureJoin(c.state.Mountpoint, "/etc/passwd")
+ if err != nil {
+ return "", "", fmt.Errorf("error creating path to container %s /etc/passwd: %w", c.ID(), err)
+ }
+ orig, err := ioutil.ReadFile(originPasswdFile)
+ if err != nil && !os.IsNotExist(err) {
+ return "", "", err
+ }
+ passwdFile, err := c.writeStringToStaticDir("passwd", string(orig)+passwdEntry)
+ if err != nil {
+ return "", "", fmt.Errorf("failed to create temporary passwd file: %w", err)
+ }
+ if err := os.Chmod(passwdFile, 0644); err != nil {
+ return "", "", err
+ }
+ passwdPath = passwdFile
+ case !ro && needsWrite:
+ logrus.Debugf("Modifying container %s /etc/passwd", c.ID())
+ containerPasswd, err := securejoin.SecureJoin(c.state.Mountpoint, "/etc/passwd")
+ if err != nil {
+ return "", "", fmt.Errorf("error looking up location of container %s /etc/passwd: %w", c.ID(), err)
+ }
+
+ f, err := os.OpenFile(containerPasswd, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
+ if err != nil {
+ return "", "", fmt.Errorf("container %s: %w", c.ID(), err)
+ }
+ defer f.Close()
+
+ if _, err := f.WriteString(passwdEntry); err != nil {
+ return "", "", fmt.Errorf("unable to append to container %s /etc/passwd: %w", c.ID(), err)
+ }
+ default:
+ logrus.Debugf("Not modifying container %s /etc/passwd", c.ID())
+ }
+ }
+ if needGroup {
+ groupEntry, err := c.generateGroupEntry()
+ if err != nil {
+ return "", "", err
+ }
+
+ needsWrite := groupEntry != ""
+ switch {
+ case ro && needsWrite:
+ logrus.Debugf("Making /etc/group for container %s", c.ID())
+ originGroupFile, err := securejoin.SecureJoin(c.state.Mountpoint, "/etc/group")
+ if err != nil {
+ return "", "", fmt.Errorf("error creating path to container %s /etc/group: %w", c.ID(), err)
+ }
+ orig, err := ioutil.ReadFile(originGroupFile)
+ if err != nil && !os.IsNotExist(err) {
+ return "", "", err
+ }
+ groupFile, err := c.writeStringToStaticDir("group", string(orig)+groupEntry)
+ if err != nil {
+ return "", "", fmt.Errorf("failed to create temporary group file: %w", err)
+ }
+ if err := os.Chmod(groupFile, 0644); err != nil {
+ return "", "", err
+ }
+ groupPath = groupFile
+ case !ro && needsWrite:
+ logrus.Debugf("Modifying container %s /etc/group", c.ID())
+ containerGroup, err := securejoin.SecureJoin(c.state.Mountpoint, "/etc/group")
+ if err != nil {
+ return "", "", fmt.Errorf("error looking up location of container %s /etc/group: %w", c.ID(), err)
+ }
+
+ f, err := os.OpenFile(containerGroup, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
+ if err != nil {
+ return "", "", fmt.Errorf("container %s: %w", c.ID(), err)
+ }
+ defer f.Close()
+
+ if _, err := f.WriteString(groupEntry); err != nil {
+ return "", "", fmt.Errorf("unable to append to container %s /etc/group: %w", c.ID(), err)
+ }
+ default:
+ logrus.Debugf("Not modifying container %s /etc/group", c.ID())
+ }
+ }
+
+ return passwdPath, groupPath, nil
+}
+
+func (c *Container) copyTimezoneFile(zonePath string) (string, error) {
+ localtimeCopy := filepath.Join(c.state.RunDir, "localtime")
+ file, err := os.Stat(zonePath)
+ if err != nil {
+ return "", err
+ }
+ if file.IsDir() {
+ return "", errors.New("invalid timezone: is a directory")
+ }
+ src, err := os.Open(zonePath)
+ if err != nil {
+ return "", err
+ }
+ defer src.Close()
+ dest, err := os.Create(localtimeCopy)
+ if err != nil {
+ return "", err
+ }
+ defer dest.Close()
+ _, err = io.Copy(dest, src)
+ if err != nil {
+ return "", err
+ }
+ if err := c.relabel(localtimeCopy, c.config.MountLabel, false); err != nil {
+ return "", err
+ }
+ if err := dest.Chown(c.RootUID(), c.RootGID()); err != nil {
+ return "", err
+ }
+ return localtimeCopy, err
+}
+
+func (c *Container) cleanupOverlayMounts() error {
+ return overlay.CleanupContent(c.config.StaticDir)
+}
+
+// Creates and mounts an empty dir to mount secrets into, if it does not already exist
+func (c *Container) createSecretMountDir() error {
+ src := filepath.Join(c.state.RunDir, "/run/secrets")
+ _, err := os.Stat(src)
+ if os.IsNotExist(err) {
+ oldUmask := umask.Set(0)
+ defer umask.Set(oldUmask)
+
+ if err := os.MkdirAll(src, 0755); err != nil {
+ return err
+ }
+ if err := label.Relabel(src, c.config.MountLabel, false); err != nil {
+ return err
+ }
+ if err := os.Chown(src, c.RootUID(), c.RootGID()); err != nil {
+ return err
+ }
+ c.state.BindMounts["/run/secrets"] = src
+ return nil
+ }
+
+ return err
+}
+
+// Fix ownership and permissions of the specified volume if necessary.
+func (c *Container) fixVolumePermissions(v *ContainerNamedVolume) error {
+ vol, err := c.runtime.state.Volume(v.Name)
+ if err != nil {
+ return fmt.Errorf("error retrieving named volume %s for container %s: %w", v.Name, c.ID(), err)
+ }
+
+ vol.lock.Lock()
+ defer vol.lock.Unlock()
+
+ // The volume may need a copy-up. Check the state.
+ if err := vol.update(); err != nil {
+ return err
+ }
+
+ // Volumes owned by a volume driver are not chowned - we don't want to
+ // mess with a mount not managed by us.
+ if vol.state.NeedsChown && !vol.UsesVolumeDriver() {
+ vol.state.NeedsChown = false
+
+ uid := int(c.config.Spec.Process.User.UID)
+ gid := int(c.config.Spec.Process.User.GID)
+
+ if c.config.IDMappings.UIDMap != nil {
+ p := idtools.IDPair{
+ UID: uid,
+ GID: gid,
+ }
+ mappings := idtools.NewIDMappingsFromMaps(c.config.IDMappings.UIDMap, c.config.IDMappings.GIDMap)
+ newPair, err := mappings.ToHost(p)
+ if err != nil {
+ return fmt.Errorf("error mapping user %d:%d: %w", uid, gid, err)
+ }
+ uid = newPair.UID
+ gid = newPair.GID
+ }
+
+ vol.state.UIDChowned = uid
+ vol.state.GIDChowned = gid
+
+ if err := vol.save(); err != nil {
+ return err
+ }
+
+ mountPoint, err := vol.MountPoint()
+ if err != nil {
+ return err
+ }
+
+ if err := os.Lchown(mountPoint, uid, gid); err != nil {
+ return err
+ }
+
+ // Make sure the new volume matches the permissions of the target directory.
+ // https://github.com/containers/podman/issues/10188
+ st, err := os.Lstat(filepath.Join(c.state.Mountpoint, v.Dest))
+ if err == nil {
+ if stat, ok := st.Sys().(*syscall.Stat_t); ok {
+ if err := os.Lchown(mountPoint, int(stat.Uid), int(stat.Gid)); err != nil {
+ return err
+ }
+ }
+ if err := os.Chmod(mountPoint, st.Mode()); err != nil {
+ return err
+ }
+ if err := setVolumeAtime(mountPoint, st); err != nil {
+ return err
+ }
+ } else if !os.IsNotExist(err) {
+ return err
+ }
+ }
+ return nil
+}
+
+func (c *Container) relabel(src, mountLabel string, recurse bool) error {
+ if !selinux.GetEnabled() || mountLabel == "" {
+ return nil
+ }
+ // only relabel on initial creation of container
+ if !c.ensureState(define.ContainerStateConfigured, define.ContainerStateUnknown) {
+ label, err := label.FileLabel(src)
+ if err != nil {
+ return err
+ }
+ // If labels are different, might be on a tmpfs
+ if label == mountLabel {
+ return nil
+ }
+ }
+ return label.Relabel(src, mountLabel, recurse)
+}
+
+func (c *Container) ChangeHostPathOwnership(src string, recurse bool, uid, gid int) error {
+ // only chown on initial creation of container
+ if !c.ensureState(define.ContainerStateConfigured, define.ContainerStateUnknown) {
+ st, err := os.Stat(src)
+ if err != nil {
+ return err
+ }
+
+ // If labels are different, might be on a tmpfs
+ if int(st.Sys().(*syscall.Stat_t).Uid) == uid && int(st.Sys().(*syscall.Stat_t).Gid) == gid {
+ return nil
+ }
+ }
+ return chown.ChangeHostPathOwnership(src, recurse, uid, gid)
+}
diff --git a/libpod/container_internal_freebsd.go b/libpod/container_internal_freebsd.go
new file mode 100644
index 000000000..40c6c5ebf
--- /dev/null
+++ b/libpod/container_internal_freebsd.go
@@ -0,0 +1,285 @@
+//go:build freebsd
+// +build freebsd
+
+package libpod
+
+import (
+ "errors"
+ "fmt"
+ "os"
+ "strings"
+ "sync"
+ "syscall"
+ "time"
+
+ "github.com/containers/common/libnetwork/types"
+ "github.com/containers/podman/v4/pkg/rootless"
+ spec "github.com/opencontainers/runtime-spec/specs-go"
+ "github.com/opencontainers/runtime-tools/generate"
+ "github.com/sirupsen/logrus"
+ "golang.org/x/sys/unix"
+)
+
+var (
+ bindOptions = []string{}
+)
+
+// Network stubs to decouple container_internal_freebsd.go from
+// networking_freebsd.go so they can be reviewed separately.
+func (r *Runtime) createNetNS(ctr *Container) (netJail string, q map[string]types.StatusBlock, retErr error) {
+ return "", nil, errors.New("not implemented (*Runtime) createNetNS")
+}
+
+func (r *Runtime) teardownNetNS(ctr *Container) error {
+ return errors.New("not implemented (*Runtime) teardownNetNS")
+}
+
+func (r *Runtime) reloadContainerNetwork(ctr *Container) (map[string]types.StatusBlock, error) {
+ return nil, errors.New("not implemented (*Runtime) reloadContainerNetwork")
+}
+
+func (c *Container) mountSHM(shmOptions string) error {
+ return nil
+}
+
+func (c *Container) unmountSHM(path string) error {
+ return nil
+}
+
+// prepare mounts the container and sets up other required resources like net
+// namespaces
+func (c *Container) prepare() error {
+ var (
+ wg sync.WaitGroup
+ jailName string
+ networkStatus map[string]types.StatusBlock
+ createNetNSErr, mountStorageErr error
+ mountPoint string
+ tmpStateLock sync.Mutex
+ )
+
+ wg.Add(2)
+
+ go func() {
+ defer wg.Done()
+ // Set up network namespace if not already set up
+ noNetNS := c.state.NetworkJail == ""
+ if c.config.CreateNetNS && noNetNS && !c.config.PostConfigureNetNS {
+ jailName, networkStatus, createNetNSErr = c.runtime.createNetNS(c)
+ if createNetNSErr != nil {
+ return
+ }
+
+ tmpStateLock.Lock()
+ defer tmpStateLock.Unlock()
+
+ // Assign NetNS attributes to container
+ c.state.NetworkJail = jailName
+ c.state.NetworkStatus = networkStatus
+ }
+ }()
+ // Mount storage if not mounted
+ go func() {
+ defer wg.Done()
+ mountPoint, mountStorageErr = c.mountStorage()
+
+ if mountStorageErr != nil {
+ return
+ }
+
+ tmpStateLock.Lock()
+ defer tmpStateLock.Unlock()
+
+ // Finish up mountStorage
+ c.state.Mounted = true
+ c.state.Mountpoint = mountPoint
+
+ logrus.Debugf("Created root filesystem for container %s at %s", c.ID(), c.state.Mountpoint)
+ }()
+
+ wg.Wait()
+
+ var createErr error
+ if mountStorageErr != nil {
+ if createErr != nil {
+ logrus.Errorf("Preparing container %s: %v", c.ID(), createErr)
+ }
+ createErr = mountStorageErr
+ }
+
+ if createErr != nil {
+ return createErr
+ }
+
+ // Save changes to container state
+ if err := c.save(); err != nil {
+ return err
+ }
+
+ return nil
+}
+
+// cleanupNetwork unmounts and cleans up the container's network
+func (c *Container) cleanupNetwork() error {
+ if c.config.NetNsCtr != "" {
+ return nil
+ }
+ netDisabled, err := c.NetworkDisabled()
+ if err != nil {
+ return err
+ }
+ if netDisabled {
+ return nil
+ }
+
+ // Stop the container's network namespace (if it has one)
+ if err := c.runtime.teardownNetNS(c); err != nil {
+ logrus.Errorf("Unable to cleanup network for container %s: %q", c.ID(), err)
+ }
+
+ if c.valid {
+ return c.save()
+ }
+
+ return nil
+}
+
+// reloadNetwork reloads the network for the given container, recreating
+// firewall rules.
+func (c *Container) reloadNetwork() error {
+ result, err := c.runtime.reloadContainerNetwork(c)
+ if err != nil {
+ return err
+ }
+
+ c.state.NetworkStatus = result
+
+ return c.save()
+}
+
+// Add an existing container's network jail
+func (c *Container) addNetworkContainer(g *generate.Generator, ctr string) error {
+ nsCtr, err := c.runtime.state.Container(ctr)
+ c.runtime.state.UpdateContainer(nsCtr)
+ if err != nil {
+ return fmt.Errorf("error retrieving dependency %s of container %s from state: %w", ctr, c.ID(), err)
+ }
+ g.AddAnnotation("org.freebsd.parentJail", nsCtr.state.NetworkJail)
+ return nil
+}
+
+func isRootlessCgroupSet(cgroup string) bool {
+ return false
+}
+
+func (c *Container) expectPodCgroup() (bool, error) {
+ return false, nil
+}
+
+func (c *Container) getOCICgroupPath() (string, error) {
+ return "", nil
+}
+
+func openDirectory(path string) (fd int, err error) {
+ const O_PATH = 0x00400000
+ return unix.Open(path, unix.O_RDONLY|O_PATH, 0)
+}
+
+func (c *Container) addNetworkNamespace(g *generate.Generator) error {
+ if c.config.CreateNetNS {
+ g.AddAnnotation("org.freebsd.parentJail", c.state.NetworkJail)
+ }
+ return nil
+}
+
+func (c *Container) addSystemdMounts(g *generate.Generator) error {
+ return nil
+}
+
+func (c *Container) addSharedNamespaces(g *generate.Generator) error {
+ if c.config.NetNsCtr != "" {
+ if err := c.addNetworkContainer(g, c.config.NetNsCtr); err != nil {
+ return err
+ }
+ }
+
+ availableUIDs, availableGIDs, err := rootless.GetAvailableIDMaps()
+ if err != nil {
+ if os.IsNotExist(err) {
+ // The kernel-provided files only exist if user namespaces are supported
+ logrus.Debugf("User or group ID mappings not available: %s", err)
+ } else {
+ return err
+ }
+ } else {
+ g.Config.Linux.UIDMappings = rootless.MaybeSplitMappings(g.Config.Linux.UIDMappings, availableUIDs)
+ g.Config.Linux.GIDMappings = rootless.MaybeSplitMappings(g.Config.Linux.GIDMappings, availableGIDs)
+ }
+
+ // Hostname handling:
+ // If we have a UTS namespace, set Hostname in the OCI spec.
+ // Set the HOSTNAME environment variable unless explicitly overridden by
+ // the user (already present in OCI spec). If we don't have a UTS ns,
+ // set it to the host's hostname instead.
+ hostname := c.Hostname()
+ foundUTS := false
+
+ // TODO: make this optional, needs progress on adding FreeBSD section to the spec
+ foundUTS = true
+ g.SetHostname(hostname)
+
+ if !foundUTS {
+ tmpHostname, err := os.Hostname()
+ if err != nil {
+ return err
+ }
+ hostname = tmpHostname
+ }
+ needEnv := true
+ for _, checkEnv := range g.Config.Process.Env {
+ if strings.SplitN(checkEnv, "=", 2)[0] == "HOSTNAME" {
+ needEnv = false
+ break
+ }
+ }
+ if needEnv {
+ g.AddProcessEnv("HOSTNAME", hostname)
+ }
+ return nil
+}
+
+func (c *Container) addRootPropagation(g *generate.Generator, mounts []spec.Mount) error {
+ return nil
+}
+
+func (c *Container) setProcessLabel(g *generate.Generator) {
+}
+
+func (c *Container) setMountLabel(g *generate.Generator) {
+}
+
+func (c *Container) setCgroupsPath(g *generate.Generator) error {
+ return nil
+}
+
+func (c *Container) addSlirp4netnsDNS(nameservers []string) []string {
+ return nameservers
+}
+
+func (c *Container) isSlirp4netnsIPv6() (bool, error) {
+ return false, nil
+}
+
+// check for net=none
+func (c *Container) hasNetNone() bool {
+ return c.state.NetworkJail == ""
+}
+
+func setVolumeAtime(mountPoint string, st os.FileInfo) error {
+ stat := st.Sys().(*syscall.Stat_t)
+ atime := time.Unix(int64(stat.Atimespec.Sec), int64(stat.Atimespec.Nsec)) //nolint: unconvert
+ if err := os.Chtimes(mountPoint, atime, st.ModTime()); err != nil {
+ return err
+ }
+ return nil
+}
diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go
index bb50ddc43..83882ecac 100644
--- a/libpod/container_internal_linux.go
+++ b/libpod/container_internal_linux.go
@@ -4,64 +4,33 @@
package libpod
import (
- "context"
- "errors"
"fmt"
- "io"
- "io/ioutil"
- "math"
"os"
- "os/user"
"path"
"path/filepath"
- "strconv"
"strings"
"sync"
"syscall"
"time"
- metadata "github.com/checkpoint-restore/checkpointctl/lib"
- "github.com/checkpoint-restore/go-criu/v5/stats"
- cdi "github.com/container-orchestrated-devices/container-device-interface/pkg/cdi"
"github.com/containernetworking/plugins/pkg/ns"
- "github.com/containers/buildah"
- "github.com/containers/buildah/pkg/chrootuser"
- "github.com/containers/buildah/pkg/overlay"
- butil "github.com/containers/buildah/util"
- "github.com/containers/common/libnetwork/etchosts"
- "github.com/containers/common/libnetwork/resolvconf"
"github.com/containers/common/libnetwork/types"
- "github.com/containers/common/pkg/apparmor"
"github.com/containers/common/pkg/cgroups"
- "github.com/containers/common/pkg/chown"
"github.com/containers/common/pkg/config"
- "github.com/containers/common/pkg/subscriptions"
- "github.com/containers/common/pkg/umask"
- cutil "github.com/containers/common/pkg/util"
- is "github.com/containers/image/v5/storage"
"github.com/containers/podman/v4/libpod/define"
- "github.com/containers/podman/v4/libpod/events"
- "github.com/containers/podman/v4/pkg/annotations"
- "github.com/containers/podman/v4/pkg/checkpoint/crutils"
- "github.com/containers/podman/v4/pkg/criu"
- "github.com/containers/podman/v4/pkg/lookup"
"github.com/containers/podman/v4/pkg/rootless"
- "github.com/containers/podman/v4/pkg/util"
"github.com/containers/podman/v4/utils"
- "github.com/containers/podman/v4/version"
- "github.com/containers/storage/pkg/archive"
- "github.com/containers/storage/pkg/idtools"
- "github.com/containers/storage/pkg/lockfile"
- securejoin "github.com/cyphar/filepath-securejoin"
- runcuser "github.com/opencontainers/runc/libcontainer/user"
spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/generate"
- "github.com/opencontainers/selinux/go-selinux"
"github.com/opencontainers/selinux/go-selinux/label"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)
+var (
+ bindOptions = []string{"bind", "rprivate"}
+)
+
func (c *Container) mountSHM(shmOptions string) error {
if err := unix.Mount("shm", c.config.ShmDir, "tmpfs", unix.MS_NOEXEC|unix.MS_NOSUID|unix.MS_NODEV,
label.FormatMountLabel(shmOptions, c.config.MountLabel)); err != nil {
@@ -177,118 +146,6 @@ func (c *Container) prepare() error {
return nil
}
-// isWorkDirSymlink returns true if resolved workdir is symlink or a chain of symlinks,
-// and final resolved target is present either on volume, mount or inside of container
-// otherwise it returns false. Following function is meant for internal use only and
-// can change at any point of time.
-func (c *Container) isWorkDirSymlink(resolvedPath string) bool {
- // We cannot create workdir since explicit --workdir is
- // set in config but workdir could also be a symlink.
- // If it's a symlink, check if the resolved target is present in the container.
- // If so, that's a valid use case: return nil.
-
- maxSymLinks := 0
- for {
- // Linux only supports a chain of 40 links.
- // Reference: https://github.com/torvalds/linux/blob/master/include/linux/namei.h#L13
- if maxSymLinks > 40 {
- break
- }
- resolvedSymlink, err := os.Readlink(resolvedPath)
- if err != nil {
- // End sym-link resolution loop.
- break
- }
- if resolvedSymlink != "" {
- _, resolvedSymlinkWorkdir, err := c.resolvePath(c.state.Mountpoint, resolvedSymlink)
- if isPathOnVolume(c, resolvedSymlinkWorkdir) || isPathOnBindMount(c, resolvedSymlinkWorkdir) {
- // Resolved symlink exists on external volume or mount
- return true
- }
- if err != nil {
- // Could not resolve path so end sym-link resolution loop.
- break
- }
- if resolvedSymlinkWorkdir != "" {
- resolvedPath = resolvedSymlinkWorkdir
- _, err := os.Stat(resolvedSymlinkWorkdir)
- if err == nil {
- // Symlink resolved successfully and resolved path exists on container,
- // this is a valid use-case so return nil.
- logrus.Debugf("Workdir is a symlink with target to %q and resolved symlink exists on container", resolvedSymlink)
- return true
- }
- }
- }
- maxSymLinks++
- }
- return false
-}
-
-// resolveWorkDir resolves the container's workdir and, depending on the
-// configuration, will create it, or error out if it does not exist.
-// Note that the container must be mounted before.
-func (c *Container) resolveWorkDir() error {
- workdir := c.WorkingDir()
-
- // If the specified workdir is a subdir of a volume or mount,
- // we don't need to do anything. The runtime is taking care of
- // that.
- if isPathOnVolume(c, workdir) || isPathOnBindMount(c, workdir) {
- logrus.Debugf("Workdir %q resolved to a volume or mount", workdir)
- return nil
- }
-
- _, resolvedWorkdir, err := c.resolvePath(c.state.Mountpoint, workdir)
- if err != nil {
- return err
- }
- logrus.Debugf("Workdir %q resolved to host path %q", workdir, resolvedWorkdir)
-
- st, err := os.Stat(resolvedWorkdir)
- if err == nil {
- if !st.IsDir() {
- return fmt.Errorf("workdir %q exists on container %s, but is not a directory", workdir, c.ID())
- }
- return nil
- }
- if !c.config.CreateWorkingDir {
- // No need to create it (e.g., `--workdir=/foo`), so let's make sure
- // the path exists on the container.
- if err != nil {
- if os.IsNotExist(err) {
- // If resolved Workdir path gets marked as a valid symlink,
- // return nil cause this is valid use-case.
- if c.isWorkDirSymlink(resolvedWorkdir) {
- return nil
- }
- return fmt.Errorf("workdir %q does not exist on container %s", workdir, c.ID())
- }
- // This might be a serious error (e.g., permission), so
- // we need to return the full error.
- return fmt.Errorf("error detecting workdir %q on container %s: %w", workdir, c.ID(), err)
- }
- return nil
- }
- if err := os.MkdirAll(resolvedWorkdir, 0755); err != nil {
- if os.IsExist(err) {
- return nil
- }
- return fmt.Errorf("error creating container %s workdir: %w", c.ID(), err)
- }
-
- // Ensure container entrypoint is created (if required).
- uid, gid, _, err := chrootuser.GetUser(c.state.Mountpoint, c.User())
- if err != nil {
- return fmt.Errorf("error looking up %s inside of the container %s: %w", c.User(), c.ID(), err)
- }
- if err := os.Chown(resolvedWorkdir, int(uid), int(gid)); err != nil {
- return fmt.Errorf("error chowning container %s workdir to container root: %w", c.ID(), err)
- }
-
- return nil
-}
-
// cleanupNetwork unmounts and cleans up the container's network
func (c *Container) cleanupNetwork() error {
if c.config.NetNsCtr != "" {
@@ -335,671 +192,6 @@ func (c *Container) reloadNetwork() error {
return c.save()
}
-func (c *Container) getUserOverrides() *lookup.Overrides {
- var hasPasswdFile, hasGroupFile bool
- overrides := lookup.Overrides{}
- for _, m := range c.config.Spec.Mounts {
- if m.Destination == "/etc/passwd" {
- overrides.ContainerEtcPasswdPath = m.Source
- hasPasswdFile = true
- }
- if m.Destination == "/etc/group" {
- overrides.ContainerEtcGroupPath = m.Source
- hasGroupFile = true
- }
- if m.Destination == "/etc" {
- if !hasPasswdFile {
- overrides.ContainerEtcPasswdPath = filepath.Join(m.Source, "passwd")
- }
- if !hasGroupFile {
- overrides.ContainerEtcGroupPath = filepath.Join(m.Source, "group")
- }
- }
- }
- if path, ok := c.state.BindMounts["/etc/passwd"]; ok {
- overrides.ContainerEtcPasswdPath = path
- }
- return &overrides
-}
-
-func lookupHostUser(name string) (*runcuser.ExecUser, error) {
- var execUser runcuser.ExecUser
- // Look up User on host
- u, err := util.LookupUser(name)
- if err != nil {
- return &execUser, err
- }
- uid, err := strconv.ParseUint(u.Uid, 8, 32)
- if err != nil {
- return &execUser, err
- }
-
- gid, err := strconv.ParseUint(u.Gid, 8, 32)
- if err != nil {
- return &execUser, err
- }
- execUser.Uid = int(uid)
- execUser.Gid = int(gid)
- execUser.Home = u.HomeDir
- return &execUser, nil
-}
-
-// Internal only function which returns upper and work dir from
-// overlay options.
-func getOverlayUpperAndWorkDir(options []string) (string, string, error) {
- upperDir := ""
- workDir := ""
- for _, o := range options {
- if strings.HasPrefix(o, "upperdir") {
- splitOpt := strings.SplitN(o, "=", 2)
- if len(splitOpt) > 1 {
- upperDir = splitOpt[1]
- if upperDir == "" {
- return "", "", errors.New("cannot accept empty value for upperdir")
- }
- }
- }
- if strings.HasPrefix(o, "workdir") {
- splitOpt := strings.SplitN(o, "=", 2)
- if len(splitOpt) > 1 {
- workDir = splitOpt[1]
- if workDir == "" {
- return "", "", errors.New("cannot accept empty value for workdir")
- }
- }
- }
- }
- if (upperDir != "" && workDir == "") || (upperDir == "" && workDir != "") {
- return "", "", errors.New("must specify both upperdir and workdir")
- }
- return upperDir, workDir, nil
-}
-
-// Generate spec for a container
-// Accepts a map of the container's dependencies
-func (c *Container) generateSpec(ctx context.Context) (*spec.Spec, error) {
- overrides := c.getUserOverrides()
- execUser, err := lookup.GetUserGroupInfo(c.state.Mountpoint, c.config.User, overrides)
- if err != nil {
- if cutil.StringInSlice(c.config.User, c.config.HostUsers) {
- execUser, err = lookupHostUser(c.config.User)
- }
- if err != nil {
- return nil, err
- }
- }
-
- // NewFromSpec() is deprecated according to its comment
- // however the recommended replace just causes a nil map panic
- //nolint:staticcheck
- g := generate.NewFromSpec(c.config.Spec)
-
- // If the flag to mount all devices is set for a privileged container, add
- // all the devices from the host's machine into the container
- if c.config.MountAllDevices {
- if err := util.AddPrivilegedDevices(&g); err != nil {
- return nil, err
- }
- }
-
- // If network namespace was requested, add it now
- if c.config.CreateNetNS {
- if c.config.PostConfigureNetNS {
- if err := g.AddOrReplaceLinuxNamespace(string(spec.NetworkNamespace), ""); err != nil {
- return nil, err
- }
- } else {
- if err := g.AddOrReplaceLinuxNamespace(string(spec.NetworkNamespace), c.state.NetNS.Path()); err != nil {
- return nil, err
- }
- }
- }
-
- // Apply AppArmor checks and load the default profile if needed.
- if len(c.config.Spec.Process.ApparmorProfile) > 0 {
- updatedProfile, err := apparmor.CheckProfileAndLoadDefault(c.config.Spec.Process.ApparmorProfile)
- if err != nil {
- return nil, err
- }
- g.SetProcessApparmorProfile(updatedProfile)
- }
-
- if err := c.makeBindMounts(); err != nil {
- return nil, err
- }
-
- if err := c.mountNotifySocket(g); err != nil {
- return nil, err
- }
-
- // Get host UID and GID based on the container process UID and GID.
- hostUID, hostGID, err := butil.GetHostIDs(util.IDtoolsToRuntimeSpec(c.config.IDMappings.UIDMap), util.IDtoolsToRuntimeSpec(c.config.IDMappings.GIDMap), uint32(execUser.Uid), uint32(execUser.Gid))
- if err != nil {
- return nil, err
- }
-
- // Add named volumes
- for _, namedVol := range c.config.NamedVolumes {
- volume, err := c.runtime.GetVolume(namedVol.Name)
- if err != nil {
- return nil, fmt.Errorf("error retrieving volume %s to add to container %s: %w", namedVol.Name, c.ID(), err)
- }
- mountPoint, err := volume.MountPoint()
- if err != nil {
- return nil, err
- }
-
- overlayFlag := false
- upperDir := ""
- workDir := ""
- for _, o := range namedVol.Options {
- if o == "O" {
- overlayFlag = true
- upperDir, workDir, err = getOverlayUpperAndWorkDir(namedVol.Options)
- if err != nil {
- return nil, err
- }
- }
- }
-
- if overlayFlag {
- var overlayMount spec.Mount
- var overlayOpts *overlay.Options
- contentDir, err := overlay.TempDir(c.config.StaticDir, c.RootUID(), c.RootGID())
- if err != nil {
- return nil, err
- }
-
- overlayOpts = &overlay.Options{RootUID: c.RootUID(),
- RootGID: c.RootGID(),
- UpperDirOptionFragment: upperDir,
- WorkDirOptionFragment: workDir,
- GraphOpts: c.runtime.store.GraphOptions(),
- }
-
- overlayMount, err = overlay.MountWithOptions(contentDir, mountPoint, namedVol.Dest, overlayOpts)
- if err != nil {
- return nil, fmt.Errorf("mounting overlay failed %q: %w", mountPoint, err)
- }
-
- for _, o := range namedVol.Options {
- if o == "U" {
- if err := c.ChangeHostPathOwnership(mountPoint, true, int(hostUID), int(hostGID)); err != nil {
- return nil, err
- }
-
- if err := c.ChangeHostPathOwnership(contentDir, true, int(hostUID), int(hostGID)); err != nil {
- return nil, err
- }
- }
- }
- g.AddMount(overlayMount)
- } else {
- volMount := spec.Mount{
- Type: "bind",
- Source: mountPoint,
- Destination: namedVol.Dest,
- Options: namedVol.Options,
- }
- g.AddMount(volMount)
- }
- }
-
- // Check if the spec file mounts contain the options z, Z or U.
- // If they have z or Z, relabel the source directory and then remove the option.
- // If they have U, chown the source directory and them remove the option.
- for i := range g.Config.Mounts {
- m := &g.Config.Mounts[i]
- var options []string
- for _, o := range m.Options {
- switch o {
- case "U":
- if m.Type == "tmpfs" {
- options = append(options, []string{fmt.Sprintf("uid=%d", execUser.Uid), fmt.Sprintf("gid=%d", execUser.Gid)}...)
- } else {
- // only chown on initial creation of container
- if err := c.ChangeHostPathOwnership(m.Source, true, int(hostUID), int(hostGID)); err != nil {
- return nil, err
- }
- }
- case "z":
- fallthrough
- case "Z":
- if err := c.relabel(m.Source, c.MountLabel(), label.IsShared(o)); err != nil {
- return nil, err
- }
-
- default:
- options = append(options, o)
- }
- }
- m.Options = options
- }
-
- g.SetProcessSelinuxLabel(c.ProcessLabel())
- g.SetLinuxMountLabel(c.MountLabel())
-
- // Add bind mounts to container
- for dstPath, srcPath := range c.state.BindMounts {
- newMount := spec.Mount{
- Type: "bind",
- Source: srcPath,
- Destination: dstPath,
- Options: []string{"bind", "rprivate"},
- }
- if c.IsReadOnly() && dstPath != "/dev/shm" {
- newMount.Options = append(newMount.Options, "ro", "nosuid", "noexec", "nodev")
- }
- if dstPath == "/dev/shm" && c.state.BindMounts["/dev/shm"] == c.config.ShmDir {
- newMount.Options = append(newMount.Options, "nosuid", "noexec", "nodev")
- }
- if !MountExists(g.Mounts(), dstPath) {
- g.AddMount(newMount)
- } else {
- logrus.Infof("User mount overriding libpod mount at %q", dstPath)
- }
- }
-
- // Add overlay volumes
- for _, overlayVol := range c.config.OverlayVolumes {
- upperDir, workDir, err := getOverlayUpperAndWorkDir(overlayVol.Options)
- if err != nil {
- return nil, err
- }
- contentDir, err := overlay.TempDir(c.config.StaticDir, c.RootUID(), c.RootGID())
- if err != nil {
- return nil, err
- }
- overlayOpts := &overlay.Options{RootUID: c.RootUID(),
- RootGID: c.RootGID(),
- UpperDirOptionFragment: upperDir,
- WorkDirOptionFragment: workDir,
- GraphOpts: c.runtime.store.GraphOptions(),
- }
-
- overlayMount, err := overlay.MountWithOptions(contentDir, overlayVol.Source, overlayVol.Dest, overlayOpts)
- if err != nil {
- return nil, fmt.Errorf("mounting overlay failed %q: %w", overlayVol.Source, err)
- }
-
- // Check overlay volume options
- for _, o := range overlayVol.Options {
- if o == "U" {
- if err := c.ChangeHostPathOwnership(overlayVol.Source, true, int(hostUID), int(hostGID)); err != nil {
- return nil, err
- }
-
- if err := c.ChangeHostPathOwnership(contentDir, true, int(hostUID), int(hostGID)); err != nil {
- return nil, err
- }
- }
- }
-
- g.AddMount(overlayMount)
- }
-
- // Add image volumes as overlay mounts
- for _, volume := range c.config.ImageVolumes {
- // Mount the specified image.
- img, _, err := c.runtime.LibimageRuntime().LookupImage(volume.Source, nil)
- if err != nil {
- return nil, fmt.Errorf("error creating image volume %q:%q: %w", volume.Source, volume.Dest, err)
- }
- mountPoint, err := img.Mount(ctx, nil, "")
- if err != nil {
- return nil, fmt.Errorf("error mounting image volume %q:%q: %w", volume.Source, volume.Dest, err)
- }
-
- contentDir, err := overlay.TempDir(c.config.StaticDir, c.RootUID(), c.RootGID())
- if err != nil {
- return nil, fmt.Errorf("failed to create TempDir in the %s directory: %w", c.config.StaticDir, err)
- }
-
- var overlayMount spec.Mount
- if volume.ReadWrite {
- overlayMount, err = overlay.Mount(contentDir, mountPoint, volume.Dest, c.RootUID(), c.RootGID(), c.runtime.store.GraphOptions())
- } else {
- overlayMount, err = overlay.MountReadOnly(contentDir, mountPoint, volume.Dest, c.RootUID(), c.RootGID(), c.runtime.store.GraphOptions())
- }
- if err != nil {
- return nil, fmt.Errorf("creating overlay mount for image %q failed: %w", volume.Source, err)
- }
- g.AddMount(overlayMount)
- }
-
- hasHomeSet := false
- for _, s := range c.config.Spec.Process.Env {
- if strings.HasPrefix(s, "HOME=") {
- hasHomeSet = true
- break
- }
- }
- if !hasHomeSet && execUser.Home != "" {
- c.config.Spec.Process.Env = append(c.config.Spec.Process.Env, fmt.Sprintf("HOME=%s", execUser.Home))
- }
-
- if c.config.User != "" {
- // User and Group must go together
- g.SetProcessUID(uint32(execUser.Uid))
- g.SetProcessGID(uint32(execUser.Gid))
- g.AddProcessAdditionalGid(uint32(execUser.Gid))
- }
-
- if c.config.Umask != "" {
- decVal, err := strconv.ParseUint(c.config.Umask, 8, 32)
- if err != nil {
- return nil, fmt.Errorf("invalid Umask Value: %w", err)
- }
- umask := uint32(decVal)
- g.Config.Process.User.Umask = &umask
- }
-
- // Add addition groups if c.config.GroupAdd is not empty
- if len(c.config.Groups) > 0 {
- gids, err := lookup.GetContainerGroups(c.config.Groups, c.state.Mountpoint, overrides)
- if err != nil {
- return nil, fmt.Errorf("error looking up supplemental groups for container %s: %w", c.ID(), err)
- }
- for _, gid := range gids {
- g.AddProcessAdditionalGid(gid)
- }
- }
-
- if c.Systemd() {
- if err := c.setupSystemd(g.Mounts(), g); err != nil {
- return nil, fmt.Errorf("error adding systemd-specific mounts: %w", err)
- }
- }
-
- // Look up and add groups the user belongs to, if a group wasn't directly specified
- if !strings.Contains(c.config.User, ":") {
- // the gidMappings that are present inside the container user namespace
- var gidMappings []idtools.IDMap
-
- switch {
- case len(c.config.IDMappings.GIDMap) > 0:
- gidMappings = c.config.IDMappings.GIDMap
- case rootless.IsRootless():
- // Check whether the current user namespace has enough gids available.
- availableGids, err := rootless.GetAvailableGids()
- if err != nil {
- return nil, fmt.Errorf("cannot read number of available GIDs: %w", err)
- }
- gidMappings = []idtools.IDMap{{
- ContainerID: 0,
- HostID: 0,
- Size: int(availableGids),
- }}
- default:
- gidMappings = []idtools.IDMap{{
- ContainerID: 0,
- HostID: 0,
- Size: math.MaxInt32,
- }}
- }
- for _, gid := range execUser.Sgids {
- isGIDAvailable := false
- for _, m := range gidMappings {
- if gid >= m.ContainerID && gid < m.ContainerID+m.Size {
- isGIDAvailable = true
- break
- }
- }
- if isGIDAvailable {
- g.AddProcessAdditionalGid(uint32(gid))
- } else {
- logrus.Warnf("Additional gid=%d is not present in the user namespace, skip setting it", gid)
- }
- }
- }
-
- // Add shared namespaces from other containers
- if c.config.IPCNsCtr != "" {
- if err := c.addNamespaceContainer(&g, IPCNS, c.config.IPCNsCtr, spec.IPCNamespace); err != nil {
- return nil, err
- }
- }
- if c.config.MountNsCtr != "" {
- if err := c.addNamespaceContainer(&g, MountNS, c.config.MountNsCtr, spec.MountNamespace); err != nil {
- return nil, err
- }
- }
- if c.config.NetNsCtr != "" {
- if err := c.addNamespaceContainer(&g, NetNS, c.config.NetNsCtr, spec.NetworkNamespace); err != nil {
- return nil, err
- }
- }
- if c.config.PIDNsCtr != "" {
- if err := c.addNamespaceContainer(&g, PIDNS, c.config.PIDNsCtr, spec.PIDNamespace); err != nil {
- return nil, err
- }
- }
- if c.config.UserNsCtr != "" {
- if err := c.addNamespaceContainer(&g, UserNS, c.config.UserNsCtr, spec.UserNamespace); err != nil {
- return nil, err
- }
- if len(g.Config.Linux.UIDMappings) == 0 {
- // runc complains if no mapping is specified, even if we join another ns. So provide a dummy mapping
- g.AddLinuxUIDMapping(uint32(0), uint32(0), uint32(1))
- g.AddLinuxGIDMapping(uint32(0), uint32(0), uint32(1))
- }
- }
-
- availableUIDs, availableGIDs, err := rootless.GetAvailableIDMaps()
- if err != nil {
- if os.IsNotExist(err) {
- // The kernel-provided files only exist if user namespaces are supported
- logrus.Debugf("User or group ID mappings not available: %s", err)
- } else {
- return nil, err
- }
- } else {
- g.Config.Linux.UIDMappings = rootless.MaybeSplitMappings(g.Config.Linux.UIDMappings, availableUIDs)
- g.Config.Linux.GIDMappings = rootless.MaybeSplitMappings(g.Config.Linux.GIDMappings, availableGIDs)
- }
-
- // Hostname handling:
- // If we have a UTS namespace, set Hostname in the OCI spec.
- // Set the HOSTNAME environment variable unless explicitly overridden by
- // the user (already present in OCI spec). If we don't have a UTS ns,
- // set it to the host's hostname instead.
- hostname := c.Hostname()
- foundUTS := false
-
- for _, i := range c.config.Spec.Linux.Namespaces {
- if i.Type == spec.UTSNamespace && i.Path == "" {
- foundUTS = true
- g.SetHostname(hostname)
- break
- }
- }
- if !foundUTS {
- tmpHostname, err := os.Hostname()
- if err != nil {
- return nil, err
- }
- hostname = tmpHostname
- }
- needEnv := true
- for _, checkEnv := range g.Config.Process.Env {
- if strings.SplitN(checkEnv, "=", 2)[0] == "HOSTNAME" {
- needEnv = false
- break
- }
- }
- if needEnv {
- g.AddProcessEnv("HOSTNAME", hostname)
- }
-
- if c.config.UTSNsCtr != "" {
- if err := c.addNamespaceContainer(&g, UTSNS, c.config.UTSNsCtr, spec.UTSNamespace); err != nil {
- return nil, err
- }
- }
- if c.config.CgroupNsCtr != "" {
- if err := c.addNamespaceContainer(&g, CgroupNS, c.config.CgroupNsCtr, spec.CgroupNamespace); err != nil {
- return nil, err
- }
- }
-
- if c.config.UserNsCtr == "" && c.config.IDMappings.AutoUserNs {
- if err := g.AddOrReplaceLinuxNamespace(string(spec.UserNamespace), ""); err != nil {
- return nil, err
- }
- g.ClearLinuxUIDMappings()
- for _, uidmap := range c.config.IDMappings.UIDMap {
- g.AddLinuxUIDMapping(uint32(uidmap.HostID), uint32(uidmap.ContainerID), uint32(uidmap.Size))
- }
- g.ClearLinuxGIDMappings()
- for _, gidmap := range c.config.IDMappings.GIDMap {
- g.AddLinuxGIDMapping(uint32(gidmap.HostID), uint32(gidmap.ContainerID), uint32(gidmap.Size))
- }
- }
-
- g.SetRootPath(c.state.Mountpoint)
- g.AddAnnotation(annotations.Created, c.config.CreatedTime.Format(time.RFC3339Nano))
- g.AddAnnotation("org.opencontainers.image.stopSignal", fmt.Sprintf("%d", c.config.StopSignal))
-
- if _, exists := g.Config.Annotations[annotations.ContainerManager]; !exists {
- g.AddAnnotation(annotations.ContainerManager, annotations.ContainerManagerLibpod)
- }
-
- cgroupPath, err := c.getOCICgroupPath()
- if err != nil {
- return nil, err
- }
-
- g.SetLinuxCgroupsPath(cgroupPath)
-
- // Warning: CDI may alter g.Config in place.
- if len(c.config.CDIDevices) > 0 {
- registry := cdi.GetRegistry(
- cdi.WithAutoRefresh(false),
- )
- if err := registry.Refresh(); err != nil {
- logrus.Debugf("The following error was triggered when refreshing the CDI registry: %v", err)
- }
- _, err := registry.InjectDevices(g.Config, c.config.CDIDevices...)
- if err != nil {
- return nil, fmt.Errorf("error setting up CDI devices: %w", err)
- }
- }
-
- // Mounts need to be sorted so paths will not cover other paths
- mounts := sortMounts(g.Mounts())
- g.ClearMounts()
-
- // Determine property of RootPropagation based on volume properties. If
- // a volume is shared, then keep root propagation shared. This should
- // work for slave and private volumes too.
- //
- // For slave volumes, it can be either [r]shared/[r]slave.
- //
- // For private volumes any root propagation value should work.
- rootPropagation := ""
- for _, m := range mounts {
- // We need to remove all symlinks from tmpfs mounts.
- // Runc and other runtimes may choke on them.
- // Easy solution: use securejoin to do a scoped evaluation of
- // the links, then trim off the mount prefix.
- if m.Type == "tmpfs" {
- finalPath, err := securejoin.SecureJoin(c.state.Mountpoint, m.Destination)
- if err != nil {
- return nil, fmt.Errorf("error resolving symlinks for mount destination %s: %w", m.Destination, err)
- }
- trimmedPath := strings.TrimPrefix(finalPath, strings.TrimSuffix(c.state.Mountpoint, "/"))
- m.Destination = trimmedPath
- }
- g.AddMount(m)
- for _, opt := range m.Options {
- switch opt {
- case MountShared, MountRShared:
- if rootPropagation != MountShared && rootPropagation != MountRShared {
- rootPropagation = MountShared
- }
- case MountSlave, MountRSlave:
- if rootPropagation != MountShared && rootPropagation != MountRShared && rootPropagation != MountSlave && rootPropagation != MountRSlave {
- rootPropagation = MountRSlave
- }
- }
- }
- }
-
- if rootPropagation != "" {
- logrus.Debugf("Set root propagation to %q", rootPropagation)
- if err := g.SetLinuxRootPropagation(rootPropagation); err != nil {
- return nil, err
- }
- }
-
- // Warning: precreate hooks may alter g.Config in place.
- if c.state.ExtensionStageHooks, err = c.setupOCIHooks(ctx, g.Config); err != nil {
- return nil, fmt.Errorf("error setting up OCI Hooks: %w", err)
- }
- if len(c.config.EnvSecrets) > 0 {
- manager, err := c.runtime.SecretsManager()
- if err != nil {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- for name, secr := range c.config.EnvSecrets {
- _, data, err := manager.LookupSecretData(secr.Name)
- if err != nil {
- return nil, err
- }
- g.AddProcessEnv(name, string(data))
- }
- }
-
- // Pass down the LISTEN_* environment (see #10443).
- for _, key := range []string{"LISTEN_PID", "LISTEN_FDS", "LISTEN_FDNAMES"} {
- if val, ok := os.LookupEnv(key); ok {
- // Force the PID to `1` since we cannot rely on (all
- // versions of) all runtimes to do it for us.
- if key == "LISTEN_PID" {
- val = "1"
- }
- g.AddProcessEnv(key, val)
- }
- }
-
- return g.Config, nil
-}
-
-// mountNotifySocket mounts the NOTIFY_SOCKET into the container if it's set
-// and if the sdnotify mode is set to container. It also sets c.notifySocket
-// to avoid redundantly looking up the env variable.
-func (c *Container) mountNotifySocket(g generate.Generator) error {
- if c.config.SdNotifySocket == "" {
- return nil
- }
- if c.config.SdNotifyMode != define.SdNotifyModeContainer {
- return nil
- }
-
- notifyDir := filepath.Join(c.bundlePath(), "notify")
- logrus.Debugf("Checking notify %q dir", notifyDir)
- if err := os.MkdirAll(notifyDir, 0755); err != nil {
- if !os.IsExist(err) {
- return fmt.Errorf("unable to create notify %q dir: %w", notifyDir, err)
- }
- }
- if err := label.Relabel(notifyDir, c.MountLabel(), true); err != nil {
- return fmt.Errorf("relabel failed %q: %w", notifyDir, err)
- }
- logrus.Debugf("Add bindmount notify %q dir", notifyDir)
- if _, ok := c.state.BindMounts["/run/notify"]; !ok {
- c.state.BindMounts["/run/notify"] = notifyDir
- }
-
- // Set the container's notify socket to the proxy socket created by conmon
- g.AddProcessEnv("NOTIFY_SOCKET", "/run/notify/notify.sock")
-
- return nil
-}
-
// systemd expects to have /run, /run/lock and /tmp on tmpfs
// It also expects to be able to write to /sys/fs/cgroup/systemd and /var/log/journal
func (c *Container) setupSystemd(mounts []spec.Mount, g generate.Generator) error {
@@ -1132,1867 +324,6 @@ func (c *Container) addNamespaceContainer(g *generate.Generator, ns LinuxNS, ctr
return nil
}
-func (c *Container) addCheckpointImageMetadata(importBuilder *buildah.Builder) error {
- // Get information about host environment
- hostInfo, err := c.Runtime().hostInfo()
- if err != nil {
- return fmt.Errorf("getting host info: %v", err)
- }
-
- criuVersion, err := criu.GetCriuVersion()
- if err != nil {
- return fmt.Errorf("getting criu version: %v", err)
- }
-
- rootfsImageID, rootfsImageName := c.Image()
-
- // Add image annotations with information about the container and the host.
- // This information is useful to check compatibility before restoring the checkpoint
-
- checkpointImageAnnotations := map[string]string{
- define.CheckpointAnnotationName: c.config.Name,
- define.CheckpointAnnotationRawImageName: c.config.RawImageName,
- define.CheckpointAnnotationRootfsImageID: rootfsImageID,
- define.CheckpointAnnotationRootfsImageName: rootfsImageName,
- define.CheckpointAnnotationPodmanVersion: version.Version.String(),
- define.CheckpointAnnotationCriuVersion: strconv.Itoa(criuVersion),
- define.CheckpointAnnotationRuntimeName: hostInfo.OCIRuntime.Name,
- define.CheckpointAnnotationRuntimeVersion: hostInfo.OCIRuntime.Version,
- define.CheckpointAnnotationConmonVersion: hostInfo.Conmon.Version,
- define.CheckpointAnnotationHostArch: hostInfo.Arch,
- define.CheckpointAnnotationHostKernel: hostInfo.Kernel,
- define.CheckpointAnnotationCgroupVersion: hostInfo.CgroupsVersion,
- define.CheckpointAnnotationDistributionVersion: hostInfo.Distribution.Version,
- define.CheckpointAnnotationDistributionName: hostInfo.Distribution.Distribution,
- }
-
- for key, value := range checkpointImageAnnotations {
- importBuilder.SetAnnotation(key, value)
- }
-
- return nil
-}
-
-func (c *Container) resolveCheckpointImageName(options *ContainerCheckpointOptions) error {
- if options.CreateImage == "" {
- return nil
- }
-
- // Resolve image name
- resolvedImageName, err := c.runtime.LibimageRuntime().ResolveName(options.CreateImage)
- if err != nil {
- return err
- }
-
- options.CreateImage = resolvedImageName
- return nil
-}
-
-func (c *Container) createCheckpointImage(ctx context.Context, options ContainerCheckpointOptions) error {
- if options.CreateImage == "" {
- return nil
- }
- logrus.Debugf("Create checkpoint image %s", options.CreateImage)
-
- // Create storage reference
- imageRef, err := is.Transport.ParseStoreReference(c.runtime.store, options.CreateImage)
- if err != nil {
- return errors.New("failed to parse image name")
- }
-
- // Build an image scratch
- builderOptions := buildah.BuilderOptions{
- FromImage: "scratch",
- }
- importBuilder, err := buildah.NewBuilder(ctx, c.runtime.store, builderOptions)
- if err != nil {
- return err
- }
- // Clean up buildah working container
- defer func() {
- if err := importBuilder.Delete(); err != nil {
- logrus.Errorf("Image builder delete failed: %v", err)
- }
- }()
-
- if err := c.prepareCheckpointExport(); err != nil {
- return err
- }
-
- // Export checkpoint into temporary tar file
- tmpDir, err := ioutil.TempDir("", "checkpoint_image_")
- if err != nil {
- return err
- }
- defer os.RemoveAll(tmpDir)
-
- options.TargetFile = path.Join(tmpDir, "checkpoint.tar")
-
- if err := c.exportCheckpoint(options); err != nil {
- return err
- }
-
- // Copy checkpoint from temporary tar file in the image
- addAndCopyOptions := buildah.AddAndCopyOptions{}
- if err := importBuilder.Add("", true, addAndCopyOptions, options.TargetFile); err != nil {
- return err
- }
-
- if err := c.addCheckpointImageMetadata(importBuilder); err != nil {
- return err
- }
-
- commitOptions := buildah.CommitOptions{
- Squash: true,
- SystemContext: c.runtime.imageContext,
- }
-
- // Create checkpoint image
- id, _, _, err := importBuilder.Commit(ctx, imageRef, commitOptions)
- if err != nil {
- return err
- }
- logrus.Debugf("Created checkpoint image: %s", id)
- return nil
-}
-
-func (c *Container) exportCheckpoint(options ContainerCheckpointOptions) error {
- if len(c.Dependencies()) == 1 {
- // Check if the dependency is an infra container. If it is we can checkpoint
- // the container out of the Pod.
- if c.config.Pod == "" {
- return errors.New("cannot export checkpoints of containers with dependencies")
- }
-
- pod, err := c.runtime.state.Pod(c.config.Pod)
- if err != nil {
- return fmt.Errorf("container %s is in pod %s, but pod cannot be retrieved: %w", c.ID(), c.config.Pod, err)
- }
- infraID, err := pod.InfraContainerID()
- if err != nil {
- return fmt.Errorf("cannot retrieve infra container ID for pod %s: %w", c.config.Pod, err)
- }
- if c.Dependencies()[0] != infraID {
- return errors.New("cannot export checkpoints of containers with dependencies")
- }
- }
- if len(c.Dependencies()) > 1 {
- return errors.New("cannot export checkpoints of containers with dependencies")
- }
- logrus.Debugf("Exporting checkpoint image of container %q to %q", c.ID(), options.TargetFile)
-
- includeFiles := []string{
- "artifacts",
- metadata.DevShmCheckpointTar,
- metadata.ConfigDumpFile,
- metadata.SpecDumpFile,
- metadata.NetworkStatusFile,
- stats.StatsDump,
- }
-
- if c.LogDriver() == define.KubernetesLogging ||
- c.LogDriver() == define.JSONLogging {
- includeFiles = append(includeFiles, "ctr.log")
- }
- if options.PreCheckPoint {
- includeFiles = append(includeFiles, preCheckpointDir)
- } else {
- includeFiles = append(includeFiles, metadata.CheckpointDirectory)
- }
- // Get root file-system changes included in the checkpoint archive
- var addToTarFiles []string
- if !options.IgnoreRootfs {
- // To correctly track deleted files, let's go through the output of 'podman diff'
- rootFsChanges, err := c.runtime.GetDiff("", c.ID(), define.DiffContainer)
- if err != nil {
- return fmt.Errorf("error exporting root file-system diff for %q: %w", c.ID(), err)
- }
-
- addToTarFiles, err := crutils.CRCreateRootFsDiffTar(&rootFsChanges, c.state.Mountpoint, c.bundlePath())
- if err != nil {
- return err
- }
-
- includeFiles = append(includeFiles, addToTarFiles...)
- }
-
- // Folder containing archived volumes that will be included in the export
- expVolDir := filepath.Join(c.bundlePath(), metadata.CheckpointVolumesDirectory)
-
- // Create an archive for each volume associated with the container
- if !options.IgnoreVolumes {
- if err := os.MkdirAll(expVolDir, 0700); err != nil {
- return fmt.Errorf("error creating volumes export directory %q: %w", expVolDir, err)
- }
-
- for _, v := range c.config.NamedVolumes {
- volumeTarFilePath := filepath.Join(metadata.CheckpointVolumesDirectory, v.Name+".tar")
- volumeTarFileFullPath := filepath.Join(c.bundlePath(), volumeTarFilePath)
-
- volumeTarFile, err := os.Create(volumeTarFileFullPath)
- if err != nil {
- return fmt.Errorf("error creating %q: %w", volumeTarFileFullPath, err)
- }
-
- volume, err := c.runtime.GetVolume(v.Name)
- if err != nil {
- return err
- }
-
- mp, err := volume.MountPoint()
- if err != nil {
- return err
- }
- if mp == "" {
- return fmt.Errorf("volume %s is not mounted, cannot export: %w", volume.Name(), define.ErrInternal)
- }
-
- input, err := archive.TarWithOptions(mp, &archive.TarOptions{
- Compression: archive.Uncompressed,
- IncludeSourceDir: true,
- })
- if err != nil {
- return fmt.Errorf("error reading volume directory %q: %w", v.Dest, err)
- }
-
- _, err = io.Copy(volumeTarFile, input)
- if err != nil {
- return err
- }
- volumeTarFile.Close()
-
- includeFiles = append(includeFiles, volumeTarFilePath)
- }
- }
-
- input, err := archive.TarWithOptions(c.bundlePath(), &archive.TarOptions{
- Compression: options.Compression,
- IncludeSourceDir: true,
- IncludeFiles: includeFiles,
- })
-
- if err != nil {
- return fmt.Errorf("error reading checkpoint directory %q: %w", c.ID(), err)
- }
-
- outFile, err := os.Create(options.TargetFile)
- if err != nil {
- return fmt.Errorf("error creating checkpoint export file %q: %w", options.TargetFile, err)
- }
- defer outFile.Close()
-
- if err := os.Chmod(options.TargetFile, 0600); err != nil {
- return err
- }
-
- _, err = io.Copy(outFile, input)
- if err != nil {
- return err
- }
-
- for _, file := range addToTarFiles {
- os.Remove(filepath.Join(c.bundlePath(), file))
- }
-
- if !options.IgnoreVolumes {
- os.RemoveAll(expVolDir)
- }
-
- return nil
-}
-
-func (c *Container) checkpointRestoreSupported(version int) error {
- if !criu.CheckForCriu(version) {
- return fmt.Errorf("checkpoint/restore requires at least CRIU %d", version)
- }
- if !c.ociRuntime.SupportsCheckpoint() {
- return errors.New("configured runtime does not support checkpoint/restore")
- }
- return nil
-}
-
-func (c *Container) checkpoint(ctx context.Context, options ContainerCheckpointOptions) (*define.CRIUCheckpointRestoreStatistics, int64, error) {
- if err := c.checkpointRestoreSupported(criu.MinCriuVersion); err != nil {
- return nil, 0, err
- }
-
- if c.state.State != define.ContainerStateRunning {
- return nil, 0, fmt.Errorf("%q is not running, cannot checkpoint: %w", c.state.State, define.ErrCtrStateInvalid)
- }
-
- if c.AutoRemove() && options.TargetFile == "" {
- return nil, 0, errors.New("cannot checkpoint containers that have been started with '--rm' unless '--export' is used")
- }
-
- if err := c.resolveCheckpointImageName(&options); err != nil {
- return nil, 0, err
- }
-
- if err := crutils.CRCreateFileWithLabel(c.bundlePath(), "dump.log", c.MountLabel()); err != nil {
- return nil, 0, err
- }
-
- // Setting CheckpointLog early in case there is a failure.
- c.state.CheckpointLog = path.Join(c.bundlePath(), "dump.log")
- c.state.CheckpointPath = c.CheckpointPath()
-
- runtimeCheckpointDuration, err := c.ociRuntime.CheckpointContainer(c, options)
- if err != nil {
- return nil, 0, err
- }
-
- // Keep the content of /dev/shm directory
- if c.config.ShmDir != "" && c.state.BindMounts["/dev/shm"] == c.config.ShmDir {
- shmDirTarFileFullPath := filepath.Join(c.bundlePath(), metadata.DevShmCheckpointTar)
-
- shmDirTarFile, err := os.Create(shmDirTarFileFullPath)
- if err != nil {
- return nil, 0, err
- }
- defer shmDirTarFile.Close()
-
- input, err := archive.TarWithOptions(c.config.ShmDir, &archive.TarOptions{
- Compression: archive.Uncompressed,
- IncludeSourceDir: true,
- })
- if err != nil {
- return nil, 0, err
- }
-
- if _, err = io.Copy(shmDirTarFile, input); err != nil {
- return nil, 0, err
- }
- }
-
- // Save network.status. This is needed to restore the container with
- // the same IP. Currently limited to one IP address in a container
- // with one interface.
- // FIXME: will this break something?
- if _, err := metadata.WriteJSONFile(c.getNetworkStatus(), c.bundlePath(), metadata.NetworkStatusFile); err != nil {
- return nil, 0, err
- }
-
- defer c.newContainerEvent(events.Checkpoint)
-
- // There is a bug from criu: https://github.com/checkpoint-restore/criu/issues/116
- // We have to change the symbolic link from absolute path to relative path
- if options.WithPrevious {
- os.Remove(path.Join(c.CheckpointPath(), "parent"))
- if err := os.Symlink("../pre-checkpoint", path.Join(c.CheckpointPath(), "parent")); err != nil {
- return nil, 0, err
- }
- }
-
- if options.TargetFile != "" {
- if err := c.exportCheckpoint(options); err != nil {
- return nil, 0, err
- }
- } else {
- if err := c.createCheckpointImage(ctx, options); err != nil {
- return nil, 0, err
- }
- }
-
- logrus.Debugf("Checkpointed container %s", c.ID())
-
- if !options.KeepRunning && !options.PreCheckPoint {
- c.state.State = define.ContainerStateStopped
- c.state.Checkpointed = true
- c.state.CheckpointedTime = time.Now()
- c.state.Restored = false
- c.state.RestoredTime = time.Time{}
-
- // Clean up Storage and Network
- if err := c.cleanup(ctx); err != nil {
- return nil, 0, err
- }
- }
-
- criuStatistics, err := func() (*define.CRIUCheckpointRestoreStatistics, error) {
- if !options.PrintStats {
- return nil, nil
- }
- statsDirectory, err := os.Open(c.bundlePath())
- if err != nil {
- return nil, fmt.Errorf("not able to open %q: %w", c.bundlePath(), err)
- }
-
- dumpStatistics, err := stats.CriuGetDumpStats(statsDirectory)
- if err != nil {
- return nil, fmt.Errorf("displaying checkpointing statistics not possible: %w", err)
- }
-
- return &define.CRIUCheckpointRestoreStatistics{
- FreezingTime: dumpStatistics.GetFreezingTime(),
- FrozenTime: dumpStatistics.GetFrozenTime(),
- MemdumpTime: dumpStatistics.GetMemdumpTime(),
- MemwriteTime: dumpStatistics.GetMemwriteTime(),
- PagesScanned: dumpStatistics.GetPagesScanned(),
- PagesWritten: dumpStatistics.GetPagesWritten(),
- }, nil
- }()
- if err != nil {
- return nil, 0, err
- }
-
- if !options.Keep && !options.PreCheckPoint {
- cleanup := []string{
- "dump.log",
- stats.StatsDump,
- metadata.ConfigDumpFile,
- metadata.SpecDumpFile,
- }
- for _, del := range cleanup {
- file := filepath.Join(c.bundlePath(), del)
- if err := os.Remove(file); err != nil {
- logrus.Debugf("Unable to remove file %s", file)
- }
- }
- // The file has been deleted. Do not mention it.
- c.state.CheckpointLog = ""
- }
-
- c.state.FinishedTime = time.Now()
- return criuStatistics, runtimeCheckpointDuration, c.save()
-}
-
-func (c *Container) generateContainerSpec() error {
- // Make sure the newly created config.json exists on disk
-
- // NewFromSpec() is deprecated according to its comment
- // however the recommended replace just causes a nil map panic
- //nolint:staticcheck
- g := generate.NewFromSpec(c.config.Spec)
-
- if err := c.saveSpec(g.Config); err != nil {
- return fmt.Errorf("saving imported container specification for restore failed: %w", err)
- }
-
- return nil
-}
-
-func (c *Container) importCheckpointImage(ctx context.Context, imageID string) error {
- img, _, err := c.Runtime().LibimageRuntime().LookupImage(imageID, nil)
- if err != nil {
- return err
- }
-
- mountPoint, err := img.Mount(ctx, nil, "")
- defer func() {
- if err := c.unmount(true); err != nil {
- logrus.Errorf("Failed to unmount container: %v", err)
- }
- }()
- if err != nil {
- return err
- }
-
- // Import all checkpoint files except ConfigDumpFile and SpecDumpFile. We
- // generate new container config files to enable to specifying a new
- // container name.
- checkpoint := []string{
- "artifacts",
- metadata.CheckpointDirectory,
- metadata.CheckpointVolumesDirectory,
- metadata.DevShmCheckpointTar,
- metadata.RootFsDiffTar,
- metadata.DeletedFilesFile,
- metadata.PodOptionsFile,
- metadata.PodDumpFile,
- }
-
- for _, name := range checkpoint {
- src := filepath.Join(mountPoint, name)
- dst := filepath.Join(c.bundlePath(), name)
- if err := archive.NewDefaultArchiver().CopyWithTar(src, dst); err != nil {
- logrus.Debugf("Can't import '%s' from checkpoint image", name)
- }
- }
-
- return c.generateContainerSpec()
-}
-
-func (c *Container) importCheckpointTar(input string) error {
- if err := crutils.CRImportCheckpointWithoutConfig(c.bundlePath(), input); err != nil {
- return err
- }
-
- return c.generateContainerSpec()
-}
-
-func (c *Container) importPreCheckpoint(input string) error {
- archiveFile, err := os.Open(input)
- if err != nil {
- return fmt.Errorf("failed to open pre-checkpoint archive for import: %w", err)
- }
-
- defer archiveFile.Close()
-
- err = archive.Untar(archiveFile, c.bundlePath(), nil)
- if err != nil {
- return fmt.Errorf("unpacking of pre-checkpoint archive %s failed: %w", input, err)
- }
- return nil
-}
-
-func (c *Container) restore(ctx context.Context, options ContainerCheckpointOptions) (criuStatistics *define.CRIUCheckpointRestoreStatistics, runtimeRestoreDuration int64, retErr error) {
- minCriuVersion := func() int {
- if options.Pod == "" {
- return criu.MinCriuVersion
- }
- return criu.PodCriuVersion
- }()
- if err := c.checkpointRestoreSupported(minCriuVersion); err != nil {
- return nil, 0, err
- }
-
- if options.Pod != "" && !crutils.CRRuntimeSupportsPodCheckpointRestore(c.ociRuntime.Path()) {
- return nil, 0, fmt.Errorf("runtime %s does not support pod restore", c.ociRuntime.Path())
- }
-
- if !c.ensureState(define.ContainerStateConfigured, define.ContainerStateExited) {
- return nil, 0, fmt.Errorf("container %s is running or paused, cannot restore: %w", c.ID(), define.ErrCtrStateInvalid)
- }
-
- if options.ImportPrevious != "" {
- if err := c.importPreCheckpoint(options.ImportPrevious); err != nil {
- return nil, 0, err
- }
- }
-
- if options.TargetFile != "" {
- if err := c.importCheckpointTar(options.TargetFile); err != nil {
- return nil, 0, err
- }
- } else if options.CheckpointImageID != "" {
- if err := c.importCheckpointImage(ctx, options.CheckpointImageID); err != nil {
- return nil, 0, err
- }
- }
-
- // Let's try to stat() CRIU's inventory file. If it does not exist, it makes
- // no sense to try a restore. This is a minimal check if a checkpoint exist.
- if _, err := os.Stat(filepath.Join(c.CheckpointPath(), "inventory.img")); os.IsNotExist(err) {
- return nil, 0, fmt.Errorf("a complete checkpoint for this container cannot be found, cannot restore: %w", err)
- }
-
- if err := crutils.CRCreateFileWithLabel(c.bundlePath(), "restore.log", c.MountLabel()); err != nil {
- return nil, 0, err
- }
-
- // Setting RestoreLog early in case there is a failure.
- c.state.RestoreLog = path.Join(c.bundlePath(), "restore.log")
- c.state.CheckpointPath = c.CheckpointPath()
-
- // Read network configuration from checkpoint
- var netStatus map[string]types.StatusBlock
- _, err := metadata.ReadJSONFile(&netStatus, c.bundlePath(), metadata.NetworkStatusFile)
- if err != nil {
- logrus.Infof("Failed to unmarshal network status, cannot restore the same ip/mac: %v", err)
- }
- // If the restored container should get a new name, the IP address of
- // the container will not be restored. This assumes that if a new name is
- // specified, the container is restored multiple times.
- // TODO: This implicit restoring with or without IP depending on an
- // unrelated restore parameter (--name) does not seem like the
- // best solution.
- if err == nil && options.Name == "" && (!options.IgnoreStaticIP || !options.IgnoreStaticMAC) {
- // The file with the network.status does exist. Let's restore the
- // container with the same networks settings as during checkpointing.
- networkOpts, err := c.networks()
- if err != nil {
- return nil, 0, err
- }
-
- netOpts := make(map[string]types.PerNetworkOptions, len(netStatus))
- for network, perNetOpts := range networkOpts {
- // unset mac and ips before we start adding the ones from the status
- perNetOpts.StaticMAC = nil
- perNetOpts.StaticIPs = nil
- for name, netInt := range netStatus[network].Interfaces {
- perNetOpts.InterfaceName = name
- if !options.IgnoreStaticIP {
- perNetOpts.StaticMAC = netInt.MacAddress
- }
- if !options.IgnoreStaticIP {
- for _, netAddress := range netInt.Subnets {
- perNetOpts.StaticIPs = append(perNetOpts.StaticIPs, netAddress.IPNet.IP)
- }
- }
- // Normally interfaces have a length of 1, only for some special cni configs we could get more.
- // For now just use the first interface to get the ips this should be good enough for most cases.
- break
- }
- netOpts[network] = perNetOpts
- }
- c.perNetworkOpts = netOpts
- }
-
- defer func() {
- if retErr != nil {
- if err := c.cleanup(ctx); err != nil {
- logrus.Errorf("Cleaning up container %s: %v", c.ID(), err)
- }
- }
- }()
-
- if err := c.prepare(); err != nil {
- return nil, 0, err
- }
-
- // Read config
- jsonPath := filepath.Join(c.bundlePath(), "config.json")
- logrus.Debugf("generate.NewFromFile at %v", jsonPath)
- g, err := generate.NewFromFile(jsonPath)
- if err != nil {
- logrus.Debugf("generate.NewFromFile failed with %v", err)
- return nil, 0, err
- }
-
- // Restoring from an import means that we are doing migration
- if options.TargetFile != "" || options.CheckpointImageID != "" {
- g.SetRootPath(c.state.Mountpoint)
- }
-
- // We want to have the same network namespace as before.
- if c.config.CreateNetNS {
- netNSPath := ""
- if !c.config.PostConfigureNetNS {
- netNSPath = c.state.NetNS.Path()
- }
-
- if err := g.AddOrReplaceLinuxNamespace(string(spec.NetworkNamespace), netNSPath); err != nil {
- return nil, 0, err
- }
- }
-
- if options.Pod != "" {
- // Running in a Pod means that we have to change all namespace settings to
- // the ones from the infrastructure container.
- pod, err := c.runtime.LookupPod(options.Pod)
- if err != nil {
- return nil, 0, fmt.Errorf("pod %q cannot be retrieved: %w", options.Pod, err)
- }
-
- infraContainer, err := pod.InfraContainer()
- if err != nil {
- return nil, 0, fmt.Errorf("cannot retrieved infra container from pod %q: %w", options.Pod, err)
- }
-
- infraContainer.lock.Lock()
- if err := infraContainer.syncContainer(); err != nil {
- infraContainer.lock.Unlock()
- return nil, 0, fmt.Errorf("error syncing infrastructure container %s status: %w", infraContainer.ID(), err)
- }
- if infraContainer.state.State != define.ContainerStateRunning {
- if err := infraContainer.initAndStart(ctx); err != nil {
- infraContainer.lock.Unlock()
- return nil, 0, fmt.Errorf("error starting infrastructure container %s status: %w", infraContainer.ID(), err)
- }
- }
- infraContainer.lock.Unlock()
-
- if c.config.IPCNsCtr != "" {
- nsPath, err := infraContainer.namespacePath(IPCNS)
- if err != nil {
- return nil, 0, fmt.Errorf("cannot retrieve IPC namespace path for Pod %q: %w", options.Pod, err)
- }
- if err := g.AddOrReplaceLinuxNamespace(string(spec.IPCNamespace), nsPath); err != nil {
- return nil, 0, err
- }
- }
-
- if c.config.NetNsCtr != "" {
- nsPath, err := infraContainer.namespacePath(NetNS)
- if err != nil {
- return nil, 0, fmt.Errorf("cannot retrieve network namespace path for Pod %q: %w", options.Pod, err)
- }
- if err := g.AddOrReplaceLinuxNamespace(string(spec.NetworkNamespace), nsPath); err != nil {
- return nil, 0, err
- }
- }
-
- if c.config.PIDNsCtr != "" {
- nsPath, err := infraContainer.namespacePath(PIDNS)
- if err != nil {
- return nil, 0, fmt.Errorf("cannot retrieve PID namespace path for Pod %q: %w", options.Pod, err)
- }
- if err := g.AddOrReplaceLinuxNamespace(string(spec.PIDNamespace), nsPath); err != nil {
- return nil, 0, err
- }
- }
-
- if c.config.UTSNsCtr != "" {
- nsPath, err := infraContainer.namespacePath(UTSNS)
- if err != nil {
- return nil, 0, fmt.Errorf("cannot retrieve UTS namespace path for Pod %q: %w", options.Pod, err)
- }
- if err := g.AddOrReplaceLinuxNamespace(string(spec.UTSNamespace), nsPath); err != nil {
- return nil, 0, err
- }
- }
-
- if c.config.CgroupNsCtr != "" {
- nsPath, err := infraContainer.namespacePath(CgroupNS)
- if err != nil {
- return nil, 0, fmt.Errorf("cannot retrieve Cgroup namespace path for Pod %q: %w", options.Pod, err)
- }
- if err := g.AddOrReplaceLinuxNamespace(string(spec.CgroupNamespace), nsPath); err != nil {
- return nil, 0, err
- }
- }
- }
-
- if err := c.makeBindMounts(); err != nil {
- return nil, 0, err
- }
-
- if options.TargetFile != "" || options.CheckpointImageID != "" {
- for dstPath, srcPath := range c.state.BindMounts {
- newMount := spec.Mount{
- Type: "bind",
- Source: srcPath,
- Destination: dstPath,
- Options: []string{"bind", "private"},
- }
- if c.IsReadOnly() && dstPath != "/dev/shm" {
- newMount.Options = append(newMount.Options, "ro", "nosuid", "noexec", "nodev")
- }
- if dstPath == "/dev/shm" && c.state.BindMounts["/dev/shm"] == c.config.ShmDir {
- newMount.Options = append(newMount.Options, "nosuid", "noexec", "nodev")
- }
- if !MountExists(g.Mounts(), dstPath) {
- g.AddMount(newMount)
- }
- }
- }
-
- // Restore /dev/shm content
- if c.config.ShmDir != "" && c.state.BindMounts["/dev/shm"] == c.config.ShmDir {
- shmDirTarFileFullPath := filepath.Join(c.bundlePath(), metadata.DevShmCheckpointTar)
- if _, err := os.Stat(shmDirTarFileFullPath); err != nil {
- logrus.Debug("Container checkpoint doesn't contain dev/shm: ", err.Error())
- } else {
- shmDirTarFile, err := os.Open(shmDirTarFileFullPath)
- if err != nil {
- return nil, 0, err
- }
- defer shmDirTarFile.Close()
-
- if err := archive.UntarUncompressed(shmDirTarFile, c.config.ShmDir, nil); err != nil {
- return nil, 0, err
- }
- }
- }
-
- // Cleanup for a working restore.
- if err := c.removeConmonFiles(); err != nil {
- return nil, 0, err
- }
-
- // Save the OCI spec to disk
- if err := c.saveSpec(g.Config); err != nil {
- return nil, 0, err
- }
-
- // When restoring from an imported archive, allow restoring the content of volumes.
- // Volumes are created in setupContainer()
- if !options.IgnoreVolumes && (options.TargetFile != "" || options.CheckpointImageID != "") {
- for _, v := range c.config.NamedVolumes {
- volumeFilePath := filepath.Join(c.bundlePath(), metadata.CheckpointVolumesDirectory, v.Name+".tar")
-
- volumeFile, err := os.Open(volumeFilePath)
- if err != nil {
- return nil, 0, fmt.Errorf("failed to open volume file %s: %w", volumeFilePath, err)
- }
- defer volumeFile.Close()
-
- volume, err := c.runtime.GetVolume(v.Name)
- if err != nil {
- return nil, 0, fmt.Errorf("failed to retrieve volume %s: %w", v.Name, err)
- }
-
- mountPoint, err := volume.MountPoint()
- if err != nil {
- return nil, 0, err
- }
- if mountPoint == "" {
- return nil, 0, fmt.Errorf("unable to import volume %s as it is not mounted: %w", volume.Name(), err)
- }
- if err := archive.UntarUncompressed(volumeFile, mountPoint, nil); err != nil {
- return nil, 0, fmt.Errorf("failed to extract volume %s to %s: %w", volumeFilePath, mountPoint, err)
- }
- }
- }
-
- // Before actually restarting the container, apply the root file-system changes
- if !options.IgnoreRootfs {
- if err := crutils.CRApplyRootFsDiffTar(c.bundlePath(), c.state.Mountpoint); err != nil {
- return nil, 0, err
- }
-
- if err := crutils.CRRemoveDeletedFiles(c.ID(), c.bundlePath(), c.state.Mountpoint); err != nil {
- return nil, 0, err
- }
- }
-
- runtimeRestoreDuration, err = c.ociRuntime.CreateContainer(c, &options)
- if err != nil {
- return nil, 0, err
- }
-
- criuStatistics, err = func() (*define.CRIUCheckpointRestoreStatistics, error) {
- if !options.PrintStats {
- return nil, nil
- }
- statsDirectory, err := os.Open(c.bundlePath())
- if err != nil {
- return nil, fmt.Errorf("not able to open %q: %w", c.bundlePath(), err)
- }
-
- restoreStatistics, err := stats.CriuGetRestoreStats(statsDirectory)
- if err != nil {
- return nil, fmt.Errorf("displaying restore statistics not possible: %w", err)
- }
-
- return &define.CRIUCheckpointRestoreStatistics{
- PagesCompared: restoreStatistics.GetPagesCompared(),
- PagesSkippedCow: restoreStatistics.GetPagesSkippedCow(),
- ForkingTime: restoreStatistics.GetForkingTime(),
- RestoreTime: restoreStatistics.GetRestoreTime(),
- PagesRestored: restoreStatistics.GetPagesRestored(),
- }, nil
- }()
- if err != nil {
- return nil, 0, err
- }
-
- logrus.Debugf("Restored container %s", c.ID())
-
- c.state.State = define.ContainerStateRunning
- c.state.Checkpointed = false
- c.state.Restored = true
- c.state.CheckpointedTime = time.Time{}
- c.state.RestoredTime = time.Now()
-
- if !options.Keep {
- // Delete all checkpoint related files. At this point, in theory, all files
- // should exist. Still ignoring errors for now as the container should be
- // restored and running. Not erroring out just because some cleanup operation
- // failed. Starting with the checkpoint directory
- err = os.RemoveAll(c.CheckpointPath())
- if err != nil {
- logrus.Debugf("Non-fatal: removal of checkpoint directory (%s) failed: %v", c.CheckpointPath(), err)
- }
- c.state.CheckpointPath = ""
- err = os.RemoveAll(c.PreCheckPointPath())
- if err != nil {
- logrus.Debugf("Non-fatal: removal of pre-checkpoint directory (%s) failed: %v", c.PreCheckPointPath(), err)
- }
- err = os.RemoveAll(c.CheckpointVolumesPath())
- if err != nil {
- logrus.Debugf("Non-fatal: removal of checkpoint volumes directory (%s) failed: %v", c.CheckpointVolumesPath(), err)
- }
- cleanup := [...]string{
- "restore.log",
- "dump.log",
- stats.StatsDump,
- stats.StatsRestore,
- metadata.DevShmCheckpointTar,
- metadata.NetworkStatusFile,
- metadata.RootFsDiffTar,
- metadata.DeletedFilesFile,
- }
- for _, del := range cleanup {
- file := filepath.Join(c.bundlePath(), del)
- err = os.Remove(file)
- if err != nil {
- logrus.Debugf("Non-fatal: removal of checkpoint file (%s) failed: %v", file, err)
- }
- }
- c.state.CheckpointLog = ""
- c.state.RestoreLog = ""
- }
-
- return criuStatistics, runtimeRestoreDuration, c.save()
-}
-
-// Retrieves a container's "root" net namespace container dependency.
-func (c *Container) getRootNetNsDepCtr() (depCtr *Container, err error) {
- containersVisited := map[string]int{c.config.ID: 1}
- nextCtr := c.config.NetNsCtr
- for nextCtr != "" {
- // Make sure we aren't in a loop
- if _, visited := containersVisited[nextCtr]; visited {
- return nil, errors.New("loop encountered while determining net namespace container")
- }
- containersVisited[nextCtr] = 1
-
- depCtr, err = c.runtime.state.Container(nextCtr)
- if err != nil {
- return nil, fmt.Errorf("error fetching dependency %s of container %s: %w", c.config.NetNsCtr, c.ID(), err)
- }
- // This should never happen without an error
- if depCtr == nil {
- break
- }
- nextCtr = depCtr.config.NetNsCtr
- }
-
- if depCtr == nil {
- return nil, errors.New("unexpected error depCtr is nil without reported error from runtime state")
- }
- return depCtr, nil
-}
-
-// Ensure standard bind mounts are mounted into all root directories (including chroot directories)
-func (c *Container) mountIntoRootDirs(mountName string, mountPath string) error {
- c.state.BindMounts[mountName] = mountPath
-
- for _, chrootDir := range c.config.ChrootDirs {
- c.state.BindMounts[filepath.Join(chrootDir, mountName)] = mountPath
- }
-
- return nil
-}
-
-// Make standard bind mounts to include in the container
-func (c *Container) makeBindMounts() error {
- if err := os.Chown(c.state.RunDir, c.RootUID(), c.RootGID()); err != nil {
- return fmt.Errorf("cannot chown run directory: %w", err)
- }
-
- if c.state.BindMounts == nil {
- c.state.BindMounts = make(map[string]string)
- }
- netDisabled, err := c.NetworkDisabled()
- if err != nil {
- return err
- }
-
- if !netDisabled {
- // If /etc/resolv.conf and /etc/hosts exist, delete them so we
- // will recreate. Only do this if we aren't sharing them with
- // another container.
- if c.config.NetNsCtr == "" {
- if resolvePath, ok := c.state.BindMounts["/etc/resolv.conf"]; ok {
- if err := os.Remove(resolvePath); err != nil && !os.IsNotExist(err) {
- return fmt.Errorf("container %s: %w", c.ID(), err)
- }
- delete(c.state.BindMounts, "/etc/resolv.conf")
- }
- if hostsPath, ok := c.state.BindMounts["/etc/hosts"]; ok {
- if err := os.Remove(hostsPath); err != nil && !os.IsNotExist(err) {
- return fmt.Errorf("container %s: %w", c.ID(), err)
- }
- delete(c.state.BindMounts, "/etc/hosts")
- }
- }
-
- if c.config.NetNsCtr != "" && (!c.config.UseImageResolvConf || !c.config.UseImageHosts) {
- // We share a net namespace.
- // We want /etc/resolv.conf and /etc/hosts from the
- // other container. Unless we're not creating both of
- // them.
- depCtr, err := c.getRootNetNsDepCtr()
- if err != nil {
- return fmt.Errorf("error fetching network namespace dependency container for container %s: %w", c.ID(), err)
- }
-
- // We need that container's bind mounts
- bindMounts, err := depCtr.BindMounts()
- if err != nil {
- return fmt.Errorf("error fetching bind mounts from dependency %s of container %s: %w", depCtr.ID(), c.ID(), err)
- }
-
- // The other container may not have a resolv.conf or /etc/hosts
- // If it doesn't, don't copy them
- resolvPath, exists := bindMounts["/etc/resolv.conf"]
- if !c.config.UseImageResolvConf && exists {
- err := c.mountIntoRootDirs("/etc/resolv.conf", resolvPath)
-
- if err != nil {
- return fmt.Errorf("error assigning mounts to container %s: %w", c.ID(), err)
- }
- }
-
- // check if dependency container has an /etc/hosts file.
- // It may not have one, so only use it if it does.
- hostsPath, exists := bindMounts[config.DefaultHostsFile]
- if !c.config.UseImageHosts && exists {
- // we cannot use the dependency container lock due ABBA deadlocks in cleanup()
- lock, err := lockfile.GetLockfile(hostsPath)
- if err != nil {
- return fmt.Errorf("failed to lock hosts file: %w", err)
- }
- lock.Lock()
-
- // add the newly added container to the hosts file
- // we always use 127.0.0.1 as ip since they have the same netns
- err = etchosts.Add(hostsPath, getLocalhostHostEntry(c))
- lock.Unlock()
- if err != nil {
- return fmt.Errorf("error creating hosts file for container %s which depends on container %s: %w", c.ID(), depCtr.ID(), err)
- }
-
- // finally, save it in the new container
- err = c.mountIntoRootDirs(config.DefaultHostsFile, hostsPath)
- if err != nil {
- return fmt.Errorf("error assigning mounts to container %s: %w", c.ID(), err)
- }
- }
-
- if !hasCurrentUserMapped(c) {
- if err := makeAccessible(resolvPath, c.RootUID(), c.RootGID()); err != nil {
- return err
- }
- if err := makeAccessible(hostsPath, c.RootUID(), c.RootGID()); err != nil {
- return err
- }
- }
- } else {
- if !c.config.UseImageResolvConf {
- if err := c.generateResolvConf(); err != nil {
- return fmt.Errorf("error creating resolv.conf for container %s: %w", c.ID(), err)
- }
- }
-
- if !c.config.UseImageHosts {
- if err := c.createHosts(); err != nil {
- return fmt.Errorf("error creating hosts file for container %s: %w", c.ID(), err)
- }
- }
- }
-
- if c.state.BindMounts["/etc/hosts"] != "" {
- if err := c.relabel(c.state.BindMounts["/etc/hosts"], c.config.MountLabel, true); err != nil {
- return err
- }
- }
-
- if c.state.BindMounts["/etc/resolv.conf"] != "" {
- if err := c.relabel(c.state.BindMounts["/etc/resolv.conf"], c.config.MountLabel, true); err != nil {
- return err
- }
- }
- } else if !c.config.UseImageHosts && c.state.BindMounts["/etc/hosts"] == "" {
- if err := c.createHosts(); err != nil {
- return fmt.Errorf("error creating hosts file for container %s: %w", c.ID(), err)
- }
- }
-
- if c.config.ShmDir != "" {
- // If ShmDir has a value SHM is always added when we mount the container
- c.state.BindMounts["/dev/shm"] = c.config.ShmDir
- }
-
- if c.config.Passwd == nil || *c.config.Passwd {
- newPasswd, newGroup, err := c.generatePasswdAndGroup()
- if err != nil {
- return fmt.Errorf("error creating temporary passwd file for container %s: %w", c.ID(), err)
- }
- if newPasswd != "" {
- // Make /etc/passwd
- // If it already exists, delete so we can recreate
- delete(c.state.BindMounts, "/etc/passwd")
- c.state.BindMounts["/etc/passwd"] = newPasswd
- }
- if newGroup != "" {
- // Make /etc/group
- // If it already exists, delete so we can recreate
- delete(c.state.BindMounts, "/etc/group")
- c.state.BindMounts["/etc/group"] = newGroup
- }
- }
-
- // Make /etc/hostname
- // This should never change, so no need to recreate if it exists
- if _, ok := c.state.BindMounts["/etc/hostname"]; !ok {
- hostnamePath, err := c.writeStringToRundir("hostname", c.Hostname())
- if err != nil {
- return fmt.Errorf("error creating hostname file for container %s: %w", c.ID(), err)
- }
- c.state.BindMounts["/etc/hostname"] = hostnamePath
- }
-
- // Make /etc/localtime
- ctrTimezone := c.Timezone()
- if ctrTimezone != "" {
- // validate the format of the timezone specified if it's not "local"
- if ctrTimezone != "local" {
- _, err = time.LoadLocation(ctrTimezone)
- if err != nil {
- return fmt.Errorf("error finding timezone for container %s: %w", c.ID(), err)
- }
- }
- if _, ok := c.state.BindMounts["/etc/localtime"]; !ok {
- var zonePath string
- if ctrTimezone == "local" {
- zonePath, err = filepath.EvalSymlinks("/etc/localtime")
- if err != nil {
- return fmt.Errorf("error finding local timezone for container %s: %w", c.ID(), err)
- }
- } else {
- zone := filepath.Join("/usr/share/zoneinfo", ctrTimezone)
- zonePath, err = filepath.EvalSymlinks(zone)
- if err != nil {
- return fmt.Errorf("error setting timezone for container %s: %w", c.ID(), err)
- }
- }
- localtimePath, err := c.copyTimezoneFile(zonePath)
- if err != nil {
- return fmt.Errorf("error setting timezone for container %s: %w", c.ID(), err)
- }
- c.state.BindMounts["/etc/localtime"] = localtimePath
- }
- }
-
- _, hasRunContainerenv := c.state.BindMounts["/run/.containerenv"]
- if !hasRunContainerenv {
- // check in the spec mounts
- for _, m := range c.config.Spec.Mounts {
- if m.Destination == "/run/.containerenv" || m.Destination == "/run" {
- hasRunContainerenv = true
- break
- }
- }
- }
-
- // Make .containerenv if it does not exist
- if !hasRunContainerenv {
- containerenv := c.runtime.graphRootMountedFlag(c.config.Spec.Mounts)
- isRootless := 0
- if rootless.IsRootless() {
- isRootless = 1
- }
- imageID, imageName := c.Image()
-
- if c.Privileged() {
- // Populate the .containerenv with container information
- containerenv = fmt.Sprintf(`engine="podman-%s"
-name=%q
-id=%q
-image=%q
-imageid=%q
-rootless=%d
-%s`, version.Version.String(), c.Name(), c.ID(), imageName, imageID, isRootless, containerenv)
- }
- containerenvPath, err := c.writeStringToRundir(".containerenv", containerenv)
- if err != nil {
- return fmt.Errorf("error creating containerenv file for container %s: %w", c.ID(), err)
- }
- c.state.BindMounts["/run/.containerenv"] = containerenvPath
- }
-
- // Add Subscription Mounts
- subscriptionMounts := subscriptions.MountsWithUIDGID(c.config.MountLabel, c.state.RunDir, c.runtime.config.Containers.DefaultMountsFile, c.state.Mountpoint, c.RootUID(), c.RootGID(), rootless.IsRootless(), false)
- for _, mount := range subscriptionMounts {
- if _, ok := c.state.BindMounts[mount.Destination]; !ok {
- c.state.BindMounts[mount.Destination] = mount.Source
- }
- }
-
- // Secrets are mounted by getting the secret data from the secrets manager,
- // copying the data into the container's static dir,
- // then mounting the copied dir into /run/secrets.
- // The secrets mounting must come after subscription mounts, since subscription mounts
- // creates the /run/secrets dir in the container where we mount as well.
- if len(c.Secrets()) > 0 {
- // create /run/secrets if subscriptions did not create
- if err := c.createSecretMountDir(); err != nil {
- return fmt.Errorf("error creating secrets mount: %w", err)
- }
- for _, secret := range c.Secrets() {
- secretFileName := secret.Name
- base := "/run/secrets"
- if secret.Target != "" {
- secretFileName = secret.Target
- // If absolute path for target given remove base.
- if filepath.IsAbs(secretFileName) {
- base = ""
- }
- }
- src := filepath.Join(c.config.SecretsPath, secret.Name)
- dest := filepath.Join(base, secretFileName)
- c.state.BindMounts[dest] = src
- }
- }
-
- return nil
-}
-
-// generateResolvConf generates a containers resolv.conf
-func (c *Container) generateResolvConf() error {
- var (
- networkNameServers []string
- networkSearchDomains []string
- )
-
- netStatus := c.getNetworkStatus()
- for _, status := range netStatus {
- if status.DNSServerIPs != nil {
- for _, nsIP := range status.DNSServerIPs {
- networkNameServers = append(networkNameServers, nsIP.String())
- }
- logrus.Debugf("Adding nameserver(s) from network status of '%q'", status.DNSServerIPs)
- }
- if status.DNSSearchDomains != nil {
- networkSearchDomains = append(networkSearchDomains, status.DNSSearchDomains...)
- logrus.Debugf("Adding search domain(s) from network status of '%q'", status.DNSSearchDomains)
- }
- }
-
- ipv6, err := c.checkForIPv6(netStatus)
- if err != nil {
- return err
- }
-
- nameservers := make([]string, 0, len(c.runtime.config.Containers.DNSServers)+len(c.config.DNSServer))
- nameservers = append(nameservers, c.runtime.config.Containers.DNSServers...)
- for _, ip := range c.config.DNSServer {
- nameservers = append(nameservers, ip.String())
- }
- // If the user provided dns, it trumps all; then dns masq; then resolv.conf
- var search []string
- keepHostServers := false
- if len(nameservers) == 0 {
- keepHostServers = true
- // first add the nameservers from the networks status
- nameservers = networkNameServers
- // when we add network dns server we also have to add the search domains
- search = networkSearchDomains
- // slirp4netns has a built in DNS forwarder.
- if c.config.NetMode.IsSlirp4netns() {
- slirp4netnsDNS, err := GetSlirp4netnsDNS(c.slirp4netnsSubnet)
- if err != nil {
- logrus.Warn("Failed to determine Slirp4netns DNS: ", err.Error())
- } else {
- nameservers = append(nameservers, slirp4netnsDNS.String())
- }
- }
- }
-
- if len(c.config.DNSSearch) > 0 || len(c.runtime.config.Containers.DNSSearches) > 0 {
- customSearch := make([]string, 0, len(c.config.DNSSearch)+len(c.runtime.config.Containers.DNSSearches))
- customSearch = append(customSearch, c.runtime.config.Containers.DNSSearches...)
- customSearch = append(customSearch, c.config.DNSSearch...)
- search = customSearch
- }
-
- options := make([]string, 0, len(c.config.DNSOption)+len(c.runtime.config.Containers.DNSOptions))
- options = append(options, c.runtime.config.Containers.DNSOptions...)
- options = append(options, c.config.DNSOption...)
-
- destPath := filepath.Join(c.state.RunDir, "resolv.conf")
-
- if err := resolvconf.New(&resolvconf.Params{
- IPv6Enabled: ipv6,
- KeepHostServers: keepHostServers,
- Nameservers: nameservers,
- Namespaces: c.config.Spec.Linux.Namespaces,
- Options: options,
- Path: destPath,
- Searches: search,
- }); err != nil {
- return fmt.Errorf("error building resolv.conf for container %s: %w", c.ID(), err)
- }
-
- return c.bindMountRootFile(destPath, resolvconf.DefaultResolvConf)
-}
-
-// Check if a container uses IPv6.
-func (c *Container) checkForIPv6(netStatus map[string]types.StatusBlock) (bool, error) {
- for _, status := range netStatus {
- for _, netInt := range status.Interfaces {
- for _, netAddress := range netInt.Subnets {
- // Note: only using To16() does not work since it also returns a valid ip for ipv4
- if netAddress.IPNet.IP.To4() == nil && netAddress.IPNet.IP.To16() != nil {
- return true, nil
- }
- }
- }
- }
-
- if c.config.NetMode.IsSlirp4netns() {
- ctrNetworkSlipOpts := []string{}
- if c.config.NetworkOptions != nil {
- ctrNetworkSlipOpts = append(ctrNetworkSlipOpts, c.config.NetworkOptions["slirp4netns"]...)
- }
- slirpOpts, err := parseSlirp4netnsNetworkOptions(c.runtime, ctrNetworkSlipOpts)
- if err != nil {
- return false, err
- }
- return slirpOpts.enableIPv6, nil
- }
-
- return false, nil
-}
-
-// Add a new nameserver to the container's resolv.conf, ensuring that it is the
-// first nameserver present.
-// Usable only with running containers.
-func (c *Container) addNameserver(ips []string) error {
- // Take no action if container is not running.
- if !c.ensureState(define.ContainerStateRunning, define.ContainerStateCreated) {
- return nil
- }
-
- // Do we have a resolv.conf at all?
- path, ok := c.state.BindMounts[resolvconf.DefaultResolvConf]
- if !ok {
- return nil
- }
-
- if err := resolvconf.Add(path, ips); err != nil {
- return fmt.Errorf("adding new nameserver to container %s resolv.conf: %w", c.ID(), err)
- }
-
- return nil
-}
-
-// Remove an entry from the existing resolv.conf of the container.
-// Usable only with running containers.
-func (c *Container) removeNameserver(ips []string) error {
- // Take no action if container is not running.
- if !c.ensureState(define.ContainerStateRunning, define.ContainerStateCreated) {
- return nil
- }
-
- // Do we have a resolv.conf at all?
- path, ok := c.state.BindMounts[resolvconf.DefaultResolvConf]
- if !ok {
- return nil
- }
-
- if err := resolvconf.Remove(path, ips); err != nil {
- return fmt.Errorf("removing nameservers from container %s resolv.conf: %w", c.ID(), err)
- }
-
- return nil
-}
-
-func getLocalhostHostEntry(c *Container) etchosts.HostEntries {
- return etchosts.HostEntries{{IP: "127.0.0.1", Names: []string{c.Hostname(), c.config.Name}}}
-}
-
-// getHostsEntries returns the container ip host entries for the correct netmode
-func (c *Container) getHostsEntries() (etchosts.HostEntries, error) {
- var entries etchosts.HostEntries
- names := []string{c.Hostname(), c.config.Name}
- switch {
- case c.config.NetMode.IsBridge():
- entries = etchosts.GetNetworkHostEntries(c.state.NetworkStatus, names...)
- case c.config.NetMode.IsSlirp4netns():
- ip, err := GetSlirp4netnsIP(c.slirp4netnsSubnet)
- if err != nil {
- return nil, err
- }
- entries = etchosts.HostEntries{{IP: ip.String(), Names: names}}
- default:
- // check for net=none
- if !c.config.CreateNetNS {
- for _, ns := range c.config.Spec.Linux.Namespaces {
- if ns.Type == spec.NetworkNamespace {
- if ns.Path == "" {
- entries = etchosts.HostEntries{{IP: "127.0.0.1", Names: names}}
- }
- break
- }
- }
- }
- }
- return entries, nil
-}
-
-func (c *Container) createHosts() error {
- var containerIPsEntries etchosts.HostEntries
- var err error
- // if we configure the netns after the container create we should not add
- // the hosts here since we have no information about the actual ips
- // instead we will add them in c.completeNetworkSetup()
- if !c.config.PostConfigureNetNS {
- containerIPsEntries, err = c.getHostsEntries()
- if err != nil {
- return fmt.Errorf("failed to get container ip host entries: %w", err)
- }
- }
- baseHostFile, err := etchosts.GetBaseHostFile(c.runtime.config.Containers.BaseHostsFile, c.state.Mountpoint)
- if err != nil {
- return err
- }
-
- targetFile := filepath.Join(c.state.RunDir, "hosts")
- err = etchosts.New(&etchosts.Params{
- BaseFile: baseHostFile,
- ExtraHosts: c.config.HostAdd,
- ContainerIPs: containerIPsEntries,
- HostContainersInternalIP: etchosts.GetHostContainersInternalIP(c.runtime.config, c.state.NetworkStatus, c.runtime.network),
- TargetFile: targetFile,
- })
- if err != nil {
- return err
- }
-
- return c.bindMountRootFile(targetFile, config.DefaultHostsFile)
-}
-
-// bindMountRootFile will chown and relabel the source file to make it usable in the container.
-// It will also add the path to the container bind mount map.
-// source is the path on the host, dest is the path in the container.
-func (c *Container) bindMountRootFile(source, dest string) error {
- if err := os.Chown(source, c.RootUID(), c.RootGID()); err != nil {
- return err
- }
- if err := label.Relabel(source, c.MountLabel(), false); err != nil {
- return err
- }
-
- return c.mountIntoRootDirs(dest, source)
-}
-
-// generateGroupEntry generates an entry or entries into /etc/group as
-// required by container configuration.
-// Generally speaking, we will make an entry under two circumstances:
-// 1. The container is started as a specific user:group, and that group is both
-// numeric, and does not already exist in /etc/group.
-// 2. It is requested that Libpod add the group that launched Podman to
-// /etc/group via AddCurrentUserPasswdEntry (though this does not trigger if
-// the group in question already exists in /etc/passwd).
-// Returns group entry (as a string that can be appended to /etc/group) and any
-// error that occurred.
-func (c *Container) generateGroupEntry() (string, error) {
- groupString := ""
-
- // Things we *can't* handle: adding the user we added in
- // generatePasswdEntry to any *existing* groups.
- addedGID := 0
- if c.config.AddCurrentUserPasswdEntry {
- entry, gid, err := c.generateCurrentUserGroupEntry()
- if err != nil {
- return "", err
- }
- groupString += entry
- addedGID = gid
- }
- if c.config.User != "" {
- entry, err := c.generateUserGroupEntry(addedGID)
- if err != nil {
- return "", err
- }
- groupString += entry
- }
-
- return groupString, nil
-}
-
-// Make an entry in /etc/group for the group of the user running podman iff we
-// are rootless.
-func (c *Container) generateCurrentUserGroupEntry() (string, int, error) {
- gid := rootless.GetRootlessGID()
- if gid == 0 {
- return "", 0, nil
- }
-
- g, err := user.LookupGroupId(strconv.Itoa(gid))
- if err != nil {
- return "", 0, fmt.Errorf("failed to get current group: %w", err)
- }
-
- // Look up group name to see if it exists in the image.
- _, err = lookup.GetGroup(c.state.Mountpoint, g.Name)
- if err != runcuser.ErrNoGroupEntries {
- return "", 0, err
- }
-
- // Look up GID to see if it exists in the image.
- _, err = lookup.GetGroup(c.state.Mountpoint, g.Gid)
- if err != runcuser.ErrNoGroupEntries {
- return "", 0, err
- }
-
- // We need to get the username of the rootless user so we can add it to
- // the group.
- username := ""
- uid := rootless.GetRootlessUID()
- if uid != 0 {
- u, err := user.LookupId(strconv.Itoa(uid))
- if err != nil {
- return "", 0, fmt.Errorf("failed to get current user to make group entry: %w", err)
- }
- username = u.Username
- }
-
- // Make the entry.
- return fmt.Sprintf("%s:x:%s:%s\n", g.Name, g.Gid, username), gid, nil
-}
-
-// Make an entry in /etc/group for the group the container was specified to run
-// as.
-func (c *Container) generateUserGroupEntry(addedGID int) (string, error) {
- if c.config.User == "" {
- return "", nil
- }
-
- splitUser := strings.SplitN(c.config.User, ":", 2)
- group := splitUser[0]
- if len(splitUser) > 1 {
- group = splitUser[1]
- }
-
- gid, err := strconv.ParseUint(group, 10, 32)
- if err != nil {
- return "", nil //nolint: nilerr
- }
-
- if addedGID != 0 && addedGID == int(gid) {
- return "", nil
- }
-
- // Check if the group already exists
- _, err = lookup.GetGroup(c.state.Mountpoint, group)
- if err != runcuser.ErrNoGroupEntries {
- return "", err
- }
-
- return fmt.Sprintf("%d:x:%d:%s\n", gid, gid, splitUser[0]), nil
-}
-
-// generatePasswdEntry generates an entry or entries into /etc/passwd as
-// required by container configuration.
-// Generally speaking, we will make an entry under two circumstances:
-// 1. The container is started as a specific user who is not in /etc/passwd.
-// This only triggers if the user is given as a *numeric* ID.
-// 2. It is requested that Libpod add the user that launched Podman to
-// /etc/passwd via AddCurrentUserPasswdEntry (though this does not trigger if
-// the user in question already exists in /etc/passwd) or the UID to be added
-// is 0).
-// 3. The user specified additional host user accounts to add the the /etc/passwd file
-// Returns password entry (as a string that can be appended to /etc/passwd) and
-// any error that occurred.
-func (c *Container) generatePasswdEntry() (string, error) {
- passwdString := ""
-
- addedUID := 0
- for _, userid := range c.config.HostUsers {
- // Look up User on host
- u, err := util.LookupUser(userid)
- if err != nil {
- return "", err
- }
- entry, err := c.userPasswdEntry(u)
- if err != nil {
- return "", err
- }
- passwdString += entry
- }
- if c.config.AddCurrentUserPasswdEntry {
- entry, uid, _, err := c.generateCurrentUserPasswdEntry()
- if err != nil {
- return "", err
- }
- passwdString += entry
- addedUID = uid
- }
- if c.config.User != "" {
- entry, err := c.generateUserPasswdEntry(addedUID)
- if err != nil {
- return "", err
- }
- passwdString += entry
- }
-
- return passwdString, nil
-}
-
-// generateCurrentUserPasswdEntry generates an /etc/passwd entry for the user
-// running the container engine.
-// Returns a passwd entry for the user, and the UID and GID of the added entry.
-func (c *Container) generateCurrentUserPasswdEntry() (string, int, int, error) {
- uid := rootless.GetRootlessUID()
- if uid == 0 {
- return "", 0, 0, nil
- }
-
- u, err := user.LookupId(strconv.Itoa(uid))
- if err != nil {
- return "", 0, 0, fmt.Errorf("failed to get current user: %w", err)
- }
- pwd, err := c.userPasswdEntry(u)
- if err != nil {
- return "", 0, 0, err
- }
-
- return pwd, uid, rootless.GetRootlessGID(), nil
-}
-
-func (c *Container) userPasswdEntry(u *user.User) (string, error) {
- // Look up the user to see if it exists in the container image.
- _, err := lookup.GetUser(c.state.Mountpoint, u.Username)
- if err != runcuser.ErrNoPasswdEntries {
- return "", err
- }
-
- // Look up the UID to see if it exists in the container image.
- _, err = lookup.GetUser(c.state.Mountpoint, u.Uid)
- if err != runcuser.ErrNoPasswdEntries {
- return "", err
- }
-
- // If the user's actual home directory exists, or was mounted in - use
- // that.
- homeDir := c.WorkingDir()
- hDir := u.HomeDir
- for hDir != "/" {
- if MountExists(c.config.Spec.Mounts, hDir) {
- homeDir = u.HomeDir
- break
- }
- hDir = filepath.Dir(hDir)
- }
- if homeDir != u.HomeDir {
- for _, hDir := range c.UserVolumes() {
- if hDir == u.HomeDir {
- homeDir = u.HomeDir
- break
- }
- }
- }
- // Set HOME environment if not already set
- hasHomeSet := false
- for _, s := range c.config.Spec.Process.Env {
- if strings.HasPrefix(s, "HOME=") {
- hasHomeSet = true
- break
- }
- }
- if !hasHomeSet {
- c.config.Spec.Process.Env = append(c.config.Spec.Process.Env, fmt.Sprintf("HOME=%s", homeDir))
- }
- if c.config.PasswdEntry != "" {
- return c.passwdEntry(u.Username, u.Uid, u.Gid, u.Name, homeDir), nil
- }
-
- return fmt.Sprintf("%s:*:%s:%s:%s:%s:/bin/sh\n", u.Username, u.Uid, u.Gid, u.Name, homeDir), nil
-}
-
-// generateUserPasswdEntry generates an /etc/passwd entry for the container user
-// to run in the container.
-// The UID and GID of the added entry will also be returned.
-// Accepts one argument, that being any UID that has already been added to the
-// passwd file by other functions; if it matches the UID we were given, we don't
-// need to do anything.
-func (c *Container) generateUserPasswdEntry(addedUID int) (string, error) {
- var (
- groupspec string
- gid int
- )
- if c.config.User == "" {
- return "", nil
- }
- splitSpec := strings.SplitN(c.config.User, ":", 2)
- userspec := splitSpec[0]
- if len(splitSpec) > 1 {
- groupspec = splitSpec[1]
- }
- // If a non numeric User, then don't generate passwd
- uid, err := strconv.ParseUint(userspec, 10, 32)
- if err != nil {
- return "", nil //nolint: nilerr
- }
-
- if addedUID != 0 && int(uid) == addedUID {
- return "", nil
- }
-
- // Look up the user to see if it exists in the container image
- _, err = lookup.GetUser(c.state.Mountpoint, userspec)
- if err != runcuser.ErrNoPasswdEntries {
- return "", err
- }
-
- if groupspec != "" {
- ugid, err := strconv.ParseUint(groupspec, 10, 32)
- if err == nil {
- gid = int(ugid)
- } else {
- group, err := lookup.GetGroup(c.state.Mountpoint, groupspec)
- if err != nil {
- return "", fmt.Errorf("unable to get gid %s from group file: %w", groupspec, err)
- }
- gid = group.Gid
- }
- }
-
- if c.config.PasswdEntry != "" {
- entry := c.passwdEntry(fmt.Sprintf("%d", uid), fmt.Sprintf("%d", uid), fmt.Sprintf("%d", gid), "container user", c.WorkingDir())
- return entry, nil
- }
-
- return fmt.Sprintf("%d:*:%d:%d:container user:%s:/bin/sh\n", uid, uid, gid, c.WorkingDir()), nil
-}
-
-func (c *Container) passwdEntry(username string, uid, gid, name, homeDir string) string {
- s := c.config.PasswdEntry
- s = strings.ReplaceAll(s, "$USERNAME", username)
- s = strings.ReplaceAll(s, "$UID", uid)
- s = strings.ReplaceAll(s, "$GID", gid)
- s = strings.ReplaceAll(s, "$NAME", name)
- s = strings.ReplaceAll(s, "$HOME", homeDir)
- return s + "\n"
-}
-
-// generatePasswdAndGroup generates container-specific passwd and group files
-// iff g.config.User is a number or we are configured to make a passwd entry for
-// the current user or the user specified HostsUsers
-// Returns path to file to mount at /etc/passwd, path to file to mount at
-// /etc/group, and any error that occurred. If no passwd/group file were
-// required, the empty string will be returned for those path (this may occur
-// even if no error happened).
-// This may modify the mounted container's /etc/passwd and /etc/group instead of
-// making copies to bind-mount in, so we don't break useradd (it wants to make a
-// copy of /etc/passwd and rename the copy to /etc/passwd, which is impossible
-// with a bind mount). This is done in cases where the container is *not*
-// read-only. In this case, the function will return nothing ("", "", nil).
-func (c *Container) generatePasswdAndGroup() (string, string, error) {
- if !c.config.AddCurrentUserPasswdEntry && c.config.User == "" &&
- len(c.config.HostUsers) == 0 {
- return "", "", nil
- }
-
- needPasswd := true
- needGroup := true
-
- // First, check if there's a mount at /etc/passwd or group, we don't
- // want to interfere with user mounts.
- if MountExists(c.config.Spec.Mounts, "/etc/passwd") {
- needPasswd = false
- }
- if MountExists(c.config.Spec.Mounts, "/etc/group") {
- needGroup = false
- }
-
- // Next, check if we already made the files. If we didn't, don't need to
- // do anything more.
- if needPasswd {
- passwdPath := filepath.Join(c.config.StaticDir, "passwd")
- if _, err := os.Stat(passwdPath); err == nil {
- needPasswd = false
- }
- }
- if needGroup {
- groupPath := filepath.Join(c.config.StaticDir, "group")
- if _, err := os.Stat(groupPath); err == nil {
- needGroup = false
- }
- }
-
- // If we don't need a /etc/passwd or /etc/group at this point we can
- // just return.
- if !needPasswd && !needGroup {
- return "", "", nil
- }
-
- passwdPath := ""
- groupPath := ""
-
- ro := c.IsReadOnly()
-
- if needPasswd {
- passwdEntry, err := c.generatePasswdEntry()
- if err != nil {
- return "", "", err
- }
-
- needsWrite := passwdEntry != ""
- switch {
- case ro && needsWrite:
- logrus.Debugf("Making /etc/passwd for container %s", c.ID())
- originPasswdFile, err := securejoin.SecureJoin(c.state.Mountpoint, "/etc/passwd")
- if err != nil {
- return "", "", fmt.Errorf("error creating path to container %s /etc/passwd: %w", c.ID(), err)
- }
- orig, err := ioutil.ReadFile(originPasswdFile)
- if err != nil && !os.IsNotExist(err) {
- return "", "", err
- }
- passwdFile, err := c.writeStringToStaticDir("passwd", string(orig)+passwdEntry)
- if err != nil {
- return "", "", fmt.Errorf("failed to create temporary passwd file: %w", err)
- }
- if err := os.Chmod(passwdFile, 0644); err != nil {
- return "", "", err
- }
- passwdPath = passwdFile
- case !ro && needsWrite:
- logrus.Debugf("Modifying container %s /etc/passwd", c.ID())
- containerPasswd, err := securejoin.SecureJoin(c.state.Mountpoint, "/etc/passwd")
- if err != nil {
- return "", "", fmt.Errorf("error looking up location of container %s /etc/passwd: %w", c.ID(), err)
- }
-
- f, err := os.OpenFile(containerPasswd, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
- if err != nil {
- return "", "", fmt.Errorf("container %s: %w", c.ID(), err)
- }
- defer f.Close()
-
- if _, err := f.WriteString(passwdEntry); err != nil {
- return "", "", fmt.Errorf("unable to append to container %s /etc/passwd: %w", c.ID(), err)
- }
- default:
- logrus.Debugf("Not modifying container %s /etc/passwd", c.ID())
- }
- }
- if needGroup {
- groupEntry, err := c.generateGroupEntry()
- if err != nil {
- return "", "", err
- }
-
- needsWrite := groupEntry != ""
- switch {
- case ro && needsWrite:
- logrus.Debugf("Making /etc/group for container %s", c.ID())
- originGroupFile, err := securejoin.SecureJoin(c.state.Mountpoint, "/etc/group")
- if err != nil {
- return "", "", fmt.Errorf("error creating path to container %s /etc/group: %w", c.ID(), err)
- }
- orig, err := ioutil.ReadFile(originGroupFile)
- if err != nil && !os.IsNotExist(err) {
- return "", "", err
- }
- groupFile, err := c.writeStringToStaticDir("group", string(orig)+groupEntry)
- if err != nil {
- return "", "", fmt.Errorf("failed to create temporary group file: %w", err)
- }
- if err := os.Chmod(groupFile, 0644); err != nil {
- return "", "", err
- }
- groupPath = groupFile
- case !ro && needsWrite:
- logrus.Debugf("Modifying container %s /etc/group", c.ID())
- containerGroup, err := securejoin.SecureJoin(c.state.Mountpoint, "/etc/group")
- if err != nil {
- return "", "", fmt.Errorf("error looking up location of container %s /etc/group: %w", c.ID(), err)
- }
-
- f, err := os.OpenFile(containerGroup, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
- if err != nil {
- return "", "", fmt.Errorf("container %s: %w", c.ID(), err)
- }
- defer f.Close()
-
- if _, err := f.WriteString(groupEntry); err != nil {
- return "", "", fmt.Errorf("unable to append to container %s /etc/group: %w", c.ID(), err)
- }
- default:
- logrus.Debugf("Not modifying container %s /etc/group", c.ID())
- }
- }
-
- return passwdPath, groupPath, nil
-}
-
func isRootlessCgroupSet(cgroup string) bool {
// old versions of podman were setting the CgroupParent to CgroupfsDefaultCgroupParent
// by default. Avoid breaking these versions and check whether the cgroup parent is
@@ -3059,198 +390,257 @@ func (c *Container) getOCICgroupPath() (string, error) {
}
}
-func (c *Container) copyTimezoneFile(zonePath string) (string, error) {
- localtimeCopy := filepath.Join(c.state.RunDir, "localtime")
- file, err := os.Stat(zonePath)
- if err != nil {
- return "", err
- }
- if file.IsDir() {
- return "", errors.New("invalid timezone: is a directory")
- }
- src, err := os.Open(zonePath)
- if err != nil {
- return "", err
- }
- defer src.Close()
- dest, err := os.Create(localtimeCopy)
- if err != nil {
- return "", err
- }
- defer dest.Close()
- _, err = io.Copy(dest, src)
- if err != nil {
- return "", err
- }
- if err := c.relabel(localtimeCopy, c.config.MountLabel, false); err != nil {
- return "", err
+// If the container is rootless, set up the slirp4netns network
+func (c *Container) setupRootlessNetwork() error {
+ // set up slirp4netns again because slirp4netns will die when conmon exits
+ if c.config.NetMode.IsSlirp4netns() {
+ err := c.runtime.setupSlirp4netns(c, c.state.NetNS)
+ if err != nil {
+ return err
+ }
}
- if err := dest.Chown(c.RootUID(), c.RootGID()); err != nil {
- return "", err
+
+ // set up rootlesskit port forwarder again since it dies when conmon exits
+ // we use rootlesskit port forwarder only as rootless and when bridge network is used
+ if rootless.IsRootless() && c.config.NetMode.IsBridge() && len(c.config.PortMappings) > 0 {
+ err := c.runtime.setupRootlessPortMappingViaRLK(c, c.state.NetNS.Path(), c.state.NetworkStatus)
+ if err != nil {
+ return err
+ }
}
- return localtimeCopy, err
+ return nil
}
-func (c *Container) cleanupOverlayMounts() error {
- return overlay.CleanupContent(c.config.StaticDir)
+func openDirectory(path string) (fd int, err error) {
+ return unix.Open(path, unix.O_RDONLY|unix.O_PATH, 0)
}
-// Creates and mounts an empty dir to mount secrets into, if it does not already exist
-func (c *Container) createSecretMountDir() error {
- src := filepath.Join(c.state.RunDir, "/run/secrets")
- _, err := os.Stat(src)
- if os.IsNotExist(err) {
- oldUmask := umask.Set(0)
- defer umask.Set(oldUmask)
+func (c *Container) addNetworkNamespace(g *generate.Generator) error {
+ if c.config.CreateNetNS {
+ if c.config.PostConfigureNetNS {
+ if err := g.AddOrReplaceLinuxNamespace(string(spec.NetworkNamespace), ""); err != nil {
+ return err
+ }
+ } else {
+ if err := g.AddOrReplaceLinuxNamespace(string(spec.NetworkNamespace), c.state.NetNS.Path()); err != nil {
+ return err
+ }
+ }
+ }
+ return nil
+}
+
+func (c *Container) addSystemdMounts(g *generate.Generator) error {
+ if c.Systemd() {
+ if err := c.setupSystemd(g.Mounts(), *g); err != nil {
+ return fmt.Errorf("error adding systemd-specific mounts: %w", err)
+ }
+ }
+ return nil
+}
- if err := os.MkdirAll(src, 0755); err != nil {
+func (c *Container) addSharedNamespaces(g *generate.Generator) error {
+ if c.config.IPCNsCtr != "" {
+ if err := c.addNamespaceContainer(g, IPCNS, c.config.IPCNsCtr, spec.IPCNamespace); err != nil {
return err
}
- if err := label.Relabel(src, c.config.MountLabel, false); err != nil {
+ }
+ if c.config.MountNsCtr != "" {
+ if err := c.addNamespaceContainer(g, MountNS, c.config.MountNsCtr, spec.MountNamespace); err != nil {
return err
}
- if err := os.Chown(src, c.RootUID(), c.RootGID()); err != nil {
+ }
+ if c.config.NetNsCtr != "" {
+ if err := c.addNamespaceContainer(g, NetNS, c.config.NetNsCtr, spec.NetworkNamespace); err != nil {
return err
}
- c.state.BindMounts["/run/secrets"] = src
- return nil
+ }
+ if c.config.PIDNsCtr != "" {
+ if err := c.addNamespaceContainer(g, PIDNS, c.config.PIDNsCtr, spec.PIDNamespace); err != nil {
+ return err
+ }
+ }
+ if c.config.UserNsCtr != "" {
+ if err := c.addNamespaceContainer(g, UserNS, c.config.UserNsCtr, spec.UserNamespace); err != nil {
+ return err
+ }
+ if len(g.Config.Linux.UIDMappings) == 0 {
+ // runc complains if no mapping is specified, even if we join another ns. So provide a dummy mapping
+ g.AddLinuxUIDMapping(uint32(0), uint32(0), uint32(1))
+ g.AddLinuxGIDMapping(uint32(0), uint32(0), uint32(1))
+ }
}
- return err
-}
-
-// Fix ownership and permissions of the specified volume if necessary.
-func (c *Container) fixVolumePermissions(v *ContainerNamedVolume) error {
- vol, err := c.runtime.state.Volume(v.Name)
+ availableUIDs, availableGIDs, err := rootless.GetAvailableIDMaps()
if err != nil {
- return fmt.Errorf("error retrieving named volume %s for container %s: %w", v.Name, c.ID(), err)
+ if os.IsNotExist(err) {
+ // The kernel-provided files only exist if user namespaces are supported
+ logrus.Debugf("User or group ID mappings not available: %s", err)
+ } else {
+ return err
+ }
+ } else {
+ g.Config.Linux.UIDMappings = rootless.MaybeSplitMappings(g.Config.Linux.UIDMappings, availableUIDs)
+ g.Config.Linux.GIDMappings = rootless.MaybeSplitMappings(g.Config.Linux.GIDMappings, availableGIDs)
}
- vol.lock.Lock()
- defer vol.lock.Unlock()
+ // Hostname handling:
+ // If we have a UTS namespace, set Hostname in the OCI spec.
+ // Set the HOSTNAME environment variable unless explicitly overridden by
+ // the user (already present in OCI spec). If we don't have a UTS ns,
+ // set it to the host's hostname instead.
+ hostname := c.Hostname()
+ foundUTS := false
- // The volume may need a copy-up. Check the state.
- if err := vol.update(); err != nil {
- return err
+ for _, i := range c.config.Spec.Linux.Namespaces {
+ if i.Type == spec.UTSNamespace && i.Path == "" {
+ foundUTS = true
+ g.SetHostname(hostname)
+ break
+ }
}
-
- // Volumes owned by a volume driver are not chowned - we don't want to
- // mess with a mount not managed by us.
- if vol.state.NeedsChown && !vol.UsesVolumeDriver() {
- vol.state.NeedsChown = false
-
- uid := int(c.config.Spec.Process.User.UID)
- gid := int(c.config.Spec.Process.User.GID)
-
- if c.config.IDMappings.UIDMap != nil {
- p := idtools.IDPair{
- UID: uid,
- GID: gid,
- }
- mappings := idtools.NewIDMappingsFromMaps(c.config.IDMappings.UIDMap, c.config.IDMappings.GIDMap)
- newPair, err := mappings.ToHost(p)
- if err != nil {
- return fmt.Errorf("error mapping user %d:%d: %w", uid, gid, err)
- }
- uid = newPair.UID
- gid = newPair.GID
+ if !foundUTS {
+ tmpHostname, err := os.Hostname()
+ if err != nil {
+ return err
}
+ hostname = tmpHostname
+ }
+ needEnv := true
+ for _, checkEnv := range g.Config.Process.Env {
+ if strings.SplitN(checkEnv, "=", 2)[0] == "HOSTNAME" {
+ needEnv = false
+ break
+ }
+ }
+ if needEnv {
+ g.AddProcessEnv("HOSTNAME", hostname)
+ }
- vol.state.UIDChowned = uid
- vol.state.GIDChowned = gid
-
- if err := vol.save(); err != nil {
+ if c.config.UTSNsCtr != "" {
+ if err := c.addNamespaceContainer(g, UTSNS, c.config.UTSNsCtr, spec.UTSNamespace); err != nil {
return err
}
-
- mountPoint, err := vol.MountPoint()
- if err != nil {
+ }
+ if c.config.CgroupNsCtr != "" {
+ if err := c.addNamespaceContainer(g, CgroupNS, c.config.CgroupNsCtr, spec.CgroupNamespace); err != nil {
return err
}
+ }
- if err := os.Lchown(mountPoint, uid, gid); err != nil {
+ if c.config.UserNsCtr == "" && c.config.IDMappings.AutoUserNs {
+ if err := g.AddOrReplaceLinuxNamespace(string(spec.UserNamespace), ""); err != nil {
return err
}
+ g.ClearLinuxUIDMappings()
+ for _, uidmap := range c.config.IDMappings.UIDMap {
+ g.AddLinuxUIDMapping(uint32(uidmap.HostID), uint32(uidmap.ContainerID), uint32(uidmap.Size))
+ }
+ g.ClearLinuxGIDMappings()
+ for _, gidmap := range c.config.IDMappings.GIDMap {
+ g.AddLinuxGIDMapping(uint32(gidmap.HostID), uint32(gidmap.ContainerID), uint32(gidmap.Size))
+ }
+ }
+ return nil
+}
- // Make sure the new volume matches the permissions of the target directory.
- // https://github.com/containers/podman/issues/10188
- st, err := os.Lstat(filepath.Join(c.state.Mountpoint, v.Dest))
- if err == nil {
- if stat, ok := st.Sys().(*syscall.Stat_t); ok {
- if err := os.Lchown(mountPoint, int(stat.Uid), int(stat.Gid)); err != nil {
- return err
+func (c *Container) addRootPropagation(g *generate.Generator, mounts []spec.Mount) error {
+ // Determine property of RootPropagation based on volume properties. If
+ // a volume is shared, then keep root propagation shared. This should
+ // work for slave and private volumes too.
+ //
+ // For slave volumes, it can be either [r]shared/[r]slave.
+ //
+ // For private volumes any root propagation value should work.
+ rootPropagation := ""
+ for _, m := range mounts {
+ for _, opt := range m.Options {
+ switch opt {
+ case MountShared, MountRShared:
+ if rootPropagation != MountShared && rootPropagation != MountRShared {
+ rootPropagation = MountShared
+ }
+ case MountSlave, MountRSlave:
+ if rootPropagation != MountShared && rootPropagation != MountRShared && rootPropagation != MountSlave && rootPropagation != MountRSlave {
+ rootPropagation = MountRSlave
}
}
- if err := os.Chmod(mountPoint, st.Mode()); err != nil {
- return err
- }
- stat := st.Sys().(*syscall.Stat_t)
- atime := time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) //nolint: unconvert
- if err := os.Chtimes(mountPoint, atime, st.ModTime()); err != nil {
- return err
- }
- } else if !os.IsNotExist(err) {
+ }
+ }
+ if rootPropagation != "" {
+ logrus.Debugf("Set root propagation to %q", rootPropagation)
+ if err := g.SetLinuxRootPropagation(rootPropagation); err != nil {
return err
}
}
return nil
}
-func (c *Container) relabel(src, mountLabel string, recurse bool) error {
- if !selinux.GetEnabled() || mountLabel == "" {
- return nil
- }
- // only relabel on initial creation of container
- if !c.ensureState(define.ContainerStateConfigured, define.ContainerStateUnknown) {
- label, err := label.FileLabel(src)
- if err != nil {
- return err
- }
- // If labels are different, might be on a tmpfs
- if label == mountLabel {
- return nil
- }
+func (c *Container) setProcessLabel(g *generate.Generator) {
+ g.SetProcessSelinuxLabel(c.ProcessLabel())
+}
+
+func (c *Container) setMountLabel(g *generate.Generator) {
+ g.SetLinuxMountLabel(c.MountLabel())
+}
+
+func (c *Container) setCgroupsPath(g *generate.Generator) error {
+ cgroupPath, err := c.getOCICgroupPath()
+ if err != nil {
+ return err
}
- return label.Relabel(src, mountLabel, recurse)
+ g.SetLinuxCgroupsPath(cgroupPath)
+ return nil
}
-func (c *Container) ChangeHostPathOwnership(src string, recurse bool, uid, gid int) error {
- // only chown on initial creation of container
- if !c.ensureState(define.ContainerStateConfigured, define.ContainerStateUnknown) {
- st, err := os.Stat(src)
+func (c *Container) addSlirp4netnsDNS(nameservers []string) []string {
+ // slirp4netns has a built in DNS forwarder.
+ if c.config.NetMode.IsSlirp4netns() {
+ slirp4netnsDNS, err := GetSlirp4netnsDNS(c.slirp4netnsSubnet)
if err != nil {
- return err
- }
-
- // If labels are different, might be on a tmpfs
- if int(st.Sys().(*syscall.Stat_t).Uid) == uid && int(st.Sys().(*syscall.Stat_t).Gid) == gid {
- return nil
+ logrus.Warn("Failed to determine Slirp4netns DNS: ", err.Error())
+ } else {
+ nameservers = append(nameservers, slirp4netnsDNS.String())
}
}
- return chown.ChangeHostPathOwnership(src, recurse, uid, gid)
+ return nameservers
}
-// If the container is rootless, set up the slirp4netns network
-func (c *Container) setupRootlessNetwork() error {
- // set up slirp4netns again because slirp4netns will die when conmon exits
+func (c *Container) isSlirp4netnsIPv6() (bool, error) {
if c.config.NetMode.IsSlirp4netns() {
- err := c.runtime.setupSlirp4netns(c, c.state.NetNS)
+ ctrNetworkSlipOpts := []string{}
+ if c.config.NetworkOptions != nil {
+ ctrNetworkSlipOpts = append(ctrNetworkSlipOpts, c.config.NetworkOptions["slirp4netns"]...)
+ }
+ slirpOpts, err := parseSlirp4netnsNetworkOptions(c.runtime, ctrNetworkSlipOpts)
if err != nil {
- return err
+ return false, err
}
+ return slirpOpts.enableIPv6, nil
}
- // set up rootlesskit port forwarder again since it dies when conmon exits
- // we use rootlesskit port forwarder only as rootless and when bridge network is used
- if rootless.IsRootless() && c.config.NetMode.IsBridge() && len(c.config.PortMappings) > 0 {
- err := c.runtime.setupRootlessPortMappingViaRLK(c, c.state.NetNS.Path(), c.state.NetworkStatus)
- if err != nil {
- return err
+ return false, nil
+}
+
+// check for net=none
+func (c *Container) hasNetNone() bool {
+ if !c.config.CreateNetNS {
+ for _, ns := range c.config.Spec.Linux.Namespaces {
+ if ns.Type == spec.NetworkNamespace {
+ if ns.Path == "" {
+ return true
+ }
+ }
}
}
- return nil
+ return false
}
-func openDirectory(path string) (fd int, err error) {
- return unix.Open(path, unix.O_RDONLY|unix.O_PATH, 0)
+func setVolumeAtime(mountPoint string, st os.FileInfo) error {
+ stat := st.Sys().(*syscall.Stat_t)
+ atime := time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)) //nolint: unconvert
+ if err := os.Chtimes(mountPoint, atime, st.ModTime()); err != nil {
+ return err
+ }
+ return nil
}
diff --git a/libpod/container_internal_unsupported.go b/libpod/container_internal_unsupported.go
index 074aeee47..1967c577b 100644
--- a/libpod/container_internal_unsupported.go
+++ b/libpod/container_internal_unsupported.go
@@ -1,5 +1,5 @@
-//go:build !linux
-// +build !linux
+//go:build !linux && !freebsd
+// +build !linux,!freebsd
package libpod
diff --git a/libpod/container_linux.go b/libpod/container_linux.go
index 8b517e69f..9c17a1966 100644
--- a/libpod/container_linux.go
+++ b/libpod/container_linux.go
@@ -5,6 +5,7 @@ package libpod
import (
"github.com/containernetworking/plugins/pkg/ns"
+ spec "github.com/opencontainers/runtime-spec/specs-go"
)
type containerPlatformState struct {
@@ -13,3 +14,17 @@ type containerPlatformState struct {
// told to join another container's network namespace
NetNS ns.NetNS `json:"-"`
}
+
+func networkDisabled(c *Container) (bool, error) {
+ if c.config.CreateNetNS {
+ return false, nil
+ }
+ if !c.config.PostConfigureNetNS {
+ for _, ns := range c.config.Spec.Linux.Namespaces {
+ if ns.Type == spec.NetworkNamespace {
+ return ns.Path == "", nil
+ }
+ }
+ }
+ return false, nil
+}
diff --git a/libpod/networking_unsupported.go b/libpod/networking_unsupported.go
index 76ffabb5e..9429287f9 100644
--- a/libpod/networking_unsupported.go
+++ b/libpod/networking_unsupported.go
@@ -5,6 +5,7 @@ package libpod
import (
"errors"
+ "net"
"path/filepath"
"github.com/containers/common/libnetwork/types"
@@ -84,3 +85,7 @@ func (r *Runtime) GetRootlessNetNs(new bool) (*RootlessNetNS, error) {
func (c *Container) convertPortMappings() []types.PortMapping {
return []types.PortMapping{}
}
+
+func GetSlirp4netnsIP(subnet *net.IPNet) (*net.IP, error) {
+ return nil, errors.New("not implemented GetSlirp4netnsIP")
+}
diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go
index b43114fab..1e1b7dad5 100644
--- a/libpod/runtime_ctr.go
+++ b/libpod/runtime_ctr.go
@@ -171,12 +171,17 @@ func (r *Runtime) initContainerVariables(rSpec *spec.Spec, config *ContainerConf
if config == nil {
ctr.config.ID = stringid.GenerateNonCryptoID()
size, err := units.FromHumanSize(r.config.Containers.ShmSize)
- if err != nil {
- return nil, fmt.Errorf("converting containers.conf ShmSize %s to an int: %w", r.config.Containers.ShmSize, err)
+ if useDevShm {
+ if err != nil {
+ return nil, fmt.Errorf("converting containers.conf ShmSize %s to an int: %w", r.config.Containers.ShmSize, err)
+ }
+ ctr.config.ShmSize = size
+ ctr.config.NoShm = false
+ ctr.config.NoShmShare = false
+ } else {
+ ctr.config.NoShm = true
+ ctr.config.NoShmShare = true
}
- ctr.config.ShmSize = size
- ctr.config.NoShm = false
- ctr.config.NoShmShare = false
ctr.config.StopSignal = 15
ctr.config.StopTimeout = r.config.Engine.StopTimeout
@@ -528,7 +533,7 @@ func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (_ *Contai
}
}
- if !MountExists(ctr.config.Spec.Mounts, "/dev/shm") && ctr.config.ShmDir == "" && !ctr.config.NoShm {
+ if useDevShm && !MountExists(ctr.config.Spec.Mounts, "/dev/shm") && ctr.config.ShmDir == "" && !ctr.config.NoShm {
ctr.config.ShmDir = filepath.Join(ctr.bundlePath(), "shm")
if err := os.MkdirAll(ctr.config.ShmDir, 0700); err != nil {
if !os.IsExist(err) {
diff --git a/libpod/runtime_ctr_freebsd.go b/libpod/runtime_ctr_freebsd.go
new file mode 100644
index 000000000..a8870a38c
--- /dev/null
+++ b/libpod/runtime_ctr_freebsd.go
@@ -0,0 +1,5 @@
+package libpod
+
+const (
+ useDevShm = false
+)
diff --git a/libpod/runtime_ctr_linux.go b/libpod/runtime_ctr_linux.go
new file mode 100644
index 000000000..7812d8238
--- /dev/null
+++ b/libpod/runtime_ctr_linux.go
@@ -0,0 +1,5 @@
+package libpod
+
+const (
+ useDevShm = true
+)
diff --git a/pkg/api/handlers/libpod/generate.go b/pkg/api/handlers/libpod/generate.go
index 48c4c59e1..431927ac5 100644
--- a/pkg/api/handlers/libpod/generate.go
+++ b/pkg/api/handlers/libpod/generate.go
@@ -17,20 +17,21 @@ func GenerateSystemd(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder)
query := struct {
- Name bool `schema:"useName"`
- New bool `schema:"new"`
- NoHeader bool `schema:"noHeader"`
- TemplateUnitFile bool `schema:"templateUnitFile"`
- RestartPolicy *string `schema:"restartPolicy"`
- RestartSec uint `schema:"restartSec"`
- StopTimeout uint `schema:"stopTimeout"`
- StartTimeout uint `schema:"startTimeout"`
- ContainerPrefix *string `schema:"containerPrefix"`
- PodPrefix *string `schema:"podPrefix"`
- Separator *string `schema:"separator"`
- Wants []string `schema:"wants"`
- After []string `schema:"after"`
- Requires []string `schema:"requires"`
+ Name bool `schema:"useName"`
+ New bool `schema:"new"`
+ NoHeader bool `schema:"noHeader"`
+ TemplateUnitFile bool `schema:"templateUnitFile"`
+ RestartPolicy *string `schema:"restartPolicy"`
+ RestartSec uint `schema:"restartSec"`
+ StopTimeout uint `schema:"stopTimeout"`
+ StartTimeout uint `schema:"startTimeout"`
+ ContainerPrefix *string `schema:"containerPrefix"`
+ PodPrefix *string `schema:"podPrefix"`
+ Separator *string `schema:"separator"`
+ Wants []string `schema:"wants"`
+ After []string `schema:"after"`
+ Requires []string `schema:"requires"`
+ AdditionalEnvVariables []string `schema:"additionalEnvVariables"`
}{
StartTimeout: 0,
StopTimeout: util.DefaultContainerConfig().Engine.StopTimeout,
@@ -58,20 +59,21 @@ func GenerateSystemd(w http.ResponseWriter, r *http.Request) {
containerEngine := abi.ContainerEngine{Libpod: runtime}
options := entities.GenerateSystemdOptions{
- Name: query.Name,
- New: query.New,
- NoHeader: query.NoHeader,
- TemplateUnitFile: query.TemplateUnitFile,
- RestartPolicy: query.RestartPolicy,
- StartTimeout: &query.StartTimeout,
- StopTimeout: &query.StopTimeout,
- ContainerPrefix: ContainerPrefix,
- PodPrefix: PodPrefix,
- Separator: Separator,
- RestartSec: &query.RestartSec,
- Wants: query.Wants,
- After: query.After,
- Requires: query.Requires,
+ Name: query.Name,
+ New: query.New,
+ NoHeader: query.NoHeader,
+ TemplateUnitFile: query.TemplateUnitFile,
+ RestartPolicy: query.RestartPolicy,
+ StartTimeout: &query.StartTimeout,
+ StopTimeout: &query.StopTimeout,
+ ContainerPrefix: ContainerPrefix,
+ PodPrefix: PodPrefix,
+ Separator: Separator,
+ RestartSec: &query.RestartSec,
+ Wants: query.Wants,
+ After: query.After,
+ Requires: query.Requires,
+ AdditionalEnvVariables: query.AdditionalEnvVariables,
}
report, err := containerEngine.GenerateSystemd(r.Context(), utils.GetName(r), options)
diff --git a/pkg/api/server/register_generate.go b/pkg/api/server/register_generate.go
index 82fbe3d09..ac2818db0 100644
--- a/pkg/api/server/register_generate.go
+++ b/pkg/api/server/register_generate.go
@@ -93,6 +93,13 @@ func (s *APIServer) registerGenerateHandlers(r *mux.Router) error {
// type: string
// default: []
// description: Systemd Requires list for the container or pods.
+ // - in: query
+ // name: additionalEnvVariables
+ // type: array
+ // items:
+ // type: string
+ // default: []
+ // description: Set environment variables to the systemd unit files.
// produces:
// - application/json
// responses:
diff --git a/pkg/bindings/generate/types.go b/pkg/bindings/generate/types.go
index 25c398c8b..31b43897c 100644
--- a/pkg/bindings/generate/types.go
+++ b/pkg/bindings/generate/types.go
@@ -38,4 +38,6 @@ type SystemdOptions struct {
After *[]string
// Requires - systemd requires list for the container or pods
Requires *[]string
+ // AdditionalEnvVariables - Sets environment variables to a systemd unit file
+ AdditionalEnvVariables *[]string
}
diff --git a/pkg/bindings/generate/types_systemd_options.go b/pkg/bindings/generate/types_systemd_options.go
index 4d436945b..3aec33a54 100644
--- a/pkg/bindings/generate/types_systemd_options.go
+++ b/pkg/bindings/generate/types_systemd_options.go
@@ -226,3 +226,18 @@ func (o *SystemdOptions) GetRequires() []string {
}
return *o.Requires
}
+
+// WithAdditionalEnvVariables set field AdditionalEnvVariables to given value
+func (o *SystemdOptions) WithAdditionalEnvVariables(value []string) *SystemdOptions {
+ o.AdditionalEnvVariables = &value
+ return o
+}
+
+// GetAdditionalEnvVariables returns value of field AdditionalEnvVariables
+func (o *SystemdOptions) GetAdditionalEnvVariables() []string {
+ if o.AdditionalEnvVariables == nil {
+ var z []string
+ return z
+ }
+ return *o.AdditionalEnvVariables
+}
diff --git a/pkg/domain/entities/generate.go b/pkg/domain/entities/generate.go
index f18e79b47..314996497 100644
--- a/pkg/domain/entities/generate.go
+++ b/pkg/domain/entities/generate.go
@@ -4,34 +4,21 @@ import "io"
// GenerateSystemdOptions control the generation of systemd unit files.
type GenerateSystemdOptions struct {
- // Name - use container/pod name instead of its ID.
- Name bool
- // New - create a new container instead of starting a new one.
- New bool
- // RestartPolicy - systemd restart policy.
- RestartPolicy *string
- // RestartSec - systemd service restartsec. Configures the time to sleep before restarting a service.
- RestartSec *uint
- // StartTimeout - time when starting the container.
- StartTimeout *uint
- // StopTimeout - time when stopping the container.
- StopTimeout *uint
- // ContainerPrefix - systemd unit name prefix for containers
- ContainerPrefix string
- // PodPrefix - systemd unit name prefix for pods
- PodPrefix string
- // Separator - systemd unit name separator between name/id and prefix
- Separator string
- // NoHeader - skip header generation
- NoHeader bool
- // TemplateUnitFile - make use of %i and %I to differentiate between the different instances of the unit
- TemplateUnitFile bool
- // Wants - systemd wants list for the container or pods
- Wants []string
- // After - systemd after list for the container or pods
- After []string
- // Requires - systemd requires list for the container or pods
- Requires []string
+ Name bool
+ New bool
+ RestartPolicy *string
+ RestartSec *uint
+ StartTimeout *uint
+ StopTimeout *uint
+ ContainerPrefix string
+ PodPrefix string
+ Separator string
+ NoHeader bool
+ TemplateUnitFile bool
+ Wants []string
+ After []string
+ Requires []string
+ AdditionalEnvVariables []string
}
// GenerateSystemdReport
diff --git a/pkg/domain/infra/tunnel/generate.go b/pkg/domain/infra/tunnel/generate.go
index ed63d363a..d3c3638cb 100644
--- a/pkg/domain/infra/tunnel/generate.go
+++ b/pkg/domain/infra/tunnel/generate.go
@@ -19,7 +19,8 @@ func (ic *ContainerEngine) GenerateSystemd(ctx context.Context, nameOrID string,
WithSeparator(opts.Separator).
WithWants(opts.Wants).
WithAfter(opts.After).
- WithRequires(opts.Requires)
+ WithRequires(opts.Requires).
+ WithAdditionalEnvVariables(opts.AdditionalEnvVariables)
if opts.StartTimeout != nil {
options.WithStartTimeout(*opts.StartTimeout)
diff --git a/pkg/machine/wsl/machine.go b/pkg/machine/wsl/machine.go
index b89e2f720..81f1d187f 100644
--- a/pkg/machine/wsl/machine.go
+++ b/pkg/machine/wsl/machine.go
@@ -44,7 +44,6 @@ const containersConf = `[containers]
[engine]
cgroup_manager = "cgroupfs"
-events_logger = "file"
`
const appendPort = `grep -q Port\ %d /etc/ssh/sshd_config || echo Port %d >> /etc/ssh/sshd_config`
diff --git a/pkg/systemd/generate/containers.go b/pkg/systemd/generate/containers.go
index 1f8c519b7..6f546b0ab 100644
--- a/pkg/systemd/generate/containers.go
+++ b/pkg/systemd/generate/containers.go
@@ -22,85 +22,40 @@ import (
// containerInfo contains data required for generating a container's systemd
// unit file.
type containerInfo struct {
- // ServiceName of the systemd service.
- ServiceName string
- // Name or ID of the container.
- ContainerNameOrID string
- // Type of the unit.
- Type string
- // NotifyAccess of the unit.
- NotifyAccess string
- // StopTimeout sets the timeout Podman waits before killing the container
- // during service stop.
- StopTimeout uint
- // RestartPolicy of the systemd unit (e.g., no, on-failure, always).
- RestartPolicy string
- // Custom number of restart attempts.
- StartLimitBurst string
- // PIDFile of the service. Required for forking services. Must point to the
- // PID of the associated conmon process.
- PIDFile string
- // ContainerIDFile to be used in the unit.
- ContainerIDFile string
- // GenerateTimestamp, if set the generated unit file has a time stamp.
- GenerateTimestamp bool
- // BoundToServices are the services this service binds to. Note that this
- // service runs after them.
- BoundToServices []string
- // PodmanVersion for the header. Will be set internally. Will be auto-filled
- // if left empty.
- PodmanVersion string
- // Executable is the path to the podman executable. Will be auto-filled if
- // left empty.
- Executable string
- // RootFlags contains the root flags which were used to create the container
- // Only used with --new
- RootFlags string
- // TimeStamp at the time of creating the unit file. Will be set internally.
- TimeStamp string
- // CreateCommand is the full command plus arguments of the process the
- // container has been created with.
- CreateCommand []string
- // containerEnv stores the container environment variables
- containerEnv []string
- // ExtraEnvs contains the container environment variables referenced
- // by only the key in the container create command, e.g. --env FOO.
- // This is only used with --new
- ExtraEnvs []string
- // EnvVariable is generate.EnvVariable and must not be set.
- EnvVariable string
- // ExecStartPre of the unit.
- ExecStartPre string
- // ExecStart of the unit.
- ExecStart string
- // TimeoutStartSec of the unit.
- TimeoutStartSec uint
- // TimeoutStopSec of the unit.
- TimeoutStopSec uint
- // ExecStop of the unit.
- ExecStop string
- // ExecStopPost of the unit.
- ExecStopPost string
- // Removes autogenerated by Podman and timestamp if set to true
- GenerateNoHeader bool
- // If not nil, the container is part of the pod. We can use the
- // podInfo to extract the relevant data.
- Pod *podInfo
- // Location of the GraphRoot for the container. Required for ensuring the
- // volume has finished mounting when coming online at boot.
- GraphRoot string
- // Location of the RunRoot for the container. Required for ensuring the tmpfs
- // or volume exists and is mounted when coming online at boot.
- RunRoot string
- // Add %i and %I to description and execute parts
- IdentifySpecifier bool
- // Wants are the list of services that this service is (weak) dependent on. This
- // option does not influence the order in which services are started or stopped.
- Wants []string
- // After ordering dependencies between the list of services and this service.
- After []string
- // Similar to Wants, but declares a stronger requirement dependency.
- Requires []string
+ ServiceName string
+ ContainerNameOrID string
+ Type string
+ NotifyAccess string
+ StopTimeout uint
+ RestartPolicy string
+ StartLimitBurst string
+ PIDFile string
+ ContainerIDFile string
+ GenerateTimestamp bool
+ BoundToServices []string
+ PodmanVersion string
+ Executable string
+ RootFlags string
+ TimeStamp string
+ CreateCommand []string
+ containerEnv []string
+ ExtraEnvs []string
+ EnvVariable string
+ AdditionalEnvVariables []string
+ ExecStartPre string
+ ExecStart string
+ TimeoutStartSec uint
+ TimeoutStopSec uint
+ ExecStop string
+ ExecStopPost string
+ GenerateNoHeader bool
+ Pod *podInfo
+ GraphRoot string
+ RunRoot string
+ IdentifySpecifier bool
+ Wants []string
+ After []string
+ Requires []string
}
const containerTemplate = headerTemplate + `
@@ -127,6 +82,10 @@ Environment={{{{.EnvVariable}}}}=%n{{{{- if (eq .IdentifySpecifier true) }}}}-%i
{{{{- if .ExtraEnvs}}}}
Environment={{{{- range $index, $value := .ExtraEnvs -}}}}{{{{if $index}}}} {{{{end}}}}{{{{ $value }}}}{{{{end}}}}
{{{{- end}}}}
+{{{{- if .AdditionalEnvVariables}}}}
+{{{{- range $index, $value := .AdditionalEnvVariables -}}}}{{{{if $index}}}}{{{{end}}}}
+Environment={{{{ $value }}}}{{{{end}}}}
+{{{{- end}}}}
Restart={{{{.RestartPolicy}}}}
{{{{- if .StartLimitBurst}}}}
StartLimitBurst={{{{.StartLimitBurst}}}}
@@ -211,19 +170,20 @@ func generateContainerInfo(ctr *libpod.Container, options entities.GenerateSyste
envs := config.Spec.Process.Env
info := containerInfo{
- ServiceName: serviceName,
- ContainerNameOrID: nameOrID,
- RestartPolicy: define.DefaultRestartPolicy,
- PIDFile: conmonPidFile,
- TimeoutStartSec: startTimeout,
- StopTimeout: stopTimeout,
- GenerateTimestamp: true,
- CreateCommand: createCommand,
- RunRoot: runRoot,
- containerEnv: envs,
- Wants: options.Wants,
- After: options.After,
- Requires: options.Requires,
+ ServiceName: serviceName,
+ ContainerNameOrID: nameOrID,
+ RestartPolicy: define.DefaultRestartPolicy,
+ PIDFile: conmonPidFile,
+ TimeoutStartSec: startTimeout,
+ StopTimeout: stopTimeout,
+ GenerateTimestamp: true,
+ CreateCommand: createCommand,
+ RunRoot: runRoot,
+ containerEnv: envs,
+ Wants: options.Wants,
+ After: options.After,
+ Requires: options.Requires,
+ AdditionalEnvVariables: options.AdditionalEnvVariables,
}
return &info, nil
@@ -324,6 +284,9 @@ func executeContainerTemplate(info *containerInfo, options entities.GenerateSyst
info.ExecStart = "{{{{.Executable}}}} start {{{{.ContainerNameOrID}}}}"
info.ExecStop = "{{{{.Executable}}}} stop {{{{if (ge .StopTimeout 0)}}}}-t {{{{.StopTimeout}}}}{{{{end}}}} {{{{.ContainerNameOrID}}}}"
info.ExecStopPost = "{{{{.Executable}}}} stop {{{{if (ge .StopTimeout 0)}}}}-t {{{{.StopTimeout}}}}{{{{end}}}} {{{{.ContainerNameOrID}}}}"
+ for i, env := range info.AdditionalEnvVariables {
+ info.AdditionalEnvVariables[i] = escapeSystemdArg(env)
+ }
// Assemble the ExecStart command when creating a new container.
//
diff --git a/pkg/systemd/generate/containers_test.go b/pkg/systemd/generate/containers_test.go
index 873cbfbb3..7f92e75b8 100644
--- a/pkg/systemd/generate/containers_test.go
+++ b/pkg/systemd/generate/containers_test.go
@@ -784,6 +784,33 @@ NotifyAccess=all
WantedBy=default.target
`
+ goodEnvironment := `# container-foobar.service
+# autogenerated by Podman CI
+
+[Unit]
+Description=Podman container-foobar.service
+Documentation=man:podman-generate-systemd(1)
+Wants=network-online.target
+After=network-online.target
+RequiresMountsFor=/var/run/containers/storage
+
+[Service]
+Environment=PODMAN_SYSTEMD_UNIT=%n
+Environment=FOO=abc
+Environment="BAR=my test"
+Environment=USER=%%a
+Restart=on-failure
+TimeoutStopSec=70
+ExecStart=/usr/bin/podman start foobar
+ExecStop=/usr/bin/podman stop -t 10 foobar
+ExecStopPost=/usr/bin/podman stop -t 10 foobar
+PIDFile=/run/containers/storage/overlay-containers/639c53578af4d84b8800b4635fa4e680ee80fd67e0e6a2d4eea48d1e3230f401/userdata/conmon.pid
+Type=forking
+
+[Install]
+WantedBy=default.target
+`
+
goodNewWithRestartPolicy := `# jadda-jadda.service
# autogenerated by Podman CI
@@ -1424,7 +1451,7 @@ WantedBy=default.target
false,
false,
},
- {"good with environment variables",
+ {"good with container environment variables",
containerInfo{
Executable: "/usr/bin/podman",
ServiceName: "jadda-jadda",
@@ -1444,6 +1471,25 @@ WantedBy=default.target
false,
false,
},
+ {"good with systemd environment variables",
+ containerInfo{
+ Executable: "/usr/bin/podman",
+ ServiceName: "container-foobar",
+ ContainerNameOrID: "foobar",
+ PIDFile: "/run/containers/storage/overlay-containers/639c53578af4d84b8800b4635fa4e680ee80fd67e0e6a2d4eea48d1e3230f401/userdata/conmon.pid",
+ StopTimeout: 10,
+ PodmanVersion: "CI",
+ GraphRoot: "/var/lib/containers/storage",
+ RunRoot: "/var/run/containers/storage",
+ EnvVariable: define.EnvVariable,
+ AdditionalEnvVariables: []string{"FOO=abc", "BAR=my test", "USER=%a"},
+ },
+ goodEnvironment,
+ false,
+ false,
+ false,
+ false,
+ },
{"good with restart policy",
containerInfo{
Executable: "/usr/bin/podman",
diff --git a/pkg/util/utils_freebsd.go b/pkg/util/utils_freebsd.go
index 17436ae81..9b0d7c8c7 100644
--- a/pkg/util/utils_freebsd.go
+++ b/pkg/util/utils_freebsd.go
@@ -5,8 +5,14 @@ package util
import (
"errors"
+
+ "github.com/opencontainers/runtime-tools/generate"
)
func GetContainerPidInformationDescriptors() ([]string, error) {
return []string{}, errors.New("this function is not supported on freebsd")
}
+
+func AddPrivilegedDevices(g *generate.Generator) error {
+ return nil
+}
diff --git a/test/e2e/events_test.go b/test/e2e/events_test.go
index 528fa143d..d54265558 100644
--- a/test/e2e/events_test.go
+++ b/test/e2e/events_test.go
@@ -42,10 +42,7 @@ var _ = Describe("Podman events", func() {
// Perhaps a future version of this test would put events in a go func and send output back over a channel
// while events occur.
- // These tests are only known to work on Fedora ATM. Other distributions
- // will be skipped.
It("podman events", func() {
- SkipIfNotFedora()
_, ec, _ := podmanTest.RunLsContainer("")
Expect(ec).To(Equal(0))
result := podmanTest.Podman([]string{"events", "--stream=false"})
@@ -54,7 +51,6 @@ var _ = Describe("Podman events", func() {
})
It("podman events with an event filter", func() {
- SkipIfNotFedora()
_, ec, _ := podmanTest.RunLsContainer("")
Expect(ec).To(Equal(0))
result := podmanTest.Podman([]string{"events", "--stream=false", "--filter", "event=start"})
@@ -81,7 +77,6 @@ var _ = Describe("Podman events", func() {
})
It("podman events with a type and filter container=id", func() {
- SkipIfNotFedora()
_, ec, cid := podmanTest.RunLsContainer("")
Expect(ec).To(Equal(0))
result := podmanTest.Podman([]string{"events", "--stream=false", "--filter", "type=pod", "--filter", fmt.Sprintf("container=%s", cid)})
@@ -91,7 +86,6 @@ var _ = Describe("Podman events", func() {
})
It("podman events with a type", func() {
- SkipIfNotFedora()
setup := podmanTest.Podman([]string{"run", "-dt", "--pod", "new:foobarpod", ALPINE, "top"})
setup.WaitWithDefaultTimeout()
stop := podmanTest.Podman([]string{"pod", "stop", "foobarpod"})
@@ -110,7 +104,6 @@ var _ = Describe("Podman events", func() {
})
It("podman events --since", func() {
- SkipIfNotFedora()
_, ec, _ := podmanTest.RunLsContainer("")
Expect(ec).To(Equal(0))
result := podmanTest.Podman([]string{"events", "--stream=false", "--since", "1m"})
@@ -119,7 +112,6 @@ var _ = Describe("Podman events", func() {
})
It("podman events --until", func() {
- SkipIfNotFedora()
_, ec, _ := podmanTest.RunLsContainer("")
Expect(ec).To(Equal(0))
result := podmanTest.Podman([]string{"events", "--stream=false", "--until", "1h"})
@@ -128,7 +120,6 @@ var _ = Describe("Podman events", func() {
})
It("podman events format", func() {
- SkipIfNotFedora()
_, ec, _ := podmanTest.RunLsContainer("")
Expect(ec).To(Equal(0))
@@ -153,6 +144,13 @@ var _ = Describe("Podman events", func() {
event = events.Event{}
err = json.Unmarshal([]byte(jsonArr[0]), &event)
Expect(err).ToNot(HaveOccurred())
+
+ test = podmanTest.Podman([]string{"events", "--stream=false", "--filter=type=container", "--format", "ID: {{.ID}}"})
+ test.WaitWithDefaultTimeout()
+ Expect(test).To(Exit(0))
+ arr := test.OutputToStringArray()
+ Expect(len(arr)).To(BeNumerically(">", 1))
+ Expect(arr[0]).To(MatchRegexp("ID: [a-fA-F0-9]{64}"))
})
It("podman events --until future", func() {
diff --git a/test/e2e/generate_systemd_test.go b/test/e2e/generate_systemd_test.go
index 45a2f1f86..f47abbc13 100644
--- a/test/e2e/generate_systemd_test.go
+++ b/test/e2e/generate_systemd_test.go
@@ -600,4 +600,75 @@ var _ = Describe("Podman generate systemd", func() {
Expect(session).Should(Exit(0))
Expect(session.OutputToString()).To(ContainSubstring(" --label key={{someval}}"))
})
+
+ It("podman generate systemd --env", func() {
+ session := podmanTest.RunTopContainer("test")
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(0))
+
+ session = podmanTest.Podman([]string{"generate", "systemd", "--env", "foo=bar", "-e", "hoge=fuga", "test"})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(0))
+ Expect(session.OutputToString()).To(ContainSubstring("Environment=foo=bar"))
+ Expect(session.OutputToString()).To(ContainSubstring("Environment=hoge=fuga"))
+
+ session = podmanTest.Podman([]string{"generate", "systemd", "--env", "=bar", "-e", "hoge=fuga", "test"})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(125))
+ Expect(session.ErrorToString()).To(ContainSubstring("invalid environment variable"))
+
+ // Use -e/--env option with --new option
+ session = podmanTest.Podman([]string{"generate", "systemd", "--env", "foo=bar", "-e", "hoge=fuga", "--new", "test"})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(0))
+ Expect(session.OutputToString()).To(ContainSubstring("Environment=foo=bar"))
+ Expect(session.OutputToString()).To(ContainSubstring("Environment=hoge=fuga"))
+
+ session = podmanTest.Podman([]string{"generate", "systemd", "--env", "foo=bar", "-e", "=fuga", "--new", "test"})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(125))
+ Expect(session.ErrorToString()).To(ContainSubstring("invalid environment variable"))
+
+ // Escape systemd arguments
+ session = podmanTest.Podman([]string{"generate", "systemd", "--env", "BAR=my test", "-e", "USER=%a", "test"})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(0))
+ Expect(session.OutputToString()).To(ContainSubstring("\"BAR=my test\""))
+ Expect(session.OutputToString()).To(ContainSubstring("USER=%%a"))
+
+ session = podmanTest.Podman([]string{"generate", "systemd", "--env", "BAR=my test", "-e", "USER=%a", "--new", "test"})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(0))
+ Expect(session.OutputToString()).To(ContainSubstring("\"BAR=my test\""))
+ Expect(session.OutputToString()).To(ContainSubstring("USER=%%a"))
+
+ // Specify the environment variables without a value
+ os.Setenv("FOO1", "BAR1")
+ os.Setenv("FOO2", "BAR2")
+ os.Setenv("FOO3", "BAR3")
+ defer os.Unsetenv("FOO1")
+ defer os.Unsetenv("FOO2")
+ defer os.Unsetenv("FOO3")
+
+ session = podmanTest.Podman([]string{"generate", "systemd", "--env", "FOO1", "test"})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(0))
+ Expect(session.OutputToString()).To(ContainSubstring("BAR1"))
+ Expect(session.OutputToString()).NotTo(ContainSubstring("BAR2"))
+ Expect(session.OutputToString()).NotTo(ContainSubstring("BAR3"))
+
+ session = podmanTest.Podman([]string{"generate", "systemd", "--env", "FOO*", "test"})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(0))
+ Expect(session.OutputToString()).To(ContainSubstring("BAR1"))
+ Expect(session.OutputToString()).To(ContainSubstring("BAR2"))
+ Expect(session.OutputToString()).To(ContainSubstring("BAR3"))
+
+ session = podmanTest.Podman([]string{"generate", "systemd", "--env", "FOO*", "--new", "test"})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(0))
+ Expect(session.OutputToString()).To(ContainSubstring("BAR1"))
+ Expect(session.OutputToString()).To(ContainSubstring("BAR2"))
+ Expect(session.OutputToString()).To(ContainSubstring("BAR3"))
+ })
})
diff --git a/test/system/255-auto-update.bats b/test/system/255-auto-update.bats
index 1f350e87f..a106914fe 100644
--- a/test/system/255-auto-update.bats
+++ b/test/system/255-auto-update.bats
@@ -373,6 +373,12 @@ After=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/bin/podman auto-update
+Environment="http_proxy=${http_proxy}"
+Environment="HTTP_PROXY=${HTTP_PROXY}"
+Environment="https_proxy=${https_proxy}"
+Environment="HTTPS_PROXY=${HTTPS_PROXY}"
+Environment="no_proxy=${no_proxy}"
+Environment="NO_PROXY=${NO_PROXY}"
[Install]
WantedBy=default.target
diff --git a/test/system/500-networking.bats b/test/system/500-networking.bats
index 5da7523f3..862bc285c 100644
--- a/test/system/500-networking.bats
+++ b/test/system/500-networking.bats
@@ -61,9 +61,9 @@ load helpers
is "$output" "$random_2" "curl 127.0.0.1:/index2.txt"
# Verify http contents: wget from a second container
- run_podman run --rm --net=host $IMAGE wget -qO - $SERVER/index.txt
+ run_podman run --rm --net=host --http-proxy=false $IMAGE wget -qO - $SERVER/index.txt
is "$output" "$random_1" "podman wget /index.txt"
- run_podman run --rm --net=host $IMAGE wget -qO - $SERVER/index2.txt
+ run_podman run --rm --net=host --http-proxy=false $IMAGE wget -qO - $SERVER/index2.txt
is "$output" "$random_2" "podman wget /index2.txt"
# Tests #4889 - two-argument form of "podman ports" was broken
diff --git a/vendor/github.com/container-orchestrated-devices/container-device-interface/pkg/cdi/cache.go b/vendor/github.com/container-orchestrated-devices/container-device-interface/pkg/cdi/cache.go
index 30aa1057b..d653ac387 100644
--- a/vendor/github.com/container-orchestrated-devices/container-device-interface/pkg/cdi/cache.go
+++ b/vendor/github.com/container-orchestrated-devices/container-device-interface/pkg/cdi/cache.go
@@ -446,7 +446,7 @@ func (w *watch) setup(dirs []string, dirErrors map[string]error) {
// Start watching Spec directories for relevant changes.
func (w *watch) start(m *sync.Mutex, refresh func() error, dirErrors map[string]error) {
- go w.watch(m, refresh, dirErrors)
+ go w.watch(w.watcher, m, refresh, dirErrors)
}
// Stop watching directories.
@@ -460,8 +460,8 @@ func (w *watch) stop() {
}
// Watch Spec directory changes, triggering a refresh if necessary.
-func (w *watch) watch(m *sync.Mutex, refresh func() error, dirErrors map[string]error) {
- watch := w.watcher
+func (w *watch) watch(fsw *fsnotify.Watcher, m *sync.Mutex, refresh func() error, dirErrors map[string]error) {
+ watch := fsw
if watch == nil {
return
}
diff --git a/vendor/github.com/container-orchestrated-devices/container-device-interface/pkg/cdi/spec-dirs.go b/vendor/github.com/container-orchestrated-devices/container-device-interface/pkg/cdi/spec-dirs.go
index 13c294592..f339349bb 100644
--- a/vendor/github.com/container-orchestrated-devices/container-device-interface/pkg/cdi/spec-dirs.go
+++ b/vendor/github.com/container-orchestrated-devices/container-device-interface/pkg/cdi/spec-dirs.go
@@ -17,10 +17,10 @@
package cdi
import (
+ "errors"
+ "io/fs"
"os"
"path/filepath"
-
- "github.com/pkg/errors"
)
const (
@@ -79,6 +79,9 @@ func scanSpecDirs(dirs []string, scanFn scanSpecFunc) error {
err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
// for initial stat failure Walk calls us with nil info
if info == nil {
+ if errors.Is(err, fs.ErrNotExist) {
+ return nil
+ }
return err
}
// first call from Walk is for dir itself, others we skip
diff --git a/vendor/modules.txt b/vendor/modules.txt
index d80f64177..cc3d7b6a7 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -61,7 +61,7 @@ github.com/checkpoint-restore/go-criu/v5/rpc
github.com/checkpoint-restore/go-criu/v5/stats
# github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e
github.com/chzyer/readline
-# github.com/container-orchestrated-devices/container-device-interface v0.5.0
+# github.com/container-orchestrated-devices/container-device-interface v0.5.1
## explicit
github.com/container-orchestrated-devices/container-device-interface/pkg/cdi
github.com/container-orchestrated-devices/container-device-interface/specs-go