Skip to content

Commit fd3a1ef

Browse files
committed
fix(orch): keep root-executed helpers unwritable under the world-writable /usr/local
1 parent f8c7b5b commit fd3a1ef

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

‎packages/orchestrator/pkg/template/build/phases/finalize/configure.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ if command -v update-ca-certificates >/dev/null 2>&1; then
4848
fi
4949
mkdir -p /usr/local/share/e2b
5050
tar -C /etc/ssl/certs -chf /usr/local/share/e2b/ssl-certs.tar .
51+
# Root extracts this tar into the boot-time cert tmpfs, so it must not be
52+
# writable by the sandbox user. Set explicitly: the configuration script's
53+
# chmod -R 777 /usr/local ran before this step, and rewriting the tar in place
54+
# on a FROM-template rebuild keeps the existing file's mode and owner.
55+
chown root:root /usr/local/share/e2b/ssl-certs.tar
56+
chmod 644 /usr/local/share/e2b/ssl-certs.tar
5157
`
5258

5359
// packCertBundle runs packCertBundleCmd in the guest as root.

‎packages/orchestrator/pkg/template/build/phases/finalize/configure.sh‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,35 @@ chown -R user:user /home/user
7575
echo "Give 777 permission to /usr/local"
7676
chmod -R 777 /usr/local
7777

78+
# The 777 above is what lets sandbox users install into /usr/local without
79+
# sudo, but it also lets them delete or replace the E2B helpers root runs at
80+
# boot (envd's ExecStartPre). Sticky keeps that convenience — anyone can still
81+
# create files here — while restricting unlink/rename to a file's owner, so the
82+
# root-owned helpers below cannot be swapped out. Defense in depth: 'user'
83+
# already has NOPASSWD sudo, so this is not a privilege boundary.
84+
# The whole ancestor chain needs it, not just the leaves: a sticky directory
85+
# whose parent is world-writable and non-sticky can be renamed aside wholesale
86+
# and recreated with replaced contents.
87+
echo "Set the sticky bit on the directories holding root-executed E2B helpers"
88+
for dir in /usr/local /usr/local/bin /usr/local/share /usr/local/share/e2b; do
89+
if [ -d "$dir" ]; then
90+
chmod 1777 "$dir"
91+
fi
92+
done
93+
echo "Restore root-owned, non-writable modes on the E2B helpers"
94+
for exe in /usr/local/bin/e2b-seed-certs /usr/local/bin/e2b-provision-runner /usr/local/share/e2b/envd.openrc; do
95+
if [ -f "$exe" ]; then
96+
chown root:root "$exe"
97+
chmod 755 "$exe"
98+
fi
99+
done
100+
# distro.env is sourced by root here and by later FROM-template builds.
101+
# ssl-certs.tar is packed after this script runs, so it is hardened there.
102+
if [ -f /usr/local/share/e2b/distro.env ]; then
103+
chown root:root /usr/local/share/e2b/distro.env
104+
chmod 644 /usr/local/share/e2b/distro.env
105+
fi
106+
78107
echo "Create /code directory"
79108
mkdir -p /code
80109
echo "Give 777 permission to /code"

0 commit comments

Comments
 (0)