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

linux_masked_paths integration test #2950

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

Conversation

@nayuta-ai nayuta-ai force-pushed the integration_test/linux_masked_paths branch from 063d558 to 6d0604c Compare October 9, 2024 16:51
@YJDoc2 YJDoc2 self-requested a review October 10, 2024 12:15
@nayuta-ai nayuta-ai force-pushed the integration_test/linux_masked_paths branch from 52b4683 to 448504e Compare October 13, 2024 15:06
@nayuta-ai nayuta-ai requested a review from utam0k October 13, 2024 15:08
@nayuta-ai
Copy link
Author

@utam0k Thank you for the review! Please review my code again.

Copy link
Collaborator

@YJDoc2 YJDoc2 left a comment

Choose a reason for hiding this comment

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

I still have to check the main test implementation, have a couple of comments, and clippy CI is failing, so please fix that as well.

tests/contest/runtimetest/src/tests.rs Outdated Show resolved Hide resolved
tests/contest/runtimetest/src/tests.rs Outdated Show resolved Hide resolved
@nayuta-ai nayuta-ai force-pushed the integration_test/linux_masked_paths branch from d3600be to 62e5e1a Compare October 15, 2024 15:19
@nayuta-ai nayuta-ai force-pushed the integration_test/linux_masked_paths branch 4 times, most recently from 7fa807b to 2baa120 Compare October 19, 2024 17:10
@nayuta-ai
Copy link
Author

@utam0k @YJDoc2
I have completed the revisions. Please check!

@nayuta-ai nayuta-ai requested a review from YJDoc2 October 19, 2024 17:14
@YJDoc2
Copy link
Collaborator

YJDoc2 commented Oct 22, 2024

I have completed the revisions. Please check!

Hey, thanks a lot, I'll try to get to this today or so.

Copy link
Collaborator

@YJDoc2 YJDoc2 left a comment

Choose a reason for hiding this comment

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

sorry it took me a while to get to this. Have some questions and comments, please take a look.

tests/contest/runtimetest/src/utils.rs Outdated Show resolved Hide resolved
tests/contest/runtimetest/src/utils.rs Outdated Show resolved Hide resolved
tests/contest/runtimetest/src/tests.rs Outdated Show resolved Hide resolved
Comment on lines 105 to 108
match fs::metadata(&test_file) {
io::Result::Ok(md) => {
bail!(
"reading path {:?} should have given error, found {:?} instead",
test_file,
md
)
}
io::Result::Err(e) => {
let err = e.kind();
if let io::ErrorKind::NotFound = err {
Ok(())
} else {
bail!("expected not found error, got {:?}", err);
}
}
}
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this check here? we should be checking this in the runtime test and here we should be creating the path, right? Or did I misunderstood anything?

Copy link
Author

@nayuta-ai nayuta-ai Oct 31, 2024

Choose a reason for hiding this comment

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

When setting a masked path, it is impossible to determine whether it is a relative path, so I added this to verify whether it meets the test requirements at the time of creation. This implementation is also adopted in runtime-tools, so verification is necessary.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok, so I see that you have carried over the implementation from go tests, but I'm still having a bit of difficulty understanding this -

  1. The go code seems to checks that if error is not null and error is not found, then return error, else return null. I.e. if the error is not found, then the prepare function will return error, other wise not. Here the behavior seems to be opposite.
  2. Also, this function/closure we pass, both here and in go code, will be executed before runtime has done anything. This is supposed to prepare the rootfs for tests running inside the container. Given that, what exactly is this checking? This will be running on plain bundle fs that is created for each test, It is ofcourse not going to find any of the files.

What I'm thinking here is that even the go tests have slightly incorrect implementation (which has happened before). Can you confirm going through comments in go code and seeing what the test is supposed to check, and what it is actually validating?

Copy link
Author

Choose a reason for hiding this comment

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

There are cases where the Go implementation may be incorrect. I'll check it out.

Copy link
Author

Choose a reason for hiding this comment

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

I posted a question in the Issue because I couldn’t fully grasp the purpose of this test.(opencontainers/runtime-tools#780

This is my own opinion, but I believe the test might be trying to illustrate a discrepancy where the path added to masked_path is specified from the host system’s perspective, resulting in an unintended relative path from / inside the container that doesn’t match the expected path.

As for addressing this test, we could:

  1. Add the above comment
  2. Wait for a response on the Issue before deciding
  3. Delete the test
  4. Refactor the test

If we choose to improve the test, I think the following approach could work:

  • Create a file inside the container we want to mask (masked-relpath).
  • Specify the relative path from the host system (./bundle/rootfs/masked-relpath) as the path to mask.
  • After creating the container, verify that the file is masked by checking if it exists at the expected path without the ./bundle/rootfs prefix.

Do you think this would be a good approach?

Copy link
Author

@nayuta-ai nayuta-ai Nov 24, 2024

Choose a reason for hiding this comment

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

As stated in the runtime-spec, setting a relative path is not allowed. Therefore, I believe the correct responsibility of contest is to produce an error when a relative path is set during testing. Based on this, I implemented the following.
c471733

Regarding runtimetest, I made it verify that paths passed to the namespace are not relative path to ensure the behavior complies with the runtime-spec.

One concern is whether to add an implementation to validate relative_path in the spec's validation. This would also affect the test behavior, so I am leaving this comment for discussion.
https://github.com/youki-dev/youki/blob/main/crates/libcontainer/src/container/init_builder.rs#L152

BTW, in runc, validation to ensure masked_path is an absolute path is not performed, so it might not be necessary.

@YJDoc2
Copy link
Collaborator

YJDoc2 commented Nov 1, 2024

@nayuta-ai , I have replied to comments, also the PR has conflicts with main, Please make the suggested changes and resolve conflicts. Thanks.

@nayuta-ai nayuta-ai force-pushed the integration_test/linux_masked_paths branch 2 times, most recently from 48739f7 to 8ec531f Compare November 1, 2024 17:05
@YJDoc2 YJDoc2 self-requested a review November 13, 2024 04:32
@nayuta-ai nayuta-ai force-pushed the integration_test/linux_masked_paths branch 2 times, most recently from 5ceb009 to d1fa11b Compare November 24, 2024 09:47
@nayuta-ai
Copy link
Author

@YJDoc2
Thank you for the review! Please review my code again.

@nayuta-ai nayuta-ai force-pushed the integration_test/linux_masked_paths branch from d1fa11b to c471733 Compare November 24, 2024 13:43
@YJDoc2
Copy link
Collaborator

YJDoc2 commented Nov 26, 2024

Hey, can I ask you to rebase/merge latest main? There is a small breaking change in test_inside_container and the functions test_read/write_access are changed slightly as well. I'll do a review after that. Thanks!

@nayuta-ai nayuta-ai force-pushed the integration_test/linux_masked_paths branch from c471733 to 469a1ab Compare November 26, 2024 10:07
@nayuta-ai
Copy link
Author

@YJDoc2
I've rebased it. Please review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants