Fix two umask-dependent failures in a fresh installation - #12
Open
naprelsky wants to merge 2 commits into
Open
Conversation
…est.
os.WriteFile applies the process umask, so under a strict umask the 0444
profiles file lands as 0400. The group and other bits that the second Load
call is supposed to reject are then never set, Load succeeds, and the test
fails on its own negative assertion:
--- FAIL: TestLoadAcceptsSystemdCredentialReadPermissions
config_test.go:248: group/other-readable profiles file outside a
credential directory was accepted
This is reachable from a normal installation: deploy/install.sh sets
umask 077 on its first line and later runs go test ./..., so a fresh
install aborts before building the relay.
Chmod the file after writing it, so the test asserts what it means
regardless of the caller's umask.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
make runs under the umask inherited from deploy/install.sh, which is 077, so it creates objs/ and objs/bin/ as 0700 and the binary as 0700. The subsequent chown -R root:root leaves them owned by root with no group or other bits, and mtproxy.service runs as User=mtproxy. systemd cannot execute the binary and reports status=203/EXEC, mtproxy hits its restart limit, and the relay stays at /readyz 503 "backend unavailable" while install.sh ends with "tproxy-server did not become ready". Set root:mtproxy 0750 on the two directories and the binary, reusing the scheme this installer already applies to /etc/mtproxy. The commands run on every invocation rather than only after a rebuild, because the rebuild guard tests -x as root, which passes on a 0700 binary, so an affected host cannot otherwise be repaired by re-running the installer. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
deploy/install.shsetsumask 077on its first line. Two later steps rely ondefault permissions and break under it, so a fresh installation on a clean
Ubuntu 24.04 host fails twice before the relay ever serves a request. Both
failures look like a broken environment rather than a permission default, which
is what cost me the time to track them down.
1. The test suite aborts the install
install.shrunsgo test ./...before building. Underumask 077,TestLoadAcceptsSystemdCredentialReadPermissionswrites its profiles file withos.WriteFile(..., 0444), the umask clears the group and other bits, and thefile lands as
0400. The negative half of the test — a group-readable profilesfile outside a credential directory must be rejected — then has nothing to
reject,
Loadsucceeds, and the test fails on its own assertion:The permission check in
loadProfilesis correct; only the test isumask-dependent. Fixed by chmod'ing the file after writing it.
2. MTProxy cannot start, so the relay never becomes ready
makeininstall-mtproxy.shalso runs underumask 077, creatingobjs/,objs/bin/andmtproto-proxyas0700. Thechown -R root:rootthat followsleaves them owned by root with no group access, while
mtproxy.serviceruns asUser=mtproxy:The relay itself starts fine but stays at
/readyz503backend unavailable,and
install.shends withtproxy-server did not become ready.Fixed with
root:mtproxy0750on the two directories and the binary, reusingthe scheme the installer already applies to
/etc/mtproxy. The commands run onevery invocation rather than only after a rebuild: the rebuild guard tests
-xas root, which passes on a
0700binary, so an already affected host cannot berepaired by re-running the installer otherwise.
A single-line alternative for the second issue would be to build under a
permissive umask, but that also relaxes everything else
makewrites, sogranting the runtime group exactly what it needs seemed closer to the intent of
the surrounding code. Happy to switch if you prefer the other shape.
Verification
On a fresh clone at
52a5feb, Ubuntu 24.04, Go 1.22:umask 077; go test -count=1 ./internal/config/fails as above;umask 077; go test -count=1 ./...andumask 022; go test -count=1 ./...both pass;bash -n deploy/install-mtproxy.shis clean;deploy/install.sh --hostname … --site-upstream …run completes,mtproxystays active,/healthzand/readyzreturn 200, and/and/?bridge=<invalid>return the operator site byte for byte.🤖 Generated with Claude Code