Commit Graph

29 Commits

Author SHA1 Message Date
Matheus Pimenta aff9ebde96
[RFC-0010] Introduce feature gate
Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com>
2025-05-19 13:39:36 +01:00
Matheus Pimenta e128d3b795
[RFC-0010] Introduce object-level workload identity for container registry APIs
Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com>
2025-05-07 18:33:59 +01:00
Stefan Prodan 3c7812d387
Update to Kubernetes 1.33.0 and Go 1.24.0
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2025-04-28 14:10:47 +03:00
hasithsen 2b320409de feat: Remove deprecated object metrics from controllers fluxcd/flux2#5083
Signed-off-by: hasithsen <sen.hasith@gmail.com>
2024-12-12 00:02:25 +05:30
Stefan Prodan e3992568f5
OCIRepository: Configure proxy for OIDC auth
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2024-09-10 18:54:32 +03:00
Matheus Pimenta 03a118a94c Add proxy support for OCIRepository API
Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com>
2024-08-15 10:29:57 -03:00
Stefan Prodan 93ad04b6c8
Update dependencies to Kubernetes v1.31.0
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2024-08-14 21:40:29 +03:00
Florian Forster 277e5c1d55
Prefer `%s` over `%v` when formatting errors.
Signed-off-by: Florian Forster <fforster@gitlab.com>
2024-07-05 15:55:33 +02:00
Florian Forster 8be37ef1d2
Fix incorrect use of format strings with the `conditions` package.
Many of the functions in the `conditions` package accept a format string and
(optional) arguments, just like `fmt.Printf` and friends.

In many places, the code passed an error message as the format string, causing
it to be interpreted by the `fmt` package. This leads to issues when the
message contains percent signs, e.g. URL-encoded values.

Consider the following code:

```go
// internal/controller/ocirepository_controller.go
revision, err := r.getRevision(ref, opts)
if err != nil {
	e := serror.NewGeneric(
		fmt.Errorf("failed to determine artifact digest: %w", err),
		ociv1.OCIPullFailedReason,
	)
	conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, e.Reason, e.Err.Error())
	return sreconcile.ResultEmpty, e
}
```

Since `getRevision()` includes the URL in the error message and the error
message is used as a format string, the resulting condition reads:

```
failed to determine artifact digest: GET https://gitlab.com/jwt/auth?scope=repository%!A(MISSING)fforster%!F(MISSING)<REDACTED>%!F(MISSING)k8s-resource-manifests%!A(MISSING)pull&service=container_registry: DENIED: access forbidden
```

This adds an explicit format string and shortens `e.Error()` and
`e.Err.Error()` to `e`, which yields the same output.

To the best of my knowledge, Go is safe from format string attacks. I **don't**
think this is a security vulnerability, but I'm also not a security expert.

Signed-off-by: Florian Forster <fforster@gitlab.com>
2024-07-05 15:55:31 +02:00
Soule BA 10434e7e1f
Introduce a semver filter in OCIRepository
If implemented a semver filter regex can be declared in conjuction with
a semver range in the OCIRepository `spec.Reference`

Signed-off-by: Soule BA <bah.soule@gmail.com>
2024-03-28 00:09:51 +01:00
Soule BA 7f3df76ccc
Use the verify defined interface in OCIRepository
Signed-off-by: Soule BA <bah.soule@gmail.com>
2024-03-26 15:35:13 +01:00
JasonTheDeveloper 553945ab8e Add verification support for notation signed artifacts
Introduces a new verification provider `notation` to verify notation signed artifacts. Currently only cosign is supported and that is a problem if the end user utilises notation.

---------

Signed-off-by: Jason <jagoodse@microsoft.com>
Signed-off-by: JasonTheDeveloper <jagoodse@microsoft.com>
Signed-off-by: Jagpreet Singh Tamber <jagpreetstamber@gmail.com>
Co-authored-by: souleb <bah.soule@gmail.com>
Co-authored-by: Jagpreet Singh Tamber <jagpreetstamber@gmail.com>
Co-authored-by: Sunny <github@darkowlzz.space>
2024-03-26 21:32:23 +11:00
Sanskar Jaiswal d855805b8f
cosign: allow identity matching for keyless verification
Add `.spec.verify.matchOIDCIdentity` to OCIRepository and HelmChart.
It allows specifying regular expressions to match against the subject and
issuer of the certificate related to the artifact signature. Its used
only if the artifact was signed using Cosign keyless signing.

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2023-10-31 08:04:34 -07:00
Hidde Beydals 20230811e4
misc: address duplicate imports
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-10-11 11:03:54 +02:00
Hidde Beydals d56d0a7ad7
misc: address `k8s.io/utils/pointer` deprecation
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-10-10 09:40:37 +02:00
Stefan Prodan cdb412e7af
oci: Skip symlinks found in upstream artifacts
Do not error out when upstream artifacts contain symlinks in the content layer, instead skip all symlinks during decompression.

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2023-09-29 13:27:19 +03:00
Ilya Dmitrichenko a5ec631cd3
Switch from `crane` package to `remote`
`crane` package is the highest level of abstraction that GGCR provides,
it's easy to use, however it doesn't give user much control.
This change moves `OCIRepository` controller logic to a lower-level
`remote` package and makes handling of references more explicit with
`name.Repository`, `name.Digest` and `name.Tag`.
It also simplifies options builder, as there is no need to have separate
sets of options for cosign and crane.

