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 test for non-trivial KBS policy #703

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

fitzthum
Copy link
Member

@fitzthum fitzthum commented Feb 8, 2025

Introduce a test to see if a more complex policy, specifically, this one:

package policy
import rego.v1

default allow = false

allow if {
    input["submods"]["cpu"]["ear.status"] != "contraindicated"
}

It's still a relatively simple policy, but testing it took a lot of changes. For this policy to pass, the RVPS has to be working. I added support to the testing framework to start the RVPS and add RVs to it. I added a bunch of other stuff to the framework to hopefully make it more robust.

There were no major bugs in Trustee itself, but I made a few minor tweaks that should make things easier to use. I also had to make a couple changes to the RVPS so that the client and the server both could be used as crates.

@fitzthum fitzthum requested a review from a team as a code owner February 8, 2025 00:33
@fitzthum fitzthum force-pushed the reference-tests branch 5 times, most recently from 64637aa to 14ee77a Compare February 8, 2025 01:35
@fitzthum
Copy link
Member Author

Btw, I have some follow-up commits to make the tests even nicer, but I figured this was enough for one PR. In the next iteration I will tweak the logic so that we can test out just about any policy by adding another case.

@fitzthum
Copy link
Member Author

cc @confidential-containers/trustee-maintainers

This PR is not as big as it might look

Copy link
Member

@portersrc portersrc left a comment

Choose a reason for hiding this comment

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

lgtm

assert!(secret.is_err());
assert_eq!(
secret.unwrap_err().to_string(),
"request unauthorized".to_string()
Copy link
Member

Choose a reason for hiding this comment

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

This is not critical, but where does this string come from, and can it be made better (i.e. not a string comparison)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah comparing errors in Rust is a little clunky and the way the client returns errors could be improved (normally it's just a cli so we didn't pay much attention to this). Probably beyond the scope of this PR tho.

In order to set reference values from the integration tests,
we need access to the rvps-tool as a crate, rather than a binary.

This will also be useful if we want to add rvps functionality to the
kbs-client or to the proposed trustee-ctl.

To keep things simple, I just added the client as a new module in the
existing crate rather than creating a new package like we do for
kbs-client.

Signed-off-by: Tobin Feldman-Fitzthum <[email protected]>
Our default policy expects the sample evidence to include a launch
digest. We could remove this from the policy, but I'd like to keep it
because it helps illustrate how the policy works.

Ideally we would add this field to the evidence in the attester, but it
doesn't seem worth it to make the extra changes for the sample evidence.

Signed-off-by: Tobin Feldman-Fitzthum <[email protected]>
We had already separated the RVPS server implementation from the RVPS
server binary, but we put this server implementation in the bin
directory.

This is no good for using the server without the binary, which is
exactly what we need to do for the integration tests.

So, let's move the server implementation into the crate itself.

Signed-off-by: Tobin Feldman-Fitzthum <[email protected]>
It seems a bit more idiomatic to call this RvpsServer

Signed-off-by: Tobin Feldman-Fitzthum <[email protected]>
This won't be an issue for people running the AS in a container, but if
you run the AS as a process, it's very easy to be confused when the
policy doesn't update.

Add a warning in case there is already a policy there.

Signed-off-by: Tobin Feldman-Fitzthum <[email protected]>
The LocalJson storage backend expects there to be json file (with an
array in it) at a given location.

In case it isn't there, let's write our own file with an empty array in
it.

Signed-off-by: Tobin Feldman-Fitzthum <[email protected]>
Copy link
Member

@Xynnn007 Xynnn007 left a comment

Choose a reason for hiding this comment

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

LGTM. Some nits.

.join("resources")
.into_os_string()
.into_string()
.unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

Note that we are return a Result<T> for this function, maybe ? is good

.join("as_policy")
.into_os_string()
.into_string()
.unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

Note that we are return a Result<T> for this function, maybe ? is good

.join("reference_values")
.into_os_string()
.into_string()
.unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

Note that we are return a Result<T> for this function, maybe ? is good


pub async fn query(address: String) -> Result<String> {
let mut client = ReferenceValueProviderServiceClient::connect(address).await?;
let req = tonic::Request::new(ReferenceValueQueryRequest {});
Copy link
Member

Choose a reason for hiding this comment

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

Not related to this PR. bd7b1c8 defines no parameter to query the reference value, we need to define the key/group/te_id name for the reference values mapping then.

Up to now, the API query makes sense, but we need to change once the mapping is defined.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah good point. query_reference_value isn't the best name either. Maybe I will do a follow-up to just fix the names temporarily as we try to figure out what to do about reference values more generally.

Let's test a more complex policy where we need to set reference values.

This means introducing the RVPS to the testing framework along with the
RVPS tool.

To handle this more complex test, let's make the test setup more robust.

Right now we only have one test that uses the remote RVPS. When we
introduce more tests that use the remote RVPS we'll need to double-check
the robustness of the current framework.

Signed-off-by: Tobin Feldman-Fitzthum <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants