VerifyNotation verifies an image(`rawRef`) with the pre-configured notation trust policy `hostsDirs` are used to resolve image `rawRef`
(ctx context.Context, rawRef string, hostsDirs []string)
| 60 | // VerifyNotation verifies an image(`rawRef`) with the pre-configured notation trust policy |
| 61 | // `hostsDirs` are used to resolve image `rawRef` |
| 62 | func VerifyNotation(ctx context.Context, rawRef string, hostsDirs []string) (string, error) { |
| 63 | digest, err := imgutil.ResolveDigest(ctx, rawRef, false, hostsDirs) |
| 64 | if err != nil { |
| 65 | log.G(ctx).WithError(err).Errorf("unable to resolve digest for an image %s: %v", rawRef, err) |
| 66 | return rawRef, err |
| 67 | } |
| 68 | ref := rawRef |
| 69 | if !strings.Contains(ref, "@") { |
| 70 | ref += "@" + digest |
| 71 | } |
| 72 | |
| 73 | log.G(ctx).Debugf("verifying image: %s", ref) |
| 74 | |
| 75 | notationExecutable, err := exec.LookPath("notation") |
| 76 | if err != nil { |
| 77 | log.G(ctx).WithError(err).Error("notation executable not found in path $PATH") |
| 78 | log.G(ctx).Info("you might consider installing notation from: https://notaryproject.dev/docs/installation/cli/") |
| 79 | return ref, err |
| 80 | } |
| 81 | |
| 82 | notationCmd := exec.Command(notationExecutable, []string{"verify"}...) |
| 83 | notationCmd.Env = os.Environ() |
| 84 | |
| 85 | notationCmd.Args = append(notationCmd.Args, ref) |
| 86 | |
| 87 | log.G(ctx).Debugf("running %s %v", notationExecutable, notationCmd.Args) |
| 88 | |
| 89 | err = processNotationIO(notationCmd) |
| 90 | if err != nil { |
| 91 | return ref, err |
| 92 | } |
| 93 | if err := notationCmd.Wait(); err != nil { |
| 94 | return ref, err |
| 95 | } |
| 96 | |
| 97 | return ref, nil |
| 98 | } |
| 99 | |
| 100 | func processNotationIO(notationCmd *exec.Cmd) error { |
| 101 | stdout, err := notationCmd.StdoutPipe() |
no test coverage detected
searching dependent graphs…