diff --git a/docs/docs/supply-chain/attestation/vuln.md b/docs/docs/supply-chain/attestation/vuln.md index e0f78a541a49..c17164f0f30b 100644 --- a/docs/docs/supply-chain/attestation/vuln.md +++ b/docs/docs/supply-chain/attestation/vuln.md @@ -30,6 +30,7 @@ $ trivy image --format cosign-vuln --output vuln.json alpine:3.10 }, "result": { "SchemaVersion": 2, + "CreatedAt": 1629894030, "ArtifactName": "alpine:3.10", "ArtifactType": "container_image", "Metadata": { diff --git a/pkg/cloud/aws/commands/run_test.go b/pkg/cloud/aws/commands/run_test.go index 70d8dc672368..292c6040c9ad 100644 --- a/pkg/cloud/aws/commands/run_test.go +++ b/pkg/cloud/aws/commands/run_test.go @@ -12,11 +12,13 @@ import ( defsecTypes "github.com/aquasecurity/defsec/pkg/types" dbTypes "github.com/aquasecurity/trivy-db/pkg/types" + "github.com/aquasecurity/trivy/pkg/clock" "github.com/aquasecurity/trivy/pkg/compliance/spec" "github.com/aquasecurity/trivy/pkg/flag" ) const expectedS3ScanResult = `{ + "CreatedAt": 1629894030, "ArtifactName": "12345678", "ArtifactType": "aws_account", "Metadata": { @@ -264,6 +266,7 @@ const expectedS3ScanResult = `{ ` const expectedCustomScanResult = `{ + "CreatedAt": 1629894030, "ArtifactName": "12345678", "ArtifactType": "aws_account", "Metadata": { @@ -544,6 +547,7 @@ const expectedCustomScanResult = `{ ` const expectedS3AndCloudTrailResult = `{ + "CreatedAt": 1629894030, "ArtifactName": "123456789", "ArtifactType": "aws_account", "Metadata": { @@ -1125,6 +1129,7 @@ Summary Report for compliance: my-custom-spec } for _, test := range tests { t.Run(test.name, func(t *testing.T) { + clock.SetFakeTime(t, time.Date(2021, 8, 25, 12, 20, 30, 5, time.UTC)) if test.allServices != nil { oldAllSupportedServicesFunc := allSupportedServicesFunc allSupportedServicesFunc = func() []string { diff --git a/pkg/cloud/report/service_test.go b/pkg/cloud/report/service_test.go index 6e4ae99c2cd4..437f1844aed0 100644 --- a/pkg/cloud/report/service_test.go +++ b/pkg/cloud/report/service_test.go @@ -4,6 +4,7 @@ import ( "os" "path/filepath" "testing" + "time" "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/stretchr/testify/assert" @@ -11,6 +12,7 @@ import ( "github.com/aquasecurity/defsec/pkg/scan" defsecTypes "github.com/aquasecurity/defsec/pkg/types" + "github.com/aquasecurity/trivy/pkg/clock" "github.com/aquasecurity/trivy-db/pkg/types" "github.com/aquasecurity/trivy/pkg/flag" ) @@ -148,6 +150,7 @@ Scan Overview for AWS Account fromCache: false, expected: `{ "ArtifactType": "aws_account", + "CreatedAt": 1629894030, "Metadata": { "ImageConfig": { "architecture": "", @@ -309,6 +312,7 @@ Scan Overview for AWS Account } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + clock.SetFakeTime(t, time.Date(2021, 8, 25, 12, 20, 30, 5, time.UTC)) report := New( "AWS", tt.options.AWSOptions.Account, diff --git a/pkg/report/writer.go b/pkg/report/writer.go index 31c606f1e5bf..2b2e1c70ddc5 100644 --- a/pkg/report/writer.go +++ b/pkg/report/writer.go @@ -9,6 +9,7 @@ import ( cr "github.com/aquasecurity/trivy/pkg/compliance/report" ftypes "github.com/aquasecurity/trivy/pkg/fanal/types" + "github.com/aquasecurity/trivy/pkg/clock" "github.com/aquasecurity/trivy/pkg/flag" "github.com/aquasecurity/trivy/pkg/log" "github.com/aquasecurity/trivy/pkg/report/cyclonedx" @@ -91,6 +92,8 @@ func Write(report types.Report, option flag.Options) error { return xerrors.Errorf("unknown format: %v", option.Format) } + report.CreatedAt = clock.Now().Unix() + if err := writer.Write(report); err != nil { return xerrors.Errorf("failed to write results: %w", err) } diff --git a/pkg/types/report.go b/pkg/types/report.go index a085ee454519..edead1568ca1 100644 --- a/pkg/types/report.go +++ b/pkg/types/report.go @@ -11,6 +11,7 @@ import ( // Report represents a scan result type Report struct { SchemaVersion int `json:",omitempty"` + CreatedAt int64 `json:",omitempty"` ArtifactName string `json:",omitempty"` ArtifactType ftypes.ArtifactType `json:",omitempty"` Metadata Metadata `json:",omitempty"`