-
Notifications
You must be signed in to change notification settings - Fork 4.5k
cmd/tls: set explicit file permissions for generated certs #22286
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
Conversation
d4a7ff7
to
351d533
Compare
351d533
to
6d2c09f
Compare
6d2c09f
to
3ac8c2d
Compare
3ac8c2d
to
95eb768
Compare
95eb768
to
8589b99
Compare
# tput complains if this isn't set to something. | ||
TERM: ansi | ||
# TODO: Disabling the "Compatibility Integration Tests" test temporarily, need to enable again once dependent pipeline issues are fixed. |
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.
Is the pipeline broken from the changes or was it broken earlier?
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.
Yes, it's an existing issue. This issue is being tracked internally here.
@@ -82,12 +82,14 @@ func (c *cmd) Run(args []string) int { | |||
return 1 | |||
} | |||
|
|||
if err := file.WriteAtomicWithPerms(certFileName, []byte(ca), 0755, 0666); err != nil { | |||
// public CA cert file | |||
if err := file.WriteAtomicWithPerms(certFileName, []byte(ca), 0755, 0644); err != nil { |
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 would recommend moving 0755 and 0644 to a constant variable with good naming for readability purposes
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.
Now updated to use variables.
@@ -193,12 +193,14 @@ func (c *cmd) Run(args []string) int { | |||
return 1 | |||
} | |||
|
|||
if err := file.WriteAtomicWithPerms(certFileName, []byte(pub), 0755, 0666); err != nil { | |||
// public cert | |||
if err := file.WriteAtomicWithPerms(certFileName, []byte(pub), 0755, 0644); err != nil { |
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 would recommend moving 0755 and 0644 to a constant variable for better readability purposes
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.
Updated the PR now
2383d3b
to
7d8f8a2
Compare
.changelog/22286.txt
Outdated
@@ -0,0 +1,3 @@ | |||
```release-note:security | |||
(cmd/tls) update ca and cert create to reduce excessive file perms for public creds |
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.
(cmd/tls)
is not adhering to specs - https://github.com/hashicorp/consul/blob/main/docs/contributing/add-a-changelog-entry.md
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.
Fixed it now
7d8f8a2
to
831e9df
Compare
831e9df
to
5cc9463
Compare
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.
LGTM
5cc9463
to
f0cd8be
Compare
Description
Consul CLI's tls create command was generating some sensitive files (e.g.
consul tls ca create -server
) that had excessive permissions at0666
for public certs created and it should be0644
. Updated the code to use0644
file perms when creating sensitive files with ca and certs.NOTE: disabled Compatibility Integration Tests until pipeline upgrade is in place
Testing & Reproduction steps
umask 000
consul tls ca create -domain=example.test
and list the directory to view generated files withls -lah
with excessive perms.consul tls cert create -server
to see similar resultsumask 022
Links
https://hashicorp.atlassian.net/browse/SECVULN-8634
PR Checklist