Skip to content

Commit

Permalink
feat(usagereporter): add session recording access usage event
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielcorado committed Nov 22, 2024
1 parent a8bff10 commit 31e8f57
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/usagereporter/teleport/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions lib/usagereporter/teleport/audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 16 additions & 0 deletions lib/usagereporter/teleport/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 31e8f57

Please sign in to comment.