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

[v15] Add usage events for database autoprovisioning (#39841) #41051

Merged
merged 4 commits into from
May 6, 2024
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
5 changes: 5 additions & 0 deletions api/proto/teleport/legacy/types/events/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3096,6 +3096,11 @@ message DatabasePermissionUpdate {
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "permission_summary"
];
// AffectedObjectCounts counts how many distinct objects of each kind were affected.
map<string, int32> AffectedObjectCounts = 6 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "affected_object_counts"
];
}

// DatabasePermissionEntry is a summary of permissions, scoped to a particular permission.
Expand Down
1,950 changes: 1,047 additions & 903 deletions api/types/events/events.pb.go

Large diffs are not rendered by default.

2,096 changes: 1,169 additions & 927 deletions gen/proto/go/prehog/v1alpha/teleport.pb.go

Large diffs are not rendered by default.

223 changes: 222 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.

25 changes: 25 additions & 0 deletions lib/usagereporter/teleport/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
apievents "github.com/gravitational/teleport/api/types/events"
prehogv1a "github.com/gravitational/teleport/gen/proto/go/prehog/v1alpha"
"github.com/gravitational/teleport/lib/events"
"github.com/gravitational/teleport/lib/srv/db/common/databaseobjectimportrule"
)

const (
Expand Down Expand Up @@ -265,6 +266,30 @@ func ConvertAuditEvent(event apievents.AuditEvent) Anonymizable {
DnsSansCount: int32(len(e.DNSSANs)),
SvidType: e.SVIDType,
}
case *apievents.DatabaseUserCreate:
return &DatabaseUserCreatedEvent{
Database: &prehogv1a.SessionStartDatabaseMetadata{
DbType: e.DatabaseType,
DbProtocol: e.DatabaseProtocol,
DbOrigin: e.DatabaseOrigin,
},
UserName: e.User,
NumRoles: int32(len(e.DatabaseRoles)),
}
case *apievents.DatabasePermissionUpdate:
out := &DatabaseUserPermissionsUpdateEvent{
Database: &prehogv1a.SessionStartDatabaseMetadata{
DbType: e.DatabaseType,
DbProtocol: e.DatabaseProtocol,
DbOrigin: e.DatabaseOrigin,
},
UserName: e.User,
NumTables: e.AffectedObjectCounts[databaseobjectimportrule.ObjectKindTable],
}
for _, entry := range e.PermissionSummary {
out.NumTablesPermissions += entry.Counts[databaseobjectimportrule.ObjectKindTable]
}
return out
}

return nil
Expand Down
Loading
Loading