Address race condition in renew-script.sh #194
Merged
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.
Description
There is currently a race condition in
renew-script.sh
that could lead to exposure of the SSH private key. This change should resolve the issue by usingmktemp
to create a temporary directory with an unpredictable name and mode 0700.The temporary directory (and therefore private key) will also be removed when no longer needed.
If
mktemp
does not exist or otherwise fails, a fallback directory will be created with a name based on the PID of the script. The mode will still be set to 0700 before the private key file is created. Since the name is predictable, there is a potential issue with symlink-based attacks. Perhaps the fallback should be removed or improved...Note that the symlink issue is also present with
$SESSION_TOKEN_CACHE
. I'm not sure how to resolve that, since the name needs to be predictable. Checking that it's a regular file would not solve the problem but would at least make such an attack more difficult. However, I could also imagine someone wanting it to be a symlink (e.g., if/tmp
is volatile and they want to maintain the cache across reboots). Anyway, this should probably be documented (with a warning to never run the script as root).Fixes #193
Type of change
Checklist:
It would be nice to have someone who uses this script test these changes.