Skip to content

Conversation

@Redent0r
Copy link

@Redent0r Redent0r commented Feb 25, 2025

Merge Checklist
Summary

This PR refactors the policy module of the agent into its own crate and exposes the necessary functions to be consumed by the agent and genpolicy unit tests.

This makes it possible to:

  • unit test PolicyCreateContainerRequest and PolicyCopyFileRequest, since they have been moved to the shared policy crate now
  • test state behavior since we are going through the agent now

For more context, see upstream PR: kata-containers#10613

Test Methodology

@Redent0r Redent0r added the upstream/merged PRs that have been merged upstream label Feb 25, 2025
@Redent0r Redent0r changed the title Saulparedes/downstream unit tests policy: test through agent Feb 25, 2025
@Redent0r Redent0r mentioned this pull request Mar 3, 2025
4 tasks
@Redent0r Redent0r force-pushed the saulparedes/downstream_unit_tests branch from 47c9ebf to ac48e0f Compare March 11, 2025 00:18
3u13r and others added 4 commits March 11, 2025 13:04
The policy module augments the policy generated with genpolicy by keeping and
providing state to each invocation.
Therefore, it is not sufficient anymore to test the passing of requests in
the genpolicy crate.

Since in Rust, integration tests cannot call functions that are not exposed
publicly, this commit factors out the policy module of the agent into its
own crate and exposes the necessary functions to be consumed by the agent
and an integration tests. The integration test itself is implemented in the
following commits.

Signed-off-by: Leonard Cohnen <[email protected]>
This commit allows to programmatically invoke genpolicy. This allows for other
rust tools that don't want to consume genpolicy as binary to generate policies.
One such use-case is the policy integration test implemented in the following
commits.

Signed-off-by: Leonard Cohnen <[email protected]>
The generated rego policies for `CreateContainerRequest` are stateful and that
state is handled in the policy crate. We use this policy crate in the
genpolicy integration test to be able to test if those state changes are
handled correctly without spinning up an agent or even a cluster.

This also allows to easily test on a e.g., CreateContainerRequest level
instead of relying on changing the yaml that is applied to a cluster.

Signed-off-by: Leonard Cohnen <[email protected]>
Move PolicyCopyFile request to shared policy crate so we can test it

Signed-off-by: Saul Paredes <[email protected]>
@Redent0r Redent0r force-pushed the saulparedes/downstream_unit_tests branch from ac48e0f to 44587d3 Compare March 11, 2025 20:10
@Redent0r Redent0r marked this pull request as ready for review March 11, 2025 20:28
@Redent0r Redent0r requested review from a team as code owners March 11, 2025 20:28
@Redent0r Redent0r merged commit d30fe0b into msft-main Mar 12, 2025
334 of 535 checks passed
@Redent0r Redent0r deleted the saulparedes/downstream_unit_tests branch March 12, 2025 19:44
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.

5 participants