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

genpolicy: add crate-scoped integration test #309

Merged
merged 1 commit into from
Feb 19, 2025

Conversation

Redent0r
Copy link

@Redent0r Redent0r commented Feb 11, 2025

Merge Checklist
  • Followed patch format from upstream recommendation: https://github.com/kata-containers/community/blob/main/CONTRIBUTING.md#patch-format
    • Included a single commit in a given PR - at least unless there are related commits and each makes sense as a change on its own.
  • Aware about the PR to be merged using "create a merge commit" rather than "squash and merge" (or similar)
  • The upstream/missing label (or upstream/not-needed) has been set on the PR.
Summary

The goal of this PR is to add a testing framework for policy. Compared with current ways of testing policy changes, these tests run fast and are self-contained, so no cluster is needed to run the tests. We also expect to improve test coverage by being able to test very specific request inputs that should be allowed or denied by the policy.

Cherry pick from kata-containers#10068

These tests will:

  • Take a pod yaml, generate it's policy, and set it in the regorus engine for testing
  • Go through a list of requests and test if it's allowed or not against that policy

Same as upstream PR, the initial set of test cases is mostly for illustration and will be expanded incrementally.

We are also modifying the genpolicy makefile such that make test runs these tests. And our CI is already wired to run make test for genpolicy. So these tests will run automatically on every PR and will be required to pass before merging. See test methodology below.

It is worth noting currently these requests are not going through the agent. So, there's some requests we can't test currently such as CreateContainerRequest, which require state handling from the agent, or CopyFileRequest, which the agent transforms to a PolicyCopyFileRequest. I'll address that by down streaming kata-containers#10613 in a separate PR. This change will make the request go through the agent.

Test Methodology

required make test for genpolicy passing https://github.com/microsoft/kata-containers/actions/runs/13397404971/job/37419817822?pr=309#step:11:445

@Redent0r Redent0r added the upstream/merged PRs that have been merged upstream label Feb 11, 2025
@Redent0r Redent0r force-pushed the saulparedes/downstream_unit_tests branch 5 times, most recently from 16f8e60 to 535a3fa Compare February 16, 2025 23:02
Provides a test runner that generates a policy and validates it
with canned requests. The initial set of test cases is mostly for
illustration and will be expanded incrementally.

In order to enable both cross-compilation on Ubuntu test runners as well
as native compilation on the Alpine tools builder, it is easiest to
switch to the vendored openssl-src variant. This builds OpenSSL from
source, which depends on Perl at build time.

Adding the test to the Makefile makes it execute in CI, on a variety of
architectures. Building on ppc64le requires a newer version of the
libz-ng-sys crate.

Fixes: kata-containers#10061

Signed-off-by: Markus Rudy <mr@edgeless.systems>
@Redent0r Redent0r force-pushed the saulparedes/downstream_unit_tests branch from 535a3fa to 323a577 Compare February 18, 2025 17:52
@Redent0r Redent0r marked this pull request as ready for review February 18, 2025 18:40
@Redent0r Redent0r requested review from a team as code owners February 18, 2025 18:40
@Redent0r Redent0r merged commit 7fe9df2 into msft-main Feb 19, 2025
229 of 295 checks passed
@Redent0r Redent0r deleted the saulparedes/downstream_unit_tests branch February 19, 2025 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream/merged PRs that have been merged upstream
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants