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

Add webhook certificate handling for k8s #114

Merged
merged 1 commit into from
May 7, 2021

Conversation

jcaamano
Copy link
Contributor

Adds support for webhooks in k8s deployments through options to handle
webhoook certificate configuration, either via providing the CA bundle
through environment variable or cert-manager annotations.

@zshi-redhat
Copy link
Collaborator

/cc @martinkennelly

@github-actions github-actions bot requested a review from martinkennelly April 14, 2021 12:38
doc/quickstart.md Outdated Show resolved Hide resolved
For example, given `cacert.pem`, `key.pem` and `cert.pem`:
```bash
kubectl -n sriov-network-operator create secret tls operator-webhook-service --cert=cert.pem --key=key.pem
kubectl -n sriov-network-operator create secret tls network-resources-injector-secret --cert=cert.pem --key=key.pem
Copy link
Member

Choose a reason for hiding this comment

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

To be able to inject the secret, do we need this annotation in the secret?:

cert-manager.io/allow-direct-injection: "true"

injection of secrets Ref

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So this option is assuming the users are creating the certificates manually and cert-manager is not being used.

service.beta.openshift.io/inject-cabundle: "true"
{{else if and (not .CaBundle) (eq .ClusterType "kubernetes") }}
cert-manager.io/inject-ca-from: {{.Namespace}}/operator-webhook-service
Copy link
Member

Choose a reason for hiding this comment

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

I read the docs on cert manager and I am wondering, why not use this?

cert-manager.io/inject-ca-from-secret

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That requires creating the secrets manually with a specific annotation which would be an actual extra step on all the procedure. It's is primarily used when bootstrapping cert-manager itself. After that, cert-manager creates the secrets from certificates for you so all you can directly annotate the certificate and save that extra step.

doc/quickstart.md Show resolved Hide resolved
And then deploy the operator:
```bash
export ENABLE_ADMISSION_CONTROLLER=true
make deploy-setup-k8s
Copy link
Member

Choose a reason for hiding this comment

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

  Warning  FailedMount  40s                  kubelet            Unable to attach or mount volumes: unmounted volumes=[tls], unattached volumes=[tls network-resources-injector-sa-token-zwls5]: timed out waiting for the condition
  Warning  FailedMount  35s (x9 over 2m43s)  kubelet            MountVolume.SetUp failed for volume "tls" : secret "network-resources-injector-secret" not found

Got the following error when tried this method on a fresh k8 cluster. I made sure WEBHOOK_CA_BUNDLEenv var wasnt exported.

Copy link
Contributor Author

@jcaamano jcaamano Apr 19, 2021

Choose a reason for hiding this comment

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

Strange, this is working for me.

The secret network-resources-injector-secret should be created in namespace sriov-network-operator from the Certificate network-resources-injector-service if cert-manager is functioning correctly. Can you describe the Certificate and check what's its status? It is also strange that it happens for one of the webhooks and not the other. I wiull try it again on my side.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried again and working for me.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's working for me too on a fresh k8s install

Copy link
Member

Choose a reason for hiding this comment

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

worked on a fresh install. Thanks!

And then deploy the operator:
```bash
export ENABLE_ADMISSION_CONTROLLER=true
make deploy-setup-k8s
Copy link
Contributor

Choose a reason for hiding this comment

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

It's working for me too on a fresh k8s install

@@ -14,6 +18,9 @@ webhooks:
name: operator-webhook-service
namespace: {{.Namespace}}
path: "/mutating-custom-resource"
{{if .CaBundle}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we check the "ClusterType" to be equals to "kubernetes" as well? Just in case WEBHOOK_CA_BUNDLE is accidentally set in "openshift" environment.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This would apply to other manifests in bindata.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea I had here is that passing the CaBundle would also be an option in Openshift. Thinking on situations where one would have a quick test or dev cluster where the ca operator is not deployed. This might not make sense though as I am not familiar with Openshift. If it does not, I can add the check for cluster type there as you mention. Let me know.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@jcaamano thanks for all the consideration!
We didn't do ca injection manually in openshift afaik, I think we could add it only for k8s at this moment.
If anything changes, we could remove the conditional check.

Copy link

Choose a reason for hiding this comment

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

@zshi-redhat I rewrote the conditions so that CaBundle is only considered for ClusterType=kubernetes. With ClusterType=openshift, CaBundle is ignored.

@zshi-redhat
Copy link
Collaborator

/cc @pliurh

@github-actions github-actions bot requested a review from pliurh April 23, 2021 04:00
Adds support for webhooks in k8s deployments through options to handle
webhoook certificate configuration, either via providing the CA bundle
through environment variable or cert-manager annotations.

Signed-off-by: Jaime Caamaño Ruiz <[email protected]>
@pliurh pliurh merged commit 36a1a6a into k8snetworkplumbingwg:master May 7, 2021
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.

6 participants