Skip to content

Commit

Permalink
Wire up audit events
Browse files Browse the repository at this point in the history
  • Loading branch information
strideynet committed Dec 4, 2024
1 parent d820728 commit f275bb3
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/types/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,9 @@ const (
// for Teleport Enterprise customers.
KindContact = "contact"

// KindWorkloadIdentity is the WorkloadIdentity resource.
KindWorkloadIdentity = "workload_identity"

// KindGitServer represents a Git server that can proxy git commands.
KindGitServer = "git_server"
// SubKindGitHub specifies the GitHub subkind of a Git server.
Expand Down
12 changes: 12 additions & 0 deletions api/types/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -2352,3 +2352,15 @@ func (m *AutoUpdateVersionUpdate) TrimToMaxSize(_ int) AuditEvent {
func (m *AutoUpdateVersionDelete) TrimToMaxSize(_ int) AuditEvent {
return m
}

func (m *WorkloadIdentityCreate) TrimToMaxSize(_ int) AuditEvent {
return m
}

func (m *WorkloadIdentityUpdate) TrimToMaxSize(_ int) AuditEvent {
return m
}

func (m *WorkloadIdentityDelete) TrimToMaxSize(_ int) AuditEvent {
return m
}
12 changes: 12 additions & 0 deletions api/types/events/oneof.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,18 @@ func ToOneOf(in AuditEvent) (*OneOf, error) {
out.Event = &OneOf_AutoUpdateVersionDelete{
AutoUpdateVersionDelete: e,
}
case *WorkloadIdentityCreate:
out.Event = &OneOf_WorkloadIdentityCreate{
WorkloadIdentityCreate: e,
}
case *WorkloadIdentityUpdate:
out.Event = &OneOf_WorkloadIdentityUpdate{
WorkloadIdentityUpdate: e,
}
case *WorkloadIdentityDelete:
out.Event = &OneOf_WorkloadIdentityDelete{
WorkloadIdentityDelete: e,
}
default:
slog.ErrorContext(context.Background(), "Attempted to convert dynamic event of unknown type into protobuf event.", "event_type", in.GetType())
unknown := &Unknown{}
Expand Down
7 changes: 7 additions & 0 deletions lib/events/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,13 @@ const (
AutoUpdateVersionUpdateEvent = "auto_update_version.update"
// AutoUpdateVersionDeleteEvent is emitted when a AutoUpdateVersion resource is deleted.
AutoUpdateVersionDeleteEvent = "auto_update_version.delete"

// WorkloadIdentityCreateEvent is emitted when a WorkloadIdentity resource is created.
WorkloadIdentityCreateEvent = "workload_identity.create"
// WorkloadIdentityUpdateEvent is emitted when a WorkloadIdentity resource is updated.
WorkloadIdentityUpdateEvent = "workload_identity.update"
// WorkloadIdentityDeleteEvent is emitted when a WorkloadIdentity resource is deleted.
WorkloadIdentityDeleteEvent = "workload_identity.delete"
)

// Add an entry to eventsMap in lib/events/events_test.go when you add
Expand Down
7 changes: 7 additions & 0 deletions lib/events/codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,13 @@ const (
// AutoUpdateVersionDeleteCode is the auto update version delete event code.
AutoUpdateVersionDeleteCode = "AUV003I"

// WorkloadIdentityCreateCode is the workload identity create event code.
WorkloadIdentityCreateCode = "WID001I"
// WorkloadIdentityUpdateCode is the workload identity update event code.
WorkloadIdentityUpdateCode = "WID002I"
// WorkloadIdentityDeleteCode is the workload identity delete event code.
WorkloadIdentityDeleteCode = "WID003I"

// UnknownCode is used when an event of unknown type is encountered.
UnknownCode = apievents.UnknownCode
)
Expand Down
7 changes: 7 additions & 0 deletions lib/events/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,13 @@ func FromEventFields(fields EventFields) (events.AuditEvent, error) {
e = &events.AutoUpdateVersionUpdate{}
case AutoUpdateVersionDeleteEvent:
e = &events.AutoUpdateVersionDelete{}

case WorkloadIdentityCreateEvent:
e = &events.WorkloadIdentityCreate{}
case WorkloadIdentityUpdateEvent:
e = &events.WorkloadIdentityUpdate{}
case WorkloadIdentityDeleteEvent:
e = &events.WorkloadIdentityDelete{}
default:
slog.ErrorContext(context.Background(), "Attempted to convert dynamic event of unknown type into protobuf event.", "event_type", eventType)
unknown := &events.Unknown{}
Expand Down
3 changes: 3 additions & 0 deletions lib/events/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ var eventsMap = map[string]apievents.AuditEvent{
AutoUpdateVersionCreateEvent: &apievents.AutoUpdateVersionCreate{},
AutoUpdateVersionUpdateEvent: &apievents.AutoUpdateVersionUpdate{},
AutoUpdateVersionDeleteEvent: &apievents.AutoUpdateVersionDelete{},
WorkloadIdentityCreateEvent: &apievents.WorkloadIdentityCreate{},
WorkloadIdentityUpdateEvent: &apievents.WorkloadIdentityUpdate{},
WorkloadIdentityDeleteEvent: &apievents.WorkloadIdentityDelete{},
}

// TestJSON tests JSON marshal events
Expand Down

0 comments on commit f275bb3

Please sign in to comment.