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

feat: use hooks as a validating webhook handlers #223

Merged
merged 19 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
rename cluster-ca to ca
  • Loading branch information
diafour committed Dec 28, 2020
commit a849e37633dfeef72bf9af892ec5bd01df77d03a
4 changes: 2 additions & 2 deletions BINDING_VALIDATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ Command line options:
A path to a server certificate for ValidatingWebhook. Can be set with $VALIDATING_WEBHOOK_SERVER_CERT.
--validating-webhook-server-key="/validating-certs/server-key.pem"
A path to a server private key for ValidatingWebhook. Can be set with $VALIDATING_WEBHOOK_SERVER_KEY.
--validating-webhook-cluster-ca="/validating-certs/cluster-ca.pem"
A path to a cluster ca bundle for ValidatingWebhook. Can be set with $VALIDATING_WEBHOOK_CLUSTER_CA.
--validating-webhook-ca="/validating-certs/ca.pem"
A path to a ca bundle for ValidatingWebhook. Can be set with $VALIDATING_WEBHOOK_CA.
--validating-webhook-client-ca=VALIDATING-WEBHOOK-CLIENT-CA ...
A path to a server certificate for ValidatingWebhook. Can be set with $VALIDATING_WEBHOOK_CLIENT_CA.
--validating-webhook-service-name=VALIDATING-WEBHOOK-SERVICE-NAME ...
Expand Down
8 changes: 4 additions & 4 deletions examples/204-validating-webhook/gen-certs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ if [[ -e server-key.pem ]] ; then
fi
fi

echo ">>> Remove server.crt server.csr server-key.pem cluster-ca.pem"
rm -f server.crt server.csr server-key.pem cluster-ca.pem
echo ">>> Remove server.crt server.csr server-key.pem ca.pem"
rm -f server.crt server.csr server-key.pem ca.pem

# generate server-key.pem server.csr
echo ">>> Generate server-key.pem"
Expand Down Expand Up @@ -74,5 +74,5 @@ kubectl get certificatesigningrequest $CERT_NAME -o jsonpath='{.status.certifica
echo ">>> Delete CertificateSigningRequest"
(kubectl delete certificatesigningrequest/${CERT_NAME} || true )

echo ">>> Retrieve cluster-ca.pem"
kubectl config view --raw --minify --flatten -o jsonpath='{.clusters[].cluster.certificate-authority-data}' | base64 -d > cluster-ca.pem
echo ">>> Retrieve ca.pem"
kubectl config view --raw --minify --flatten -o jsonpath='{.clusters[].cluster.certificate-authority-data}' | base64 -d > ca.pem
6 changes: 2 additions & 4 deletions examples/204-validating-webhook/templates/certs-secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ data:
{{ .Files.Get "validating-certs/server.crt" | b64enc }}
server-key.pem: |
{{ .Files.Get "validating-certs/server-key.pem" | b64enc }}
cluster-ca.pem: |
{{ .Files.Get "validating-certs/cluster-ca.pem" | b64enc }}
# client-ca.pem: |
{{/* .Files.Get "validating-certs/client-ca.pem" | b64enc */}}
ca.pem: |
{{ .Files.Get "validating-certs/ca.pem" | b64enc }}
14 changes: 7 additions & 7 deletions pkg/app/validating-webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
type validatingWebhookSettings struct {
ServerCertPath string
ServerKeyPath string
ClusterCAPath string
ClusterCABundle []byte
CAPath string
CABundle []byte
ClientCAPaths []string
ServiceName string
ConfigurationName string
Expand All @@ -19,7 +19,7 @@ type validatingWebhookSettings struct {
var ValidatingWebhookSettings = &validatingWebhookSettings{
ServerCertPath: "/validating-certs/server.crt",
ServerKeyPath: "/validating-certs/server-key.pem",
ClusterCAPath: "/validating-certs/cluster-ca.pem",
CAPath: "/validating-certs/ca.pem",
ClientCAPaths: nil,
ServiceName: "shell-operator-validating-svc",
ConfigurationName: "shell-operator-hooks",
Expand All @@ -45,10 +45,10 @@ func DefineValidatingWebhookFlags(cmd *kingpin.CmdClause) {
Envar("VALIDATING_WEBHOOK_SERVER_KEY").
Default(ValidatingWebhookSettings.ServerKeyPath).
StringVar(&ValidatingWebhookSettings.ServerKeyPath)
cmd.Flag("validating-webhook-cluster-ca", "A path to a cluster ca bundle for ValidatingWebhookConfiguration. Can be set with $VALIDATING_WEBHOOK_CLUSTER_CA.").
Envar("VALIDATING_WEBHOOK_CLUSTER_CA").
Default(ValidatingWebhookSettings.ClusterCAPath).
StringVar(&ValidatingWebhookSettings.ClusterCAPath)
cmd.Flag("validating-webhook-ca", "A path to a ca certificate for ValidatingWebhookConfiguration. Can be set with $VALIDATING_WEBHOOK_CA.").
Envar("VALIDATING_WEBHOOK_CA").
Default(ValidatingWebhookSettings.CAPath).
StringVar(&ValidatingWebhookSettings.CAPath)
cmd.Flag("validating-webhook-client-ca", "A path to a server certificate for ValidatingWebhookConfiguration. Can be set with $VALIDATING_WEBHOOK_CLIENT_CA.").
Envar("VALIDATING_WEBHOOK_CLIENT_CA").
StringsVar(&ValidatingWebhookSettings.ClientCAPaths)
Expand Down
2 changes: 1 addition & 1 deletion pkg/validating_webhook/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (m *WebhookManager) Init() error {
m.DefaultConfigurationId = DefaultConfigurationId
}
// settings
caBundleBytes, err := ioutil.ReadFile(app.ValidatingWebhookSettings.ClusterCAPath)
caBundleBytes, err := ioutil.ReadFile(app.ValidatingWebhookSettings.CAPath)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/validating_webhook/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func Test_Manager_AddWebhook(t *testing.T) {
vs.ServiceName = "webhook-service"
vs.ServerKeyPath = "testdata/demo-certs/server-key.pem"
vs.ServerCertPath = "testdata/demo-certs/server.crt"
vs.ClusterCAPath = "testdata/demo-certs/cluster-ca.pem"
vs.CAPath = "testdata/demo-certs/cluster-ca.pem"

err := m.Init()

Expand Down