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

Change monitoring workflow configuration argument to optional #543

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/reusable_monitoring.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ on:
type: boolean
config:
description: 'multiline yaml of configuration settings for identity monitor run'
required: true
required: false
type: string

permissions:
Expand Down Expand Up @@ -81,7 +81,7 @@ jobs:
run: cat ${{ env.LOG_FILE }}
# Skip on first run
continue-on-error: true
- run: go run ./cmd/rekor_monitor --config ${{ inputs.config }} --file ${{ env.LOG_FILE }} --once=${{ inputs.once }} --user-agent "${{ format('{0}/{1}/{2}', needs.detect-workflow.outputs.repository, needs.detect-workflow.outputs.ref, github.run_id) }}"
- run: go run ./cmd/rekor_monitor --file ${{ env.LOG_FILE }} --once=${{ inputs.once }} --user-agent "${{ format('{0}/{1}/{2}', needs.detect-workflow.outputs.repository, needs.detect-workflow.outputs.ref, github.run_id) }} --config ${{ inputs.config }}"
- name: Upload checkpoint
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
Expand Down
34 changes: 11 additions & 23 deletions cmd/rekor_monitor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,11 @@ func main() {
configYamlInput := flag.String("config", "", "path to yaml configuration file containing identity monitor settings")
once := flag.Bool("once", true, "whether to run the monitor on a repeated interval or once")
serverURL := flag.String("url", publicRekorServerURL, "URL to the rekor server that is to be monitored")
logInfoFile := flag.String("file", logInfoFileName, "path to the initial log info checkpoint file to be read from")
interval := flag.Duration("interval", 5*time.Minute, "Length of interval between each periodical consistency check")
userAgentString := flag.String("user-agent", "", "details to include in the user agent string")
flag.Parse()

if *configFilePath == "" && *configYamlInput == "" {
linus-sun marked this conversation as resolved.
Show resolved Hide resolved
log.Fatalf("empty configuration input")
}

if *configFilePath != "" && *configYamlInput != "" {
log.Fatalf("only input one of configuration file path or yaml input")
}

var config notifications.IdentityMonitorConfiguration

if *configFilePath != "" {
Expand All @@ -88,11 +81,6 @@ func main() {
config.OutputIdentitiesFile = outputIdentitiesFileName
}

err := rekor.VerifyConsistencyCheckInputs(interval, &config.LogInfoFile, once)
if err != nil {
log.Fatal(err)
}

rekorClient, err := client.GetRekorClient(*serverURL, client.WithUserAgent(strings.TrimSpace(fmt.Sprintf("rekor-monitor/%s (%s; %s) %s", version.GetVersionInfo().GitVersion, runtime.GOOS, runtime.GOARCH, *userAgentString))))
if err != nil {
log.Fatalf("getting Rekor client: %v", err)
Expand Down Expand Up @@ -145,10 +133,16 @@ func main() {
}
}

err = rekor.RunConsistencyCheck(rekorClient, verifier, *logInfoFile)
Copy link
Contributor

Choose a reason for hiding this comment

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

For a follow up - I noticed RunConsistencyCheck calls GetLogInfo, so we could reduce duplication by having RunConsistencyCheck return the log info struct.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will work on this in a follow-up PR now

if err != nil {
fmt.Fprintf(os.Stderr, "error running consistency check: %v", err)
return
}

if config.StartIndex == nil {
if config.LogInfoFile != "" {
if *logInfoFile != "" {
var prevCheckpoint *util.SignedCheckpoint
prevCheckpoint, err = file.ReadLatestCheckpoint(config.LogInfoFile)
prevCheckpoint, err = file.ReadLatestCheckpoint(*logInfoFile)
if err != nil {
fmt.Fprintf(os.Stderr, "reading checkpoint log: %v", err)
return
Expand All @@ -157,13 +151,12 @@ func main() {
checkpointStartIndex := rekor.GetCheckpointIndex(logInfo, prevCheckpoint)
config.StartIndex = &checkpointStartIndex
} else {
defaultStartIndex := 0
config.StartIndex = &defaultStartIndex
fmt.Fprintf(os.Stderr, "no start index set and no log checkpoint")
return
}
}
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 the default of 0? Scrapping the entire log is hard to do without careful rate limiting on the client side. If no start index is provided and no checkpoint is provided, then just throw an error.


if config.EndIndex == nil {

checkpoint, err := rekor.ReadLatestCheckpoint(logInfo)
if err != nil {
fmt.Fprintf(os.Stderr, "error reading checkpoint: %v", err)
Expand All @@ -176,11 +169,6 @@ func main() {

if *config.StartIndex >= *config.EndIndex {
fmt.Fprintf(os.Stderr, "start index %d must be strictly less than end index %d", *config.StartIndex, *config.EndIndex)
}

err = rekor.RunConsistencyCheck(rekorClient, verifier, config.LogInfoFile)
if err != nil {
fmt.Fprintf(os.Stderr, "error running consistency check: %v", err)
return
}

Expand Down
Loading