Skip to content

Commit f23ed77

Browse files
authored
feat(misconf): Support private registries for misconf check bundle (aquasecurity#6327)
1 parent df024e8 commit f23ed77

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

pkg/cloud/aws/scanner/scanner.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (s *AWSScanner) Scan(ctx context.Context, option flag.Options) (scan.Result
6969
var policyPaths []string
7070
var downloadedPolicyPaths []string
7171
var err error
72-
downloadedPolicyPaths, err = operation.InitBuiltinPolicies(context.Background(), option.CacheDir, option.Quiet, option.SkipPolicyUpdate, option.MisconfOptions.PolicyBundleRepository)
72+
downloadedPolicyPaths, err = operation.InitBuiltinPolicies(context.Background(), option.CacheDir, option.Quiet, option.SkipPolicyUpdate, option.MisconfOptions.PolicyBundleRepository, option.RegistryOpts())
7373
if err != nil {
7474
if !option.SkipPolicyUpdate {
7575
log.Logger.Errorf("Falling back to embedded policies: %s", err)

pkg/commands/artifact/run.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ func initScannerConfig(opts flag.Options, cacheClient cache.Cache) (ScannerConfi
584584

585585
var downloadedPolicyPaths []string
586586
var disableEmbedded bool
587-
downloadedPolicyPaths, err := operation.InitBuiltinPolicies(context.Background(), opts.CacheDir, opts.Quiet, opts.SkipPolicyUpdate, opts.MisconfOptions.PolicyBundleRepository)
587+
downloadedPolicyPaths, err := operation.InitBuiltinPolicies(context.Background(), opts.CacheDir, opts.Quiet, opts.SkipPolicyUpdate, opts.MisconfOptions.PolicyBundleRepository, opts.RegistryOpts())
588588
if err != nil {
589589
if !opts.SkipPolicyUpdate {
590590
log.Logger.Errorf("Falling back to embedded policies: %s", err)

pkg/commands/operation/operation.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func showDBInfo(cacheDir string) error {
148148
}
149149

150150
// InitBuiltinPolicies downloads the built-in policies and loads them
151-
func InitBuiltinPolicies(ctx context.Context, cacheDir string, quiet, skipUpdate bool, policyBundleRepository string) ([]string, error) {
151+
func InitBuiltinPolicies(ctx context.Context, cacheDir string, quiet, skipUpdate bool, policyBundleRepository string, registryOpts ftypes.RegistryOptions) ([]string, error) {
152152
mu.Lock()
153153
defer mu.Unlock()
154154

@@ -159,7 +159,7 @@ func InitBuiltinPolicies(ctx context.Context, cacheDir string, quiet, skipUpdate
159159

160160
needsUpdate := false
161161
if !skipUpdate {
162-
needsUpdate, err = client.NeedsUpdate(ctx)
162+
needsUpdate, err = client.NeedsUpdate(ctx, registryOpts)
163163
if err != nil {
164164
return nil, xerrors.Errorf("unable to check if built-in policies need to be updated: %w", err)
165165
}
@@ -168,7 +168,7 @@ func InitBuiltinPolicies(ctx context.Context, cacheDir string, quiet, skipUpdate
168168
if needsUpdate {
169169
log.Logger.Info("Need to update the built-in policies")
170170
log.Logger.Info("Downloading the built-in policies...")
171-
if err = client.DownloadBuiltinPolicies(ctx); err != nil {
171+
if err = client.DownloadBuiltinPolicies(ctx, registryOpts); err != nil {
172172
return nil, xerrors.Errorf("failed to download built-in policies: %w", err)
173173
}
174174
}

pkg/policy/policy.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ func NewClient(cacheDir string, quiet bool, policyBundleRepo string, opts ...Opt
8989
}, nil
9090
}
9191

92-
func (c *Client) populateOCIArtifact() error {
92+
func (c *Client) populateOCIArtifact(registryOpts types.RegistryOptions) error {
9393
if c.artifact == nil {
9494
log.Logger.Debugf("Using URL: %s to load policy bundle", c.policyBundleRepo)
95-
art, err := oci.NewArtifact(c.policyBundleRepo, c.quiet, types.RegistryOptions{})
95+
art, err := oci.NewArtifact(c.policyBundleRepo, c.quiet, registryOpts)
9696
if err != nil {
9797
return xerrors.Errorf("OCI artifact error: %w", err)
9898
}
@@ -102,8 +102,8 @@ func (c *Client) populateOCIArtifact() error {
102102
}
103103

104104
// DownloadBuiltinPolicies download default policies from GitHub Pages
105-
func (c *Client) DownloadBuiltinPolicies(ctx context.Context) error {
106-
if err := c.populateOCIArtifact(); err != nil {
105+
func (c *Client) DownloadBuiltinPolicies(ctx context.Context, registryOpts types.RegistryOptions) error {
106+
if err := c.populateOCIArtifact(registryOpts); err != nil {
107107
return xerrors.Errorf("OPA bundle error: %w", err)
108108
}
109109

@@ -154,7 +154,7 @@ func (c *Client) LoadBuiltinPolicies() ([]string, error) {
154154
}
155155

156156
// NeedsUpdate returns if the default policy should be updated
157-
func (c *Client) NeedsUpdate(ctx context.Context) (bool, error) {
157+
func (c *Client) NeedsUpdate(ctx context.Context, registryOpts types.RegistryOptions) (bool, error) {
158158
meta, err := c.GetMetadata()
159159
if err != nil {
160160
return true, nil
@@ -165,7 +165,7 @@ func (c *Client) NeedsUpdate(ctx context.Context) (bool, error) {
165165
return false, nil
166166
}
167167

168-
if err = c.populateOCIArtifact(); err != nil {
168+
if err = c.populateOCIArtifact(registryOpts); err != nil {
169169
return false, xerrors.Errorf("OPA bundle error: %w", err)
170170
}
171171

pkg/policy/policy_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ func TestClient_NeedsUpdate(t *testing.T) {
264264
require.NoError(t, err)
265265

266266
// Assert results
267-
got, err := c.NeedsUpdate(context.Background())
267+
got, err := c.NeedsUpdate(context.Background(), ftypes.RegistryOptions{})
268268
assert.Equal(t, tt.wantErr, err != nil)
269269
assert.Equal(t, tt.want, got)
270270
})
@@ -367,7 +367,7 @@ func TestClient_DownloadBuiltinPolicies(t *testing.T) {
367367
c, err := policy.NewClient(tempDir, true, "", policy.WithClock(tt.clock), policy.WithOCIArtifact(art))
368368
require.NoError(t, err)
369369

370-
err = c.DownloadBuiltinPolicies(context.Background())
370+
err = c.DownloadBuiltinPolicies(context.Background(), ftypes.RegistryOptions{})
371371
if tt.wantErr != "" {
372372
require.NotNil(t, err)
373373
assert.Contains(t, err.Error(), tt.wantErr)

0 commit comments

Comments
 (0)