You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Users can sign images produced with ko publish using tools like cosign.
For example:
$ cosign sign -key cosign.key $(ko publish ./)
ko resolve produces potentially many images, which makes this a bit harder. You could ko resolve then scan the resulting YAML for ko-built image references and sign all of those with some bash magic, but 🤮 .
Would it be useful to have a ko resolve --sign cosign.key flag that used the provided key to sign all images built during ko resolve?
ko publish --sign cosign.key could also be a convenience alias for, effectively, cosign sign $(ko publish), which wouldn't require users to have cosign installed.
Generally my preference would be to bias towards the ephemeral key route and use the same ephemeral key to sign all of the images produced (we should probably also start to think about incorporating a variety of opinionated attributes based on things we know about the build).
re: many images
something like mink produced ~25 images at its peak, for ~5 architectures, so 1 key vs ~150 keys (25*5 + 25) is probably a better way to go 🤣
This PR includes a technique I have been using to incorporate keyless signing into some ko-like tools: sigstore/cosign#647
Basically it only kicks in when COSIGN_EXPERIMENTAL=true for now, which is similar to how we've gated certain features with GGCR_EXPERIMENTAL_*, and this feels like an extremely lightweight way to integrate things.
We sacrifice some amount of configurability, but my inclination here would be to probably adjust how cosign itself works to use envconfig as a way to support a standard scheme for env-var fallback for configuration (no cobra, so no viper).
+1 to KO_EXPERIMENTAL_SOMETHING to iterate on this. How do we imagine this looking when it graduates from an experiment? We don't have a good example of doing that in GGCR as far as I know.
Ideally we'd end in a state where things are signed by default using ambient tokens if available, which can be disabled with a flag or config. Do we want to support signing with explicit keys? Or just leave that for cosign?
I think the first order of business will be to get the distroless images signed against Fulcio.
For configuring things, I think trying to standardize on env vars in cosign upstream would be my preference (for portability across tools).
For opting out (beyond experiment), I think some .ko.yaml syntax is called for, we can introduce this to ease folks into it too.
Another step between “experiment guarded” and “opt-out” to encourage folks to start signing will be to always verify, but make verification non-fatal (print warnings).
I also think we probably want some sort of refresh token flow for users before we move beyond experimental.
sorry this ended up sort of stream of consciousness.
Ok, full keyboard so here's sort of what I'm thinking in terms of phasing this in.
No change unless TBD *EXPERIMENT* env var is set, at which point base images must be signed, and published images are signed.
(once the default base images are signed against Fulcio)
Start verifying base images all the time, but verification is only fatal when TBD *EXPERIMENT* flag is set. When it isn't set we emit a warning. We still only sign things when it is set. We will need to sort out a way to opt-out of verification for each base image (likely in .ko.yaml?).
(once keyless signing is no longer "experimental" in Sigstore)
Start signing output images whenever ambient OIDC auth is available. Provide a way to require this (e.g. release envs), or opt-out entirely (e.g. dev environments avoiding 3LOs).
(once we have a clear opt-out path for base images)
Start to make verification of base images fatal by default.
As with --platform=all, we should never require signing by default (e.g. this would slow dev loops with 3LOs, and break using ko in PRs which won't have OIDC).
If we find out that being more aggressive signing things in dev is important (e.g. back-pressure from cosigned rejecting things), then we can always revisit this, but hopefully by then we have some sort of OIDC refresh token flow.
Starting to poke through code, I think the most natural integration point for signing is likely to implement a new publisher.Interface that composes with another publisher similar to the caching version:
// Wrap publisher in a memoizing publisher implementation.
return publish.NewCaching(innerPublisher)
}
If we have a signing publisher, we can accumulate / pass through images to an inner publisher, and then sign all of the accumulated images in Close() before closing the inner publisher. I think this would mean we use a single key to sign the entire set of images we publish 🤞
As I'm writing this I realize that cosign likely doesn't have functions that take a v1.Image (really build.Result) and return the v1.Image containing the signature, so we can't leverage the inner publisher to write the signature, which means the only publisher this should compose with right now is the default publisher. It would be cool to write such a function in cosign because it would allow us to emit signed images in tarballs and OCI layouts as well.
... generates a new cert for every image, and send the user through a separate 3LO for each one, so on big projects (e.g. knative.dev/serving) this is sort of prohibitive.
ko resolve -f config/ \
--fulcio-url https://staging.fulcio.not-sigstore.dev \
-a foo=bar \
--oidc-issuer=some.other-issuer.example \
...
Maybe we should wait for the [EXPERIMENTAL] stuff to become un-experimental -- sad as it would be to have to wait for the nice things -- before adding all those cosign flags to ko?
Maybe we should wait for the [EXPERIMENTAL] stuff to become un-experimental -- sad as it would be to have to wait for the nice things -- before adding all those cosign flags to ko?
I don't really think experimental will change much in the flag surface either way.
We've also been talking about plumbing sufficient environment variables into cosign to configure custom sigstore instances. The idea is to enable a pattern like minikube's env setup:
eval $(configure-sigstore-env)
cosign sign foo
Where the former emits a set of:
FOO=bar
BAZ=blah
I think we should aim to align with that model for configuring ko so that it can compose with tooling the same way cosign does.
Perhaps we should have a way to configure keyful via the env too?
OIDC signing for cosign is no longer experimental, after the recent Sigstore GA.
I still need to use COSIGN_EXPERIMENTAL for doing OIDC
I love the keyless signing but then wondering how we can configure keyless signing w/o browser, typically to have integration with CI/automation. I see lots of --odic* options to cosign but wondering will we be able to configure github/google oAuth via those options ( if so excuse my ignorance here). I see this https://docs.sigstore.dev/cosign/openid_signing#oauth-flows but not sure that helps CI/automation cases as there will be manual intervention
Perhaps we should have a way to configure keyful via the env too?
IMHO that should be, as may CI tools set values using env vars
I love the keyless signing but then wondering how we can configure keyless signing w/o browser, typically to have integration with CI/automation. I see lots of --odic* options to cosign but wondering will we be able to configure github/google oAuth via those options ( if so excuse my ignorance here). I see this https://docs.sigstore.dev/cosign/openid_signing#oauth-flows but not sure that helps CI/automation cases as there will be manual intervention
GitHub OIDC and Google and Amazon Workload Identity OIDC are all pretty straightforward to detect and use automatically, without flags.
The oidc flags for cosign sign for example mostly duplicate those that would be configured by the env vars Matt described.
When you run cosign sign inside GitHub Actions with OIDC enabled (id-token: write), cosign will automatically pick up the credentials from the environment and not require a browser.
To do this, cosign checks for the presence of a ACTIONS_ID_TOKEN_REQUEST_URL env var, which is set when the workflow is run with the id-token:write permission. If set, requests that URL with another GitHub-provided token. The response is an OIDC token that cosign can pass to Fulcio to get a short-lived signing cert, which it uses to sign the image and log to Rekor.
All of this should already be abstracted by sign.SignCmd, and ko would ideally do a similar thing using a future better-factored Go API.
@imjasonh have you tried using GitHub OIDC outside of GH Actions similar to how we can do GCP --identity-token signing ? I checked the GH Docs but not finding any clue on how to get the id-token from GH PAT
@imjasonh have you tried using GitHub OIDC outside of GH Actions similar to how we can do GCP --identity-token signing ? I checked the GH Docs but not finding any clue on how to get the id-token from GH PAT
I don't believe this is supported. GitHub OIDC is only a workload identity, and not a user identity based on a PAT.
We'll undoubtedly need to support keyful signing too, but my hope is that's rarer.
I might be in this situation. We have an internal build system that runs on Kubernetes and connects to Buildkit directly where we can "reliably" inject a private key for a build Job. I think supporting key-based signing would be a good start for Ko too and I'd like to help contribute if it's on the roadmap as this might be the fastest way for us to start signing images.
It looks like this issue has gone somewhat fallow... the last comments I see are in #603 (comment), which mention the need to reduce sigstore's dependency tree. Is that still the blocker, or is it implementation of Matt's environment setup in cosign in #357 (comment) ?
Yeah, I think that cosign needs to go on a major diet.
We've been achieving signing of ko (and apko) build images and attesting SBOMs and more with a set of terraform providers, which skirt this (direct) dependency.
I could see this being a good avenue for further exploration and integration into ko. If it works, I think we should at least un-internalize it, and maybe even split it out into its own repo, possibly upstream into sigstore. I know we've wanted a slimmer cosign-as-a-library for (checks calendar) about two and a half years now. Maybe this is it?
See my most recent comments in #603 (comment) -- it looks like the sigstore-go library (new as of April of this year) should be able to provide a lower-dependency avenue for implementing image signing.
Activity
dlorenc commentedon May 7, 2021
Great idea!
jonjohnsonjr commentedon May 7, 2021
This is where I really want a sidechannel for build outputs (my stupid "layoutput" thing).
mattmoor commentedon Aug 6, 2021
+1 to native integration here.
Generally my preference would be to bias towards the ephemeral key route and use the same ephemeral key to sign all of the images produced (we should probably also start to think about incorporating a variety of opinionated attributes based on things we know about the build).
re: many images
something like
minkproduced ~25 images at its peak, for ~5 architectures, so 1 key vs ~150 keys (25*5 + 25) is probably a better way to go 🤣mattmoor commentedon Sep 11, 2021
This PR includes a technique I have been using to incorporate keyless signing into some ko-like tools: sigstore/cosign#647
Basically it only kicks in when
COSIGN_EXPERIMENTAL=truefor now, which is similar to how we've gated certain features withGGCR_EXPERIMENTAL_*, and this feels like an extremely lightweight way to integrate things.We sacrifice some amount of configurability, but my inclination here would be to probably adjust how
cosignitself works to useenvconfigas a way to support a standard scheme for env-var fallback for configuration (no cobra, so no viper).imjasonh commentedon Sep 11, 2021
+1 to
KO_EXPERIMENTAL_SOMETHINGto iterate on this. How do we imagine this looking when it graduates from an experiment? We don't have a good example of doing that in GGCR as far as I know.Ideally we'd end in a state where things are signed by default using ambient tokens if available, which can be disabled with a flag or config. Do we want to support signing with explicit keys? Or just leave that for cosign?
mattmoor commentedon Sep 11, 2021
I think the first order of business will be to get the distroless images signed against Fulcio.
For configuring things, I think trying to standardize on env vars in cosign upstream would be my preference (for portability across tools).
For opting out (beyond experiment), I think some .ko.yaml syntax is called for, we can introduce this to ease folks into it too.
Another step between “experiment guarded” and “opt-out” to encourage folks to start signing will be to always verify, but make verification non-fatal (print warnings).
I also think we probably want some sort of refresh token flow for users before we move beyond experimental.
sorry this ended up sort of stream of consciousness.
mattmoor commentedon Sep 11, 2021
Ok, full keyboard so here's sort of what I'm thinking in terms of phasing this in.
*EXPERIMENT*env var is set, at which point base images must be signed, and published images are signed.(once the default base images are signed against Fulcio)
*EXPERIMENT*flag is set. When it isn't set we emit a warning. We still only sign things when it is set. We will need to sort out a way to opt-out of verification for each base image (likely in.ko.yaml?).(once keyless signing is no longer "experimental" in Sigstore)
(once we have a clear opt-out path for base images)
As with
--platform=all, we should never require signing by default (e.g. this would slow dev loops with 3LOs, and break usingkoin PRs which won't have OIDC).If we find out that being more aggressive signing things in dev is important (e.g. back-pressure from
cosignedrejecting things), then we can always revisit this, but hopefully by then we have some sort of OIDC refresh token flow.mattmoor commentedon Sep 12, 2021
Starting to poke through code, I think the most natural integration point for signing is likely to implement a new
publisher.Interfacethat composes with another publisher similar to the caching version:If we have a signing publisher, we can accumulate / pass through images to an inner publisher, and then sign all of the accumulated images in
Close()before closing the inner publisher. I think this would mean we use a single key to sign the entire set of images we publish 🤞As I'm writing this I realize that
cosignlikely doesn't have functions that take av1.Image(reallybuild.Result) and return thev1.Imagecontaining the signature, so we can't leverage the inner publisher to write the signature, which means the only publisher this should compose with right now is the default publisher. It would be cool to write such a function incosignbecause it would allow us to emit signed images in tarballs and OCI layouts as well.mattmoor commentedon Sep 12, 2021
So it looks like currently:
... generates a new cert for every image, and send the user through a separate 3LO for each one, so on big projects (e.g.
knative.dev/serving) this is sort of prohibitive.cc @dlorenc
Start to sketch out integration with `cosign`.
Start to sketch out integration with `cosign`.
Start to sketch out integration with `cosign`.
imjasonh commentedon Dec 15, 2021
Have we thought through what new CLI flags we'd need?
Regardless of how cosign-as-an-sdk evolves,
cosign signhas quite a lot of flags -- are we going to need all of these in everykosurface?Maybe we should wait for the [EXPERIMENTAL] stuff to become un-experimental -- sad as it would be to have to wait for the nice things -- before adding all those
cosignflags toko?dlorenc commentedon Dec 15, 2021
I don't really think experimental will change much in the flag surface either way.
11 remaining items
mattmoor commentedon Nov 21, 2022
We've also been talking about plumbing sufficient environment variables into
cosignto configure custom sigstore instances. The idea is to enable a pattern like minikube'senvsetup:Where the former emits a set of:
I think we should aim to align with that model for configuring
koso that it can compose with tooling the same waycosigndoes.Perhaps we should have a way to configure keyful via the env too?
kameshsampath commentedon Nov 22, 2022
I love the keyless signing but then wondering how we can configure keyless signing w/o browser, typically to have integration with CI/automation. I see lots of
--odic*options to cosign but wondering will we be able to configure github/google oAuth via those options ( if so excuse my ignorance here). I see this https://docs.sigstore.dev/cosign/openid_signing#oauth-flows but not sure that helps CI/automation cases as there will be manual interventionkameshsampath commentedon Nov 22, 2022
I also faced an dependencies issue as detailed here sigstore/cosign#2477
imjasonh commentedon Nov 22, 2022
GitHub OIDC and Google and Amazon Workload Identity OIDC are all pretty straightforward to detect and use automatically, without flags.
The
oidcflags forcosign signfor example mostly duplicate those that would be configured by the env vars Matt described.kameshsampath commentedon Nov 22, 2022
That should be better, we should wait for it IMHO
kameshsampath commentedon Nov 22, 2022
@imjasonh when trying the https://docs.sigstore.dev/cosign/openid_signing#oauth-flows I still see we get prompted to open browser or other kind of manual intervention. Not sure how they play with automation/CI workflow , I mean just by providing
--oidc*parameters.imjasonh commentedon Nov 22, 2022
When you run
cosign signinside GitHub Actions with OIDC enabled (id-token: write),cosignwill automatically pick up the credentials from the environment and not require a browser.For example:
This will sign the image as the GitHub Actions workload identity. You can see what that looks like in Rekor here: https://rekor.tlog.dev/?logIndex=7576978
To do this,
cosignchecks for the presence of aACTIONS_ID_TOKEN_REQUEST_URLenv var, which is set when the workflow is run with theid-token:writepermission. If set, requests that URL with another GitHub-provided token. The response is an OIDC token thatcosigncan pass to Fulcio to get a short-lived signing cert, which it uses to sign the image and log to Rekor.All of this should already be abstracted by
sign.SignCmd, andkowould ideally do a similar thing using a future better-factored Go API.kameshsampath commentedon Dec 2, 2022
@imjasonh have you tried using GitHub OIDC outside of GH Actions similar to how we can do GCP
--identity-tokensigning ? I checked the GH Docs but not finding any clue on how to get theid-tokenfrom GH PATimjasonh commentedon Dec 2, 2022
I don't believe this is supported. GitHub OIDC is only a workload identity, and not a user identity based on a PAT.
RealHarshThakur commentedon Jan 15, 2023
I might be in this situation. We have an internal build system that runs on Kubernetes and connects to Buildkit directly where we can "reliably" inject a private key for a build Job. I think supporting key-based signing would be a good start for Ko too and I'd like to help contribute if it's on the roadmap as this might be the fastest way for us to start signing images.
evankanderson commentedon Jul 19, 2023
It looks like this issue has gone somewhat fallow... the last comments I see are in #603 (comment), which mention the need to reduce sigstore's dependency tree. Is that still the blocker, or is it implementation of Matt's environment setup in cosign in #357 (comment) ?
mattmoor commentedon Jul 19, 2023
Yeah, I think that cosign needs to go on a major diet.
We've been achieving signing of ko (and apko) build images and attesting SBOMs and more with a set of terraform providers, which skirt this (direct) dependency.
imjasonh commentedon Aug 16, 2023
@jonjohnsonjr has done a fair bit of hacking and cutting on cosign's code to use it in tf-cosign, with an internal fork called
secant: https://github.com/chainguard-dev/terraform-provider-cosign/tree/main/internal/secantI could see this being a good avenue for further exploration and integration into
ko. If it works, I think we should at least un-internalize it, and maybe even split it out into its own repo, possibly upstream into sigstore. I know we've wanted a slimmer cosign-as-a-library for (checks calendar) about two and a half years now. Maybe this is it?evankanderson commentedon Dec 4, 2023
See my most recent comments in #603 (comment) -- it looks like the
sigstore-golibrary (new as of April of this year) should be able to provide a lower-dependency avenue for implementing image signing.try with oidc perm from here ko-build/ko#357