Skip to content

Commit 0e68dc9

Browse files
committed
cmd/create, cmd/initContainer: Mount the devpts file system at runtime
Anything that's specified during 'podman create ...' gets statically baked into the container's configuration, and is either difficult or impossible to change afterwards. This means that Toolbx containers created with older versions of Toolbx keep diverging from those created with newer versions. Hence, making it complicated to keep older containers working with newer Toolbx. Mounting the devpts file system at runtime as part of the Toolbx container's entry point will make it possible to update the attributes of the mount, if necessary, for both existing and newly created containers. For what it's worth, this does alter the mount options by removing 'context'. With 'podman create --mount type=devpts,destination=/dev/pts' it was: $ mount | grep ... devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime, context="system_u:object_r:container_file_t:s0:c1022,c1023", gid=100005,mode=620,ptmxmode=666) Now with 'mount -t devpts -o noexec,nosuid,gid=5,mode=620,ptmxmode=666' it is: $ mount | grep devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel, gid=100005,mode=620,ptmxmode=666) containers#1016
1 parent fb15655 commit 0e68dc9

File tree

2 files changed

+46
-14
lines changed

2 files changed

+46
-14
lines changed

src/cmd/create.go

-14
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,6 @@ func createContainer(container, image, release, authFile string, showCommandToEn
245245

246246
runtimeDirectoryMountArg := runtimeDirectory + ":" + runtimeDirectory
247247

248-
logrus.Debug("Checking if 'podman create' supports '--mount type=devpts'")
249-
250-
var devPtsMount []string
251-
252-
if podman.CheckVersion("2.1.0") {
253-
logrus.Debug("'podman create' supports '--mount type=devpts'")
254-
devPtsMount = []string{"--mount", "type=devpts,destination=/dev/pts"}
255-
}
256-
257248
var usernsArg string
258249
if currentUser.Uid == "0" {
259250
usernsArg = "host"
@@ -404,11 +395,6 @@ func createContainer(container, image, release, authFile string, showCommandToEn
404395
"--hostname", "toolbox",
405396
"--ipc", "host",
406397
"--label", "com.github.containers.toolbox=true",
407-
}...)
408-
409-
createArgs = append(createArgs, devPtsMount...)
410-
411-
createArgs = append(createArgs, []string{
412398
"--name", container,
413399
"--network", "host",
414400
"--no-hosts",

src/cmd/initContainer.go

+46
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ func initContainer(cmd *cobra.Command, args []string) error {
256256
}
257257
}
258258

259+
if err := mountDevPts(); err != nil {
260+
return err
261+
}
262+
259263
if utils.PathExists("/etc/krb5.conf.d") && !utils.PathExists("/etc/krb5.conf.d/kcm_default_ccache") {
260264
logrus.Debug("Setting KCM as the default Kerberos credential cache")
261265

@@ -522,6 +526,48 @@ func mountBind(containerPath, source, flags string) error {
522526
return nil
523527
}
524528

529+
func mountDevPts() error {
530+
optionsArgs := []string{
531+
"noexec",
532+
"nosuid",
533+
}
534+
535+
const ttyGroup = "tty"
536+
logrus.Debugf("Looking up group %s", ttyGroup)
537+
538+
if _, err := user.LookupGroup(ttyGroup); err != nil {
539+
logrus.Debugf("Looking up group %s failed: %s", ttyGroup, err)
540+
} else {
541+
const optionsGIDArg = "gid=" + ttyGroup
542+
optionsArgs = append(optionsArgs, []string{
543+
optionsGIDArg,
544+
}...)
545+
}
546+
547+
optionsArgs = append(optionsArgs, []string{
548+
"mode=620",
549+
"ptmxmode=666",
550+
}...)
551+
552+
optionsArg := strings.Join(optionsArgs, ",")
553+
554+
const devPtsFS = "devpts"
555+
const devPtsMountPoint = "/dev/pts"
556+
557+
mountArgs := []string{
558+
"--types", devPtsFS,
559+
"--options", optionsArg,
560+
devPtsFS,
561+
devPtsMountPoint,
562+
}
563+
564+
if err := shell.Run("mount", nil, nil, nil, mountArgs...); err != nil {
565+
return fmt.Errorf("failed to mount a %s file system at %s: %w", devPtsFS, devPtsMountPoint, err)
566+
}
567+
568+
return nil
569+
}
570+
525571
// redirectPath serves for creating symbolic links for crucial system
526572
// configuration files to their counterparts on the host's file system.
527573
//

0 commit comments

Comments
 (0)