-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add optional state file permissions #2238
Conversation
Should we add a test for this? |
824dfd1
to
0402537
Compare
I wanted to write a test and searched for tests related to |
0402537
to
10758b5
Compare
History.md
Outdated
@@ -49,6 +49,9 @@ | |||
* JSON parse cluster worker stats instead of regex (#2124) | |||
* Support parallel tests in verbose progress reporting (#2223) | |||
|
|||
* Security | |||
* New configuration option to set state file permissions (#2238) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be added under "features" rather than a new section
It's possible there are no tests for state_path. You don't have to write tests for that, but we do need tests for this. What's the current file permissions of a created statefile today? What information is in the statefile that would need to protected from read or write? |
I guess it depends on the umask, but 644 in most conditions. See theforeman/foreman#7578 (comment) |
Do you think we should change the default here? |
I think a default of 0640 is a more sane default but may break existing deployments. Given the security nature of it, I think that's fine though as long as there's a clear note in the changelog. |
b8f0423
to
9cd118b
Compare
I will look into this.
control_url, control_auth_token - these will let any user control the puma server. |
Tests are added now. |
I'm not comfortable with changing people's file permissions w/o them setting it themselves, so I'll be merging this as-is. Thank you so much for adding tests btw 🙇 |
Yes, that was my thought too. Lets get this optional for now and make it default in future if needed.
Absolutely! |
eeda1b9
to
ad8a4c4
Compare
Squashed commits and rebased with master. |
no idea why |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternative:
require 'tmpdir'
Dir.mktmpdir do |dir|
tmp_file = File.join(tmp_file, 'puma.state')
# ... rest of the code
end
This means you don't need to think about cleanup. An additional benefit is that you're sure that the file doesn't exist beforehand. Thinking about that also triggered another review comment.
lib/puma/state_file.rb
Outdated
File.write path, YAML.dump(@options) | ||
File.chmod(permission, path) if permission |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a race condition here: the file is created possibly insecure and then fixed. A more secure way is to ensure permissions before writing. For example (untested):
File.write path, YAML.dump(@options) | |
File.chmod(permission, path) if permission | |
if permission | |
FileUtils.touch(path) | |
File.chmod(permission, path) | |
end | |
File.write path, YAML.dump(@options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you can do this in a single transaction block that might be a bit more clean:
File.open(path) do |file|
file.chmod(permission) if permission
file.write(YAML.dump(@options))
end
Appreciate your thoughtful reviews @ekohl 🙏 |
4c09b5c
to
84a28bd
Compare
Review comments updated, commits squashed. |
It looks 2 of the windows tests are failing, I will check |
JFYI, Windows testing of Ruby was non-existent with Ruby 2.2 and 2.3. The issue is whatever is creating the paths like: See: Not sure where it's happening... |
58287b2
to
df8984e
Compare
I spent a good amount of time looking into the windows 2.2/2.3 failures and figured Now all the commits are squashed and PR rebased. Let me know if any questions. |
Before this commit, it was possible that the puma.state file would be world readable which may not be desirable in production environments. This introduces a new optional configuration option to set desired state file permissions.
df8984e
to
cc05732
Compare
it doesn't look like the mac 2.7 failure is related to this PR. |
I don't have permissions to remove |
@nateberkopec @ekohl let me know what you think about the recent changes. Our foreman PR is blocked on this. Any help is appreciated to get this going and get merged. Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, but I'm not a maintainer on this project so I might be missing things.
@nateberkopec let me know if you need anything before merging this. |
thank you @nateberkopec |
Thanks @nateberkopec ! To help us with planning, when do you think we will see a release with this fix in it? |
@nateberkopec Any chance we could get a 4.3.6 with this change in it? the @theforeman project would be grateful |
Description
Before this commit, it was possible that the puma.state file would be world-readable which may not be desirable in production environments. This introduces a new optional configuration option to set desired state file permissions.
Your checklist for this pull request
[changelog skip]
the pull request title.[ci skip]
to the title of the PR.#issue
" to the PR description or my commit messages.