Skip to content
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

Add image digests #214

Open
Tracked by #4245
michalschott opened this issue Dec 30, 2021 · 2 comments
Open
Tracked by #4245

Add image digests #214

michalschott opened this issue Dec 30, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@michalschott
Copy link

Would be good to have something like:

  • {"$imagepolicy": "<policy-namespace>:<policy-name>:digest"} resolving to image digest, for instance @sha256:foobar
  • {"$imagepolicy": "<policy-namespace>:<policy-name>:tagWithDigest"} resolving to image tag with digest, for instance v0.1.5@sha256:foobar
@relu relu added the enhancement New feature or request label Dec 30, 2021
@kingdonb
Copy link
Member

kingdonb commented Jan 6, 2022

This is a good idea.

For reference, the currently supported policy markers are here:

https://fluxcd.io/docs/guides/image-update/#configure-image-update-for-custom-resources

I can't think of any reason this wouldn't work for tagWithDigest, but I'm not sure how the digest policy marker would work. Would we still be scanning for image tags, and they still need to be sortable just as before, only the automation writes a digest into the YAML field? So we get the latest tag based on sortable tags, but when we write the value into the file, we just write the digest there.

(Flux doesn't care what value is in the field and it's not doing any comparison against the current value, so that still makes sense... it seems like there aren't any problems that can't be solved with this idea 👍 )

@relu
Copy link
Member

relu commented Jan 6, 2022

Extracting the digest information from the repository is achievable, it's just that we would need to also store this information in our embedded badger database together with the tags that would reference it. This would most likely yield in a breaking change on the side of the IRC. I've been thinking about how to make this work but couldn't really come up yet with a good solution just yet. An implementation for #202 would also touch on how/what we store in the database so it might make sense to include that in the conversation as well.

So we get the latest tag based on sortable tags, but when we write the value into the file, we just write the digest there.

That's kind of how I imagine it would work.

makkes pushed a commit that referenced this issue Apr 5, 2023
The new API field `.status.latestDigest` in the `ImagePolicy` kind
stores the digest of the image referred to by the the
`.status.latestImage` field.

This new field can be used to pin an image to an immutable descriptor
rather than to a potentially moving tag, increasing the security of
workloads deployed on a cluster.

The goal is to make use of the digest in IAC so that manifests can be
updated with the actual image digest.

This commit changes the format of the data stored in the caching
badger database from a list of strings to a list of `database.Tag`
objects where each tag carries a tag name and a digest value.

`ImageRepositoryReconciler` now fetched the digest of each image+tag
when it scans the registry for new tags. To accomplish this it issues
a HEAD request against the registry for each tag with the response
carrying the digest in the headers. Since this is a potentially
expensive operation involving network roundtrips for each tag, a
goroutine is spawned for each HEAD request to parallelize the fetching
process.

Migration from the old database format to the new one is taken care of
by the `badger.unmarshal` function which falls back to trying to
unmarshal the data into a string slice in case the attempt to
unmarshal it into a `database.Tag` slice fails. Subsequent `SetTags`
calls then store the data in the new format.

Because of its potential to significantly increase the amount of
network requests, the feature is disabled by default and can be
enabled using a feature flag for now.

closes #214

Signed-off-by: Max Jonas Werner <mail@makk.es>
makkes pushed a commit that referenced this issue Apr 6, 2023
The new API field `.status.latestDigest` in the `ImagePolicy` kind
stores the digest of the image referred to by the the
`.status.latestImage` field.

This new field can be used to pin an image to an immutable descriptor
rather than to a potentially moving tag, increasing the security of
workloads deployed on a cluster.

The goal is to make use of the digest in IAC so that manifests can be
updated with the actual image digest.

This commit changes the format of the data stored in the caching
badger database from a list of strings to a list of `database.Tag`
objects where each tag carries a tag name and a digest value.

`ImageRepositoryReconciler` now fetched the digest of each image+tag
when it scans the registry for new tags. To accomplish this it issues
a HEAD request against the registry for each tag with the response
carrying the digest in the headers. Since this is a potentially
expensive operation involving network roundtrips for each tag, a
goroutine is spawned for each HEAD request to parallelize the fetching
process.

Migration from the old database format to the new one is taken care of
by the `badger.unmarshal` function which falls back to trying to
unmarshal the data into a string slice in case the attempt to
unmarshal it into a `database.Tag` slice fails. Subsequent `SetTags`
calls then store the data in the new format.

Because of its potential to significantly increase the amount of
network requests, the feature is disabled by default and can be
enabled using a feature flag for now.

closes #214

Signed-off-by: Max Jonas Werner <mail@makk.es>
makkes pushed a commit that referenced this issue Apr 6, 2023
The new API field `.status.latestDigest` in the `ImagePolicy` kind
stores the digest of the image referred to by the the
`.status.latestImage` field.

This new field can be used to pin an image to an immutable descriptor
rather than to a potentially moving tag, increasing the security of
workloads deployed on a cluster.

The goal is to make use of the digest in IAC so that manifests can be
updated with the actual image digest.

This commit changes the format of the data stored in the caching
badger database from a list of strings to a list of `database.Tag`
objects where each tag carries a tag name and a digest value.

`ImageRepositoryReconciler` now fetched the digest of each image+tag
when it scans the registry for new tags. To accomplish this it issues
a HEAD request against the registry for each tag with the response
carrying the digest in the headers. Since this is a potentially
expensive operation involving network roundtrips for each tag, a
goroutine is spawned for each HEAD request to parallelize the fetching
process.

Migration from the old database format to the new one is taken care of
by the `badger.unmarshal` function which falls back to trying to
unmarshal the data into a string slice in case the attempt to
unmarshal it into a `database.Tag` slice fails. Subsequent `SetTags`
calls then store the data in the new format.

Because of its potential to significantly increase the amount of
network requests, the feature is disabled by default and can be
enabled using a feature flag for now.

closes #214

Signed-off-by: Max Jonas Werner <mail@makk.es>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants