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 logic to detect and use ambient OIDC from exec envs. #644

Merged
merged 1 commit into from
Sep 11, 2021

Conversation

mattmoor
Copy link
Member

This is based on some work I have been doing here: https://github.com/mattmoor/oidc-magic

At present, it is fairly tedious to use the "keyless" flow inside of environments that have a form of ambient OIDC (e.g. GKE workload identity). For example, in the context of Tekton, one needs to overlay cosign on an image like docker.io/google/cloud-sdk:slim, and then during execution have the step do something like:

command: ["/bin/sh"]
args:
- "-c"
- |
  # Generate an identity token.
  IDENTITY_TOKEN=$(gcloud auth print-identity-token --audiences=sigstore)

  # Use the identity token to sign the image.
  cosign sign \
    -identity-token $IDENTITY_TOKEN \
    my.registry/the-image@sha256:deadbeef

This change adds support for detecting when cosign is executing within an environment with this kind of ambient authentication, and automatically producing one when -identity-token is not specified (and COSIGN_EXPERIMENTAL=true).

This means the same signing can now be done with:

args: ["sign", "my.registry/the-image@sha256:deadbeef"]

This is much simpler, but also the image will be both smaller (distroless) and more portable (not just GCP, but any provider we link).

This is based on some work I have been doing here: https://github.com/mattmoor/oidc-magic

At present, it is fairly tedious to use the "keyless" flow inside of environments that have a form of ambient OIDC (e.g. GKE workload identity).  For example, in the context of Tekton, one needs to overlay `cosign` on an image like `docker.io/google/cloud-sdk:slim`, and then during execution have the step do something like:

```yaml
command: ["/bin/sh"]
args:
- "-c"
- |
  # Generate an identity token.
  IDENTITY_TOKEN=$(gcloud auth print-identity-token --audiences=sigstore)

  # Use the identity token to sign the image.
  cosign sign \
    -identity-token $IDENTITY_TOKEN \
    my.registry/the-image@sha256:deadbeef
```

This change adds support for detecting when `cosign` is executing within an environment with this kind of ambient authentication, and automatically producing one when `-identity-token` is not specified (and `COSIGN_EXPERIMENTAL=true`).

This means the same signing can now be done with:

```yaml
args: ["sign", "my.registry/the-image@sha256:deadbeef"]
```

This is much simpler, but also the image will be both smaller (distroless) and more portable (not just GCP, but any provider we link).

Signed-off-by: Matt Moore <mattomata@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants