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

[v17] Add database User Agent to session start usage event #51705

Open
wants to merge 4 commits into
base: branch/v17
Choose a base branch
from
Open
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
27 changes: 19 additions & 8 deletions gen/proto/go/prehog/v1alpha/teleport.pb.go

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

16 changes: 15 additions & 1 deletion gen/proto/ts/prehog/v1alpha/teleport_pb.ts

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

1 change: 1 addition & 0 deletions lib/usagereporter/teleport/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func ConvertAuditEvent(event apievents.AuditEvent) Anonymizable {
DbType: e.DatabaseType,
DbProtocol: e.DatabaseProtocol,
DbOrigin: e.DatabaseOrigin,
UserAgent: e.UserAgent,
},
UserKind: prehogUserKindFromEventKind(e.UserKind),
}
Expand Down
39 changes: 39 additions & 0 deletions lib/usagereporter/teleport/audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,45 @@ func TestConvertAuditEvent(t *testing.T) {
},
},
},
{
desc: "DatabaseSessionStart",
event: &apievents.DatabaseSessionStart{
UserMetadata: apievents.UserMetadata{User: "alice"},
DatabaseMetadata: apievents.DatabaseMetadata{
DatabaseService: "postgres-local",
DatabaseProtocol: "postgres",
DatabaseName: "postgres",
DatabaseUser: "alice",
DatabaseType: "self-hosted",
DatabaseOrigin: "config-file",
},
ClientMetadata: apievents.ClientMetadata{UserAgent: "psql"},
},
expected: &SessionStartEvent{
SessionType: string(types.DatabaseSessionKind),
Database: &prehogv1a.SessionStartDatabaseMetadata{
DbType: "self-hosted",
DbProtocol: "postgres",
DbOrigin: "config-file",
UserAgent: "psql",
},
UserName: "alice",
},
expectedAnonymized: &prehogv1a.SubmitEventRequest{
Event: &prehogv1a.SubmitEventRequest_SessionStartV2{
SessionStartV2: &prehogv1a.SessionStartEvent{
SessionType: string(types.DatabaseSessionKind),
Database: &prehogv1a.SessionStartDatabaseMetadata{
DbType: "self-hosted",
DbProtocol: "postgres",
DbOrigin: "config-file",
UserAgent: "psql",
},
UserName: anonymizer.AnonymizeString("alice"),
},
},
},
},
}

for _, tt := range cases {
Expand Down
1 change: 1 addition & 0 deletions lib/usagereporter/teleport/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func (u *SessionStartEvent) Anonymize(a utils.Anonymizer) prehogv1a.SubmitEventR
DbType: u.Database.DbType,
DbProtocol: u.Database.DbProtocol,
DbOrigin: u.Database.DbOrigin,
UserAgent: u.Database.UserAgent,
}
}
if u.Desktop != nil {
Expand Down
2 changes: 2 additions & 0 deletions proto/prehog/v1alpha/teleport.proto
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ message SessionStartDatabaseMetadata {
string db_protocol = 2;
// database origin source.
string db_origin = 3;
// Indicates the client used on the session.
string user_agent = 4;
}

// SessionStartDesktop Metadata contains additional information about
Expand Down
Loading