Skip to content

Commit

Permalink
Changes required to support tag based risk factors (#1563)
Browse files Browse the repository at this point in the history
* support risk factors in space policy

* add tags to risk factors

* Allow setting owner on risk factors
  • Loading branch information
jaym authored Feb 5, 2025
1 parent 276280b commit 85dc538
Show file tree
Hide file tree
Showing 7 changed files with 1,766 additions and 1,819 deletions.
2 changes: 1 addition & 1 deletion internal/datalakes/inmemory/policyhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func (db *Db) getRiskFactor(ctx context.Context, mrn string) (*policy.RiskFactor
return found.(*policy.RiskFactor), nil
}

func (db *Db) SetRiskFactor(ctx context.Context, riskFactor *policy.RiskFactor) error {
func (db *Db) SetRiskFactor(ctx context.Context, ownerMrn string, riskFactor *policy.RiskFactor) error {
db.cache.Set(dbIDRiskFactor+riskFactor.Mrn, riskFactor, 1)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/datalakes/inmemory/policyresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ func (db *Db) SetResolvedPolicy(ctx context.Context, mrn string, resolvedPolicy
if _, err := db.getRiskFactor(ctx, rf.Mrn); err == nil {
continue
}
if err := db.SetRiskFactor(ctx, rf); err != nil {
if err := db.SetRiskFactor(ctx, "", rf); err != nil {
return err
}
}
Expand Down
3,574 changes: 1,760 additions & 1,814 deletions policy/cnspec_policy.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions policy/cnspec_policy.proto
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ message RiskFactor {
string indicator = 75;

cnquery.explorer.Action action = 77;
map<string,string> tags = 78;
}

message RiskFactorDocs {
Expand Down
2 changes: 1 addition & 1 deletion policy/datalake.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type DataLake interface {
// SetPolicy stores a given policy in the data lake
SetPolicy(ctx context.Context, policy *Policy, filters []*explorer.Mquery) error
// SetRiskFactor creates and stores a risk factor
SetRiskFactor(ctx context.Context, riskFactor *RiskFactor) error
SetRiskFactor(ctx context.Context, ownerMrn string, riskFactor *RiskFactor) error

// List all policies for a given owner
// Note: Owner MRN is required
Expand Down
2 changes: 1 addition & 1 deletion policy/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (s *LocalServices) SetBundleMap(ctx context.Context, bundleMap *PolicyBundl
}

for _, risk := range bundleMap.RiskFactors {
if err := s.DataLake.SetRiskFactor(ctx, risk); err != nil {
if err := s.DataLake.SetRiskFactor(ctx, bundleMap.OwnerMrn, risk); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion policy/resolved_policy_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ func (b *resolvedPolicyBuilder) addPolicy(policy *Policy) bool {

hasMatchingRiskFactor := false
for _, r := range policy.RiskFactors {
if len(r.Checks) == 0 || isOverride(r.Action, GroupType_UNCATEGORIZED) {
if len(r.Checks) == 0 {
continue
}

Expand Down

0 comments on commit 85dc538

Please sign in to comment.