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

fix: Fix missing checks on product include/exclude glob for attestation. #66

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

Conversation

matglas
Copy link
Contributor

@matglas matglas commented Nov 15, 2023

This change addresses a problem with --attestor-product-exclude-glob and --attestor-product-include-glob they only worked for the Subject collection, but not for the Product attestation. Also it did not allow for include overwriting the exclude on sub elements.

Changes:

  • It add the two glob arguments to the RecordArtifacts. These allow you to pass glob statements the same way they are created in Product attestor for the arguments.
  • All references are updated to pass nil where the do not have a implementation. This is a breaking change for any API contract for those using this as a library. So maybe I need to change the commit to fix!: for breaking change depending on the way we want to maintain contracts.
  • The Product.Subjects() and File.shouldRecord() command now allow for include to take precedence over the exclude.

Fixes #65

@mikhailswift
Copy link
Member

mikhailswift commented Nov 15, 2023

Hi @matglas, thanks for the contribution!

I should explain my thought process behind this decision so we can determine the best course of action. Long story short, I intended to still include files in the product and material attestors so we could still use them for integrity checking between steps. The thought is that it would be less than desirable if I could fool a policy to sneak files into a compilation process by just including a CLI argument to ignore those files. Or mess with something in an ignored folder to compromise a build (ignoring npm_modules, and then injecting some code into a module for example).

The decision to have this apply to just the in-toto statement's subjects was because we probably don't need to consider every file in node_modules a subject, but we may still care about the file integrity of that folder.

However, I can still imagine use cases where we may want to exclude files from the materials and product attestors. And perhaps an implementation of in-toto's artifact rules would help mitigate my concerns.

I know from experience that it's painful to create an attestation about an npm install and get a huge attestation output due to the sheer number of files included in the product attestor. Not sure of the use case you had in mind, but that was a driving reason for this feature initially.

@matglas
Copy link
Contributor Author

matglas commented Nov 15, 2023

Thank for the response. I completely get it and understand its would be best for policy checking. When I implemented it I already doubted a little. But here is my case.

In my case we are building a mono repo. So thats already a lot of file to index and checksum. Then the output of our build tool, https://please.build, has intermediate output of different targets which is there inside a plz-out folder but it also has all the intermediate stuff that is needed to build the final artifacts. That is not one project with node modules but multiple. If I don't use the glob like I implemented my output file is over a 1gb in size and take almost ~10 minutes to create.

@matglas
Copy link
Contributor Author

matglas commented Nov 15, 2023

To add. The final thing that I want to verify is the a package of all the things so I would not need the intermediate files. They are in the package. But with the current setup I have for executing build in the pipeline I do not have the option yet to remove the intermediates after I packaged it.

I might be able to add a wrapper on the build command and only keep what I need.

@matglas
Copy link
Contributor Author

matglas commented Nov 23, 2023

I did notice my logic in the code is not fully working. If you knly specify the exclude it still includes everything because the include is a * by default.

@matglas matglas force-pushed the fix-product-glob branch 4 times, most recently from 713f5d6 to 3e451ed Compare April 12, 2024 10:00
@matglas
Copy link
Contributor Author

matglas commented Apr 12, 2024

I implemented the logic to fix the default glob combined with an exclude. And I added configuration output so a policy can reason about if it wants to accept this configuration. Because of the output change in the attestation I bumped the version number too.

@jkjell jkjell force-pushed the fix-product-glob branch from 3e451ed to 21f60ba Compare April 17, 2024 13:40
@matglas
Copy link
Contributor Author

matglas commented Apr 17, 2024

Hi @jkjell I see you pushed changes. But because I'm not too familiar with github and this process yet I can't really understand what happened. Can you explain what you did?

I just pushed some more changes. And merged main back to my branch if I'm correct.

@matglas
Copy link
Contributor Author

matglas commented Apr 17, 2024

Also I noticed that the test jobs for product attestor fail. I need to fix those.

@matglas matglas force-pushed the fix-product-glob branch 3 times, most recently from 5227e45 to a622435 Compare April 18, 2024 06:52
@matglas
Copy link
Contributor Author

matglas commented Apr 18, 2024

Did an rebase to sign-off all commits.

Copy link
Member

@jkjell jkjell left a comment

Choose a reason for hiding this comment

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

I think this is just about ready! Just a minor suggestion to allow the Configuration to be omitted if no globs are used.

attestation/product/product.go Outdated Show resolved Hide resolved
attestation/product/product.go Outdated Show resolved Hide resolved
attestation/material/material.go Show resolved Hide resolved
)

const (
Name = "material"
Type = "https://witness.dev/attestations/material/v0.1"
Type = "https://witness.dev/attestations/material/v0.2"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jkjell I was just thinking if we might need to mention somewhere that the version is bumped. Like a changelog of some sorts? This will break current policies that are in place. Same goes for the product.

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 added CHANGELOG-ATTESTORS.md.

attestation/product/product.go Outdated Show resolved Hide resolved
@matglas matglas force-pushed the fix-product-glob branch 4 times, most recently from bf3026d to c6cebd3 Compare May 14, 2024 07:21
matglas and others added 7 commits August 9, 2024 18:30
When not adding a include it would always catch every file and
the exclude would be of no benefit.

Signed-off-by: Matthias Glastra <[email protected]>
Signed-off-by: Matthias Glastra <[email protected]>
Signed-off-by: John Kjell <[email protected]>
Co-authored-by: John Kjell <[email protected]>
Signed-off-by: Matthias Glastra <[email protected]>
}
}

return json.Marshal(output)
}

func (a *Attestor) UnmarshalJSON(data []byte) error {
Copy link
Member

Choose a reason for hiding this comment

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

We'll need to make this backwards compatible. I think we can check a.Type() for the version and unmarshal into the new struct format.

@jkjell
Copy link
Member

jkjell commented Aug 11, 2024

@matglas I brought everything up-to-date and resolved the conflicts. I added one more comment about backwards compatibility. I think if we can get that and testing to ensure it works, we should be good. On resolving the conflicts, there was some overlap with a tracing PR that @mikhailswift reviewed. He's back tomorrow so, it'll be good to have him take a look and make sure I didn't break that either. ☺️

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.

Product include and exclude glob is not working correctly.
3 participants