-
Notifications
You must be signed in to change notification settings - Fork 2.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 cert rotation command #4495
Add cert rotation command #4495
Conversation
pkg/cli/cert/cert.go
Outdated
|
||
for _, cert := range certList { | ||
if err := os.Remove(cert); err == nil { | ||
logrus.Infof("Certificate %s is deleted", cert) |
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 wonder if we could replace "deleted" with "processed" or something lighter.
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.
A couple of nits; are we doing enough safe-guarding to prevent a user from accidentally rotating certs on a K3s cluster while K3s is still running? What happens if this command is run on a live cluster?
const regenerateDynamicListenerFile = "dynamic-cert-regenerate" | ||
dynamicListenerRegenFilePath := filepath.Join(c.config.DataDir, "tls", regenerateDynamicListenerFile) | ||
if _, err := os.Stat(dynamicListenerRegenFilePath); err == nil { | ||
os.Remove(dynamicListenerRegenFilePath) |
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.
What happens if the certificate rotation fails and we are prematurely removing this file?
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.
These files are backed up before this operation begins. We output the path to the backup directory.
Signed-off-by: galal-hussein <[email protected]>
Signed-off-by: Brian Downs <[email protected]>
Signed-off-by: galal-hussein <[email protected]>
Signed-off-by: galal-hussein <[email protected]>
d8e1481
to
ab6aede
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
Signed-off-by: galal-hussein <[email protected]>
4cf57b4
to
ec12317
Compare
Signed-off-by: galal-hussein <[email protected]>
@brandond Added fixes according to your comments, and to add some context around the UX, here what the user will see if certificate rotate command is issued:
Without the debug mode the user will just see the services that will be rotated |
Signed-off-by: galal-hussein <[email protected]>
LGTM; are the test failures legit or a flake? |
I think flakes, I will restart |
* Add cert rotation command Signed-off-by: galal-hussein <[email protected]> * add function to check for dynamic listener file Signed-off-by: Brian Downs <[email protected]> * Add dynamiclistener cert rotation support Signed-off-by: galal-hussein <[email protected]> * fixes to the cert rotation Signed-off-by: galal-hussein <[email protected]> * fix ci tests Signed-off-by: galal-hussein <[email protected]> * fixes to certificate rotation command Signed-off-by: galal-hussein <[email protected]> * more fixes Signed-off-by: galal-hussein <[email protected]> Co-authored-by: Brian Downs <[email protected]>
* Add cert rotation command Signed-off-by: galal-hussein <[email protected]> * add function to check for dynamic listener file Signed-off-by: Brian Downs <[email protected]> * Add dynamiclistener cert rotation support Signed-off-by: galal-hussein <[email protected]> * fixes to the cert rotation Signed-off-by: galal-hussein <[email protected]> * fix ci tests Signed-off-by: galal-hussein <[email protected]> * fixes to certificate rotation command Signed-off-by: galal-hussein <[email protected]> * more fixes Signed-off-by: galal-hussein <[email protected]> Co-authored-by: Brian Downs <[email protected]>
* Add cert rotation command Signed-off-by: galal-hussein <[email protected]> * add function to check for dynamic listener file Signed-off-by: Brian Downs <[email protected]> * Add dynamiclistener cert rotation support Signed-off-by: galal-hussein <[email protected]> * fixes to the cert rotation Signed-off-by: galal-hussein <[email protected]> * fix ci tests Signed-off-by: galal-hussein <[email protected]> * fixes to certificate rotation command Signed-off-by: galal-hussein <[email protected]> * more fixes Signed-off-by: galal-hussein <[email protected]> Co-authored-by: Brian Downs <[email protected]>
* Add cert rotation command Signed-off-by: galal-hussein <[email protected]> * add function to check for dynamic listener file Signed-off-by: Brian Downs <[email protected]> * Add dynamiclistener cert rotation support Signed-off-by: galal-hussein <[email protected]> * fixes to the cert rotation Signed-off-by: galal-hussein <[email protected]> * fix ci tests Signed-off-by: galal-hussein <[email protected]> * fixes to certificate rotation command Signed-off-by: galal-hussein <[email protected]> * more fixes Signed-off-by: galal-hussein <[email protected]> Co-authored-by: Brian Downs <[email protected]>
* Add cert rotation command (#4495) * Add cert rotation command Signed-off-by: galal-hussein <[email protected]> * add function to check for dynamic listener file Signed-off-by: Brian Downs <[email protected]> * Add dynamiclistener cert rotation support Signed-off-by: galal-hussein <[email protected]> * fixes to the cert rotation Signed-off-by: galal-hussein <[email protected]> * fix ci tests Signed-off-by: galal-hussein <[email protected]> * fixes to certificate rotation command Signed-off-by: galal-hussein <[email protected]> * more fixes Signed-off-by: galal-hussein <[email protected]> Co-authored-by: Brian Downs <[email protected]> * Upgrade dynamic listener Signed-off-by: galal-hussein <[email protected]> Co-authored-by: Brian Downs <[email protected]>
* Add cert rotation command (#4495) * Add cert rotation command Signed-off-by: galal-hussein <[email protected]> * add function to check for dynamic listener file Signed-off-by: Brian Downs <[email protected]> * Add dynamiclistener cert rotation support Signed-off-by: galal-hussein <[email protected]> * fixes to the cert rotation Signed-off-by: galal-hussein <[email protected]> * fix ci tests Signed-off-by: galal-hussein <[email protected]> * fixes to certificate rotation command Signed-off-by: galal-hussein <[email protected]> * more fixes Signed-off-by: galal-hussein <[email protected]> Co-authored-by: Brian Downs <[email protected]> * Upgrade dynamic listener Signed-off-by: galal-hussein <[email protected]> * go mod tidy Signed-off-by: galal-hussein <[email protected]> Co-authored-by: Brian Downs <[email protected]>
* Add cert rotation command (#4495) * Add cert rotation command Signed-off-by: galal-hussein <[email protected]> * add function to check for dynamic listener file Signed-off-by: Brian Downs <[email protected]> * Add dynamiclistener cert rotation support Signed-off-by: galal-hussein <[email protected]> * fixes to the cert rotation Signed-off-by: galal-hussein <[email protected]> * fix ci tests Signed-off-by: galal-hussein <[email protected]> * fixes to certificate rotation command Signed-off-by: galal-hussein <[email protected]> * more fixes Signed-off-by: galal-hussein <[email protected]> Co-authored-by: Brian Downs <[email protected]> * Upgrade dynamic listener Signed-off-by: galal-hussein <[email protected]> * go mod tidy Signed-off-by: galal-hussein <[email protected]> Co-authored-by: Brian Downs <[email protected]>
* Add cert rotation command Signed-off-by: galal-hussein <[email protected]> * add function to check for dynamic listener file Signed-off-by: Brian Downs <[email protected]> * Add dynamiclistener cert rotation support Signed-off-by: galal-hussein <[email protected]> * fixes to the cert rotation Signed-off-by: galal-hussein <[email protected]> * fix ci tests Signed-off-by: galal-hussein <[email protected]> * fixes to certificate rotation command Signed-off-by: galal-hussein <[email protected]> * more fixes Signed-off-by: galal-hussein <[email protected]> Co-authored-by: Brian Downs <[email protected]> Co-authored-by: Brian Downs <[email protected]>
Validated cert rotation using the steps outlined roughly above.
k3s version v1.20.13+k3s-6d3c31ad (6d3c31ad) k3s version v1.21.7+k3s-7b629008 (7b629008) k3s version v1.22.4+k3s-2dc4e2c3 (2dc4e2c3) |
Signed-off-by: galal-hussein [email protected]
Proposed Changes
Types of Changes
New Feature
Verification
k3s cert rotate
This command will back up tls certs for server and agent excepts for CA certs and service key, and then remove these files allowing k3s on the next restart to regenerate the files.
Linked Issues
User-Facing Change
A new command is added to k3s
cert
which supposed to contain subcommands for certificate management, this PR include therotate
subcommand which will rotate the TLS certs for server or agent.