Skip to content

Commit

Permalink
llbsolver: fix policy rule ordering
Browse files Browse the repository at this point in the history
The older of rules in policy matters. Eg. in [DENY *, ALLOW ref]
mixing the order would deny all sources so map can't be used
to deduplicate the rules.

Signed-off-by: Tonis Tiigi <[email protected]>
  • Loading branch information
tonistiigi committed Jul 12, 2023
1 parent 31a9120 commit bf292c7
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions solver/llbsolver/solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -981,27 +981,20 @@ func loadEntitlements(b solver.Builder) (entitlements.Set, error) {
}

func loadSourcePolicy(b solver.Builder) (*spb.Policy, error) {
set := make(map[spb.Rule]struct{}, 0)
var srcPol spb.Policy
err := b.EachValue(context.TODO(), keySourcePolicy, func(v interface{}) error {
x, ok := v.(spb.Policy)
if !ok {
return errors.Errorf("invalid source policy %T", v)
}
for _, f := range x.Rules {
set[*f] = struct{}{}
r := *f
srcPol.Rules = append(srcPol.Rules, &r)
}
return nil
})
if err != nil {
return nil, err
}
var srcPol *spb.Policy
if len(set) > 0 {
srcPol = &spb.Policy{}
for k := range set {
k := k
srcPol.Rules = append(srcPol.Rules, &k)
}
}
return srcPol, nil
return &srcPol, nil
}

0 comments on commit bf292c7

Please sign in to comment.