Skip to content

Commit 76475e3

Browse files
committed
docs: update the docs with cloud settings
1 parent 17dbf9a commit 76475e3

File tree

10 files changed

+186
-15
lines changed

10 files changed

+186
-15
lines changed

docs/docs/references/configuration/cli/trivy_config.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ trivy config [flags] DIR
1414
--cf-params strings specify paths to override the CloudFormation parameters files
1515
--check-namespaces strings Rego namespaces
1616
--checks-bundle-repository string OCI registry URL to retrieve checks bundle from (default "mirror.gcr.io/aquasec/trivy-checks:1")
17+
--cloud-api-url string API URL for Trivy Cloud platform (default "https://api.trivy.dev")
18+
--cloud-download-secret-config Download secret configurations from Trivy Cloud platform (default true)
19+
--cloud-server-scanning Use server-side image scanning in Trivy Cloud platform (default true)
20+
--cloud-token string Token used to athenticate with Trivy Cloud platform
21+
--cloud-trivy-server-url string Trivy Server URL for Trivy Cloud platform (default "https://scan.trivy.dev")
22+
--cloud-upload-results Upload results to Trivy Cloud platform (default true)
1723
--compliance string compliance report to generate
1824
--config-check strings specify the paths to the Rego check files or to the directories containing them, applying config files
1925
--config-data strings specify paths from which data for the Rego checks will be recursively loaded

docs/docs/references/configuration/cli/trivy_filesystem.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ trivy filesystem [flags] PATH
2424
--cf-params strings specify paths to override the CloudFormation parameters files
2525
--check-namespaces strings Rego namespaces
2626
--checks-bundle-repository string OCI registry URL to retrieve checks bundle from (default "mirror.gcr.io/aquasec/trivy-checks:1")
27+
--cloud-api-url string API URL for Trivy Cloud platform (default "https://api.trivy.dev")
28+
--cloud-download-secret-config Download secret configurations from Trivy Cloud platform (default true)
29+
--cloud-server-scanning Use server-side image scanning in Trivy Cloud platform (default true)
30+
--cloud-token string Token used to athenticate with Trivy Cloud platform
31+
--cloud-trivy-server-url string Trivy Server URL for Trivy Cloud platform (default "https://scan.trivy.dev")
32+
--cloud-upload-results Upload results to Trivy Cloud platform (default true)
2733
--compliance string compliance report to generate
2834
--config-check strings specify the paths to the Rego check files or to the directories containing them, applying config files
2935
--config-data strings specify paths from which data for the Rego checks will be recursively loaded

docs/docs/references/configuration/cli/trivy_image.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ trivy image [flags] IMAGE_NAME
3939
--check-namespaces strings Rego namespaces
4040
--checks-bundle-repository string OCI registry URL to retrieve checks bundle from (default "mirror.gcr.io/aquasec/trivy-checks:1")
4141
--cloud-api-url string API URL for Trivy Cloud platform (default "https://api.trivy.dev")
42-
--cloud-download-misconfig-config Download misconfig configurations from Trivy Cloud platform (default true)
4342
--cloud-download-secret-config Download secret configurations from Trivy Cloud platform (default true)
4443
--cloud-server-scanning Use server-side image scanning in Trivy Cloud platform (default true)
4544
--cloud-token string Token used to athenticate with Trivy Cloud platform

docs/docs/references/configuration/cli/trivy_repository.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ trivy repository [flags] (REPO_PATH | REPO_URL)
2424
--cf-params strings specify paths to override the CloudFormation parameters files
2525
--check-namespaces strings Rego namespaces
2626
--checks-bundle-repository string OCI registry URL to retrieve checks bundle from (default "mirror.gcr.io/aquasec/trivy-checks:1")
27+
--cloud-api-url string API URL for Trivy Cloud platform (default "https://api.trivy.dev")
28+
--cloud-download-secret-config Download secret configurations from Trivy Cloud platform (default true)
29+
--cloud-server-scanning Use server-side image scanning in Trivy Cloud platform (default true)
30+
--cloud-token string Token used to athenticate with Trivy Cloud platform
31+
--cloud-trivy-server-url string Trivy Server URL for Trivy Cloud platform (default "https://scan.trivy.dev")
32+
--cloud-upload-results Upload results to Trivy Cloud platform (default true)
2733
--commit string pass the commit hash to be scanned
2834
--config-check strings specify the paths to the Rego check files or to the directories containing them, applying config files
2935
--config-data strings specify paths from which data for the Rego checks will be recursively loaded

docs/docs/references/configuration/cli/trivy_rootfs.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ trivy rootfs [flags] ROOTDIR
2727
--cf-params strings specify paths to override the CloudFormation parameters files
2828
--check-namespaces strings Rego namespaces
2929
--checks-bundle-repository string OCI registry URL to retrieve checks bundle from (default "mirror.gcr.io/aquasec/trivy-checks:1")
30+
--cloud-api-url string API URL for Trivy Cloud platform (default "https://api.trivy.dev")
31+
--cloud-download-secret-config Download secret configurations from Trivy Cloud platform (default true)
32+
--cloud-server-scanning Use server-side image scanning in Trivy Cloud platform (default true)
33+
--cloud-token string Token used to athenticate with Trivy Cloud platform
34+
--cloud-trivy-server-url string Trivy Server URL for Trivy Cloud platform (default "https://scan.trivy.dev")
35+
--cloud-upload-results Upload results to Trivy Cloud platform (default true)
3036
--config-check strings specify the paths to the Rego check files or to the directories containing them, applying config files
3137
--config-data strings specify paths from which data for the Rego checks will be recursively loaded
3238
--config-file-schemas strings specify paths to JSON configuration file schemas to determine that a file matches some configuration and pass the schema to Rego checks for type checking

docs/docs/references/configuration/cli/trivy_vm.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ trivy vm [flags] VM_IMAGE
2424
--cache-backend string [EXPERIMENTAL] cache backend (e.g. redis://localhost:6379) (default "fs")
2525
--cache-ttl duration cache TTL when using redis as cache backend
2626
--checks-bundle-repository string OCI registry URL to retrieve checks bundle from (default "mirror.gcr.io/aquasec/trivy-checks:1")
27+
--cloud-api-url string API URL for Trivy Cloud platform (default "https://api.trivy.dev")
28+
--cloud-download-secret-config Download secret configurations from Trivy Cloud platform (default true)
29+
--cloud-server-scanning Use server-side image scanning in Trivy Cloud platform (default true)
30+
--cloud-token string Token used to athenticate with Trivy Cloud platform
31+
--cloud-trivy-server-url string Trivy Server URL for Trivy Cloud platform (default "https://scan.trivy.dev")
32+
--cloud-upload-results Upload results to Trivy Cloud platform (default true)
2733
--compliance string compliance report to generate
2834
--config-file-schemas strings specify paths to JSON configuration file schemas to determine that a file matches some configuration and pass the schema to Rego checks for type checking
2935
--custom-headers strings custom headers in client mode

pkg/commands/app.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ func NewFilesystemCommand(globalFlags *flag.GlobalFlagGroup) *cobra.Command {
351351
flag.NewScanFlagGroup(),
352352
flag.NewSecretFlagGroup(),
353353
flag.NewVulnerabilityFlagGroup(),
354+
flag.NewCloudFlagGroup(),
354355
}
355356

356357
cmd := &cobra.Command{
@@ -417,6 +418,7 @@ func NewRootfsCommand(globalFlags *flag.GlobalFlagGroup) *cobra.Command {
417418
flag.NewScanFlagGroup(),
418419
flag.NewSecretFlagGroup(),
419420
flag.NewVulnerabilityFlagGroup(),
421+
flag.NewCloudFlagGroup(),
420422
}
421423

422424
cmd := &cobra.Command{
@@ -482,6 +484,7 @@ func NewRepositoryCommand(globalFlags *flag.GlobalFlagGroup) *cobra.Command {
482484
flag.NewSecretFlagGroup(),
483485
flag.NewVulnerabilityFlagGroup(),
484486
flag.NewRepoFlagGroup(),
487+
flag.NewCloudFlagGroup(),
485488
}
486489

487490
cmd := &cobra.Command{
@@ -704,6 +707,7 @@ func NewConfigCommand(globalFlags *flag.GlobalFlagGroup) *cobra.Command {
704707
flag.NewModuleFlagGroup(),
705708
flag.NewRegistryFlagGroup(),
706709
flag.NewRegoFlagGroup(),
710+
flag.NewCloudFlagGroup(),
707711
&flag.K8sFlagGroup{
708712
// Keep only --k8s-version flag and disable others
709713
K8sVersion: flag.K8sVersionFlag.Clone(),
@@ -1097,6 +1101,7 @@ func NewVMCommand(globalFlags *flag.GlobalFlagGroup) *cobra.Command {
10971101
flag.NewScanFlagGroup(),
10981102
flag.NewSecretFlagGroup(),
10991103
flag.NewVulnerabilityFlagGroup(),
1104+
flag.NewCloudFlagGroup(),
11001105
&flag.AWSFlagGroup{
11011106
Region: &flag.Flag[string]{
11021107
Name: "aws-region",

pkg/commands/cloud/run.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/aquasecurity/trivy/pkg/extension"
1212
"github.com/aquasecurity/trivy/pkg/flag"
1313
"github.com/aquasecurity/trivy/pkg/log"
14+
"github.com/aquasecurity/trivy/pkg/types"
1415
)
1516

1617
// UpdateOptsForCloudIntegration checks if the Trivy Cloud integration is enabled and configures the options accordingly
@@ -38,7 +39,7 @@ func UpdateOptsForCloudIntegration(ctx context.Context, opts *flag.Options) erro
3839
opts.CustomHeaders.Set("Authorization", fmt.Sprintf("Bearer %s", accessToken))
3940
}
4041

41-
if opts.CloudOptions.SecretConfig || opts.CloudOptions.MisconfigConfig {
42+
if opts.CloudOptions.SecretConfig && opts.Scanners.Enabled(types.SecretScanner) {
4243
if err := cloud.GetConfigs(ctx, opts, accessToken); err != nil {
4344
return xerrors.Errorf("failed to download configs: %w", err)
4445
}

pkg/commands/cloud/run_test.go

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
package cloud
2+
3+
import (
4+
"context"
5+
"net/http"
6+
"net/http/httptest"
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
11+
12+
"github.com/aquasecurity/trivy/pkg/flag"
13+
"github.com/aquasecurity/trivy/pkg/types"
14+
)
15+
16+
type mockCloudServer struct {
17+
server *httptest.Server
18+
configAvailable bool
19+
}
20+
21+
func (m *mockCloudServer) Start() {
22+
m.server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
23+
if r.Header.Get("Authorization") != "Bearer valid-cloud-token" && r.Header.Get("Authorization") != "Bearer test-access-token" {
24+
w.WriteHeader(http.StatusUnauthorized)
25+
return
26+
}
27+
if r.URL.Path == "/api-keys/access-tokens" {
28+
w.WriteHeader(http.StatusCreated)
29+
w.Write([]byte(`{"token": "test-access-token"}`))
30+
return
31+
}
32+
33+
if r.URL.Path == "/configs/secrets/secret-config.yaml" {
34+
if !m.configAvailable {
35+
w.WriteHeader(http.StatusNotFound)
36+
return
37+
}
38+
if r.Header.Get("Authorization") != "Bearer test-access-token" {
39+
w.WriteHeader(http.StatusUnauthorized)
40+
return
41+
}
42+
w.WriteHeader(http.StatusOK)
43+
w.Write([]byte(`{"content": {"key": "value"}}`))
44+
return
45+
}
46+
47+
w.WriteHeader(http.StatusNotFound)
48+
}))
49+
}
50+
51+
func (m *mockCloudServer) Close() {
52+
m.server.Close()
53+
}
54+
55+
func TestUpdateOptsForCloudIntegration(t *testing.T) {
56+
mockServer := &mockCloudServer{}
57+
mockServer.Start()
58+
defer mockServer.Close()
59+
60+
tests := []struct {
61+
name string
62+
opts *flag.Options
63+
configAvailable bool
64+
errorContains string
65+
}{
66+
{
67+
name: "valid token and config to download",
68+
opts: &flag.Options{
69+
CloudOptions: flag.CloudOptions{
70+
CloudToken: "valid-cloud-token",
71+
ApiURL: mockServer.server.URL,
72+
TrivyServerURL: mockServer.server.URL,
73+
SecretConfig: true,
74+
},
75+
ScanOptions: flag.ScanOptions{
76+
Scanners: types.Scanners{types.SecretScanner},
77+
},
78+
},
79+
configAvailable: true,
80+
},
81+
{
82+
name: "valid token but config not requested",
83+
opts: &flag.Options{
84+
CloudOptions: flag.CloudOptions{
85+
CloudToken: "valid-cloud-token",
86+
ApiURL: mockServer.server.URL,
87+
TrivyServerURL: mockServer.server.URL,
88+
SecretConfig: false,
89+
},
90+
ScanOptions: flag.ScanOptions{
91+
Scanners: types.Scanners{types.SecretScanner},
92+
},
93+
},
94+
configAvailable: true,
95+
},
96+
{
97+
name: "valid token but config not available",
98+
opts: &flag.Options{
99+
CloudOptions: flag.CloudOptions{
100+
CloudToken: "valid-cloud-token",
101+
ApiURL: mockServer.server.URL,
102+
TrivyServerURL: mockServer.server.URL,
103+
SecretConfig: false,
104+
},
105+
},
106+
configAvailable: false,
107+
},
108+
{
109+
name: "invalid token 401 status code",
110+
opts: &flag.Options{
111+
CloudOptions: flag.CloudOptions{
112+
CloudToken: "invalid-token",
113+
ApiURL: mockServer.server.URL,
114+
TrivyServerURL: mockServer.server.URL,
115+
SecretConfig: false,
116+
},
117+
ScanOptions: flag.ScanOptions{
118+
Scanners: types.Scanners{types.SecretScanner},
119+
},
120+
},
121+
configAvailable: true,
122+
errorContains: "failed to get access token for Trivy Cloud",
123+
},
124+
}
125+
126+
for _, tt := range tests {
127+
t.Run(tt.name, func(t *testing.T) {
128+
tempDir := t.TempDir()
129+
t.Setenv("XDG_DATA_HOME", tempDir)
130+
mockServer.configAvailable = tt.configAvailable
131+
132+
err := UpdateOptsForCloudIntegration(context.Background(), tt.opts)
133+
134+
if tt.errorContains != "" {
135+
require.ErrorContains(t, err, tt.errorContains)
136+
return
137+
}
138+
139+
require.NoError(t, err)
140+
141+
if tt.opts.CloudOptions.SecretConfig && tt.opts.ScanOptions.Scanners.Enabled(types.SecretScanner) {
142+
assert.NotEmpty(t, tt.opts.SecretOptions.SecretConfigPath)
143+
assert.FileExists(t, tt.opts.SecretOptions.SecretConfigPath)
144+
} else {
145+
assert.Empty(t, tt.opts.SecretOptions.SecretConfigPath)
146+
}
147+
})
148+
}
149+
}

pkg/flag/cloud_flags.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@ var (
4444
TelemetrySafe: true,
4545
}
4646

47-
CloudMisconfigConfigFlag = Flag[bool]{
48-
Name: "cloud-download-misconfig-config",
49-
ConfigName: "cloud.download-misconfig-config",
50-
Default: true,
51-
Usage: "Download misconfig configurations from Trivy Cloud platform",
52-
TelemetrySafe: true,
53-
}
54-
5547
CloudUseServerSideScanningFlag = Flag[bool]{
5648
Name: "cloud-server-scanning",
5749
ConfigName: "cloud.server-scanning",
@@ -67,7 +59,6 @@ type CloudFlagGroup struct {
6759
CloudTrivyServerURL *Flag[string]
6860
CloudUploadResults *Flag[bool]
6961
CloudSecretConfig *Flag[bool]
70-
CloudMisconfigConfig *Flag[bool]
7162
CloudUseServerSideScanning *Flag[bool]
7263
}
7364

@@ -78,7 +69,6 @@ func NewCloudFlagGroup() *CloudFlagGroup {
7869
CloudTrivyServerURL: CloudTrivyServerURLFlag.Clone(),
7970
CloudUploadResults: CloudUploadResultsFlag.Clone(),
8071
CloudSecretConfig: CloudSecretConfigFlag.Clone(),
81-
CloudMisconfigConfig: CloudMisconfigConfigFlag.Clone(),
8272
CloudUseServerSideScanning: CloudUseServerSideScanningFlag.Clone(),
8373
}
8474
}
@@ -94,7 +84,6 @@ func (f *CloudFlagGroup) Flags() []Flagger {
9484
f.CloudTrivyServerURL,
9585
f.CloudUploadResults,
9686
f.CloudSecretConfig,
97-
f.CloudMisconfigConfig,
9887
f.CloudUseServerSideScanning,
9988
}
10089
}
@@ -111,7 +100,6 @@ type CloudOptions struct {
111100
TrivyServerURL string
112101
UploadResults bool
113102
SecretConfig bool
114-
MisconfigConfig bool
115103
UseServerSideScanning bool
116104
}
117105

@@ -123,7 +111,6 @@ func (f *CloudFlagGroup) ToOptions(opts *Options) error {
123111
TrivyServerURL: f.CloudTrivyServerURL.Value(),
124112
UploadResults: f.CloudUploadResults.Value(),
125113
SecretConfig: f.CloudSecretConfig.Value(),
126-
MisconfigConfig: f.CloudMisconfigConfig.Value(),
127114
UseServerSideScanning: f.CloudUseServerSideScanning.Value(),
128115
}
129116
return nil

0 commit comments

Comments
 (0)