-
Notifications
You must be signed in to change notification settings - Fork 331
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
Allow overriding webhook secret data keys #2662
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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test coverage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure will add
@@ -26,9 +26,11 @@ import ( | |||
|
|||
const ( | |||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add godoc for these new vars.
ServerKeyEnv = "KNATIVE_SECRET_WEBHOOK_SERVER_KEY" | |
ServerKeyEnvOverride = "KNATIVE_WEBHOOK_SERVER_KEY" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about WEBHOOK_CERTS_SECRET_SERVER_KEY/CERT
? Cause I use WEBHOOK_CERTS_SECRET_NAME
in #2685
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok will do the webhook options approach thanks.
webhook/webhook.go
Outdated
@@ -148,13 +148,13 @@ func New( | |||
logger.Errorw("failed to fetch secret", zap.Error(err)) | |||
return nil, nil | |||
} | |||
|
|||
serverKey, ok := secret.Data[certresources.ServerKey] | |||
sKey, sCert := certresources.GetSecretDataKeyNamesOrDefault() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment doesn't match the var name.
Maybe SecretPrivateKeyName
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
ServerKey = "server-key.pem" |
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like this could be a private helper in the webhook
package
webhook/webhook_integration_test.go
Outdated
@@ -105,8 +105,69 @@ func TestMissingContentType(t *testing.T) { | |||
metricstest.CheckStatsNotReported(t, requestCountName, requestLatenciesName) | |||
} | |||
|
|||
func TestMissingContentTypeCustomSecret(t *testing.T) { | |||
defaultOptions := newCustomOptions() | |||
certresources.MakeSecret = customSecretWithOverrides |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Needs 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