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

Refactor consistency check workflow #513

Merged
merged 2 commits into from
Nov 4, 2024

Conversation

linus-sun
Copy link
Collaborator

@linus-sun linus-sun commented Oct 29, 2024

Summary

This PR does the following:

  • Renames the verifier task to rekor_consistency to more accurately reflect its functionality
  • refactors RunConsistencyCheck to take the looping functionality out of the check itself and moves it into the workflow
  • refactors RunConsistencyCheck to move its identity monitor functionality into a separate function, writeIdentitiesBetweenCheckpoints

This PR has been tested remotely via a GitHub reusable workflow: https://github.com/linus-sun/rekor-log-monitor/actions/runs/11582060548/job/32244210000

Release Note

  • Workflow configuration inputs changed to take in either a yaml as a string or local file path

Documentation

Readme has been updated to reflect new configuration input

@linus-sun linus-sun force-pushed the linussun/refactor-verifier branch 3 times, most recently from 8390178 to cfce3f4 Compare October 29, 2024 20:29
Copy link

codecov bot commented Oct 29, 2024

Codecov Report

Attention: Patch coverage is 0% with 45 lines in your changes missing coverage. Please review.

Project coverage is 62.12%. Comparing base (d271ec7) to head (cff5a77).
Report is 153 commits behind head on main.

Files with missing lines Patch % Lines
pkg/rekor/verifier.go 0.00% 27 Missing ⚠️
cmd/rekor_consistency/main.go 0.00% 18 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #513      +/-   ##
==========================================
- Coverage   64.02%   62.12%   -1.91%     
==========================================
  Files           4       18      +14     
  Lines         303     1299     +996     
==========================================
+ Hits          194      807     +613     
- Misses         78      413     +335     
- Partials       31       79      +48     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@linus-sun linus-sun force-pushed the linussun/refactor-verifier branch 2 times, most recently from b9e07db to 8599c52 Compare October 29, 2024 20:36
@linus-sun linus-sun marked this pull request as ready for review October 29, 2024 20:47
// 3. Write latest checkpoint to file

// To get an immediate first tick
for ; ; <-ticker.C {
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you want to include a loop here? RunConsistencyCheck includes a loop.

I would suggest renaming the file with git mv and then making changes, which I believe will properly show the diff in github.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removing loop from within RunConsistencyCheck tried renaming via git mv, but diff doesn't still seem to be tracked- might be because I already renamed without using git mv

cmd/consistency/main.go Outdated Show resolved Hide resolved
@linus-sun linus-sun force-pushed the linussun/refactor-verifier branch 6 times, most recently from de2807b to 9491b69 Compare October 30, 2024 17:27
return fmt.Errorf("failed to get log info: %v", err)
}
checkpoint, err := verifyLatestCheckpointSignature(logInfo, verifier)
func RunConsistencyCheck(rekorClient *client.Rekor, verifier signature.Verifier, logInfoFile string, mvs identity.MonitoredValues, outputIdentitiesFile string, once bool) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove once as a parameter?

"github.com/sigstore/rekor-monitor/pkg/identity"
)

type ConsistencyCheckConfiguration struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about omitting this and sticking to CLI flags? I think that yaml is great for complex input or for server configuration, but since we expect this to be run as a tool, these can be flags.

Given we also have other flags already, I don't think we need a configuration too.

If we remove this, then we can have a monitored-values flag as a string and a monitored-value-file flag as a path to a file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to address the last part of this:

If we remove this, then we can have a monitored-values flag as a string and a monitored-value-file flag as a path to a file.

Adding a flag for passing by file as well?

configFilePath := flag.String("config-file", "", "Name of the file containing the consistency check workflow configuration settings")
configString := flag.String("config-string", "", "Consistency check workflow configuration settings input as a string")
once := flag.Bool("once", false, "Perform consistency check once and exit")
logInfoFile := flag.String("file", "", "path to log info file")
Copy link
Contributor

Choose a reason for hiding this comment

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

You can specify default values instead of an empty string, and if --file is set, it'll override the value.

@@ -76,7 +76,7 @@ jobs:
run: cat ${{ env.LOG_FILE }}
# Skip on first run
continue-on-error: true
- run: go run ./cmd/verifier --file ${{ env.LOG_FILE }} --once --monitored-values "${{ inputs.identities }}" --user-agent "${{ format('{0}/{1}/{2}', needs.detect-workflow.outputs.repository, needs.detect-workflow.outputs.ref, github.run_id) }}"
- run: go run ./cmd/consistency --file ${{ env.LOG_FILE }} --once --config-string "${{ inputs.config }}" --user-agent "${{ format('{0}/{1}/{2}', needs.detect-workflow.outputs.repository, needs.detect-workflow.outputs.ref, github.run_id) }}"
Copy link
Contributor

Choose a reason for hiding this comment

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

rekor_consistency?

@linus-sun linus-sun force-pushed the linussun/refactor-verifier branch 6 times, most recently from 3662a5b to c554e93 Compare October 31, 2024 19:32
Copy link
Contributor

@haydentherapper haydentherapper left a comment

Choose a reason for hiding this comment

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

Just two small comments, looks good otherwise!

"runtime"
"strings"
"time"

"github.com/sigstore/rekor-monitor/pkg/identity"
"github.com/sigstore/rekor-monitor/pkg/rekor"
"github.com/sigstore/rekor/pkg/client"
"gopkg.in/yaml.v3"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this necessary? v2 is a few years older than v3.

if err := yaml.Unmarshal([]byte(*monitoredValsInput), &monitoredVals); err != nil {
log.Fatalf("error parsing identities: %v", err)
}
for _, certID := range monitoredVals.CertificateIdentities {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we keep the output? I think it's helpful to verify that you're monitoring the correct values.

@linus-sun linus-sun force-pushed the linussun/refactor-verifier branch from c554e93 to 15d9ce3 Compare November 1, 2024 17:25
go.mod Outdated Show resolved Hide resolved
cmd/rekor_consistency/main.go Outdated Show resolved Hide resolved
@linus-sun linus-sun force-pushed the linussun/refactor-verifier branch 3 times, most recently from 5305cb3 to 350346d Compare November 4, 2024 17:30
haydentherapper
haydentherapper previously approved these changes Nov 4, 2024
@haydentherapper
Copy link
Contributor

LGTM, can you rebase and run go mod tidy to resolve the conflict? Can you also update the PR description to reflect what's in this PR?

@haydentherapper haydentherapper merged commit a0aed3d into sigstore:main Nov 4, 2024
8 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.

2 participants