Skip to content

Commit

Permalink
upgrade in-toto-golang to adapt SLSA Provenance (sigstore#582)
Browse files Browse the repository at this point in the history
Signed-off-by: Batuhan Apaydın <[email protected]>
  • Loading branch information
developer-guy committed Aug 26, 2021
1 parent 2f22e90 commit 72025c9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
16 changes: 8 additions & 8 deletions cmd/cosign/cli/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func Attest() *ffcli.Command {
predicatePath = flagset.String("predicate", "", "path to the predicate file.")
force = flagset.Bool("f", false, "skip warnings and confirmations")
idToken = flagset.String("identity-token", "", "[EXPERIMENTAL] identity token to use for certificate from fulcio")
predicateType = flagset.String("type", "custom", "specify predicate type (default: custom) (provenance|link|spdx)")
predicateType = flagset.String("type", "custom", "specify predicate type (default: custom) (slsaprovenance|link|spdx)")
)
return &ffcli.Command{
Name: "attest",
Expand All @@ -60,25 +60,25 @@ func Attest() *ffcli.Command {
EXAMPLES
# attach an attestation to a container image Google sign-in (experimental)
COSIGN_EXPERIMENTAL=1 cosign attest -predicate <FILE> <IMAGE>
COSIGN_EXPERIMENTAL=1 cosign attest -predicate <FILE> -type <TYPE> <IMAGE>
# attach an attestation to a container image with a local key pair file
cosign attest -predicate <FILE> -key cosign.key <IMAGE>
cosign attest -predicate <FILE> -type <TYPE> -key cosign.key <IMAGE>
# attach an attestation to a container image with a key pair stored in Azure Key Vault
cosign attest -predicate <FILE> -key azurekms://[VAULT_NAME][VAULT_URI]/[KEY] <IMAGE>
cosign attest -predicate <FILE> -type <TYPE> -key azurekms://[VAULT_NAME][VAULT_URI]/[KEY] <IMAGE>
# attach an attestation to a container image with a key pair stored in AWS KMS
cosign attest -predicate <FILE> -key awskms://[ENDPOINT]/[ID/ALIAS/ARN] <IMAGE>
cosign attest -predicate <FILE> -type <TYPE> -key awskms://[ENDPOINT]/[ID/ALIAS/ARN] <IMAGE>
# attach an attestation to a container image with a key pair stored in Google Cloud KMS
cosign attest -predicate <FILE> -key gcpkms://projects/[PROJECT]/locations/global/keyRings/[KEYRING]/cryptoKeys/[KEY]/versions/[VERSION] <IMAGE>
cosign attest -predicate <FILE> -type <TYPE> -key gcpkms://projects/[PROJECT]/locations/global/keyRings/[KEYRING]/cryptoKeys/[KEY]/versions/[VERSION] <IMAGE>
# attach an attestation to a container image with a key pair stored in Hashicorp Vault
cosign attest -predicate <FILE> -key hashivault://[KEY] <IMAGE>
cosign attest -predicate <FILE> -type <TYPE> -key hashivault://[KEY] <IMAGE>
# attach an attestation to a container image which does not fully support OCI media types
COSIGN_DOCKER_MEDIA_TYPES=1 cosign attest -predicate <FILE> -key cosign.key legacy-registry.example.com/my/image
COSIGN_DOCKER_MEDIA_TYPES=1 cosign attest -predicate <FILE> -type <TYPE> -key cosign.key legacy-registry.example.com/my/image
`,
FlagSet: flagset,
Exec: func(ctx context.Context, args []string) error {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ require (
github.com/hashicorp/vault/api v1.1.1 // indirect
github.com/hashicorp/vault/sdk v0.2.1 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/in-toto/in-toto-golang v0.2.1-0.20210627200632-886210ae2ab9
github.com/in-toto/in-toto-golang v0.2.1-0.20210806133539-f50646681592
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jedisct1/go-minisign v0.0.0-20210703085342-c1f07ee84431 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -954,8 +954,9 @@ github.com/imdario/mergo v0.3.10/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/in-toto/in-toto-golang v0.2.1-0.20210627200632-886210ae2ab9 h1:j7klXz5kh0ydPmHkBtJ/Al27G1/au4sH7OkGhkgRJWg=
github.com/in-toto/in-toto-golang v0.2.1-0.20210627200632-886210ae2ab9/go.mod h1:Skbg04kmfB7IAnEIsspKPg/ny1eiFt/TgPr9SDCHusA=
github.com/in-toto/in-toto-golang v0.2.1-0.20210806133539-f50646681592 h1:g9IxkZZUCtXHtU3fBXY+1WhEL6Hmcaelk4o4VGYSmsA=
github.com/in-toto/in-toto-golang v0.2.1-0.20210806133539-f50646681592/go.mod h1:Skbg04kmfB7IAnEIsspKPg/ny1eiFt/TgPr9SDCHusA=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
Expand Down
8 changes: 4 additions & 4 deletions pkg/cosign/attestation/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ func GenerateStatement(opts GenerateOpts) (interface{}, error) {
now := opts.Time()
stamp := now.UTC().Format(time.RFC3339)
return generateCustomStatement(rawPayload, opts.Digest, opts.Repo, stamp)
case "provenance":
return generateProvenanceStatement(rawPayload, opts.Digest, opts.Repo)
case "slsaprovenance":
return generateSLSAProvenanceStatement(rawPayload, opts.Digest, opts.Repo)
case "spdx":
return generateSPDXStatement(rawPayload, opts.Digest, opts.Repo)
case "link":
Expand Down Expand Up @@ -107,7 +107,7 @@ func generateCustomStatement(rawPayload []byte, digest, repo, timestamp string)
}, nil
}

func generateProvenanceStatement(rawPayload []byte, digest string, repo string) (interface{}, error) {
func generateSLSAProvenanceStatement(rawPayload []byte, digest string, repo string) (interface{}, error) {
var predicate in_toto.ProvenancePredicate
err := checkRequiredJSONFields(rawPayload, reflect.TypeOf(predicate))
if err != nil {
Expand All @@ -118,7 +118,7 @@ func generateProvenanceStatement(rawPayload []byte, digest string, repo string)
return "", errors.Wrap(err, "unmarshal Provenance predicate")
}
return in_toto.ProvenanceStatement{
StatementHeader: generateStatementHeader(digest, repo, in_toto.PredicateProvenanceV01),
StatementHeader: generateStatementHeader(digest, repo, in_toto.PredicateSLSAProvenanceV01),
Predicate: predicate,
}, nil
}
Expand Down

0 comments on commit 72025c9

Please sign in to comment.