fix(config): preserve owner on atomic writes - #536
Open
hashbender wants to merge 1 commit into
Open
Conversation
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.
What does this PR do?
Preserves the existing uid/gid when Hermes rewrites files through the shared atomic JSON/YAML write helpers.
The root cause is that
os.replace()swaps in the temporary file. When a command is run as root against a Docker/NAS-backed Hermes home, the temp file can be root-owned even if the originalconfig.yamlwas owned by the runtime user. Mode preservation alone does not prevent the replacement file from becoming unreadable to the Hermes process.This restores the original owner on POSIX platforms after the atomic replace, best effort. Unsupported platforms and unprivileged callers continue normally if ownership cannot be changed.
Related Issue
No GitHub issue. Reported from support logs showing
/opt/data/config.yamlbecoming unreadable after a gateway setup/config write.Type of Change
Changes Made
utils.py: capture the original file owner before atomic JSON/YAML writes and restore it afteratomic_replace().utils.py: apply the same owner preservation toatomic_roundtrip_yaml_update().tests/test_atomic_replace_symlinks.py: add focused tests for JSON writes, YAML writes through symlinks, and roundtrip YAML updates without requiring root.How to Test
pytest tests/test_atomic_replace_symlinks.py -qpytest tests/test_atomic_replace_symlinks.py tests/hermes_cli/test_atomic_json_write.py tests/hermes_cli/test_atomic_yaml_write.py tests/test_yaml_indent_consistency_31999.py -qconfig.yamlkeeps the original owner.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs
Focused local checks:
Full
pytest tests/ -qwas not run locally; this PR came from support triage and the local run was intentionally scoped to the touched atomic-write behavior.Mirror-of: NousResearch#56644
NousResearch#56644