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

Implement in_toto_run #7

Merged
merged 28 commits into from
Aug 12, 2021
Merged

Conversation

joyliu-q
Copy link
Contributor

@joyliu-q joyliu-q commented Jun 30, 2021

The following PR is part of the Google Summer of Code 2021 program.

The in-toto GSoC project is to develop in-toto-rs capabilities to support rebuilderd (Issue #4), which includes two parts:

  1. Add runlib.rs; implement link generation using in_toto_run.
  2. Use in_toto_run and link generation within rebuilderd.

This PR addresses part 1.

Features

  • Skeleton of runlib with TODOs
  • Function record_artifacts - recursive traversal and hashing of paths provided
  • Function run_command - executes commands on a software supply chain step & return byproducts (stderr & stdoutput)
  • Link Generation given materials, products, and byproducts provided
  • Generate Signed Link
  • Example Usage of in_toto_run

Keep-in-minds

This pull request fulfills the following requirements:

  • Tests have been added for the bug fix or new feature
  • Docs have been added for the bug fix or new feature

src/runlib.rs Outdated Show resolved Hide resolved
This is not the finalized implementation, just an extended version of the skeleton.
- Filled in skeleton with basic implementation (optimization needed)
- Moved recording functionality (directory traversal) into a separate
function
- Moved run command to separate function (more error handling needed)
src/runlib.rs Outdated Show resolved Hide resolved
src/runlib.rs Outdated Show resolved Hide resolved
src/runlib.rs Outdated Show resolved Hide resolved
let args = (&cmd_args[1..])
.iter()
.map(|arg| {
if VirtualTargetPath::new((*arg).into()).is_ok() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I realized the usage of VirtualTargetPath to check that the argument is a path is not necessarily valid. Should we check with 3rd party or manually (e.g. starts with "./")

pub fn in_toto_run(
name: &str,
// run_dir: Option<&str>,
material_paths: &[&str],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we make the path arguments &[&str] or Vec<String> (or maybe Vec<VirtualTargetPath>?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same with name and other params (&str vs String)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After a discussion with @adityasaky, we decided to stick with more accessible types like string slices as opposed to custom types such as VirtualTargetPath for function parameters (similar to other in-toto implementations) and handle those conversions internally.

joyliu-q added 8 commits July 3, 2021 17:40
- Broke record_artifacts function into smaller components: record_artifact (hashing & formatting artifact data for one artifact), record_artifacts (handling symbolic link), and helper functions (dir_entry_to_path, normalize_path)
- Add various types of symbolic links to tests folder and modified tests to accomodate
- Add symbolic link support in record_artifacts (to be iterated later if needed)
Some(str) => String::from(str),
None => {
return Err(Error::Programming(format!(
"Invalid Path {}; non-UTF-8 string",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this a valid usage of Error::Programming or should I create a specific error for this situation?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I don't think this should be a programming error, as this could occur when not-a-bug happens right? what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha. I looked at the errors and the one that came closest to its meaning ("Walkdir encountered an invalid path format. This might be because of something internal or maybe the paths you supplied were invalid") is IllegalArgument error (or maybe Opaque), or maybe implementing a new error specific to this use case. Replaced with IllegalArgument, but let me know if something else would be better.

@joyliu-q joyliu-q marked this pull request as ready for review August 6, 2021 20:15
Copy link
Member

@adityasaky adityasaky left a comment

Choose a reason for hiding this comment

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

Took a quick pass at the PR, I'll take a closer look in the next day or two.

src/models/helpers.rs Outdated Show resolved Hide resolved
src/models/link/metadata.rs Outdated Show resolved Hide resolved
src/models/metadata.rs Show resolved Hide resolved
@@ -0,0 +1 @@
in_toto says hi
Copy link
Member

Choose a reason for hiding this comment

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

hi in_toto how do u do

Copy link
Member

@SantiagoTorres SantiagoTorres left a comment

Choose a reason for hiding this comment

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

Some very small nits. Fantastic work @joyliu-q !

// Format output into Byproduct
let mut byproducts: BTreeMap<String, String> = BTreeMap::new();

if cmd_args.len() == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not entirely sure about the logic following this. If cmd_args is empty, then return empty? when would this happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If no cmd_args are provided (e.g. input is &[]), the let executable = cmd_args[0]; line would fail. Because of the data type of cmd_args is &[&str], providing an empty slice as the input is definitely possible (maybe to denote for no cmd_args supplied). In that case, there would be no byproducts and an empty BTreeMap would be returned.

examples/in_toto_run_test.rs Show resolved Hide resolved
src/models/link/metadata.rs Outdated Show resolved Hide resolved
Some(str) => String::from(str),
None => {
return Err(Error::Programming(format!(
"Invalid Path {}; non-UTF-8 string",
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I don't think this should be a programming error, as this could occur when not-a-bug happens right? what do you think?

src/runlib.rs Show resolved Hide resolved
src/models/link/mod.rs Outdated Show resolved Hide resolved
@adityasaky
Copy link
Member

Excellent work, @joyliu-q! I think apart from figuring out the _type field, this looks great to me. :)

@adityasaky
Copy link
Member

LGTM, thanks @joyliu-q!

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