Repository navigation
Restrict runtime file permissions at startup and fix the service unit template (SEC 2/27) - #247
Merged
Merged
Conversation
… template (SEC 2/27) On every start the app sets the project dir to 0700, .env and config.json to 0600 and clears group/other write bits under data/ and models/. config.json is created 0600 even under a loose umask. README unit template drops Group=www-data and adds UMask=0077.
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
utils.harden_runtime_permissions()runs first in themain.pylifespan: project dir0700,.envandconfig.json0600, group/other write bits cleared underdata/andmodels/(symlinks skipped, idempotent, unchangeable paths reported in one warning).config.jsonis now created0600on first boot and for the atomic temp file inupdate_config_atomic(config._open_private), independent of umask..envalready keeps/creates0600through python-dotenv >= 1.2.2 (covered by a test).Group=www-data, addsUMask=0077; short File permissions note;assets/system_architecture.mdsection 7.main.harden_runtime_permissionsso the suite never chmods the checkout.Not shipped by this PR (prod ops, after deploy + restart)
/etc/systemd/system/stock_analysis_project.service: removeGroup=www-data, addUMask=0077, thensudo systemctl daemon-reloadand restart..envsecret (APP_SECRET_KEY, API key with the Home Assistant update at the same time, embed and confirm tokens, SMTP, Nextcloud, FRED, Hugging Face, dashboard password). Rotate only after the first restart on this code, so the new values are written into an already-private.env.Test plan
pytest tests/test_05_config_and_utils.py tests/test_06_auth.py tests/test_rss_feed.py(175 passed)stat -c '%a %U:%G %n' . .env config.json data models data/analysis.dbshows700,600,600and no group/other write bit