Commit Graph

105 Commits

Author SHA1 Message Date
Sunny 3dacb3140e optional interval and default timeout for helmrepo
With static HelmRepository OCI, the interval become optional. Make
interval optional in the API. Introduce getters for interval, in the
form of GetRequeueAfter(), and timeout with internal default values.

HelmRepository will not have interval and timeout fields unless it's
explicitly set.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2023-11-22 21:05:57 +05:30
Sunny cf3735e2a2 Static helmrepository OCI
Remove the HelmRepositoryOCI reconciler and make HelmRepository of type
OCI static. The existing HelmRepository OCI objects are migrated to
static object by removing their finalizers and status. New
HelmRepository OCI objects go through one time migration to remove the
status. These are not reconciled again, unless the type is changed to
default. On type switching from HelmRepository default to OCI, the
finalizer, status and artifact are removed to make the object static. On
switching from OCI to default, a complete reconciliation of
HelmRepository takes place to build artifact and add status and
finalizer.

The HelmRepository .spec.url has a new validation to check the URL
scheme. This is to add some validation to HelmRepository OCI since it's
not backed by a reconciler for full validation.

Add HelmRepositoryOCIMigrationPredicate predicate to detect and allow
reconciliation of HelmRepository OCI objects that need migration. The
other predicates that filtered the HelmRepository events based on the
type have been removed as all the HelmRepositories will now be
reconciled by a single reconciler. HelmRepositoryOCIMigrationPredicate
readily allows non-OCI objects and only checks if a migration is needed
for OCI type object.

Add controller tests for different migration scenarios.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2023-11-22 21:05:51 +05:30
Sanskar Jaiswal dfcede03f2
helmrepo: only configure tls login option when required
Modify `GetHelmClientOpts()` to only configure the TLS login option when
an authentication login option is configured. This prevents the
reconciler from trying to authenticate against public registries.

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2023-11-22 10:05:45 +05:30
Stefan Prodan 58828350d5
Update dependencies to Kubernetes 1.28
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2023-11-20 16:50:44 +02:00
Hidde Beydals 646089e07e
storage: change default file permissions
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-11-06 12:22:40 +01: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
Stefan Prodan b655149786
bucket: Add prefix filtering capability
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2023-10-17 14:13:04 +03:00
Hidde Beydals 04612b539b
misc: fix hypothetical implicit memory aliasing
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-10-11 11:03:56 +02:00
Hidde Beydals a70b3f37c0
misc: remove unused code
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-10-11 11:03:55 +02:00
Hidde Beydals cdb43f1999
misc: add test case for invalid tag signature
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-10-11 11:03:55 +02: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 d9dbd1bdb7
misc: `rand.Seed` deprecation
See: https://pkg.go.dev/math/rand@go1.20#Seed

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-10-10 09:40:44 +02:00
Hidde Beydals 0a27f6ac90
misc: `iotuil` deprecation
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-10-10 09:40:43 +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
Hidde Beydals 3a0c27926e
misc: simplify by directly returning bool
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-10-09 15:11:09 +02:00
Hidde Beydals 691d925add
misc: ensure return errs are captured
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-10-09 15:11:09 +02:00
Hidde Beydals 0288645875
misc: properly handle f.Close() defer
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-10-09 15:10:49 +02:00
Hidde Beydals 8d1c755dd1
misc: remove unnecessary use of fmt.Sprintf
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-10-09 15:00:10 +02:00
Hidde Beydals 25400d8810
misc: remove redundant return statements
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-10-09 15:00:04 +02:00
Hidde Beydals 354a8e8dbf
misc: use `Err` prefix for errors
Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-10-09 14:59:58 +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
Sunny dd86bb9d34 Remove event error
Remove deprecated Event error. Event error was used for scenarios where
an error should result in an event/notification. It was introduced as a
contextual error along with Stalling and Waiting errors but was later
replaced with Generic error which doesn't have any contextual meaning.
The Generic error provided error configuration which allowed defining
how the error should be handled. This replaced the contextual error
handling with error action handlers which behaved on the error
configuration of the errors.

The Generic error was first introduced to be used in GitRepository
reconciler and was used by new reconcilers like the OCIRepository
reconcilers. The old reconcilers bucket, helmrepository and helmchart
reconcilers were still using the deprecated Event error. This change
replaces the Event errors in these reconcilers with a Generic error.

It also fixes a bug in the Generic error constructor which configured
the error to be logged by default. This resulted in an error to be
logged by the result processor and the runtime, double logging. This
behavior has been changed to not log explicitly and allow the runtime to
log the error. Since the Generic error is based on defining the error
handling behavior in the error configuration, a generic error that needs
to be ignored (not returned to the runtime), but logged can enable the
logging behavior explicitly on the Generic error instance. This is done
in GitRepository reconciler for no-op reconciliations where an ignore
error is returned.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
2023-09-15 17:41:43 +05:30
Sanskar Jaiswal f787fc7046
helmrepo: fix Secret type check for TLS via `.spec.secretRef`
This is a regression fix introduced in a302c71 which would wrongly check
for the type of the Secret specified in `.spec.secretRef` while
configuring TLS data.

