Skip to content

discourse-doctor: prevent others from reading sensitive log content #987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MichaIng
Copy link
Contributor

The log file is world-readable until the script finished, while sensitive settings are written to it at the very start. If the container is not running, a rebuild is done, which can leave the file with sensitive content world-readable for quite a long time.

This commit makes the log file readable to root only, while the script is running, and applies default mode only after sensitive content has been reducted, for convenience and to remain a non-breaking change.

An alternative would be to redact sensitive content right after it was written, in the get_discourse_config() function, but it would require more code and sensitive content might be printed later as well if a rebuild is done.

discourse-doctor Outdated
@@ -348,6 +350,8 @@ print_done() {
initialize_log_file() {
rm -f $LOG_FILE
touch $LOG_FILE
# prevent others from reading sensitive content from the log
chmod 0600 $LOG_FILE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of touch + chmod we should do it in a single command with install -m 0600 /dev/null $LOG_FILE. Then you can remove the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Change applied and rebase.

The log file is world-readable until the script finished, while sensitive settings are written to it at the very start. If the container is not running, a rebuild is done, which can leave the file with sensitive content world-readable for quite a long time.

This commit makes the log file readable to root only, while the script is running, and applies default mode only after sensitive content has been reducted, for convenience and to remain a non-breaking change.

An alternative would be to redact sensitive content right after it was written, in the `get_discourse_config()` function, but it would require more code and sensitive content might be printed later as well if a rebuild is done.

Signed-off-by: MichaIng <[email protected]>
@MichaIng MichaIng force-pushed the harden-doctor-log-mode branch from e217d97 to f8e35af Compare August 22, 2025 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants