opencontainers / opencontainers/runc

Launching runc through Python blocks shell input if "terminal" is set to true

Open
#1,965 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
13.5k
Forks
2.3k
Avg merge
2d 8h
Merged PRs (30d)
30

Description

Hello everyone and thank you for the great work 👍

I tried to start a very simple container through a Python script, and it happens that after runc exits, the shell input is "blocked" or "hidden":

  • With bash (version 5.0), you can type things, but it will not appear on the screen and you have to type "reset" + enter to reset the terminal and then be able to see what you are typing again
  • With sh, it just blocks the terminal in __GI___libc_read (fd=0, buf=0x55c6697d1ac0, nbytes=8192) call and you have to kill it

To setup the container, i just created a /tmp/roots directory, mount binded my / into it and used this configuration file generated from runc spec after having removed the mounts part:

{
	"ociVersion": "1.0.1-dev",
	"process": {
		"terminal": true,
		"user": {
			"uid": 0,
			"gid": 0
		},
		"args": [
			"sleep",
			"2"
		],
		"env": [
			"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
			"TERM=xterm"
		],
		"cwd": "/",
		"capabilities": {
			"bounding": [
				"CAP_AUDIT_WRITE",
				"CAP_KILL",
				"CAP_NET_BIND_SERVICE"
			],
			"effective": [
				"CAP_AUDIT_WRITE",
				"CAP_KILL",
				"CAP_NET_BIND_SERVICE"
			],
			"inheritable": [
				"CAP_AUDIT_WRITE",
				"CAP_KILL",
				"CAP_NET_BIND_SERVICE"
			],
			"permitted": [
				"CAP_AUDIT_WRITE",
				"CAP_KILL",
				"CAP_NET_BIND_SERVICE"
			],
			"ambient": [
				"CAP_AUDIT_WRITE",
				"CAP_KILL",
				"CAP_NET_BIND_SERVICE"
			]
		},
		"rlimits": [
			{
				"type": "RLIMIT_NOFILE",
				"hard": 1024,
				"soft": 1024
			}
		],
		"noNewPrivileges": true
	},
	"root": {
		"path": "rootfs",
		"readonly": true
	},
	"hostname": "runc",
	"linux": {
		"resources": {
			"devices": [
				{
					"allow": false,
					"access": "rwm"
				}
			]
		},
		"namespaces": [
			{
				"type": "pid"
			},
			{
				"type": "network"
			},
			{
				"type": "ipc"
			},
			{
				"type": "uts"
			},
			{
				"type": "mount"
			}
		],
		"maskedPaths": [
			"/proc/kcore",
			"/proc/latency_stats",
			"/proc/timer_list",
			"/proc/timer_stats",
			"/proc/sched_debug",
			"/sys/firmware",
			"/proc/scsi"
		],
		"readonlyPaths": [
			"/proc/asound",
			"/proc/bus",
			"/proc/fs",
			"/proc/irq",
			"/proc/sys",
			"/proc/sysrq-trigger"
		]
	}
}

The Python script is very simple:

import subprocess
import atexit
import time

ARGS = ['runc', 'run', 'myrunc']
print(ARGS)
PROCESS = subprocess.Popen(ARGS)
print('Started subprocess with pid {}'.format(PROCESS.pid))
time.sleep(2)
atexit.register(PROCESS.terminate)

Looking at other issues, i found that it might be related to #1721 because if i set terminal to false, it works fine.

I am using runc 1.0-rc6 on kernel 4.20.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the provided Python subprocess script, runc 1.0-rc6, and the shown configuration with process.terminal set to true; compare it with terminal set to false. Trace the runc run terminal handling and verify that, after the container exits, bash and sh still accept and display shell input normally.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, linux, python
Domain
cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.