Skip to content

Commit

Permalink
Support changing of lsm mount context on restore
Browse files Browse the repository at this point in the history
Wire through CRIU's support to change the mount context on restore.

This is especially useful if restoring a container in a different pod.

Single container restore uses the same SELinux process label and
same mount context as during checkpointing. If a container is being
restored into an existing pod the process label and the mount context
needs to be changed to the context of the pod.

Changing process label on restore is already supported by runc. This
patch adds the possibility to change the mount context.

Signed-off-by: Adrian Reber <[email protected]>
  • Loading branch information
adrianreber committed Jul 7, 2021
1 parent 9a57283 commit 02139ea
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libcontainer/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,12 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error {
}
req.Opts.LsmProfile = proto.String(criuOpts.LsmProfile)
}
if criuOpts.LsmMountContext != "" {
if err := c.checkCriuVersion(31600); err != nil {
return errors.New("--mount-context requires at least CRIU 3.16")
}
req.Opts.LsmMountContext = proto.String(criuOpts.LsmMountContext)
}

if criuOpts.WorkDirectory != "" {
// Since a container can be C/R'ed multiple times,
Expand Down
1 change: 1 addition & 0 deletions libcontainer/criu_opts_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ type CriuOpts struct {
LazyPages bool // restore memory pages lazily using userfaultfd
StatusFd int // fd for feedback when lazy server is ready
LsmProfile string // LSM profile used to restore the container
LsmMountContext string // LSM mount context value to use during restore
}
8 changes: 8 additions & 0 deletions man/runc-restore.8.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ daemon. See [criu --lazy-pages option](https://criu.org/CLI/opt/--lazy-pages).
**apparamor** or **selinux**, and _label_ is a valid LSM label. For example,
**--lsm-profile "selinux:system_u:system_r:container_t:s0:c82,c137"**.

**--mount-context** _context_
: Specify an LSM mount context to be used during restore. Only mounts with an
existing context will have their context replaced. With this option it is
possible to change SELinux mount options. Instead of mounting with the
checkpointed context like `context="system_u:object_r:container_file_t:s0:c31,c779"`
the mount context will be replaced with the value specified using **--mount-context**.
For example, **--mount-context "system_u:object_r:container_file_t:s0:c82,c137"**.

# SEE ALSO
**criu**(8),
**runc-checkpoint**(8),
Expand Down
6 changes: 6 additions & 0 deletions restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ using the runc checkpoint command.`,
Value: "",
Usage: "Specify an LSM profile to be used during restore in the form of TYPE:NAME.",
},
cli.StringFlag{
Name: "lsm-mount-context",
Value: "",
Usage: "Specify an LSM mount context to be used during restore.",
},
},
Action: func(context *cli.Context) error {
if err := checkArgs(context, 1, exactArgs); err != nil {
Expand Down Expand Up @@ -145,5 +150,6 @@ func criuOptions(context *cli.Context) *libcontainer.CriuOpts {
LazyPages: context.Bool("lazy-pages"),
StatusFd: context.Int("status-fd"),
LsmProfile: context.String("lsm-profile"),
LsmMountContext: context.String("lsm-mount-context"),
}
}

0 comments on commit 02139ea

Please sign in to comment.