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

Adding warning to pin to digest #2311

Merged
merged 1 commit into from
Oct 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/cosign/cli/sign/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ func SignCmd(ro *options.RootOptions, ko options.KeyOpts, regOpts options.Regist
return fmt.Errorf("unable to resolve attachment %s for image %s", attachment, inputImg)
}

if _, ok := ref.(name.Tag); ok {
fmt.Println("Warning: Tag used in reference to identify the image. Consider supplying the digest for immutability.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's annoying, but I'm going to bikeshed the message a little bit. Appreciate your patience 🙂

Can you revise the message to something like:

WARNING: Image reference %s uses a tag, not a digest, to identify the image to sign.

This can lead you to sign a different image than the intended one. Please use a digest (example.com/ubuntu@sha256:abcdef...) rather than tag (example.com/ubuntu:latest) for the input to cosign. The ability to refer to images by tag will be removed in a future release.

%s: inputImg

Feel free to make modifications, but I want to hit the following points:

  1. "Warning" should be "WARNING" for consistency with other messages in the codebase.
  2. Gives motivation.
  3. Tells you how to fix the issue with examples.
  4. Mentions that digest references will be required in the future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we print the warning after we resolve the digest, the error message can give you exactly the command to run instead, without needing a placeholder digest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we print the warning after we resolve the digest, the error message can give you exactly the command to run instead, without needing a placeholder digest.

I was thinking this... but by telling the user the digest they should plan to use... doesn't that hold them susceptible for the very problem that the warning tries to avoid? Instead the warning should say "make sure you figure out what the digest of the image is, but we are not the ones to tell you now, just know for next time". Maybe I have other thought it @imjasonh

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to @ChaosInTheCRD here.

BTW I'm following up in #2313 so we can have discussion there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use fmt.Fprintln(os.Stderr, "...") instead? We like to reserve STDOUT for the output of the command.

}

if digest, ok := ref.(name.Digest); ok && !recursive {
se, err := ociremote.SignedEntity(ref, opts...)
if err != nil {
Expand Down