Skip to content

Commit

Permalink
Link & SLSA attestor (#381)
Browse files Browse the repository at this point in the history
* Add support for the new Link and SLSA Attestors in the CLI.
---------

Signed-off-by: John Kjell <john@testifysec.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Tom Meadows <tom@tmlabs.co.uk>
Co-authored-by: Mikhail Swift <mikhail@testifysec.com>
  • Loading branch information
4 people committed May 10, 2024
1 parent 0cd05b6 commit fc48494
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 172 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/codeql.yml
Expand Up @@ -52,6 +52,10 @@ jobs:
- name: Checkout repository
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4

- name: Setup Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: 1.21.x
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@d39d31e687223d841ef683f52467bd88e9b21c14 # v3.25.3
Expand Down
54 changes: 30 additions & 24 deletions cmd/run.go
Expand Up @@ -71,11 +71,6 @@ func runRun(ctx context.Context, ro options.RunOptions, args []string, signers .
return fmt.Errorf("no signers found")
}

out, err := loadOutfile(ro.OutFilePath)
if err != nil {
return fmt.Errorf("failed to open out file: %w", err)
}

timestampers := []timestamp.Timestamper{}
for _, url := range ro.TimestampServers {
timestampers = append(timestampers, timestamp.NewTimestamper(timestamp.TimestampWithUrl(url)))
Expand Down Expand Up @@ -117,7 +112,7 @@ func runRun(ctx context.Context, ro options.RunOptions, args []string, signers .
continue
}

attestor, err = registry.SetOptions(attestor, setters...)
attestor, err := registry.SetOptions(attestor, setters...)
if err != nil {
return fmt.Errorf("failed to set attestor option for %v: %w", attestor.Type(), err)
}
Expand All @@ -132,36 +127,47 @@ func runRun(ctx context.Context, ro options.RunOptions, args []string, signers .
roHashes = append(roHashes, cryptoutil.DigestValue{Hash: hash, GitOID: false})
}

defer out.Close()
result, err := witness.Run(
results, err := witness.RunWithExports(
ro.StepName,
signers[0],
witness.RunWithAttestors(attestors),
witness.RunWithAttestationOpts(attestation.WithWorkingDir(ro.WorkingDir), attestation.WithHashes(roHashes)),
witness.RunWithTimestampers(timestampers...),
witness.RunWithSigners(signers...),
)
if err != nil {
return err
}

signedBytes, err := json.Marshal(&result.SignedEnvelope)
if err != nil {
return fmt.Errorf("failed to marshal envelope: %w", err)
}
for _, result := range results {
signedBytes, err := json.Marshal(&result.SignedEnvelope)
if err != nil {
return fmt.Errorf("failed to marshal envelope: %w", err)
}

log.Infof("Writing signed envelope to %s\n", ro.OutFilePath)
if _, err := out.Write(signedBytes); err != nil {
return fmt.Errorf("failed to write envelope to out file: %w", err)
}
// TODO: Find out explicit way to describe "prefix" in CLI options
outfile := ro.OutFilePath
if result.AttestorName != "" {
outfile += "-" + result.AttestorName + ".json"
}

if ro.ArchivistaOptions.Enable {
archivistaClient := archivista.New(ro.ArchivistaOptions.Url)
if gitoid, err := archivistaClient.Store(ctx, result.SignedEnvelope); err != nil {
return fmt.Errorf("failed to store artifact in archivista: %w", err)
} else {
log.Infof("Stored in archivista as %v\n", gitoid)
out, err := loadOutfile(outfile)
if err != nil {
return fmt.Errorf("failed to open out file: %w", err)
}
defer out.Close()

if _, err := out.Write(signedBytes); err != nil {
return fmt.Errorf("failed to write envelope to out file: %w", err)
}
}

if ro.ArchivistaOptions.Enable {
archivistaClient := archivista.New(ro.ArchivistaOptions.Url)
if gitoid, err := archivistaClient.Store(ctx, result.SignedEnvelope); err != nil {
return fmt.Errorf("failed to store artifact in archivista: %w", err)
} else {
log.Infof("Stored in archivista as %v\n", gitoid)
}
}
}
return nil
}
6 changes: 3 additions & 3 deletions cmd/verify.go
Expand Up @@ -124,7 +124,7 @@ func runVerify(ctx context.Context, vo options.VerifyOptions, verifiers ...crypt
}
}

verifiedEvidence, err := witness.Verify(
verifiedResult, err := witness.Verify(
ctx,
policyEnvelope,
verifiers,
Expand All @@ -138,8 +138,8 @@ func runVerify(ctx context.Context, vo options.VerifyOptions, verifiers ...crypt
log.Info("Verification succeeded")
log.Info("Evidence:")
num := 0
for _, stepEvidence := range verifiedEvidence {
for _, e := range stepEvidence {
for _, stepEvidence := range verifiedResult.StepResults {
for _, e := range stepEvidence.Passed {
log.Info(fmt.Sprintf("%d: %s", num, e.Reference))
num++
}
Expand Down
2 changes: 2 additions & 0 deletions docs/commands.md
Expand Up @@ -44,9 +44,11 @@ witness run [cmd] [flags]
```
--archivista-server string URL of the Archivista server to store or retrieve attestations (default "https://archivista.testifysec.io")
-a, --attestations strings Attestations to record ('product' and 'material' are always recorded) (default [environment,git])
--attestor-link-export Export the Link predicate in its own attestation
--attestor-maven-pom-path string The path to the Project Object Model (POM) XML file used for task being attested (default "pom.xml"). (default "pom.xml")
--attestor-product-exclude-glob string Pattern to use when recording products. Files that match this pattern will be excluded as subjects on the attestation.
--attestor-product-include-glob string Pattern to use when recording products. Files that match this pattern will be included as subjects on the attestation. (default "*")
--attestor-slsa-export Export the SLSA provenance predicate in its own attestation
--enable-archivista Use Archivista to store or retrieve attestations
--hashes strings Hashes selected for digest calculation. Defaults to SHA256 (default [sha256])
-h, --help help for run
Expand Down
88 changes: 45 additions & 43 deletions go.mod
Expand Up @@ -5,7 +5,7 @@ go 1.22.0
toolchain go1.22.2

require (
github.com/in-toto/go-witness v0.3.1
github.com/in-toto/go-witness v0.3.2-0.20240509152614-87975b4168e0
github.com/olekukonko/tablewriter v0.0.5
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0
Expand All @@ -16,43 +16,43 @@ require (
)

require (
github.com/coreos/go-oidc/v3 v3.9.0 // indirect
github.com/coreos/go-oidc/v3 v3.10.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/segmentio/ksuid v1.0.4 // indirect
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 // indirect
github.com/spiffe/go-spiffe/v2 v2.1.7 // indirect
github.com/zclconf/go-cty v1.14.2 // indirect
golang.org/x/oauth2 v0.17.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
golang.org/x/oauth2 v0.19.0 // indirect
)

require (
cloud.google.com/go/compute v1.24.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.6 // indirect
cloud.google.com/go/kms v1.15.7 // indirect
cloud.google.com/go/auth v0.3.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
cloud.google.com/go/compute/metadata v0.3.0 // indirect
cloud.google.com/go/iam v1.1.7 // indirect
cloud.google.com/go/kms v1.15.9 // indirect
dario.cat/mergo v1.0.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/OneOfOne/xxhash v1.2.8 // indirect
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/agnivade/levenshtein v1.1.1 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/aws/aws-sdk-go v1.50.27 // indirect
github.com/aws/aws-sdk-go-v2 v1.25.2 // indirect
github.com/aws/aws-sdk-go-v2/config v1.27.4 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.4 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.2 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.2 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.2 // indirect
github.com/aws/aws-sdk-go v1.50.38 // indirect
github.com/aws/aws-sdk-go-v2 v1.26.1 // indirect
github.com/aws/aws-sdk-go-v2/config v1.27.11 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.11 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.1 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.1 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.2 // indirect
github.com/aws/aws-sdk-go-v2/service/kms v1.29.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.20.1 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.28.1 // indirect
github.com/aws/smithy-go v1.20.1 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7 // indirect
github.com/aws/aws-sdk-go-v2/service/kms v1.31.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.20.5 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.4 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.28.6 // indirect
github.com/aws/smithy-go v1.20.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
Expand All @@ -70,6 +70,7 @@ require (
github.com/go-git/go-git/v5 v5.11.0 // indirect
github.com/go-ini/ini v1.67.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.3 // indirect
github.com/go-jose/go-jose/v4 v4.0.1 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gobwas/glob v0.2.3 // indirect
Expand All @@ -81,14 +82,15 @@ require (
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.1 // indirect
github.com/googleapis/gax-go/v2 v2.12.3 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
github.com/hashicorp/hcl v1.0.1-vault-3 // indirect
github.com/in-toto/archivista v0.4.0 // indirect
github.com/in-toto/attestation v1.0.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jellydator/ttlcache/v3 v3.1.1 // indirect
github.com/jellydator/ttlcache/v3 v3.2.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/letsencrypt/boulder v0.0.0-20240226214708-a97e074b5a3e // indirect
Expand All @@ -106,16 +108,16 @@ require (
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.19.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/common v0.51.1 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/secure-systems-lab/go-securesystemslib v0.8.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/sigstore/fulcio v1.4.4 // indirect
github.com/sigstore/sigstore v1.8.1 // indirect
github.com/sigstore/fulcio v1.4.5 // indirect
github.com/sigstore/sigstore v1.8.3 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
Expand All @@ -130,29 +132,29 @@ require (
github.com/yashtewari/glob-intersection v0.2.0 // indirect
github.com/zeebo/errs v1.3.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.48.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.48.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/sdk v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.18.0 // indirect
google.golang.org/api v0.167.0 // indirect
google.golang.org/genproto v0.0.0-20240221002015-b0ce06bbee7c // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c // indirect
google.golang.org/grpc v1.62.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
golang.org/x/tools v0.19.0 // indirect
google.golang.org/api v0.177.0 // indirect
google.golang.org/genproto v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240429193739-8cf5692501f6 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6 // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.34.0 // indirect
gopkg.in/go-jose/go-jose.v2 v2.6.3 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down

0 comments on commit fc48494

Please sign in to comment.