Skip to content
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
11 changes: 11 additions & 0 deletions deploy/install-mtproxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ if [[ ! -x "$source_directory/objs/bin/mtproto-proxy" ]] ||
rm -rf "$temporary"
fi

# make runs under the installer's umask, and deploy/install.sh sets 0077, so
# objs/, objs/bin/ and the binary end up mode 0700, and the chown above leaves
# them root:root. mtproxy.service runs as User=mtproxy, which can neither
# traverse those directories nor execute the binary: systemd reports
# status=203/EXEC and the relay stays at /readyz 503. Grant the runtime group
# exactly what it needs, reusing the root:mtproxy 0750 scheme this installer
# already applies to /etc/mtproxy. This runs on every invocation, not only
# after a rebuild, so re-running the installer repairs an affected host.
chown root:mtproxy "$source_directory/objs" "$source_directory/objs/bin" "$source_directory/objs/bin/mtproto-proxy"
chmod 0750 "$source_directory/objs" "$source_directory/objs/bin" "$source_directory/objs/bin/mtproto-proxy"

install -d -o root -g mtproxy -m 0750 /etc/mtproxy
secret_temp="$(mktemp /etc/mtproxy/proxy-secret.XXXXXX)"
config_temp="$(mktemp /etc/mtproxy/proxy-multi.conf.XXXXXX)"
Expand Down
8 changes: 8 additions & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,14 @@ func TestLoadAcceptsSystemdCredentialReadPermissions(t *testing.T) {
if err := os.WriteFile(profiles, []byte(content), 0444); err != nil {
t.Fatal(err)
}
// os.WriteFile applies the process umask. Under a strict umask, and
// deploy/install.sh sets 0077 before running the suite, the file lands as
// 0400, so the group/other bits the second Load call must reject are never
// set and the negative assertion below fails. Set the mode explicitly so
// the test states what it means regardless of the caller's umask.
if err := os.Chmod(profiles, 0444); err != nil {
t.Fatal(err)
}
t.Setenv("CREDENTIALS_DIRECTORY", credentials)
server := `{"public_hostname":"proxy.example.com","public_dir":"public","profiles_file":"credentials/profiles.json"}`
path := filepath.Join(directory, "config.json")
Expand Down