fix(cmd/register): service account key permissions - #103
Open
bassosimone wants to merge 1 commit into
Open
bassosimone wants to merge 1 commit into
bassosimone wants to merge 1 commit into
Conversation
The service account key is written with 0644 permissions. Because it is a secret, it should instead be written with 0600. I noticed this issue when analyzing `byos-debian` where the key is written to `/var/lib/mlab/node`. The directory itself is `02750` and this prevents users that are not in the `mlab-node` group from reading the file. However, in that context, services such as `ndt-server` are able to read the secret even though they do not need to. This patch doesn't address that, but I am working on another set of patches to privilege-separate core services and measurement services. I did not spend time focusing on whether this was a security issue for autonode. As regards autonode, my main focus has been trying to understand whether changing the permissions could break it, and I concluded that this is not the case (see below). To address the permissions, this patch does the following: 1. call `os.WriteFile` with `0600`, which covers new files only while existing files are just truncated w/o a `chmod` 2. `os.Chmod` with `0600` thus covering already existing files Following the Boy Scout rule, this patch also changes the wording and spelling of some comments and adds minor style tweaks. Regarding why I am confident that autonode containers (and namely `jostler` and `uuid-annotator`) run as root, this is why: 1. the three `Dockefile`s do not specify `USER` 2. there is no `user:` in the `docker-compose.yml` As such, this change is safe. Even if the file was owned by another user and had `0600`, root holds `CAP_DAC_OVERRIDE` so it is able to read the service account key anyway.
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.
The service account key is written with 0644 permissions. Because it is a secret, it should instead be written with 0600.
I noticed this issue when analyzing
byos-debianwhere the key is written to/var/lib/mlab/node. The directory itself is02750and this prevents users that are not in themlab-nodegroup from reading the file. However, in that context, services such asndt-serverare able to read the secret even though they do not need to. This patch doesn't address that, but I am working on another set of patches to privilege-separate core services and measurement services.I did not spend time focusing on whether this was a security issue for autonode. As regards autonode, my main focus has been trying to understand whether changing the permissions could break it, and I concluded that this is not the case (see below).
To address the permissions, this patch does the following:
call
os.WriteFilewith0600, which covers new files only while existing files are just truncated w/o achmodos.Chmodwith0600thus covering already existing filesFollowing the Boy Scout rule, this patch also changes the wording and spelling of some comments and adds minor style tweaks.
Regarding why I am confident that autonode containers (and namely
jostleranduuid-annotator) run as root, this is why:the three
Dockefiles do not specifyUSERthere is no
user:in thedocker-compose.ymlAs such, this change is safe. Even if the file was owned by another user and had
0600, root holdsCAP_DAC_OVERRIDEso it is able to read the service account key anyway.This change is