Introduce `LegacyTLSClientConfigFromSecret` which does not check the
Secret type while constructing the TLS config.

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2023-09-06 00:27:45 +05:30
Sanskar Jaiswal 2a7f67de48
gitrepo: add support for specifying CA data via `ca.crt`
Check the auth secret for the `ca.crt` key for CA certificate data.
`ca.crt` takes precdence over `caFile`.

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2023-08-22 18:23:05 +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
Sanskar Jaiswal 4bd6bcc9e9
helmrepo: adopt Kubernetes 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.

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2023-08-22 18:23:04 +05:30
Sanskar Jaiswal 035d514af3
gitrepo: add tests for verifying tag signatures
Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2023-08-22 13:00:18 +05:30
Sanskar Jaiswal 59898cd86b
gitrepo: add support for verifying tags
Add support for verifying tags and optionally the commit object it
points to. Modify the reconciler to trigger a full reconciliation if the
object contains a verification configuration that implies that we need
to verify one (or more) Git objects that we haven't previosuly verified.

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2023-08-22 13:00:15 +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
Somtochi Onyekwere 1aa9cf2219 archive helm index in JSON format
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
2023-08-07 16:10:03 +02:00
Soule BA d45c08cba6
Add support for custom certificate and skip-tls-verify in helm OCI
If implemented user will be able to provide their own custom start and
bypass tls verification when interacting with OCI registries over https
to pull helmCharts.

Signed-off-by: Soule BA <soule@weave.works>
2023-08-07 16:07:04 +03: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 fce7c10fc0
oci: add tests for insecure cosign support; refactor test utils
Add tests to test Cosign support for insecure registries. Furthermore,
refactor OCI test utils to be more user friendly and enable accurate
testing of HTTPS and HTTP OCI registries by circumnavigating Docker's
automatic connection downgrade for registries hosted on localhost.

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2023-07-31 13:50:18 +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 944f4cfa10
gitrepo: Add support for specifying proxy per `GitRepository`
Add `.spec.proxySecretRef.name` to the `GitRepository` API to allow
referencing a secret containing the proxy settings to be used for all
remote Git operations for the particular `GitRepository` object.
It takes precedence over any proxy configured through enviornment
variables.

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2023-07-24 16:29:57 +05:30
Hidde Beydals 995cab57d4
Revert "Disable "empty repository" Git test"
This reverts commit 60571c08f1.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-07-03 12:18:33 +02:00
Kevin McDermott c159d260db Add verification key to repository verified status
This adds the ID of the key that was successful to the verified status
for GitRepository resources.

Signed-off-by: Kevin McDermott <kevin@weave.works>
2023-06-28 09:28:02 +01:00
Stefan Prodan 9b78bc6612
Update Cosign to v2.1.0
Adapt tests to match Cosign 2.1 error messages

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
2023-06-26 12:33:20 +03:00
Hidde Beydals 60571c08f1
Disable "empty repository" Git test
This is required because the test fails with Git >=v2.41.0 due to
changes to commands used by the Git test server. Causing the server to
return an error when cloning an empty repository, instead of yielding
an empty object.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-06-23 16:58:05 +02:00
Hidde Beydals 2f4b200571
Re-instantiate non-optimized clone fallback
This adds a bit back which got removed in
69f567bdc7, as there are reasons for the
controller to perform a non-optimized clone.

However, we always want to attempt the optimized version first without
it being put behind a feature gate. Which was the original intent of
the referenced commit.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-06-23 15:53:11 +02:00
Sanskar Jaiswal 69f567bdc7
gitrepo: remove `OptimizedGitClones` as a feature gate
Remove the `OptimizedGitClones` feature gate, making optimized Git
clones when using a branch or tag to checkout, the default behavior.

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2023-06-21 16:48:18 +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
Sanskar Jaiswal 68244b7d31
update dependencies and switch to `go-git/go-git`
* github.com/fluxcd/pkg/git => v0.12.2
* github.com/fluxcd/pkg/git/gogit => v0.11.1
* github.com/fluxcd/pkg/gittestserver => v0.8.4
* github.com/fluxcd/pkg/oci => v0.27.0
* github.com/fluxcd/pkg/sourceignore => v0.3.4

Switch from `fluxcd/go-git`to `go-git/go-git` v5.7.0, as all changes made
to our fork have been contributed back upstream.

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2023-05-26 13:46:48 +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
Hidde Beydals 0ec49784b5
oci: sort remaining quirks in cosign verify logic
This commit properly sets `IgnoreTlog` to `true` when a public key is
provided to check the signature against, which matches the (silent)
default behavior from cosign v1.

However, during this exercise it has become apparant that this
assumption isn't necessarily true. As you can theoretically have a
custom key and a tlog entry.

Given this, we should inventarise the possible configuration options
and the potential value they have to users (e.g. defining a custom
Rekor URL seems to be valuable as well), and extend our API to
facilitate these needs.

In addition to the above, the CTLog public keys are now properly
retrieved to avoid a `none of the CTFE keys have been found` error.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-05-22 11:08:16 +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
Rashed Kamal 2736b748e6
storage: set `0o744` for files with exec mode set
This commit ensures that files with exec permissions set continue to be
executable by the user extracting the archive.

This is not of use to any of Flux itself, but does help downstream
dependents making use of the controller to facilitate artifact
acquisitions for their (CI/CD) software suite.

Co-authored-by: Hidde Beydals <hidde@hhh.computer>
Signed-off-by: Rashed Kamal <krashed@vmware.com>
2023-05-12 10:11:08 +02:00
Hidde Beydals 6f762c7ef6
storage: change methods to value receiver
Given:

- None of the methods of the `Storage` are mutating the storage
  itself.
- It must be instantiated to be usable, as there is a strict
  reliance on values.
- The struct itself is light.

This seems to be more fitting.

Signed-off-by: Hidde Beydals <hidde@hhh.computer>
2023-05-10 17:09:48 +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
Hidde Beydals 67e9c94abf
storage: add VerifyArtifact method
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