fix(gateway): restrict ppid==1 systemd detection to Linux only - #25566
Closed
alaamohanad169-ship-it wants to merge 2 commits into
Closed
fix(gateway): restrict ppid==1 systemd detection to Linux only#25566alaamohanad169-ship-it wants to merge 2 commits into
alaamohanad169-ship-it wants to merge 2 commits into
Conversation
The installer creates ~/.hermes/.env via cp or touch, both of which inherit the process umask. On Ubuntu (umask 0022) the result is 0644; on some server environments with umask 0002 the result is 0664. No explicit chmod was applied after file creation, leaving API keys and tokens visible to other users on the system. Add chmod 0600 immediately after .env creation in copy_config_templates(), with a || true fallback for NixOS/containers where the activation script owns permissions. Also tightens permissions when the file already exists, so users with 0664 on disk are hardened on next upgrade. Fixes #25477
When shutdown_forensics.py detects ppid == 1, it assumes the process
runs under systemd. On macOS, PID 1 is launchd, not systemd. This
causes the gateway to incorrectly use systemd-specific shutdown logic
on macOS.
Restrict the ppid == 1 heuristic to Linux only:
sys.platform.startswith("linux") and ppid == 1
The INVOCATION_ID env var check remains platform-independent (it's only
set by systemd on Linux, so no false positive on macOS).
Fixes #25508
Test plan:
- test_under_systemd_false_on_macos_when_ppid_is_one
- test_under_systemd_true_on_linux_when_ppid_is_one
- test_under_systemd_invocation_id_overrides_platform
- All 33 tests in test_shutdown_forensics.py pass
1 task
Collaborator
|
Duplicate of #25525 — same fix restricting |
This was referenced Aug 3, 2026
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.
Summary
Fixes #25508 — When
shutdown_forensics.pydetectsppid == 1, it assumes the process runs under systemd. On macOS, PID 1 is launchd (Apple's service manager), not systemd. This causes the gateway to incorrectly use systemd-specific shutdown logic on macOS.Root Cause
In
gateway/shutdown_forensics.pyline 143:The
ppid == 1check is platform-agnostic, but PID 1 only implies systemd on Linux.Fix
Restrict the
ppid == 1heuristic to Linux only:The
INVOCATION_IDenvironment variable check remains platform-independent (it's only set by systemd on Linux, so no false positive on macOS).Test Plan
tests/gateway/test_shutdown_forensics.py:test_under_systemd_false_on_macos_when_ppid_is_one— macOS + ppid==1 →under_systemd=Falsetest_under_systemd_true_on_linux_when_ppid_is_one— Linux + ppid==1 →under_systemd=Truetest_under_systemd_invocation_id_overrides_platform—INVOCATION_IDalways winstest_shutdown_forensics.pypass (30 existing + 3 new)