Commit Graph

221 Commits

Author SHA1 Message Date
Prashant Rewar fef5da99bd
Replace all usages of deprecated wait.PollImmediate with wait.PollUntilContextTimeout (#3004)
Signed-off-by: Prashant Rewar <108176843+prashantrewar@users.noreply.github.com>
2024-04-02 14:44:03 +00:00
zhouhaibing089 03bf3de6e2
webhook: add options to disable resource_namespace tag in metrics (#2931)
* webhook: add options to disable resource_namespace tag in metrics

To add some context, historically, `resource_name` was removed from this
tag list due to its high potential of causing high metrics cardinality.
See [knative/pkg#1464][1] for more information.

While that's great, but it might not be sufficient for large scale use
cases where namespaces can be super dynamic (with generateName, too) or
grows fase enough. There is an issue report from
[tektoncd/pipeline#3171][2] which talks about this.

This proposal makes it possible to disable `resource_namespace` tag via
an option function. The default behavior is not changed, so no user
impact if any of existing users rely on this tag. There is no API
contract change either due to the beauty of variadic functions.

Now downstream projects can consume this by override `StatsReporter` in
webhook context options with their own preference. As a caveat here, if
downstream project does choose to override `StatsReporter`, the default
`ReportMetrics` function shouldn't be called by default as they may now
have a different set of tag keys to report. As such, this function is
only called if the default `StatsReporter` is used.

[1]: https://github.com/knative/pkg/pull/1464
[2]: https://github.com/tektoncd/pipeline/issues/3171

* webhook: add StatsReporterOptions in webhook.Options

There are two ways to customize StatsReporter:

1. Use a whole new StatsReporter implementation.
1. Or pass Option funcs to customize the default StatsReporter.

Option 1 is less practical at this time due to the metrics registration
conflict. `webhook.RegisterMetrics()` is called regardless which
StatsReporter implementation is used (which is a problem by itself). The
second option is more practical since it works well without dealing with
metrics conflicts.

The `webhook.Option` in particular allows people to discard certain
metrics tags.
2024-04-01 19:02:21 +00:00
navin de3e9cc204
Fixing all deprecated use of sets.String (#2915)
* Fixing all deprecated use of sets.String

* review comments

* Fixing deprecated use of sets.String
2024-01-08 15:21:18 +00:00
cola a65a9e2510
lower log level for AdmissionController.Admit validation failures (#2905)
Signed-off-by: pingjiang <xiangpingjiang1998@gmail.com>
2024-01-08 15:09:14 +00:00
Stavros Kontopoulos b8c14ce9f9
[CVE-2023-44487] Disable http2 for webhooks (#2871)
* disable http2 for webhooks

* add comment
2023-10-23 14:38:02 +00:00
Stavros Kontopoulos 8d3f951063
Allow overriding webhook secret data keys (#2662)
* override secret data keys when creating new webhooks

* fixes

* cleanup

* use webhook options

* remove unused env var keys

* fix docs

* update opt names and refactor integration test

* fixes
2023-08-02 19:19:48 +00:00
Hector Fernandez 4dbc3122f3
fix boilerplate (#2753)
Signed-off-by: Hector Fernandez <hector@chainguard.dev>
2023-06-12 15:40:44 +00:00
Hector Fernandez 15605c78a2
Defaulting Controller options for all kind of webhooks (#2738)
* functional options

* move options to its own package

Signed-off-by: Hector Fernandez <hector@chainguard.dev>

* add controller options to the webhook options

Signed-off-by: Hector Fernandez <hector@chainguard.dev>

* create custom options funcs for each webhook type

Signed-off-by: Hector Fernandez <hector@chainguard.dev>

* address comments from reviewers

Signed-off-by: Hector Fernandez <hector@chainguard.dev>

---------

Signed-off-by: Hector Fernandez <hector@chainguard.dev>
Co-authored-by: dprotaso <dprotaso@gmail.com>
2023-06-12 08:38:02 +00:00
Dave Protasowski 9bda38b216
Fix some webhook testing tech debt (#2751)
* TestRegistrationStopChanFire now uses ephemeral ports

* For TLS servers dial TLS

* have server error logs appear in zap

* log the correct error

* pass ephemeral listeners to the webhook for testing
2023-05-25 14:35:25 +00:00
Izabela Gomes 53f04b373c
Make minimum TLS version configurable for webhooks (#2721)
* make minimum tls version configurable

* change default min TLS version to 1.3

* change opencensus tls min version to 1.3

* Update env var name

Co-authored-by: Dave Protasowski <dprotaso@gmail.com>

* use webhook options to configure min tls version

* add unit tests for webhook tlsMinVersion option

* Update webhook/env.go

Co-authored-by: Dave Protasowski <dprotaso@gmail.com>

* address feeback

---------

Co-authored-by: Dave Protasowski <dprotaso@gmail.com>
2023-04-14 15:45:51 +00:00
kmahapatra 511b3941d4
potential fix for flakey tlsBackoff (#2702) 2023-03-10 20:46:25 +00:00
Christoph Stäbler 0902ea8432
Parameterize WEBHOOK_NAME env key in error message (#2701) 2023-03-10 16:52:24 +00:00
Hyeonki Hong fd00e037d1
Add certs secret name read from env (#2685)
* Add certs secret name read from env

* Rename webhookNameEnv to webhookNameEnvKey

* Add test code for certs secret name from env

* Add missing input case to test CertsSecretNameFromEnv

* Change CertsSecretName to SecretName
2023-03-06 15:41:24 +00:00
kmahapatra 2f55fe00c5
Fix potential slowloris attack (#2682) 2023-02-15 23:47:51 +00:00
Dave Protasowski 8532ae0645
update OWNERS files to use teams with active members (#2672)
* update OWNERS files to use teams with active members

* add eventing-wg leads as approvers to /apis
2023-02-06 16:58:45 +00:00
Dave Protasowski 44d1d7d978
Go1.19 changes (#2631)
* run goimports

* ignore linter errors for now

* fix boilerplate
2022-11-03 22:34:05 +00:00
Matt Moore 92ed919344
Fix: Mute the linter on error return values. (#2627)
🐛 My previous change has revive/stylecheck warnings because I made the `warn` return value `[]error` and it wants the `error` last, which is kind of silly.

This mutes the linter on this signature, since it hits both revive and stylecheck

/kind bug
2022-11-02 19:46:06 +00:00
Matt Moore 198b463706
Cleanup: Turn multiple warnings into multiple warnings. (#2619)
🧹 Previously we lacked a public method for turning our `apis.FieldError` multi-error into a list of constituent error messages, so when we turned things into a webhook warning we simply used the combined serialization of all of the warnings.  Thanks to Nghia's recent change, we can now access the list of warnings to return as a list of errors.

/kind cleanup
2022-10-27 17:34:07 +00:00
Pierangelo Di Pilato fb2e4fbaa4
Preserve webhook namespaceSelector.matchLabels (#2605)
* Preserve webhook namespaceSelector.matchLabels

I have a webhook with this definition and the reconciler is
removing the matchLabels field:

Current resource:
```
				  namespaceSelector:
				    matchExpressions:
				    - key: webhooks.knative.dev/exclude
				      operator: DoesNotExist
				  objectSelector:
				    matchLabels:
				      app.kubernetes.io/component: kafka-dispatcher

```

Applied resource:
```
				    namespaceSelector:
				      matchExpressions: [ ]
				      matchLabels:
				        app.kubernetes.io/name: knative-eventing
				    objectSelector:
				      matchLabels:
				        app.kubernetes.io/component: kafka-dispatcher
```

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

* Optimize cases that don't need ensureLabelSelectorRequirements

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
2022-10-06 21:14:31 +00:00
Pierangelo Di Pilato 717747b6ba
Register webhook GVKs for validating callbacks (#2590)
When a callback is registered for a gvk that isn't part of the
handlers that callback is never called since there is no webhook
rule associated with that GVK.

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
2022-09-14 07:19:48 +00:00
Dave Protasowski 3d24b8416b
fix lint warnings (#2589)
* resolve deprecation warnings

* drop use of ioutil

* fix license

* run hack/update-codegen.sh
2022-09-12 18:15:45 +00:00
Kenny Leung 93b66e6a87
Update: report stats for request (#2584)
* report stats for request

Signed-off-by: Kenny Leung <kleung@chainguard.dev>

* fix ref

Signed-off-by: Kenny Leung <kleung@chainguard.dev>

* fix import

Signed-off-by: Kenny Leung <kleung@chainguard.dev>

* update

Signed-off-by: Kenny Leung <kleung@chainguard.dev>

* gofmt

Signed-off-by: Kenny Leung <kleung@chainguard.dev>

* fix test

Signed-off-by: Kenny Leung <kleung@chainguard.dev>

* fix boiler

Signed-off-by: Kenny Leung <kleung@chainguard.dev>

Signed-off-by: Kenny Leung <kleung@chainguard.dev>
2022-08-26 16:29:20 +00:00
Andrés Torres a650186419
Make request body available in admission context (#2583)
* Make request body available in admission context

Signed-off-by: Andrés Torres <andrest@vmware.com>

* Add newline at the end of file

Signed-off-by: Andrés Torres <andrest@vmware.com>

Signed-off-by: Andrés Torres <andrest@vmware.com>
2022-08-26 15:50:19 +00:00
Ville Aikas a6afcab5bd
Fix #2115, allow selective verbs / subresources for webhooks. (#2547)
* WIP: just one option exploration.

Signed-off-by: Ville Aikas <vaikas@chainguard.dev>

* Another option. New signature and new type for configuration.

Signed-off-by: Ville Aikas <vaikas@chainguard.dev>

* Use interfaces and type assertions.

Signed-off-by: Ville Aikas <vaikas@chainguard.dev>

* log custom config with debug.

Signed-off-by: Ville Aikas <vaikas@chainguard.dev>

* Address PR feedback.

Signed-off-by: Ville Aikas <vaikas@chainguard.dev>

Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
2022-08-24 01:10:17 +00:00
Ville Aikas da7191979f
split warnings. Fix issue: 2581 (#2582)
* split warnings. Fix issue: 2581

Signed-off-by: Ville Aikas <vaikas@chainguard.dev>

* Add tests for splits. Simplify.

Signed-off-by: Ville Aikas <vaikas@chainguard.dev>

Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
2022-08-23 19:52:18 +00:00
Ville Aikas f1f36a2c97
Fix subresource update logic. (#2546)
* Fix subresource update logic.

Signed-off-by: Ville Aikas <vaikas@chainguard.dev>

* Rename IsInSubResourceUpdate => GetUpdatedSubresource

Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
2022-07-15 18:32:28 +00:00
Paul Schweigert 5569169b0c
update boilerplate date (#2539)
Signed-off-by: Paul S. Schweigert <paulschw@us.ibm.com>
2022-06-30 22:25:31 +00:00
Matt Moore f5db22566a
Drop `UserInfo` from logger tagging in webhook. (#2535)
* Drop `UserInfo` from logger tagging in webhook.

This can get big, and can contain mildly sensitive data that some users don't want showing up in logs.

If we keep this, than we should perhaps restrict what we tag to one of the less unbounded fields (e.g. don't include `Extra`)

* Switch UserInfo to contain just Username
2022-06-29 01:27:30 +00:00
Paul Schweigert aad4309963
sets mutating webhook ReinvocationPolicy to ifNeeded (#2472)
Signed-off-by: Paul S. Schweigert <paulschw@us.ibm.com>
2022-06-07 15:53:37 +00:00
Matt Moore 16b36b7fca
Add support for admission webhook warnings. (#2498)
* Add support for admission webhook warnings.

This extends `apis.FieldError` to support designating certain FieldErrors as "warnings" (or explicitly as "errors", however, this is the default for back-compat).

You can turn an `apis.FieldError` into a warning using: `fe.At(apis.WarningLevel)` or force it into an error using: `fe.At(apis.ErrorLevel)`.

You can get the errors at a particular diagnostic level using: `fe.Filter(apis.WarningLevel)`.

This change also hooks this into the admission webhook infrastructure to support surfacing the "warning" level `apis.FieldError`s via the `Warnings` section of the `AdmissionResponse`.

Fixes: #2497

* Add a comment about the use of defer.
2022-05-02 21:56:57 +00:00
Pierangelo Di Pilato a850b9e047
Use t.Setenv instead of os.Setenv in tests (#2454)
Go 1.17 introduced a new handy API for setting env vars scoped for
a single test so we can avoid the hard to read set and reset env
loops.

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
2022-03-10 10:00:48 -08:00
Todd 9b5c41135d
allow overriding the default grace period of 45 seconds (#2423)
This allows users to configure a faster restart of their
webhook if desired while retaining the current behavior.
2022-02-28 11:40:09 -08:00
Pierangelo Di Pilato f4b57aef00
Fix invalid creator or lastModifier annotations on core resources (#2409)
When the admission request is for a resource with an empty string as
group, which happens on core resources, the `creator` or `lastModifier`
annotations are invalid since they become `/creator` or
`/lastModifier`.

This patch removes the `/` when group = `""`.

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
2022-01-31 06:49:30 -08:00
Pierangelo Di Pilato 0a429cba1c
Allow Unstructured callback from Defaulting Webhook (#2363)
* Add support for callback defaults

Signed-off-by: Pierangelo Di Pilato <pdipilat@redhat.com>

* Put unstr object in ctx and set user info

Signed-off-by: Pierangelo Di Pilato <pdipilat@redhat.com>

* Move get callback at the top

Signed-off-by: Pierangelo Di Pilato <pdipilat@redhat.com>

* Panic when using delete verb

Signed-off-by: Pierangelo Di Pilato <pdipilat@redhat.com>

* Split tests and add callback ctx tests

Signed-off-by: Pierangelo Di Pilato <pdipilat@redhat.com>

* Set user info annotations

Signed-off-by: Pierangelo Di Pilato <pdipilat@redhat.com>

* Register Webhook Rules from callbacks

Signed-off-by: Pierangelo Di Pilato <pdipilat@redhat.com>

* Adapt unstructured objects to apis.HasSpec

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

* Change json tag name to match struct field name

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
2022-01-14 06:18:42 -08:00
knative-automation e61a20dd64
Update actions (#2313)
Signed-off-by: Knative Automation <automation@knative.team>
2021-10-15 12:26:13 -07:00
Matt Moore 11a3414ec3
Provide the webhook infrastructure with the raw request context. (#2305)
Today, we can use `Path()` of `/foo/` (trailing slash) to support prefix-matched webhooks, but unfortunately the request context is lost when `Admit()` or `Convert()` is called.

This ensures that information flows through associated with context for anyone who would like this metadata for additional processing.
2021-10-05 13:22:44 -07:00
Dave Protasowski dec98b4261
fix a small lint warning (#2270) 2021-09-02 22:55:57 -07:00
Dave Protasowski 0482448aac
allow unknown metadata fields (#2249)
* allow unknown metadata fields

* fix lint warnings

* include tests for nested structures in the metadata value
this is for catching any regressions
2021-09-02 07:33:06 -07:00
Matt Moore 9c7fd8e14f
Introduce `NewContext`, deprecate `NewImplFull`. (#2222)
* Introduce `NewContext`, deprecate `NewImplFull`.

Our generated `NewImpl` methods have long taken `context.Context`, but despite many iterations the forms we expose from our `controller` package never have.  This change contains several elements:
1. Expose a new `NewContext` method that takes `context.Context` in addition to the current `NewImplFull` signature.
2. Call `NewContext` instead of the deprecated `NewImpl` from our generated controller code.
3. Call `NewContext` from all our webhook reconcilers.

* Add a Tracker to controller.Impl to cut down on downstream boilerplate.
2021-08-21 14:00:34 -07:00
Markus Thömmes 35bcd16656
Drop redundant pointers and decoders (#2211) 2021-08-17 02:04:16 -07:00
Matt Moore 552bbc1061
Support the webhook serving over non-TLS. (#2204)
This reworks the way we setup the TLS Config for the webhook, so that when the `opts.SecretName` is omitted we serve over non-TLS.
2021-08-02 20:22:47 -07:00
Matt Moore c367a9d696
Drop Client as it is only used in tests (#2203) 2021-07-30 18:05:05 -07:00
NovaHe 8d21ce6c63
set webhooks OwnerReferences to namespace (#2044) (#2098) 2021-06-10 19:26:43 -07:00
Dave Protasowski eaa823c765
bump k8s to v1.20.7 (#2145)
* bump k8s deps to v1.20.7

* fix migrator test pkg

* dynamicclient now expects List types to be declare either via a scheme or manually

* fix error message comparison

* drop excess vendor licenses

* Using the injection fake dynamic client will preserve pre-1.20 behaviour

This is accomplished by preprocessing the scheme/fixtures and declaring
a custom scheme were we map our types & lists to unstructured.* types

* revert webhook factory changes

* ensure objects to the dynamic client are unstructured

* seed the default dynamic client with k8s scheme

* include duckv1 types in default fake dynamic client scheme

* use default k8s scheme
looks like eventing adds to this scheme but we should import the correct one vs the one from the  fake package

* drop duckv1 from default scheme

* set APIVersion/Kind if empty

* refactor ToUnstructured helper to a new package
2021-06-10 06:56:43 -07:00
Markus Thömmes 79f8b3fe03
Auto-generate webhook certs with ECDSA for FIPS compliance (#2136) 2021-06-01 04:11:37 -07:00
Dave Protasowski 6484377731
update boilerplate date (#2134) 2021-05-28 13:21:29 -07:00
Markus Thömmes 980a33719a
Fix revive related linting issues (#2131) 2021-05-26 01:10:28 -07:00
Evan Anderson 728bc4ad4e
Update OWNERS_ALIASES to match autogen in community (#2078) 2021-04-08 07:42:51 -07:00
Markus Thömmes 808d62257d
Escape path before returning it in a response (#2075) 2021-03-30 09:22:21 -07:00
Jason Hall 3b7934e599
Update webhook/README.md to reflect current packages (#2062)
`NewAdmissionController` was moved to `resourcesemantics/validation` in #848 and this doc wasn't updated.
2021-03-30 00:33:20 -07:00