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

feat: Enable Witness Policy verify from Archivista #438

Merged
merged 2 commits into from May 8, 2024

Conversation

kairoaraujo
Copy link
Collaborator

@kairoaraujo kairoaraujo commented May 2, 2024

What this PR does / why we need it

Enables Witness to retrieve Policy from Archivista.

If a user provides a Policy gitoid, Witness will attempt to retrieve it from Archivista.

To maintain backward compatibility, Witness first tries to load the file locally. If the local file loading fails and an Archivista is configured, it will retrieve the Policy from Archivista.

Which issue(s) this PR fixes (optional)

Requires:

Acceptance Criteria Met

  • Docs changes if needed
  • Testing changes if needed
  • All workflow checks passing (automatically enforced)
  • All review conversations resolved (automatically enforced)
  • DCO Sign-off

Special notes for your reviewer:

Copy link

netlify bot commented May 2, 2024

Deploy Preview for witness-project canceled.

Name Link
🔨 Latest commit c34388c
🔍 Latest deploy log https://app.netlify.com/sites/witness-project/deploys/663a39be0b75040007f6b2b7

cmd/verify.go Outdated
@@ -83,16 +95,9 @@ func runVerify(ctx context.Context, vo options.VerifyOptions, verifiers ...crypt
verifiers = append(verifiers, v)
}

inFile, err := os.Open(vo.PolicyFilePath)
policyEnvelope, err := pkg.LoadPolicy(ctx, vo.PolicyFilePath, pkg.NewArchivistaClient(vo.ArchivistaOptions.Url, archivistaClient))
Copy link
Collaborator

Choose a reason for hiding this comment

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

So I reckon that we could benefit from splitting the options up between --policy-file and --policy-sha. We have gone down the route of a more declarative experience on Witness rather than the "magic" approach.

Having said this I am not 100% sure what the best flag definitions would be for this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I avoided it because we break compatibility with existent deployments, as it will break the verification.

I'm ok with doing a more declarative.
Should I go for this change?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a good point that I hadn't fully considered. Let me think about it for a couple of minutes 😄

Copy link
Collaborator

Choose a reason for hiding this comment

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

Usually I find splitting go packages inside pkg into logical directories. The convention that I would usually expect here would be pkg/archivista/archivista.go, so that when pkg expands it is well organized 😄.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also I think that maybe this client would be better defined in the Archivista repo possibly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I thought of adding the interface to Archivista, but Archivista is moving toward being a service.
Later, I thought of doing it in the go-witness; in the end, I felt that having it in Witness is less opinionated and leaves the applications to build their interfaces as go-witness provides the struct.

I think it is another piece that should be in internal as you well mentioned in the comment below.
What do you think about my thoughts here?

pkg/policy.go Outdated Show resolved Hide resolved
pkg/policy.go Outdated
// Load policy from a file or Archivista
//
// It prefers to load from a file, if it fails, it tries to load from Archivista
func LoadPolicy(ctx context.Context, policy string, ac ArchivistaClienter) (dsse.Envelope, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not totally 100% sure on this, but again this could go in go-witness rather than in here?

I suppose we don't want people to depend on this the Witness CLI as a library. In which case, we probably would be better off changing pkg/ to internal/. That way, the packages defined inside internal/ can only be used internally within the witness repo and other people can't depend on the logic 😄.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree with you. LoadPolicy is an implementation for Witness in the sense that it has a specific use case.
I also agree that it should be moved to internal. Thanks.

@ChaosInTheCRD
Copy link
Collaborator

ChaosInTheCRD commented May 3, 2024

Just as a side note, we probably want to add to the docs so this feature is clear for users to see that they can use / try out 😄. Awesome functionality, Really excited to start using it.

@kairoaraujo kairoaraujo force-pushed the retrieve_archivista_policy branch 2 times, most recently from 1d21153 to adc1318 Compare May 3, 2024 11:27
Enables Witness to retrieve Policy from Archivista.

If a user provides a Policy `gitoid`, Witness will attempt to
retrieve it from Archivista.

To maintain backward compatibility, Witness first tries to load
the file locally. If the local file loading fails and an
Archivista is configured, it will retrieve the Policy from
Archivista.

Signed-off-by: Kairo Araujo <kairo.araujo@testifysec.com>
Signed-off-by: Kairo Araujo <kairo.araujo@testifysec.com>
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.

Thank you for making this so simple and easy to review. ❤️ the added testing to.

@jkjell jkjell merged commit 0cd05b6 into in-toto:main May 8, 2024
17 checks passed
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.

None yet

3 participants