Skip to content

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

Merged
merged 5 commits into from
May 23, 2025

Conversation

sujay-hashicorp
Copy link
Contributor

@sujay-hashicorp sujay-hashicorp commented Apr 23, 2025

Description

Consul CLI's tls create command was generating some sensitive files (e.g. consul tls ca create -server) that had excessive permissions at 0666 for public certs created and it should be 0644. Updated the code to use 0644 file perms when creating sensitive files with ca and certs.
NOTE: disabled Compatibility Integration Tests until pipeline upgrade is in place

Testing & Reproduction steps

  1. Update default OS masking to view actual code behaviour: umask 000
  2. Run consul tls ca create -domain=example.test and list the directory to view generated files with ls -lah with excessive perms.
  3. Run consul tls cert create -server to see similar results
  4. Revert OS level masking to default: umask 022

Links

https://hashicorp.atlassian.net/browse/SECVULN-8634

PR Checklist

  • updated test coverage
  • external facing docs updated
  • appropriate backport labels added
  • not a security concern

@sujay-hashicorp sujay-hashicorp requested a review from a team as a code owner April 23, 2025 09:24
Copy link

hashicorp-cla-app bot commented Apr 23, 2025

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added the theme/cli Flags and documentation for the CLI interface label Apr 23, 2025
@sujay-hashicorp sujay-hashicorp added the backport/all Apply backports for all active releases per .release/versions.hcl label Apr 23, 2025
sujay-hashicorp added a commit that referenced this pull request Apr 23, 2025
sujay-hashicorp added a commit that referenced this pull request May 7, 2025
@sujay-hashicorp sujay-hashicorp force-pushed the sujay/tls-file-perms branch from d4a7ff7 to 351d533 Compare May 7, 2025 05:50
sujay-hashicorp added a commit that referenced this pull request May 12, 2025
sujay-hashicorp added a commit that referenced this pull request May 15, 2025
sujay-hashicorp added a commit that referenced this pull request May 15, 2025
sujay-hashicorp added a commit that referenced this pull request May 20, 2025
# 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.

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?

Copy link
Contributor Author

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 {

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

Copy link
Contributor Author

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 {

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the PR now

@sujay-hashicorp sujay-hashicorp requested a review from sriramr98 May 23, 2025 10:36
@sujay-hashicorp sujay-hashicorp force-pushed the sujay/tls-file-perms branch 2 times, most recently from 2383d3b to 7d8f8a2 Compare May 23, 2025 10:49
sriramr98
sriramr98 previously approved these changes May 23, 2025
@@ -0,0 +1,3 @@
```release-note:security
(cmd/tls) update ca and cert create to reduce excessive file perms for public creds
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed it now

sreeram77
sreeram77 previously approved these changes May 23, 2025
Copy link
Member

@sreeram77 sreeram77 left a comment

Choose a reason for hiding this comment

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

LGTM

@sujay-hashicorp sujay-hashicorp merged commit d13c81f into main May 23, 2025
94 checks passed
@sujay-hashicorp sujay-hashicorp deleted the sujay/tls-file-perms branch May 23, 2025 13:09
@hc-github-team-consul-core hc-github-team-consul-core added backport/1.21 Changes are backported to 1.21 backport/ent/1.18 Changes are backported to 1.18 ent backport/ent/1.19 Changes are backported to 1.19 ent backport/ent/1.20 backport to ent 1.20 labels May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/all Apply backports for all active releases per .release/versions.hcl backport/ent/1.18 Changes are backported to 1.18 ent backport/ent/1.19 Changes are backported to 1.19 ent backport/ent/1.20 backport to ent 1.20 backport/1.21 Changes are backported to 1.21 theme/cli Flags and documentation for the CLI interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants