Skip to content
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
7 changes: 5 additions & 2 deletions app/cli/cmd/attestation_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ The name uses letters, digits, "_" and "-", up to 64 characters. Events with the
If the event cannot be recorded, the command shows a warning and exits with success, so it never breaks the pipeline.`,
Example: ` # Record the start and the end of a step
chainloop attestation event --name sast-scan --status started --message "Semgrep, ruleset p/ci"
chainloop attestation event --name sast-scan --status succeeded`,
chainloop attestation event --name sast-scan --status succeeded

# Record a step that did not run
chainloop attestation event --name dast-scan --status skipped --message "no web target"`,
// the arguments are checked in RunE, so that a wrong call is a warning too
Args: cobra.ArbitraryArgs,
Annotations: map[string]string{
useAPIToken: trueString,
supportsFederatedAuthAnnotation: trueString,
},
RunE: func(cmd *cobra.Command, args []string) error {
// a progress signal never breaks the pipeline (spec R-009), so every
// a progress signal never breaks the pipeline (spec R-013), so every
// failure, also a wrong call, is a warning and the command exits with success
if len(args) > 0 {
logger.Warn().Msgf("the event was not recorded: unexpected arguments %q, set the step with --name", args)
Expand Down
2 changes: 2 additions & 0 deletions app/cli/cmd/workflow_run_timeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ func timelineSymbol(status string) string {
return text.FgHiRed.Sprint("✗")
case action.RunEventStatusCanceled:
return text.FgYellow.Sprint("⊘")
case action.RunEventStatusSkipped:
return text.FgHiBlack.Sprint("↷")
default:
return text.FgYellow.Sprint("●")
}
Expand Down
18 changes: 18 additions & 0 deletions app/cli/cmd/workflow_run_timeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,24 @@ func TestRenderRunTimeline(t *testing.T) {
"├─ 10:01:02 ● step `approval` waiting for approval\n" +
"└─ 10:02:02 ✓ pushed and stored\n",
},
{
name: "stored run, with skipped custom steps",
events: []*action.RunEvent{
started,
custom(60*time.Second, "dast-scan", "skipped", "no web target"),
custom(70*time.Second, "unit-tests", "started", ""),
custom(90*time.Second, "unit-tests", "skipped", "cached"),
{CreatedAt: at(120 * time.Second), Key: timelineKeyAttestation, Status: timelineSucceeded},
},
stored: &action.PolicyEvaluationStatus{},
want: "Timeline · started 10:00:02 · finished 10:02:02 (2m0s) · stored\n" +
"├─ 10:00:02 ✓ initialized policies: 2 passed\n" +
"├─ 10:01:02 ↷ step `dast-scan` no web target\n" +
"├─ 10:01:12 ↷ step `unit-tests` took 20s\n" +
"│ ├─ 10:01:12 ● started\n" +
"│ └─ 10:01:32 ↷ cached\n" +
"└─ 10:02:02 ✓ pushed and stored\n",
},
{
name: "stored run",
events: []*action.RunEvent{
Expand Down
5 changes: 4 additions & 1 deletion app/cli/documentation/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ Examples
Record the start and the end of a step
chainloop attestation event --name sast-scan --status started --message "Semgrep, ruleset p/ci"
chainloop attestation event --name sast-scan --status succeeded

Record a step that did not run
chainloop attestation event --name dast-scan --status skipped --message "no web target"
```

Options
Expand All @@ -334,7 +337,7 @@ Options
-h, --help[=true|false] help for event
--message string message of the event, up to 1 KB
--name string name of the step (required), with letters, digits, _ and -, up to 64 characters
--status string status of the step (required), valid options are started, succeeded, failed, canceled
--status string status of the step (required), valid options are started, succeeded, failed, canceled, skipped
```

Options inherited from parent commands
Expand Down
6 changes: 4 additions & 2 deletions app/cli/pkg/action/attestation_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@ const (
RunEventStatusSucceeded = "succeeded"
RunEventStatusFailed = "failed"
RunEventStatusCanceled = "canceled"
RunEventStatusSkipped = "skipped"
)

// RunEventStatuses are the statuses that a custom run event accepts
var RunEventStatuses = []string{RunEventStatusStarted, RunEventStatusSucceeded, RunEventStatusFailed, RunEventStatusCanceled}
var RunEventStatuses = []string{RunEventStatusStarted, RunEventStatusSucceeded, RunEventStatusFailed, RunEventStatusCanceled, RunEventStatusSkipped}

// runEventStatusToPb limits the statuses that the CLI accepts to the ones of the spec (R-009)
// runEventStatusToPb limits the statuses that the CLI accepts to the ones of the spec (R-013)
var runEventStatusToPb = map[string]pb.WorkflowRunEvent_Status{
RunEventStatusStarted: pb.WorkflowRunEvent_STATUS_STARTED,
RunEventStatusSucceeded: pb.WorkflowRunEvent_STATUS_SUCCEEDED,
RunEventStatusFailed: pb.WorkflowRunEvent_STATUS_FAILED,
RunEventStatusCanceled: pb.WorkflowRunEvent_STATUS_CANCELED,
RunEventStatusSkipped: pb.WorkflowRunEvent_STATUS_SKIPPED,
}

// ParseRunEventStatus returns the API status of a custom run event
Expand Down
1 change: 1 addition & 0 deletions app/cli/pkg/action/attestation_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func TestAttestationEvent(t *testing.T) {
{name: "succeeded", initialized: true, status: RunEventStatusSucceeded, wantStatus: pb.WorkflowRunEvent_STATUS_SUCCEEDED},
{name: "failed", initialized: true, status: RunEventStatusFailed, wantStatus: pb.WorkflowRunEvent_STATUS_FAILED},
{name: "canceled", initialized: true, status: RunEventStatusCanceled, wantStatus: pb.WorkflowRunEvent_STATUS_CANCELED},
{name: "skipped", initialized: true, status: RunEventStatusSkipped, wantStatus: pb.WorkflowRunEvent_STATUS_SKIPPED},
{name: "no attestation in progress", status: RunEventStatusStarted, wantErr: ErrAttestationNotInitialized},
// remote state needs no local state: the control plane checks that the run is in progress
{name: "remote state", attestationID: testRunID, status: RunEventStatusSucceeded, wantStatus: pb.WorkflowRunEvent_STATUS_SUCCEEDED},
Expand Down
11 changes: 8 additions & 3 deletions app/controlplane/api/controlplane/v1/workflow_run.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/controlplane/api/controlplane/v1/workflow_run.proto
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ message WorkflowRunEvent {
STATUS_SUCCEEDED = 2;
STATUS_FAILED = 3;
STATUS_CANCELED = 4;
// The step did not run. Only custom events accept it.
STATUS_SKIPPED = 5;
}

message AttestationAttributes {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/controlplane/internal/service/workflowrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,12 +662,14 @@ var (
pb.WorkflowRunEvent_STATUS_SUCCEEDED: biz.WorkflowRunEventStatusSucceeded,
pb.WorkflowRunEvent_STATUS_FAILED: biz.WorkflowRunEventStatusFailed,
pb.WorkflowRunEvent_STATUS_CANCELED: biz.WorkflowRunEventStatusCanceled,
pb.WorkflowRunEvent_STATUS_SKIPPED: biz.WorkflowRunEventStatusSkipped,
}
bizToPbRunEventStatus = map[biz.WorkflowRunEventStatus]pb.WorkflowRunEvent_Status{
biz.WorkflowRunEventStatusStarted: pb.WorkflowRunEvent_STATUS_STARTED,
biz.WorkflowRunEventStatusSucceeded: pb.WorkflowRunEvent_STATUS_SUCCEEDED,
biz.WorkflowRunEventStatusFailed: pb.WorkflowRunEvent_STATUS_FAILED,
biz.WorkflowRunEventStatusCanceled: pb.WorkflowRunEvent_STATUS_CANCELED,
biz.WorkflowRunEventStatusSkipped: pb.WorkflowRunEvent_STATUS_SKIPPED,
}
bizToPbRunEventSource = map[biz.WorkflowRunEventSource]pb.WorkflowRunEvent_Source{
biz.WorkflowRunEventSourceCLI: pb.WorkflowRunEvent_SOURCE_CLI,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,22 @@ func (s *workflowRunEventRBACIntegrationSuite) TestRecordCustomEvent() {
s.Zero(resp.GetProgress().GetRequiredProvided())
}

func (s *workflowRunEventRBACIntegrationSuite) TestRecordSkippedCustomEvent() {
ctx := s.attCtxForToken(s.org, s.orgToken)
runID := s.runA.ID.String()

_, err := s.attSvc.RecordEvent(ctx, &pb.AttestationServiceRecordEventRequest{WorkflowRunId: runID, Event: &pb.WorkflowRunEvent{
Type: pb.WorkflowRunEvent_TYPE_CUSTOM, Key: "dast-scan", Status: pb.WorkflowRunEvent_STATUS_SKIPPED, Message: "no web target",
}})
s.Require().NoError(err)

resp, err := s.runSvc.GetProgress(s.apiCtxForToken(s.org, s.orgToken), &pb.WorkflowRunServiceGetProgressRequest{WorkflowRunId: runID})
s.Require().NoError(err)
s.Require().Len(resp.GetEvents(), 1)
s.Equal(pb.WorkflowRunEvent_STATUS_SKIPPED, resp.GetEvents()[0].GetStatus())
s.Equal("no web target", resp.GetEvents()[0].GetMessage())
}

func (s *workflowRunEventRBACIntegrationSuite) TestRecordEventValidation() {
ctx := s.attCtxForToken(s.org, s.orgToken)
runID := s.runA.ID.String()
Expand Down Expand Up @@ -390,6 +406,12 @@ func (s *workflowRunEventRBACIntegrationSuite) TestRecordEventValidation() {
Type: pb.WorkflowRunEvent_TYPE_CUSTOM, Key: strings.Repeat("a", 65), Status: pb.WorkflowRunEvent_STATUS_SUCCEEDED,
},
},
{
name: "skipped event that is not custom",
event: &pb.WorkflowRunEvent{
Type: pb.WorkflowRunEvent_TYPE_MATERIAL, Key: "chainloop.material.sbom", Status: pb.WorkflowRunEvent_STATUS_SKIPPED,
},
},
{
name: "custom event with attributes",
event: &pb.WorkflowRunEvent{
Expand Down
8 changes: 8 additions & 0 deletions app/controlplane/pkg/biz/workflowrunevent.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,16 @@ const (
WorkflowRunEventStatusSucceeded WorkflowRunEventStatus = "succeeded"
WorkflowRunEventStatusFailed WorkflowRunEventStatus = "failed"
WorkflowRunEventStatusCanceled WorkflowRunEventStatus = "canceled"
// WorkflowRunEventStatusSkipped is a step that did not run. Only custom events accept it.
WorkflowRunEventStatusSkipped WorkflowRunEventStatus = "skipped"
)

// Values implements the ent enum interface
func (WorkflowRunEventStatus) Values() []string {
return []string{
string(WorkflowRunEventStatusStarted), string(WorkflowRunEventStatusSucceeded),
string(WorkflowRunEventStatusFailed), string(WorkflowRunEventStatusCanceled),
string(WorkflowRunEventStatusSkipped),
}
}

Expand Down Expand Up @@ -211,6 +214,11 @@ func validateWorkflowRunEvent(ev *WorkflowRunEvent) error {
return err
}

// the automatic events describe actions of the CLI, which always run
if ev.Status == WorkflowRunEventStatusSkipped && ev.Type != WorkflowRunEventTypeCustom {
return NewErrValidationStr(fmt.Sprintf("only custom events can be %q", WorkflowRunEventStatusSkipped))
}

if len(ev.Message) > MaxWorkflowRunEventMessageBytes {
return NewErrValidationStr(fmt.Sprintf("event message is longer than %d bytes", MaxWorkflowRunEventMessageBytes))
}
Expand Down
14 changes: 14 additions & 0 deletions app/controlplane/pkg/biz/workflowrunevent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ func TestValidateWorkflowRunEvent(t *testing.T) {
event: &WorkflowRunEvent{Type: WorkflowRunEventTypeCustom, Key: strings.Repeat("a", MaxWorkflowRunEventCustomKeyChars+1)},
wantErr: "longer than",
},
{
name: "skipped custom event",
event: &WorkflowRunEvent{Type: WorkflowRunEventTypeCustom, Key: "dast-scan", Status: WorkflowRunEventStatusSkipped},
},
{
name: "skipped material event",
event: &WorkflowRunEvent{Type: WorkflowRunEventTypeMaterial, Key: sbomKey, Status: WorkflowRunEventStatusSkipped, Attributes: material},
wantErr: "only custom events",
},
{
name: "skipped attestation event",
event: &WorkflowRunEvent{Type: WorkflowRunEventTypeAttestation, Key: WorkflowRunEventKeyAttestation, Status: WorkflowRunEventStatusSkipped},
wantErr: "only custom events",
},
{
name: "custom event with attributes",
event: &WorkflowRunEvent{Type: WorkflowRunEventTypeCustom, Key: "sast-scan", Attributes: material},
Expand Down
2 changes: 1 addition & 1 deletion app/controlplane/pkg/data/ent/migrate/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ var (
{Name: "source", Type: field.TypeEnum, Enums: []string{"cli", "control_plane"}},
{Name: "type", Type: field.TypeEnum, Enums: []string{"attestation", "material", "custom"}},
{Name: "key", Type: field.TypeString},
{Name: "status", Type: field.TypeEnum, Enums: []string{"started", "succeeded", "failed", "canceled"}},
{Name: "status", Type: field.TypeEnum, Enums: []string{"started", "succeeded", "failed", "canceled", "skipped"}},
{Name: "message", Type: field.TypeString, Nullable: true, Size: 2147483647},
{Name: "attributes", Type: field.TypeJSON, Nullable: true},
{Name: "workflow_run_id", Type: field.TypeUUID},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading