From 31e8f573291c0ea8438431b50dbc09054e3fe6bc Mon Sep 17 00:00:00 2001 From: Gabriel Corado Date: Mon, 7 Oct 2024 10:48:36 -0300 Subject: [PATCH] feat(usagereporter): add session recording access usage event --- lib/usagereporter/teleport/audit.go | 6 ++++++ lib/usagereporter/teleport/audit_test.go | 26 ++++++++++++++++++++++++ lib/usagereporter/teleport/types.go | 16 +++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/lib/usagereporter/teleport/audit.go b/lib/usagereporter/teleport/audit.go index f0586bd4093df..99080ca03905c 100644 --- a/lib/usagereporter/teleport/audit.go +++ b/lib/usagereporter/teleport/audit.go @@ -299,6 +299,12 @@ func ConvertAuditEvent(event apievents.AuditEvent) Anonymizable { } case *apievents.CrownJewelCreate: return &AccessGraphCrownJewelCreateEvent{} + case *apievents.SessionRecordingAccess: + return &SessionRecordingAccessEvent{ + SessionType: e.SessionType, + UserName: e.User, + Format: e.Format, + } } return nil diff --git a/lib/usagereporter/teleport/audit_test.go b/lib/usagereporter/teleport/audit_test.go index 3cd643c9998b8..982b046b54d1a 100644 --- a/lib/usagereporter/teleport/audit_test.go +++ b/lib/usagereporter/teleport/audit_test.go @@ -22,6 +22,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/gravitational/teleport" + "github.com/gravitational/teleport/api/types" apievents "github.com/gravitational/teleport/api/types/events" prehogv1a "github.com/gravitational/teleport/gen/proto/go/prehog/v1alpha" "github.com/gravitational/teleport/lib/utils" @@ -212,6 +214,30 @@ func TestConvertAuditEvent(t *testing.T) { }, }, }, + { + desc: "SessionRecordingAccess", + event: &apievents.SessionRecordingAccess{ + UserMetadata: apievents.UserMetadata{ + User: "some-user", + }, + SessionType: string(types.SSHSessionKind), + Format: teleport.PTY, + }, + expected: &SessionRecordingAccessEvent{ + SessionType: string(types.SSHSessionKind), + UserName: "some-user", + Format: teleport.PTY, + }, + expectedAnonymized: &prehogv1a.SubmitEventRequest{ + Event: &prehogv1a.SubmitEventRequest_SessionRecordingAccess{ + SessionRecordingAccess: &prehogv1a.SessionRecordingAccessEvent{ + SessionType: string(types.SSHSessionKind), + UserName: anonymizer.AnonymizeString("some-user"), + Format: teleport.PTY, + }, + }, + }, + }, } for _, tt := range cases { diff --git a/lib/usagereporter/teleport/types.go b/lib/usagereporter/teleport/types.go index f6ab2e4105cc3..9f6843323cbbd 100644 --- a/lib/usagereporter/teleport/types.go +++ b/lib/usagereporter/teleport/types.go @@ -1272,6 +1272,22 @@ func (u *UserTaskStateEvent) Anonymize(a utils.Anonymizer) prehogv1a.SubmitEvent } } +// SessionRecordingAccessEvent is an event that is emitted after an user access +// a session recording. +type SessionRecordingAccessEvent prehogv1a.SessionRecordingAccessEvent + +func (s *SessionRecordingAccessEvent) Anonymize(a utils.Anonymizer) prehogv1a.SubmitEventRequest { + return prehogv1a.SubmitEventRequest{ + Event: &prehogv1a.SubmitEventRequest_SessionRecordingAccess{ + SessionRecordingAccess: &prehogv1a.SessionRecordingAccessEvent{ + SessionType: s.SessionType, + UserName: a.AnonymizeString(s.UserName), + Format: s.Format, + }, + }, + } +} + // ConvertUsageEvent converts a usage event from an API object into an // anonymizable event. All events that can be submitted externally via the Auth // API need to be defined here.