detached 122e784

fix(guest): run steps with umask 022, as GitHub's runners do (#38)

commit
122e784c35227cd36fcf9c16f401a95a7c03ed34
author
brice · · 2026-10-17 18:47 UTC
committer
bnema · · 2026-10-17 18:47 UTC
parent
76a5504
signature
SSH UnverifiedSHA256:VOCA5lYARHcbKDZ7GhTV45VmcjWnJ6ZQIBazj17LivA The key is unknown
refs
tag: v0.4.1
3 files · +26 -0
M internal/guest/exec.go +3 -0
@@ -95,6 +95,9 @@ func (c *ExecConfig) defaults() {
9595 // group with escalating signals (see ExecConfig).
9696 func Exec(ctx context.Context, cfg ExecConfig) (int, error) {
9797 cfg.defaults()
98+ // The steps inherit the executor's umask: GitHub's 022, whatever started
99+ // the executor (Init sets it too; a container's entrypoint may not).
100+ syscall.Umask(StepUmask)
98101 raw, err := cfg.Target.Dial(ctx, cfg.ConnectTimeout)
99102 if err != nil {
100103 return 1, err
@@ -95,6 +95,9 @@ func (c *ExecConfig) defaults() {
95 // group with escalating signals (see ExecConfig).95 // group with escalating signals (see ExecConfig).
96 func Exec(ctx context.Context, cfg ExecConfig) (int, error) {96 func Exec(ctx context.Context, cfg ExecConfig) (int, error) {
97 cfg.defaults()97 cfg.defaults()
98+ // The steps inherit the executor's umask: GitHub's 022, whatever started
99+ // the executor (Init sets it too; a container's entrypoint may not).
100+ syscall.Umask(StepUmask)
98 raw, err := cfg.Target.Dial(ctx, cfg.ConnectTimeout)101 raw, err := cfg.Target.Dial(ctx, cfg.ConnectTimeout)
99 if err != nil {102 if err != nil {
100 return 1, err103 return 1, err
M internal/guest/guest_test.go +15 -0
@@ -675,3 +675,18 @@ func TestStopDockerdKillsAndReapsATermIgnoringDaemon(t *testing.T) {
675675 t.Fatal("dockerd was not reaped (zombie or alive)")
676676 }
677677 }
678+
679+// A step runs with GitHub's umask 022 even when the executor was started with
680+// 0, as the kernel starts a VM's init: its files and directories are not
681+// world-writable.
682+func TestExecStepsGetUmask022(t *testing.T) {
683+ old := syscall.Umask(0)
684+ defer syscall.Umask(old)
685+ out, _, _, _, code, err := host(t, `umask`, 0, nil)
686+ if err != nil || code != 0 {
687+ t.Fatalf("code=%d err=%v", code, err)
688+ }
689+ if strings.TrimSpace(out) != "0022" {
690+ t.Fatalf("umask = %q, want 0022", out)
691+ }
692+}
@@ -675,3 +675,18 @@ func TestStopDockerdKillsAndReapsATermIgnoringDaemon(t *testing.T) {
675 t.Fatal("dockerd was not reaped (zombie or alive)")675 t.Fatal("dockerd was not reaped (zombie or alive)")
676 }676 }
677 }677 }
678+
679+// A step runs with GitHub's umask 022 even when the executor was started with
680+// 0, as the kernel starts a VM's init: its files and directories are not
681+// world-writable.
682+func TestExecStepsGetUmask022(t *testing.T) {
683+ old := syscall.Umask(0)
684+ defer syscall.Umask(old)
685+ out, _, _, _, code, err := host(t, `umask`, 0, nil)
686+ if err != nil || code != 0 {
687+ t.Fatalf("code=%d err=%v", code, err)
688+ }
689+ if strings.TrimSpace(out) != "0022" {
690+ t.Fatalf("umask = %q, want 0022", out)
691+ }
692+}
M internal/guest/init.go +8 -0
@@ -63,6 +63,10 @@ type InitConfig struct {
6363 // powering the VM off, or exiting with the executor's code in a container.
6464 func Init(ctx context.Context, cfg InitConfig) int {
6565 log := zerowrap.FromCtx(ctx)
66+ // The kernel starts a VM's init with umask 0, which dockerd, the executor
67+ // and every step would inherit: files and t.TempDir() directories would be
68+ // world-writable. GitHub's runners have 022, and so do the jobs here.
69+ syscall.Umask(StepUmask)
6670 if cfg.Getpid == nil {
6771 cfg.Getpid = os.Getpid
6872 }
@@ -102,6 +106,10 @@ func Init(ctx context.Context, cfg InitConfig) int {
102106 return code
103107 }
104108
109+// StepUmask is the umask of everything the init starts, steps included: the
110+// one of GitHub's hosted runners.
111+const StepUmask = 0o022
112+
105113 // defaultPath is the PATH of a sandbox whose init was started by the kernel
106114 // with an empty environment.
107115 const defaultPath = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
@@ -63,6 +63,10 @@ type InitConfig struct {
63 // powering the VM off, or exiting with the executor's code in a container.63 // powering the VM off, or exiting with the executor's code in a container.
64 func Init(ctx context.Context, cfg InitConfig) int {64 func Init(ctx context.Context, cfg InitConfig) int {
65 log := zerowrap.FromCtx(ctx)65 log := zerowrap.FromCtx(ctx)
66+ // The kernel starts a VM's init with umask 0, which dockerd, the executor
67+ // and every step would inherit: files and t.TempDir() directories would be
68+ // world-writable. GitHub's runners have 022, and so do the jobs here.
69+ syscall.Umask(StepUmask)
66 if cfg.Getpid == nil {70 if cfg.Getpid == nil {
67 cfg.Getpid = os.Getpid71 cfg.Getpid = os.Getpid
68 }72 }
@@ -102,6 +106,10 @@ func Init(ctx context.Context, cfg InitConfig) int {
102 return code106 return code
103 }107 }
104 108
109+// StepUmask is the umask of everything the init starts, steps included: the
110+// one of GitHub's hosted runners.
111+const StepUmask = 0o022
112+
105 // defaultPath is the PATH of a sandbox whose init was started by the kernel113 // defaultPath is the PATH of a sandbox whose init was started by the kernel
106 // with an empty environment.114 // with an empty environment.
107 const defaultPath = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"115 const defaultPath = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 4

Tags 11

↑↓ moveenter openesc close