| 1 | package clusterscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/cluster`/ |
| 2 | |
| 3 | import ( |
| 4 | "contextscip-go gomod github.com/golang/go/src go1.20 context/" |
| 5 | "fmtscip-go gomod github.com/golang/go/src go1.20 fmt/" |
| 6 | "timescip-go gomod github.com/golang/go/src go1.20 time/" |
| 7 | |
| 8 | crcerrorsscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/errors`/ "github.com/crc-org/crc/v2/pkg/crc/errorsscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/errors`/" |
| 9 | "github.com/crc-org/crc/v2/pkg/crc/loggingscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/logging`/" |
| 10 | "github.com/crc-org/crc/v2/pkg/crc/ocscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/oc`/" |
| 11 | "github.com/crc-org/crc/v2/pkg/crc/sshscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/ssh`/" |
| 12 | |
| 13 | k8scertsscip-go gomod k8s.io/api v0.27.4 `k8s.io/api/certificates/v1beta1`/ "k8s.io/api/certificates/v1beta1scip-go gomod k8s.io/api v0.27.4 `k8s.io/api/certificates/v1beta1`/" |
| 14 | ) |
| 15 | |
| 16 | func isPendingscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/cluster`/isPending().(csr *k8scertsscip-go gomod k8s.io/api v0.27.4 `k8s.io/api/certificates/v1beta1`/.CertificateSigningRequestscip-go gomod k8s.io/api v0.27.4 `k8s.io/api/certificates/v1beta1`/CertificateSigningRequest#) bool { |
| 17 | return len(csr.Statusscip-go gomod k8s.io/api v0.27.4 `k8s.io/api/certificates/v1beta1`/CertificateSigningRequest#Status..Conditionsscip-go gomod k8s.io/api v0.27.4 `k8s.io/api/certificates/v1beta1`/CertificateSigningRequestStatus#Conditions.) == 0 && len(csr.Statusscip-go gomod k8s.io/api v0.27.4 `k8s.io/api/certificates/v1beta1`/CertificateSigningRequest#Status..Certificatescip-go gomod k8s.io/api v0.27.4 `k8s.io/api/certificates/v1beta1`/CertificateSigningRequestStatus#Certificate.) == 0 |
| 18 | } |
| 19 | |
| 20 | func approvePendingCSRsscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/cluster`/approvePendingCSRs().(ctx contextscip-go gomod github.com/golang/go/src go1.20 context/.Contextscip-go gomod github.com/golang/go/src go1.20 context/Context#, ocConfig ocscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/oc`/.Configscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/oc`/Config#, expectedSignerName string) error { |
| 21 | return crcerrorsscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/errors`/.Retryscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/errors`/Retry().(ctx, 8*timescip-go gomod github.com/golang/go/src go1.20 time/.Minutescip-go gomod github.com/golang/go/src go1.20 time/Minute., func() error { |
| 22 | csrs, err := getCSRListscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/cluster`/getCSRList().(ctx, ocConfig, expectedSignerName) |
| 23 | if err != nil { |
| 24 | return &crcerrorsscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/errors`/.RetriableErrorscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/errors`/RetriableError#{Errscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/errors`/RetriableError#Err.: err} |
| 25 | } |
| 26 | csrsApproved := false |
| 27 | for i := range csrs.Itemsscip-go gomod k8s.io/api v0.27.4 `k8s.io/api/certificates/v1beta1`/CertificateSigningRequestList#Items. { |
| 28 | csr := &csrs.Itemsscip-go gomod k8s.io/api v0.27.4 `k8s.io/api/certificates/v1beta1`/CertificateSigningRequestList#Items.[i] |
| 29 | if !isPendingscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/cluster`/isPending().(csr) { |
| 30 | continue |
| 31 | } |
| 32 | loggingscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/logging`/.Debugfscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/logging`/Debugf().("Approving csr %s (signerName: %s)", csr.ObjectMetascip-go gomod k8s.io/api v0.27.4 `k8s.io/api/certificates/v1beta1`/CertificateSigningRequest#ObjectMeta..Namescip-go gomod k8s.io/apimachinery v0.27.4 `k8s.io/apimachinery/pkg/apis/meta/v1`/ObjectMeta#Name., expectedSignerName) |
| 33 | _, stderr, err := ocConfig.RunOcCommandscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/oc`/Config#RunOcCommand().("adm", "certificate", "approve", csr.ObjectMetascip-go gomod k8s.io/api v0.27.4 `k8s.io/api/certificates/v1beta1`/CertificateSigningRequest#ObjectMeta..Namescip-go gomod k8s.io/apimachinery v0.27.4 `k8s.io/apimachinery/pkg/apis/meta/v1`/ObjectMeta#Name.) |
| 34 | if err != nil { |
| 35 | return fmtscip-go gomod github.com/golang/go/src go1.20 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.20 fmt/Errorf().("Not able to approve csr (%v : %s)", err, stderr) |
| 36 | } |
| 37 | csrsApproved = true |
| 38 | } |
| 39 | if !csrsApproved { |
| 40 | return &crcerrorsscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/errors`/.RetriableErrorscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/errors`/RetriableError#{Errscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/errors`/RetriableError#Err.: fmtscip-go gomod github.com/golang/go/src go1.20 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.20 fmt/Errorf().("No Pending CSR with signerName %s", expectedSignerName)} |
| 41 | } |
| 42 | return nil |
| 43 | }, timescip-go gomod github.com/golang/go/src go1.20 time/.Secondscip-go gomod github.com/golang/go/src go1.20 time/Second.*5) |
| 44 | } |
| 45 | |
| 46 | func ApproveCSRAndWaitForCertsRenewalscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/cluster`/ApproveCSRAndWaitForCertsRenewal().(ctx contextscip-go gomod github.com/golang/go/src go1.20 context/.Contextscip-go gomod github.com/golang/go/src go1.20 context/Context#, sshRunner *sshscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/ssh`/.Runnerscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/ssh`/Runner#, ocConfig ocscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/oc`/.Configscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/oc`/Config#, client, server bool) error { |
| 47 | const ( |
| 48 | kubeletClientSignerName = "kubernetes.io/kube-apiserver-client-kubelet" |
| 49 | authClientSignerName = "kubernetes.io/kube-apiserver-client" |
| 50 | ) |
| 51 | |
| 52 | // First, kubelet starts and tries to connect to API server. If its certificate is expired, it asks for a new one |
| 53 | // Admin needs to approve it. The Kubernetes controller manager will then issue the cert, kubelet will fetch it and use it. |
| 54 | // Kubelet stores the cert in /var/lib/kubelet/pki/kubelet-client-current.pem |
| 55 | if client { |
| 56 | loggingscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/logging`/.Infoscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/logging`/Info().("Kubelet client certificate has expired, renewing it... [will take up to 8 minutes]") |
| 57 | if err := approvePendingCSRsscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/cluster`/approvePendingCSRs().(ctx, ocConfig, kubeletClientSignerName); err != nil { |
| 58 | loggingscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/logging`/.Debugfscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/logging`/Debugf().("Error approving pending kube-apiserver-client-kubelet CSRs: %v", err) |
| 59 | return err |
| 60 | } |
| 61 | |
| 62 | // This deleteCSR block only needed for 4.8 version and should be removed when we start shipping 4.9 or |
| 63 | // if the patch backported to 4.8 z stream. |
| 64 | // https://github.com/openshift/library-go/pull/1190 and https://github.com/openshift/cluster-authentication-operator/pull/475 |
| 65 | // https://bugzilla.redhat.com/show_bug.cgi?id=1997906 |
| 66 | if err := deleteCSRscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/cluster`/deleteCSR().(ctx, ocConfig, authClientSignerName); err != nil { |
| 67 | loggingscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/logging`/.Debugfscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/logging`/Debugf().("Error deleting openshift-authenticator csr: %v", err) |
| 68 | return err |
| 69 | } |
| 70 | if err := crcerrorsscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/errors`/.Retryscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/errors`/Retry().(ctx, 5*timescip-go gomod github.com/golang/go/src go1.20 time/.Minutescip-go gomod github.com/golang/go/src go1.20 time/Minute., waitForCertRenewalscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/cluster`/waitForCertRenewal().(sshRunner, KubeletClientCertscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/cluster`/KubeletClientCert.), timescip-go gomod github.com/golang/go/src go1.20 time/.Secondscip-go gomod github.com/golang/go/src go1.20 time/Second.*5); err != nil { |
| 71 | loggingscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/logging`/.Debugfscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/logging`/Debugf().("Error approving pending kube-apiserver-client-kubelet CSR: %v", err) |
| 72 | return err |
| 73 | } |
| 74 | } |
| 75 | // API server needs to connect to kubelet for some features like logs, port forwards. This communication is backed by a cert |
| 76 | // store in /var/lib/kubelet/pki/kubelet-server-current.pem |
| 77 | // After kubelet connected to the API server, if the serving cert is expireed, kubelet asks for a new CSR. |
| 78 | // This CSR is automatically approved by the cluster-machine-approver. The k8s controller manager issues the cert and kubelet fetches it. |
| 79 | if server { |
| 80 | loggingscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/logging`/.Infoscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/logging`/Info().("Kubelet serving certificate has expired, waiting for automatic renewal... [will take up to 8 minutes]") |
| 81 | return crcerrorsscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/errors`/.Retryscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/errors`/Retry().(ctx, 5*timescip-go gomod github.com/golang/go/src go1.20 time/.Minutescip-go gomod github.com/golang/go/src go1.20 time/Minute., waitForCertRenewalscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/cluster`/waitForCertRenewal().(sshRunner, KubeletServerCertscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/cluster`/KubeletServerCert.), timescip-go gomod github.com/golang/go/src go1.20 time/.Secondscip-go gomod github.com/golang/go/src go1.20 time/Second.*5) |
| 82 | } |
| 83 | return nil |
| 84 | } |
| 85 | |
| 86 | func waitForCertRenewalscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/cluster`/waitForCertRenewal().(sshRunner *sshscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/ssh`/.Runnerscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/ssh`/Runner#, cert string) func() error { |
| 87 | return func() error { |
| 88 | expired, err := checkCertValidityscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/cluster`/checkCertValidity().(sshRunner, cert) |
| 89 | if err != nil { |
| 90 | return err |
| 91 | } |
| 92 | if !expired { |
| 93 | return nil |
| 94 | } |
| 95 | return &crcerrorsscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/errors`/.RetriableErrorscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/errors`/RetriableError#{Errscip-go gomod github.com/crc-org/crc/v2 . `github.com/crc-org/crc/v2/pkg/crc/errors`/RetriableError#Err.: fmtscip-go gomod github.com/golang/go/src go1.20 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.20 fmt/Errorf().("certificate %s still expired", cert)} |
| 96 | } |
| 97 | } |