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

Small CSR tweaks #1758

Merged
merged 2 commits into from
Jan 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions pkg/tasks/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,9 @@ func saveCABundleOnControlPlane(s *state.State, _ *kubeoneapi.HostConfig, conn s
}

func approvePendingCSR(s *state.State, node *kubeoneapi.HostConfig, conn ssh.Connection) error {
s.Logger.Infof("Looking for CSRs to approve...")

// Need to wait for the second CSR to appear
time.Sleep(20 * time.Second)
sleepTime := 20 * time.Second
s.Logger.Infof("Waiting %s for CSRs to approve...", sleepTime)
time.Sleep(sleepTime)

csrList := certificatesv1.CertificateSigningRequestList{}
if err := s.DynamicClient.List(s.Context, &csrList); err != nil {
Expand Down Expand Up @@ -235,26 +234,26 @@ func approvePendingCSR(s *state.State, node *kubeoneapi.HostConfig, conn ssh.Con

func validateCSR(spec certificatesv1.CertificateSigningRequestSpec, node *kubeoneapi.HostConfig) error {
if fmt.Sprintf("%s:%s", nodeUser, node.Hostname) != spec.Username {
return errors.New("")
return fmt.Errorf("CSR username %q and node hostname %q do not match", spec.Username, node.Hostname)
Copy link
Member

Choose a reason for hiding this comment

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

I guess this should be errors.New instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

I like Errorf better since it manifests that "format" is used

Copy link
Member

Choose a reason for hiding this comment

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

There’s also Errorf in the errors package, so we get to use same package everywhere. Just a nit though.

}

if !sets.NewString(spec.Groups...).HasAll(groupNodes, groupAuthenticated) {
return errors.New("")
return errors.New("CSR groups is expecter to be an authenticated node")
}

for _, usage := range spec.Usages {
if !isUsageInUsageList(usage, allowedUsages) {
return errors.New("")
return errors.New("CSR usages is invalid")
}
}

csrBlock, rest := pem.Decode(spec.Request)
if csrBlock == nil {
return fmt.Errorf("no certificate request found for the given CSR")
return errors.New("no certificate request found for the given CSR")
}

if len(rest) != 0 {
return fmt.Errorf("found more than one PEM encoded block in the result")
return errors.New("found more than one PEM encoded block in the result")
}

certReq, err := x509.ParseCertificateRequest(csrBlock.Bytes)
Expand Down