Allow overriding webhook secret data keys#2662
Allow overriding webhook secret data keys#2662knative-prow[bot] merged 8 commits intoknative:mainfrom
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #2662 +/- ##
==========================================
+ Coverage 81.75% 81.77% +0.02%
==========================================
Files 167 167
Lines 10201 10214 +13
==========================================
+ Hits 8340 8353 +13
Misses 1614 1614
Partials 247 247
☔ View full report in Codecov by Sentry. |
|
@dprotaso gentle ping |
webhook/webhook.go
Outdated
| if val, ok := os.LookupEnv(certresources.ServerKeyEnv); ok { | ||
| sKey = val | ||
| } | ||
| if val, ok := os.LookupEnv(certresources.ServerCertEnv); ok { | ||
| sCert = val | ||
| } |
| // ServerKey is the name of the key associated with the secret's private key. | ||
| ServerKey = "server-key.pem" | ||
| ServerKey = "server-key.pem" | ||
| ServerKeyEnv = "KNATIVE_SECRET_WEBHOOK_SERVER_KEY" |
There was a problem hiding this comment.
add godoc for these new vars.
| ServerKeyEnv = "KNATIVE_SECRET_WEBHOOK_SERVER_KEY" | |
| ServerKeyEnvOverride = "KNATIVE_WEBHOOK_SERVER_KEY" |
There was a problem hiding this comment.
How about WEBHOOK_CERTS_SECRET_SERVER_KEY/CERT? Cause I use WEBHOOK_CERTS_SECRET_NAME in #2685
There was a problem hiding this comment.
I like the KNATIVE prefix tbh to separate from other env vars that could co-exist. Other than that its up to @dprotaso no strong preference.
There was a problem hiding this comment.
We don't have KNATIVE_ prefixes for other environment variables ie. SYSTEM_NAMESPACE so I suggest dropping the prefix so that we remain consistent
6066fa5 to
5c5c9b8
Compare
|
/retest |
| // ServerKeyEnv is the env var name for the webhook secret's key eg. `tls.key`. | ||
| ServerKeyEnv = "KNATIVE_WEBHOOK_SERVER_KEY" | ||
| // ServerCert is the name of the key associated with the secret's public key. | ||
| ServerCert = "server-cert.pem" | ||
| // ServerCertEnv is the env var name for the webhook secret's ca data key eg. `tls.crt`. | ||
| ServerCertEnv = "KNATIVE_WEBHOOK_SERVER_CERT" |
There was a problem hiding this comment.
I realize now the env vars don't influence the certificates & keys being created. Thus I don't think these overrides should be in this package.
This package is for creating and updating certificates
There was a problem hiding this comment.
Ok will do the webhook options approach thanks.
webhook/webhook.go
Outdated
| } | ||
|
|
||
| serverKey, ok := secret.Data[certresources.ServerKey] | ||
| sKey, sCert := certresources.GetSecretDataKeyNamesOrDefault() |
There was a problem hiding this comment.
Are you creating custom webhooks binaries where you drop the certificate controller?
If so it might be better to add these overrides to the webhook.Options and when they're empty default them to the keys in the certificates/resources package.
There was a problem hiding this comment.
Makes sense the env var thingy is a bit too intrusive.
|
This Pull Request is stale because it has been open for 90 days with |
d0b449a to
9f240b9
Compare
|
@dprotaso gentle ping this is ready for review. |
webhook/webhook.go
Outdated
| // ServerKeyEnv is the name for the webhook secret's data key eg. `tls.key`. | ||
| // Default value is `server-key.pem` if no value is passed. | ||
| ServerKey string |
There was a problem hiding this comment.
Comment doesn't match the var name.
Maybe SecretPrivateKeyName ?
There was a problem hiding this comment.
I will change but to clarify the reason I kept that name is that I wanted to make explicit that I am overriding the same values here:
webhook/webhook.go
Outdated
| // ServerCertEnv is the name for the webhook secret's ca data key eg. `tls.crt`. | ||
| // Default value is `server-cert.pem` if no value is passed. | ||
| ServerCert string |
There was a problem hiding this comment.
Comment doesn't match var name
Maybe SecretCertifcateName ?
| func GetSecretDataKeyNamesOrDefault(sKey string, sCert string) (serverKey string, serverCert string) { | ||
| serverKey = ServerKey | ||
| serverCert = ServerCert | ||
|
|
||
| if sKey != "" { | ||
| serverKey = sKey | ||
| } | ||
| if sCert != "" { | ||
| serverCert = sCert | ||
| } | ||
| return serverKey, serverCert | ||
| } |
There was a problem hiding this comment.
seems like this could be a private helper in the webhook package
webhook/webhook_integration_test.go
Outdated
|
|
||
| func TestMissingContentTypeCustomSecret(t *testing.T) { | ||
| defaultOptions := newCustomOptions() | ||
| certresources.MakeSecret = customSecretWithOverrides |
There was a problem hiding this comment.
This might cause flakiness when running tests in parallel.
We should just have this test perform it's own setup (ie. create it's own cert etc)
Also the test name and assertions is a bit misleading TestMissingContentTypeCustomSecret - we really want to assert that the right certificate is presented. Thus we should skip stuff that's not relevant
There was a problem hiding this comment.
@dprotaso I copied the logic in certificates_test.go so probably that is unsafe too or is it that it always returns the default one and it worked so far? In any case I will take a look to separate it.
There was a problem hiding this comment.
Anyway I updated the test to be more compact and have its own setup.
b0270dc to
12544e2
Compare
|
@dprotaso gentle ping. |
1 similar comment
|
@dprotaso gentle ping. |
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dprotaso, skonto The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Changes
We would like to be able to override the default keys so in general any external webhook that extends
webhook.AdmissionController or webhook.ConversionController can be used.
/kind enhancement