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

The webhook not start because of certFile check when deploy g8r out of cluster #41

Closed
Poor12 opened this issue Apr 24, 2022 · 4 comments

Comments

@Poor12
Copy link

Poor12 commented Apr 24, 2022

I have a special scene which g8r is deployed out of cluster and I configure the --kubeconfig option in controller-runtime to make g8r watch the user behavior in the cluster which I would like to.

In this case, cert-controller will generate ca and update the secret which is in the remote cluster. However, the local file, such as tls.crt in certDir will not update. So, because of the certFile check below, the webhook will not start.

// ensureCertsMounted ensure the cert files exist.
func (cr *CertRotator) ensureCertsMounted() {
checkFn := func() (bool, error) {
certFile := cr.CertDir + "/" + certName
_, err := os.Stat(certFile)
if err == nil {
return true, nil
}
return false, nil
}
if err := wait.ExponentialBackoff(wait.Backoff{
Duration: 1 * time.Second,
Factor: 2,
Jitter: 1,
Steps: 10,
}, checkFn); err != nil {
crLog.Error(err, "max retries for checking certs existence")
close(cr.certsNotMounted)
return
}
crLog.Info(fmt.Sprintf("certs are ready in %s", cr.CertDir))
close(cr.certsMounted)
}

I wonder if it check the tls.crt in the secret is better. And actually the caBundle which is injected in webhook is based on the secret, not the certFile. Or we should some sync logic if the caFile in the secret is different from the local File. I think the latter is better.

@Poor12
Copy link
Author

Poor12 commented Apr 24, 2022

cc @maxsmythe @adrianludwin

@adrianludwin
Copy link
Contributor

adrianludwin commented Apr 24, 2022 via email

@maxsmythe
Copy link
Contributor

+1 @adrianludwin

cert-controller is mainly a way to avoid dependencies on 3rd party certificate management systems for dev/test/release and simple deployments. More complex cases will likely need to disable cert controller and figure out a solution that works for their specific use case.

WRT checking the contents of the secret...

The reason for checking the contents of the folder is because that is where the private key used by the webhook server is read from (it signs the webhook response, which is verified by the public key in the VWH config), so that folder being populated is necessary for the webhook to begin serving.

In this case, it's probably easiest to disable cert-controller and have something else handle generating certs and making sure the contents of the VWH config and webhook server secret folder are in sync (a K8s secret may not be necessary when running off-cluster, especially if there is nothing handling mounting the secret contents to a folder like there would be on K8s).

@Poor12
Copy link
Author

Poor12 commented May 5, 2022

Thanks for explanation. I will try to use another way to fix it and be glad to share some best practice where gatekeeper is used in multicluster or off-cluster.

@Poor12 Poor12 closed this as completed May 5, 2022
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

No branches or pull requests

3 participants