Signed-off-by: Ilya Dmitrichenko <errordeveloper@gmail.com>
2023-09-29 10:17:49 +01:00
Sunny 5a92e8b215 Return generic error for patch failures
Introduce a new event reason for patch operation failure and update all
the returned errors from serial patcher to be a generic error so that
they are handled like any other error with an associated warning event.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2023-09-15 17:41:43 +05:30
Sanskar Jaiswal 6fe3c96311
ocirepo: adopt Kubernetes style TLS secrets for .spec.certSecretRef
Adopt Kubernetes TLS secrets API to check for TLS data in the Secret
referred to by `.spec.certSecretRef`, i.e. check for keys `tls.crt` and
`tls.key` for the certificate and private key. Use `ca.crt` for the CA
certificate.
Deprecate the usage of `caFile`, `certFile` and `keyFile` keys.

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2023-08-22 18:23:05 +05:30
Sunny e7d7681b1b Delete stale metrics on object delete
Move record suspend metrics next to readiness and duration metrics so
that it gets recorded along with others always at the end and the
metrics delete, which requires the knowledge of deleted finalizers,
applies to suspend too.

HelmRepository cache event metrics for a given helmrepo also continues
to be exported even after the object is deleted. This change deletes
the cache event metrics when the object is deleted.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2023-08-15 02:35:35 +05:30
Hidde Beydals 6f3eb22613
controller: jitter requeue interval
This adds a `--interval-jitter-percentage` flag to the controller to
add a +/- percentage jitter to the interval defined in resources
(defaults to 10%).

Effectively, this results in a reconcilation every 4.5 - 5.5 minutes
for a resource with an interval of 5 minutes.

Main reason to add this change is to mitigate spikes in memory and
CPU usage caused by many resources being configured with the same
interval.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-08-07 16:23:26 +02:00
Sunny ca0f0ffb8d Handle delete before adding finalizer
In Reconcile() methods, move the object deletion above add finalizer.
Finalizers can't be set when an object is being deleted.

Introduce a cacheless client in suite_test to use for testing this
change. It ensures that the Reconcile() call always operates on the
latest version of the object which has the deletion timestamp and
existing finalizer.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2023-07-31 15:32:07 +05:30
Sanskar Jaiswal 71f1080b41
ocirepo: add cosign support for insecure http registries
Add support for verifying insecure HTTP OCI repositories with cosign. If
`.spec.insecure` set to true, then cosign uses plain HTTP connections to
communicate with the registry.

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2023-07-31 13:50:18 +05:30
Sanskar Jaiswal 79adec586b
helm: add support for specifying TLS auth via `.spec.certSecretRef`
Add support for specifying TLS auth data via `.spec.certSecretRef` in
HelmRepository and log a deprecation warning if TLS is configured via
`.spec.secretRef`. Introduce (and refactor) Helm client builder and
auth helpers to reduce duplicated code and increase uniformity and
testability.

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2023-07-31 13:29:17 +05:30
Sanskar Jaiswal ef1df00fda
switch from `fluxcd/pkg/untar` to `fluxcd/pkg/tar`
Switch from `fluxcd/pkg/untar` to `fluxcd/pkg/tar` v0.2.0 as the former
has been deprecated. Ref: https://github.com/fluxcd/pkg/blob/main/untar/go.mod#L1

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2023-05-26 13:46:56 +05:30
Hidde Beydals eeef91a4b9
Update controller-runtime (v0.15) and K8s (v1.27)
This deals with various breaking changes in controller-runtime, as
documented in the release notes:
https://github.com/kubernetes-sigs/controller-runtime/releases/tag/v0.15.0

In short:

- `Watches` now use a `client.Object` instead of a `source.Kind`.
- `handler.MapFunc` signature accepts a Go context, which is used to
  log any errors, instead of silently ignoring them and/or panicking.
- Fake clients used in tests are now configured using
  `WithStatusSubresource` to enable the correct behavior for status
  updates and patches.
- Max concurrent reconciles is configured on the manager, instead of
  configuring them per reconciler instance.
- Various manager configuration options have been moved to new
  structures and/or fields.

In addition to this, all other dependencies which had updates are
updated to their latest (compatible) versions as well.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-05-24 09:05:42 +02:00
Stefan Prodan f58c229bc6 Update cosign to v2
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2023-05-22 11:08:12 +02:00
Hidde Beydals 3c87ad64e4
controller: verify digest of artifact in storage
This commits adds verification of the digest of the artifact in storage
to all reconcilers which manage artifacts.

When the artifact does not have a digest or if it mismatches with the
file in storage, the file is removed from the storage and status of the
object.

This hardens the storage against potential tampering, in addition to
resolving an issue where users upgrading from a (much) older version of
the controller would run into an error after the checksum field was
removed from the API.

This would cause the controller to not advertise any checksum at all,
while not producing a new one until a new revision was detected.
Resulting in fetch failures for consumers while they would try to
verify the digest of the advertised artifact.

While not strictly part of this exercise, some of the tests were
altered to prepare the storage used in test cases to become isolated
by strictly using the `storage` provided via the callback. Actually
isolating this has however been left as a task at a later moment.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-05-10 17:09:47 +02:00
Sunny e16d6ebde8 Move controllers to internal/controller
Make the controller implementations private.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2023-05-03 15:35:45 +05:30