Skip to content
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

actions/config: ensure config file is created with mode 0644 #152

Merged
merged 1 commit into from
Oct 24, 2019
Merged

actions/config: ensure config file is created with mode 0644 #152

merged 1 commit into from
Oct 24, 2019

Conversation

ebiggers
Copy link
Collaborator

If the user has set a restrictive umask, e.g. 0077, then
/etc/fscrypt.conf would be created without the world-readable bit set.
Fix it by overriding the umask when creating the file.

Resolves #151

@ebiggers ebiggers mentioned this pull request Sep 29, 2019
Copy link
Member

@josephlr josephlr left a comment

Choose a reason for hiding this comment

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

This looks good, and thanks for adding the test.

Just a few minor nits.

configFile, err := os.OpenFile(ConfigFileLocation, createFlags, configPermissions)
unix.Umask(oldMask)
Copy link
Member

Choose a reason for hiding this comment

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

I initially though this should be a defer in case os.OpenFile panics, but now I realize it's OK, as we shouldn't open any additional files on panic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I decided to change it to just do the OpenFile() in a helper function that overrides umask.

t.Fatal(err)
}
ConfigFileLocation = tempFile.Name()
os.Remove(ConfigFileLocation)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this os.Remove and the defer os.Remove below?

It seems like it might be better to just use ioutil.TempDir and then cleanup everything in a single call.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good idea. I changed it to do that instead.

ConfigFileLocation = tempFile.Name()
os.Remove(ConfigFileLocation)

err = CreateConfigFile(time.Millisecond, false)
Copy link
Member

Choose a reason for hiding this comment

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

Combine this line with the line below, for style consistancy.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

If the user has set a restrictive umask, e.g. 0077, then
/etc/fscrypt.conf would be created without the world-readable bit set.
Fix it by overriding the umask when creating the file.

Resolves #151
@ebiggers
Copy link
Collaborator Author

@josephlr, any more comments on this pull request?

@josephlr josephlr merged commit a5b805f into google:master Oct 24, 2019
@ebiggers ebiggers deleted the fscrypt-conf-mode branch October 24, 2019 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auto unlock not working
2 participants