Skip to content

Commit 71b0bd0

Browse files
committed
chore: enable cross-user linux tests in CI
Summary: This library has functionality that allows it to run subprocesses as a user that is different from the current user. We have unit/integration tests that verify this functionality is working. Right now, a developer is expected to run the scripts/run_sudo_tests.sh set of tests before putting up a pull request to make sure that a change doesn't break the functionality. This isn't reliable so we should have these tests enabled in the GitHub CI; this does that. Signed-off-by: Daniel Neilson <[email protected]>
1 parent 0ae482d commit 71b0bd0

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

.github/workflows/reuse_python_build.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,41 @@ jobs:
4343
echo "::add-mask::$plaintext_password"
4444
echo OJD_SESSIONS_USER_PASSWORD=$plaintext_password >> $env:GITHUB_ENV
4545
46+
- name: Create Linux Test User
47+
if: ${{ matrix.os == 'ubuntu-latest' }}
48+
run: |
49+
set -eou pipefail
50+
51+
TARGET_USER=targetuser
52+
SHARED_GROUP=sharedgroup
53+
DISJOINT_USER=disjointuser
54+
DISJOINT_GROUP=disjointgroup
55+
56+
echo HOSTUSER=$(whoami)
57+
58+
sudo addgroup $SHARED_GROUP
59+
sudo useradd -ms /bin/bash -G $SHARED_GROUP $TARGET_USER
60+
sudo usermod -a -G $SHARED_GROUP $(whoami)
61+
sudo usermod -g $SHARED_GROUP $(whoami)
62+
echo "$(whoami) ALL=($TARGET_USER,$(whoami)) NOPASSWD: ALL" | sudo tee -a /etc/sudoers.d/$(whoami)
63+
64+
sudo addgroup $DISJOINT_GROUP
65+
sudo useradd -ms /bin/bash -G $DISJOINT_GROUP $DISJOINT_USER
66+
67+
for user in $TARGET_USER $DISJOINT_USER $(whoami)
68+
do
69+
echo "$user is UID: $(id -u $user)"
70+
groups $user
71+
done
72+
73+
echo OPENJD_TEST_SUDO_TARGET_USER=$TARGET_USER >> $GITHUB_ENV
74+
echo OPENJD_TEST_SUDO_SHARED_GROUP=$SHARED_GROUP >> $GITHUB_ENV
75+
echo OPENJD_TEST_SUDO_DISJOINT_USER=$DISJOINT_USER >> $GITHUB_ENV
76+
echo OPENJD_TEST_SUDO_DISJOINT_GROUP=$DISJOINT_GROUP >> $GITHUB_ENV
77+
78+
umask
79+
cat /etc/group
80+
4681
- name: Set up Python ${{ matrix.python-version }}
4782
uses: actions/setup-python@v5
4883
with:

src/openjd/sessions/_embedded_files.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ def write_file_for_user(
5555

5656
if os.name == "posix":
5757
if user is not None:
58+
# DEBUGGING - Print permissions of the whole file path
59+
print("For file:", filename)
60+
for i in range(1, len(filename.parts) + 1):
61+
subpath = Path().joinpath(*filename.parts[0:i])
62+
print(subpath, subpath.stat())
63+
# END DEBUGGING
5864
user = cast(PosixSessionUser, user)
5965
# Set the group of the file
6066
chown(filename, group=user.group)

0 commit comments

Comments
 (0)