Skip to content

Commit fc48494

Browse files
John Kjelldependabot[bot]ChaosInTheCRDMikhail Swift
authored
Link & SLSA attestor (#381)
* 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>
1 parent 0cd05b6 commit fc48494

File tree

6 files changed

+180
-172
lines changed

6 files changed

+180
-172
lines changed

.github/workflows/codeql.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ jobs:
5252
- name: Checkout repository
5353
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
5454

55+
- name: Setup Go
56+
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
57+
with:
58+
go-version: 1.21.x
5559
# Initializes the CodeQL tools for scanning.
5660
- name: Initialize CodeQL
5761
uses: github/codeql-action/init@d39d31e687223d841ef683f52467bd88e9b21c14 # v3.25.3

cmd/run.go

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ func runRun(ctx context.Context, ro options.RunOptions, args []string, signers .
7171
return fmt.Errorf("no signers found")
7272
}
7373

74-
out, err := loadOutfile(ro.OutFilePath)
75-
if err != nil {
76-
return fmt.Errorf("failed to open out file: %w", err)
77-
}
78-
7974
timestampers := []timestamp.Timestamper{}
8075
for _, url := range ro.TimestampServers {
8176
timestampers = append(timestampers, timestamp.NewTimestamper(timestamp.TimestampWithUrl(url)))
@@ -117,7 +112,7 @@ func runRun(ctx context.Context, ro options.RunOptions, args []string, signers .
117112
continue
118113
}
119114

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

135-
defer out.Close()
136-
result, err := witness.Run(
130+
results, err := witness.RunWithExports(
137131
ro.StepName,
138-
signers[0],
139132
witness.RunWithAttestors(attestors),
140133
witness.RunWithAttestationOpts(attestation.WithWorkingDir(ro.WorkingDir), attestation.WithHashes(roHashes)),
141134
witness.RunWithTimestampers(timestampers...),
135+
witness.RunWithSigners(signers...),
142136
)
143137
if err != nil {
144138
return err
145139
}
146140

147-
signedBytes, err := json.Marshal(&result.SignedEnvelope)
148-
if err != nil {
149-
return fmt.Errorf("failed to marshal envelope: %w", err)
150-
}
141+
for _, result := range results {
142+
signedBytes, err := json.Marshal(&result.SignedEnvelope)
143+
if err != nil {
144+
return fmt.Errorf("failed to marshal envelope: %w", err)
145+
}
151146

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

157-
if ro.ArchivistaOptions.Enable {
158-
archivistaClient := archivista.New(ro.ArchivistaOptions.Url)
159-
if gitoid, err := archivistaClient.Store(ctx, result.SignedEnvelope); err != nil {
160-
return fmt.Errorf("failed to store artifact in archivista: %w", err)
161-
} else {
162-
log.Infof("Stored in archivista as %v\n", gitoid)
153+
out, err := loadOutfile(outfile)
154+
if err != nil {
155+
return fmt.Errorf("failed to open out file: %w", err)
156+
}
157+
defer out.Close()
158+
159+
if _, err := out.Write(signedBytes); err != nil {
160+
return fmt.Errorf("failed to write envelope to out file: %w", err)
163161
}
164-
}
165162

163+
if ro.ArchivistaOptions.Enable {
164+
archivistaClient := archivista.New(ro.ArchivistaOptions.Url)
165+
if gitoid, err := archivistaClient.Store(ctx, result.SignedEnvelope); err != nil {
166+
return fmt.Errorf("failed to store artifact in archivista: %w", err)
167+
} else {
168+
log.Infof("Stored in archivista as %v\n", gitoid)
169+
}
170+
}
171+
}
166172
return nil
167173
}

cmd/verify.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func runVerify(ctx context.Context, vo options.VerifyOptions, verifiers ...crypt
124124
}
125125
}
126126

127-
verifiedEvidence, err := witness.Verify(
127+
verifiedResult, err := witness.Verify(
128128
ctx,
129129
policyEnvelope,
130130
verifiers,
@@ -138,8 +138,8 @@ func runVerify(ctx context.Context, vo options.VerifyOptions, verifiers ...crypt
138138
log.Info("Verification succeeded")
139139
log.Info("Evidence:")
140140
num := 0
141-
for _, stepEvidence := range verifiedEvidence {
142-
for _, e := range stepEvidence {
141+
for _, stepEvidence := range verifiedResult.StepResults {
142+
for _, e := range stepEvidence.Passed {
143143
log.Info(fmt.Sprintf("%d: %s", num, e.Reference))
144144
num++
145145
}

docs/commands.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ witness run [cmd] [flags]
4444
```
4545
--archivista-server string URL of the Archivista server to store or retrieve attestations (default "https://archivista.testifysec.io")
4646
-a, --attestations strings Attestations to record ('product' and 'material' are always recorded) (default [environment,git])
47+
--attestor-link-export Export the Link predicate in its own attestation
4748
--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")
4849
--attestor-product-exclude-glob string Pattern to use when recording products. Files that match this pattern will be excluded as subjects on the attestation.
4950
--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 "*")
51+
--attestor-slsa-export Export the SLSA provenance predicate in its own attestation
5052
--enable-archivista Use Archivista to store or retrieve attestations
5153
--hashes strings Hashes selected for digest calculation. Defaults to SHA256 (default [sha256])
5254
-h, --help help for run

go.mod

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.22.0
55
toolchain go1.22.2
66

77
require (
8-
github.com/in-toto/go-witness v0.3.1
8+
github.com/in-toto/go-witness v0.3.2-0.20240509152614-87975b4168e0
99
github.com/olekukonko/tablewriter v0.0.5
1010
github.com/sirupsen/logrus v1.9.3
1111
github.com/spf13/cobra v1.8.0
@@ -16,43 +16,43 @@ require (
1616
)
1717

1818
require (
19-
github.com/coreos/go-oidc/v3 v3.9.0 // indirect
19+
github.com/coreos/go-oidc/v3 v3.10.0 // indirect
2020
github.com/jmespath/go-jmespath v0.4.0 // indirect
2121
github.com/opencontainers/go-digest v1.0.0 // indirect
2222
github.com/segmentio/ksuid v1.0.4 // indirect
2323
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 // indirect
2424
github.com/spiffe/go-spiffe/v2 v2.1.7 // indirect
2525
github.com/zclconf/go-cty v1.14.2 // indirect
26-
golang.org/x/oauth2 v0.17.0 // indirect
27-
google.golang.org/appengine v1.6.8 // indirect
26+
golang.org/x/oauth2 v0.19.0 // indirect
2827
)
2928

3029
require (
31-
cloud.google.com/go/compute v1.24.0 // indirect
32-
cloud.google.com/go/compute/metadata v0.2.3 // indirect
33-
cloud.google.com/go/iam v1.1.6 // indirect
34-
cloud.google.com/go/kms v1.15.7 // indirect
30+
cloud.google.com/go/auth v0.3.0 // indirect
31+
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
32+
cloud.google.com/go/compute/metadata v0.3.0 // indirect
33+
cloud.google.com/go/iam v1.1.7 // indirect
34+
cloud.google.com/go/kms v1.15.9 // indirect
3535
dario.cat/mergo v1.0.0 // indirect
3636
github.com/Microsoft/go-winio v0.6.1 // indirect
3737
github.com/OneOfOne/xxhash v1.2.8 // indirect
3838
github.com/ProtonMail/go-crypto v1.0.0 // indirect
3939
github.com/agnivade/levenshtein v1.1.1 // indirect
4040
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
41-
github.com/aws/aws-sdk-go v1.50.27 // indirect
42-
github.com/aws/aws-sdk-go-v2 v1.25.2 // indirect
43-
github.com/aws/aws-sdk-go-v2/config v1.27.4 // indirect
44-
github.com/aws/aws-sdk-go-v2/credentials v1.17.4 // indirect
45-
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.2 // indirect
46-
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.2 // indirect
47-
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.2 // indirect
41+
github.com/aws/aws-sdk-go v1.50.38 // indirect
42+
github.com/aws/aws-sdk-go-v2 v1.26.1 // indirect
43+
github.com/aws/aws-sdk-go-v2/config v1.27.11 // indirect
44+
github.com/aws/aws-sdk-go-v2/credentials v1.17.11 // indirect
45+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.1 // indirect
46+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5 // indirect
47+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5 // indirect
4848
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
49-
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.1 // indirect
50-
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.2 // indirect
51-
github.com/aws/aws-sdk-go-v2/service/kms v1.29.1 // indirect
52-
github.com/aws/aws-sdk-go-v2/service/sso v1.20.1 // indirect
53-
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.1 // indirect
54-
github.com/aws/aws-sdk-go-v2/service/sts v1.28.1 // indirect
55-
github.com/aws/smithy-go v1.20.1 // indirect
49+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect
50+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7 // indirect
51+
github.com/aws/aws-sdk-go-v2/service/kms v1.31.0 // indirect
52+
github.com/aws/aws-sdk-go-v2/service/sso v1.20.5 // indirect
53+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.4 // indirect
54+
github.com/aws/aws-sdk-go-v2/service/sts v1.28.6 // indirect
55+
github.com/aws/smithy-go v1.20.2 // indirect
5656
github.com/beorn7/perks v1.0.1 // indirect
5757
github.com/cespare/xxhash/v2 v2.2.0 // indirect
5858
github.com/cloudflare/circl v1.3.7 // indirect
@@ -70,6 +70,7 @@ require (
7070
github.com/go-git/go-git/v5 v5.11.0 // indirect
7171
github.com/go-ini/ini v1.67.0 // indirect
7272
github.com/go-jose/go-jose/v3 v3.0.3 // indirect
73+
github.com/go-jose/go-jose/v4 v4.0.1 // indirect
7374
github.com/go-logr/logr v1.4.1 // indirect
7475
github.com/go-logr/stdr v1.2.2 // indirect
7576
github.com/gobwas/glob v0.2.3 // indirect
@@ -81,14 +82,15 @@ require (
8182
github.com/google/s2a-go v0.1.7 // indirect
8283
github.com/google/uuid v1.6.0 // indirect
8384
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
84-
github.com/googleapis/gax-go/v2 v2.12.1 // indirect
85+
github.com/googleapis/gax-go/v2 v2.12.3 // indirect
8586
github.com/gorilla/mux v1.8.1 // indirect
8687
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
8788
github.com/hashicorp/hcl v1.0.1-vault-3 // indirect
8889
github.com/in-toto/archivista v0.4.0 // indirect
90+
github.com/in-toto/attestation v1.0.1 // indirect
8991
github.com/inconshreveable/mousetrap v1.1.0 // indirect
9092
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
91-
github.com/jellydator/ttlcache/v3 v3.1.1 // indirect
93+
github.com/jellydator/ttlcache/v3 v3.2.0 // indirect
9294
github.com/json-iterator/go v1.1.12 // indirect
9395
github.com/kevinburke/ssh_config v1.2.0 // indirect
9496
github.com/letsencrypt/boulder v0.0.0-20240226214708-a97e074b5a3e // indirect
@@ -106,16 +108,16 @@ require (
106108
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
107109
github.com/prometheus/client_golang v1.19.0 // indirect
108110
github.com/prometheus/client_model v0.6.0 // indirect
109-
github.com/prometheus/common v0.48.0 // indirect
111+
github.com/prometheus/common v0.51.1 // indirect
110112
github.com/prometheus/procfs v0.12.0 // indirect
111113
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
112114
github.com/russross/blackfriday/v2 v2.1.0 // indirect
113115
github.com/sagikazarmark/locafero v0.4.0 // indirect
114116
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
115117
github.com/secure-systems-lab/go-securesystemslib v0.8.0 // indirect
116118
github.com/sergi/go-diff v1.3.1 // indirect
117-
github.com/sigstore/fulcio v1.4.4 // indirect
118-
github.com/sigstore/sigstore v1.8.1 // indirect
119+
github.com/sigstore/fulcio v1.4.5 // indirect
120+
github.com/sigstore/sigstore v1.8.3 // indirect
119121
github.com/skeema/knownhosts v1.2.1 // indirect
120122
github.com/sourcegraph/conc v0.3.0 // indirect
121123
github.com/spf13/afero v1.11.0 // indirect
@@ -130,29 +132,29 @@ require (
130132
github.com/yashtewari/glob-intersection v0.2.0 // indirect
131133
github.com/zeebo/errs v1.3.0 // indirect
132134
go.opencensus.io v0.24.0 // indirect
133-
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.48.0 // indirect
134-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.48.0 // indirect
135+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
136+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
135137
go.opentelemetry.io/otel v1.24.0 // indirect
136138
go.opentelemetry.io/otel/metric v1.24.0 // indirect
137139
go.opentelemetry.io/otel/sdk v1.24.0 // indirect
138140
go.opentelemetry.io/otel/trace v1.24.0 // indirect
139141
go.uber.org/multierr v1.11.0 // indirect
140-
golang.org/x/crypto v0.21.0 // indirect
141-
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 // indirect
142-
golang.org/x/mod v0.15.0 // indirect
143-
golang.org/x/net v0.23.0 // indirect
144-
golang.org/x/sync v0.6.0 // indirect
145-
golang.org/x/sys v0.18.0 // indirect
146-
golang.org/x/term v0.18.0 // indirect
142+
golang.org/x/crypto v0.22.0 // indirect
143+
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
144+
golang.org/x/mod v0.16.0 // indirect
145+
golang.org/x/net v0.24.0 // indirect
146+
golang.org/x/sync v0.7.0 // indirect
147+
golang.org/x/sys v0.19.0 // indirect
148+
golang.org/x/term v0.19.0 // indirect
147149
golang.org/x/text v0.14.0 // indirect
148150
golang.org/x/time v0.5.0 // indirect
149-
golang.org/x/tools v0.18.0 // indirect
150-
google.golang.org/api v0.167.0 // indirect
151-
google.golang.org/genproto v0.0.0-20240221002015-b0ce06bbee7c // indirect
152-
google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c // indirect
153-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c // indirect
154-
google.golang.org/grpc v1.62.0 // indirect
155-
google.golang.org/protobuf v1.33.0 // indirect
151+
golang.org/x/tools v0.19.0 // indirect
152+
google.golang.org/api v0.177.0 // indirect
153+
google.golang.org/genproto v0.0.0-20240401170217-c3f982113cda // indirect
154+
google.golang.org/genproto/googleapis/api v0.0.0-20240429193739-8cf5692501f6 // indirect
155+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6 // indirect
156+
google.golang.org/grpc v1.63.2 // indirect
157+
google.golang.org/protobuf v1.34.0 // indirect
156158
gopkg.in/go-jose/go-jose.v2 v2.6.3 // indirect
157159
gopkg.in/inf.v0 v0.9.1 // indirect
158160
gopkg.in/ini.v1 v1.67.0 // indirect

0 commit comments

Comments
 (0)