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

Changes for cli command to renew certificate #912

Merged
merged 12 commits into from
Mar 23, 2022

Conversation

pravinpushkar
Copy link
Contributor

@pravinpushkar pravinpushkar commented Mar 4, 2022

Signed-off-by: Pravin Pushkar ppushkar@microsoft.com

Description

Adding new commands to renew expiring certificate.

# Generates new root and issuer certificates for kubernetest cluster
dapr mtls renew-certificate -k --valid-until <no of days> --restart

# Uses existing private root.key to generate new root and issuer certificates for kubernetes cluster
dapr mtls renew-certificate -k --certificate-password-file myprivatekey.key --valid-until <no of days>

# Rotates certificate of your kubernetes cluster with provided ca.cert, issuer.crt and issuer.key file path
dapr mtls renew-certificate -k --ca-root-certificate <ca.crt> --issuer-private-key <issuer.key> --issuer-public-certificate <issuer.crt> --restart

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

Please reference the issue this PR will close: #892

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

@pravinpushkar pravinpushkar requested review from a team as code owners March 4, 2022 14:20
@pravinpushkar pravinpushkar force-pushed the feature/renew_cert branch 3 times, most recently from a650191 to dc38140 Compare March 9, 2022 11:01
Short: "Rotates Dapr root certificate of your kubernetes cluster",
Example: `
# Generates new root and issuer certificates for kubernetest cluster
dapr mtls renew-cert -k --valid-until <no of days> --restart true
Copy link
Member

Choose a reason for hiding this comment

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

Other mtls commands don't seem to support the -k flag. Is that expected?

dapr mtls expiry -k
Error: unknown shorthand flag: 'k' in -k

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is expected in case we want to enhance it for standalone.
export and expiry does not make much sense for standalone mode imo.
In general, I think it should be with the specific subcommands whether -k flag is needed or not.

Copy link
Member

Choose a reason for hiding this comment

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

If mtls only supports k8s, then the subcommands should also enforce it ideally. Instead of silently failing, we should complain that it's a required flag and only k8s mode is supported. This can be tracked separately, but I think we should do it. Thoughts?

/cc @mukundansundar

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will be adding RenewCertificateCmd.MarkFlagRequired("kubernetes") in new commit.
We can enforce this flag through all subcommands but it will change the current behavior from dapr mtls expiry to of dapr mts expiry -k
@mukundansundar

@codecov
Copy link

codecov bot commented Mar 9, 2022

Codecov Report

Merging #912 (038f841) into master (ce0af7c) will decrease coverage by 1.41%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master     #912      +/-   ##
==========================================
- Coverage   22.31%   20.90%   -1.42%     
==========================================
  Files          30       32       +2     
  Lines        1734     1851     +117     
==========================================
  Hits          387      387              
- Misses       1293     1410     +117     
  Partials       54       54              
Impacted Files Coverage Δ
pkg/kubernetes/common.go 0.00% <0.00%> (ø)
pkg/kubernetes/renew_certificate.go 0.00% <0.00%> (ø)
pkg/kubernetes/upgrade.go 21.91% <0.00%> (+3.09%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ce0af7c...038f841. Read the comment docs.

@pravinpushkar pravinpushkar changed the title [WIP] Changes for cli command to renew certificate Changes for cli command to renew certificate Mar 11, 2022
@pravinpushkar pravinpushkar force-pushed the feature/renew_cert branch 4 times, most recently from 82feed2 to e802685 Compare March 14, 2022 17:49
@artursouza artursouza self-assigned this Mar 15, 2022
@pravinpushkar pravinpushkar force-pushed the feature/renew_cert branch 2 times, most recently from 4045818 to 97ac56f Compare March 21, 2022 06:02
yaron2
yaron2 previously requested changes Mar 21, 2022
@pravinpushkar pravinpushkar force-pushed the feature/renew_cert branch 3 times, most recently from 8802c82 to 9be44d0 Compare March 22, 2022 09:16
Copy link
Collaborator

@mukundansundar mukundansundar left a comment

Choose a reason for hiding this comment

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

few more changes please ...

logErrorAndExit(err)
}
} else if privateKey != "" {
print.InfoStatusEvent(os.Stdout, "Using password file to generate root certificate")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
print.InfoStatusEvent(os.Stdout, "Using password file to generate root certificate")
print.InfoStatusEvent(os.Stdout, "Using existing private key file to generate root certificate")

Copy link
Collaborator

Choose a reason for hiding this comment

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

This change needs to be done?

assert.Contains(t, output, "Certificate rotation is successful!")

// remove cert directory created earlier.
os.RemoveAll("./certs")
Copy link
Collaborator

Choose a reason for hiding this comment

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

not like to have a folder created by one test removed by another .... can this be in the Kubernetes_test.go file instead of common ?
A single flow ...

  1. create a folder ./certs
  2. Run GenerateNewCerts -- export cert to the previously created folder
  3. Run the UserProvidedNewCertsAndRenew test ....
  4. Remove the ./certs folder that was created in step 1

1 and 4 in the Test function ... and the rest can be what it is now ...

@mukundansundar
Copy link
Collaborator

@yaron2 @artursouza Don't we also need to restart sidecar-injector and dashboard as part of certificate rotation ?

@yaron2
Copy link
Member

yaron2 commented Mar 22, 2022

@yaron2 @artursouza Don't we also need to restart sidecar-injector and dashboard as part of certificate rotation ?

Sentry watches certs from the filesystem.

artursouza
artursouza previously approved these changes Mar 22, 2022
@yaron2 yaron2 dismissed their stale review March 22, 2022 17:21

Addressed

yaron2
yaron2 previously requested changes Mar 22, 2022
@mukundansundar
Copy link
Collaborator

During release validations during endgame ... test this against a cluster running apps and validate working.

@mukundansundar
Copy link
Collaborator

@pravinpushkar Wait for all containers to be up needs to be added in this PR.

Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>
Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>
Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>
Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>
Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>
Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>
Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>
Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>
Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>
Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>
Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>
Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>
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.

Renew or Replace auto-generated TLS certificates using the CLI
5 participants