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 certwatcher to webhook server #429

Merged

Conversation

ggriffiths
Copy link
Member

@ggriffiths ggriffiths commented Nov 18, 2020

Signed-off-by: Grant Griffiths grant@portworx.com

What type of PR is this?
/kind bug

What this PR does / why we need it:

Which issue(s) this PR fixes:
Fixes #422

Special notes for your reviewer:
n/a

Does this PR introduce a user-facing change?:

The validation-webhook server will now watch for changes to --tls-cert-file and --tls-private-key-file and update the server's TLS config accordingly.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Nov 18, 2020
@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Nov 18, 2020
@xing-yang
Copy link
Collaborator

Thanks @ggriffiths! That was quick:)

@xing-yang
Copy link
Collaborator

/assign @yuxiangqian

@xing-yang
Copy link
Collaborator

/assign

Signed-off-by: Grant Griffiths <grant@portworx.com>
@xing-yang
Copy link
Collaborator

@ggriffiths Can you do some manual testing and simulate a cert rotation?

@ggriffiths
Copy link
Member Author

Yes I'll give that a shot.
/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 19, 2020
@ggriffiths
Copy link
Member Author

Tested this with valid and invalid certs @xing-yang. The valid cert was rotated and refreshed in memory. The invalid cert caused problems without a pod restart, as expected.

Valid cert rotation:

  1. attempted to create invalid snapshot, correctly denied
[grant@PDC4-SM26-N8 external-snapshotter]$ date
Tue Dec  1 15:32:50 PST 2020
[grant@PDC4-SM26-N8 external-snapshotter]$ kubectl create -f ./examples/kubernetes/invalid-snapshot.yaml
Error from server: error when creating "./examples/kubernetes/invalid-snapshot.yaml": admission webhook "validation-webhook.snapshot.storage.k8s.io" denied the request: only one of Spec.Source.PersistentVolumeClaimName = pvc and Spec.Source.VolumeSnapshotContentName = vsc should be set
  1. Re-generated the cert
[grant@PDC4-SM26-N8 external-snapshotter]$ ./deploy/kubernetes/webhook-example/create-cert.sh --service snapshot-validation-service --secret snapshot-validation-secret --namespace kube-system
creating certs in tmpdir /tmp/tmp.9eOHCqeCsm 
Generating RSA private key, 2048 bit long modulus
...........................................................+++
..........................+++
e is 65537 (0x10001)
certificatesigningrequest.certificates.k8s.io "snapshot-validation-service.kube-system" deleted
certificatesigningrequest.certificates.k8s.io/snapshot-validation-service.kube-system created
NAME                                      AGE   REQUESTOR          CONDITION
snapshot-validation-service.kube-system   0s    kubernetes-admin   Pending
certificatesigningrequest.certificates.k8s.io/snapshot-validation-service.kube-system approved
secret/snapshot-validation-secret configured
[grant@PDC4-SM26-N8 external-snapshotter]$ date
Tue Dec  1 15:33:14 PST 2020
  1. TLS certificate updated in the validation pod
    I1201 23:33:20.251368 1 certwatcher.go:129] Updated current TLS certificate

  2. Validation webhook still works

[grant@PDC4-SM26-N8 external-snapshotter]$ kubectl create -f ./examples/kubernetes/invalid-snapshot.yaml
Error from server: error when creating "./examples/kubernetes/invalid-snapshot.yaml": admission webhook "validation-webhook.snapshot.storage.k8s.io" denied the request: only one of Spec.Source.PersistentVolumeClaimName = pvc and Spec.Source.VolumeSnapshotContentName = vsc should be set

Performed a similar flow above with an invalid cert and saw the below error, as expected.

[grant@PDC4-SM26-N8 external-snapshotter]$ kk apply -f examples/kubernetes/invalid-snapshot.yaml 
Error from server (InternalError): error when creating "examples/kubernetes/invalid-snapshot.yaml": Internal error occurred: failed calling webhook "validation-webhook.snapshot.storage.k8s.io": Post https://snapshot-validation-service.kube-system.svc:443/volumesnapshot?timeout=2s: x509: certificate has expired or is not yet vali

@ggriffiths
Copy link
Member Author

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 2, 2020
@xing-yang
Copy link
Collaborator

Thanks @ggriffiths!

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 2, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ggriffiths, xing-yang

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 2, 2020
@k8s-ci-robot k8s-ci-robot merged commit 95f3197 into kubernetes-csi:master Dec 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

snapshot-validation-webhook should reload server certificate on update
4 participants