Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add platform filtering support to mapping.yml #167

Merged
merged 6 commits into from
Sep 18, 2024
Merged

Add platform filtering support to mapping.yml #167

merged 6 commits into from
Sep 18, 2024

Conversation

kipz
Copy link
Contributor

@kipz kipz commented Sep 17, 2024

This will help us roll out policy platform by platform, and control the amount of historical image signing we will need

e.g. only linux/amd64 images will be matched by the rule below:

version: v1
kind: policy-mapping
policies:
  - id: docker-official-images
    description: Docker Official Images
    files:
      - path: doi/policy.rego
rules:
  - pattern: "^public[.]ecr[.]aws/docker/library/(.*)$"
    platforms: ["linux/amd64"]
    rewrite: docker.io/library/$1
  • Also, rename config package to mapping, and move matching code over there from policy package

@kipz kipz requested a review from a team as a code owner September 17, 2024 14:16
@github-actions github-actions bot added the chore label Sep 17, 2024
@kipz kipz enabled auto-merge (squash) September 17, 2024 14:16
Copy link

codecov bot commented Sep 17, 2024

Codecov Report

Attention: Patch coverage is 90.80460% with 8 lines in your changes missing coverage. Please review.

Project coverage is 69.58%. Comparing base (05caa95) to head (0ca448c).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
mapping/match.go 90.47% 4 Missing ⚠️
mapping/mapping.go 84.61% 1 Missing and 1 partial ⚠️
verify.go 81.81% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #167      +/-   ##
==========================================
+ Coverage   69.46%   69.58%   +0.11%     
==========================================
  Files          44       44              
  Lines        2505     2528      +23     
==========================================
+ Hits         1740     1759      +19     
- Misses        475      477       +2     
- Partials      290      292       +2     
Flag Coverage Δ
unittests 69.58% <90.80%> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@whalelines whalelines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few questions

@@ -1,4 +1,4 @@
package config
package mapping
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That feels right

- path: doi/policy.rego
rules:
- pattern: "^docker[.]io/library/(.*)$"
platforms: ["linux/amd64"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a test with two values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, it's an array, so I think the same paths will be exercised...happy to add one if you like?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added.

@@ -55,7 +55,12 @@ func (verifier *tufVerifier) Verify(ctx context.Context, src *oci.ImageSpec) (re
return nil, fmt.Errorf("failed to resolve image name: %w", err)
}
policyResolver := policy.NewResolver(verifier.tufClient, verifier.opts)
resolvedPolicy, err := policyResolver.ResolvePolicy(ctx, imageName)

platform, err := detailsResolver.ImagePlatform(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is platform used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's how the input image platform makes it down to the policy

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@whalelines For better or worse, it would actually be a compiler error if it wasn't!

Comment on lines +49 to +62
case rule.PolicyID == "" && rule.Replacement == "":
return nil, fmt.Errorf("rule %s has neither policy-id nor rewrite", rule.Pattern)
case rule.PolicyID != "" && rule.Replacement != "":
return nil, fmt.Errorf("rule %s has both policy-id and rewrite", rule.Pattern)
case rule.PolicyID != "":
policy := mappings.Policies[rule.PolicyID]
if policy != nil {
return &PolicyMatch{
MatchType: MatchTypePolicy,
Policy: policy,
Rule: rule,
MatchedName: imageName,
}, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code seems very familiar. Does it exist somewhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was a move from the policy package.

mapping/match.go Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
mapping/match.go Show resolved Hide resolved
mapping/match_test.go Show resolved Hide resolved
@@ -55,7 +55,12 @@ func (verifier *tufVerifier) Verify(ctx context.Context, src *oci.ImageSpec) (re
return nil, fmt.Errorf("failed to resolve image name: %w", err)
}
policyResolver := policy.NewResolver(verifier.tufClient, verifier.opts)
resolvedPolicy, err := policyResolver.ResolvePolicy(ctx, imageName)

platform, err := detailsResolver.ImagePlatform(ctx)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@whalelines For better or worse, it would actually be a compiler error if it wasn't!

@kipz kipz disabled auto-merge September 18, 2024 13:39
Copy link
Contributor

@whalelines whalelines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kipz kipz merged commit 4a70e5a into main Sep 18, 2024
9 checks passed
@kipz kipz deleted the kipz_platform branch September 18, 2024 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants