Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Change ownership of /dev/std* #131

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions scubainit/scubainit.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,22 @@ main(int argc, char **argv)
goto fail;
if (add_shadow(ETC_SHADOW, m_user) != 0)
goto fail;

/**
* Change ownership of /dev/std*
* See issue #126
*/
for (int fd = 0; fd <= 2; fd++) {
if (!isatty(fd)) {
verbose("fd %d: is not a TTY; not changing ownership\n", fd);
continue;
}
verbose("fd %d: is a TTY; changing owner to %d:%d\n", fd, m_uid, m_gid);
if (fchown(fd, m_uid, m_gid) != 0) {
errmsg("Failed to fchown(%d, %d, %d): %m\n", fd, m_uid, m_gid);
goto fail;
}
}
}

/* Call pre-su hook */
Expand Down
18 changes: 18 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,24 @@ def test_redirect_stdin(self):

assert_str_equalish(out, test_str)

def test_dev_stdout(self):
"""Verify processes can write to /dev/stdout"""
with open(".scuba.yml", "w") as f:
f.write("image: {}\n".format(DOCKER_IMAGE))

test_str = "Writing to /dev/stdout works"
args = [
#'--verbose',
"/bin/sh",
"-c",
'echo "{}" > /dev/stdout'.format(test_str),
]

# We have to mock tty, otherwise the container will get a pipe and scubainit can't chown that
out, _ = self.run_scuba(args, mock_isatty=True)

assert_str_equalish(out, test_str)

def _test_user(
self,
expected_uid,
Expand Down