[4.0.6 Backport] CBG-5396: User Access history Compaction#8327
Merged
Conversation
Redocly previews |
Contributor
There was a problem hiding this comment.
Pull request overview
Backport of CBG-5396 to 4.0.6. Adds two admin endpoints — GET /{db}/_user/{name}/_access_history and POST /{db}/_user/{name}/_access_history/compact — plus the underlying authenticator support to retrieve a user's per-collection revoked-channel history and to compact (remove) entries from it. Includes audit events, OpenAPI docs, and tests.
Changes:
- New admin REST handlers
getUserChannelHistory/compactUserChannelHistory, wired inrouting.go, returning/accepting a per-scope/per-collection channel history shape; default_default._defaulthistory is sourced from the principal's top-levelChannelHistory. - New
Principal.CompactChannelHistoryandTimedSetHistory.PruneHistoryByKeyhelpers, plusCollectionAccessHistoryaggregation across collections (including the default collection) on the principal. - New audit events
AuditIDUserAccessHistoryRead(54105) andAuditIDUserAccessHistoryCompact(54106), corresponding OpenAPI specs/schemas, and unit/REST/upgrade/audit tests.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| rest/routing.go | Registers GET/POST routes for _access_history and _access_history/compact. |
| rest/admin_api.go | Implements getUserChannelHistory and compactUserChannelHistory handlers, response types, and audit emission. |
| auth/principal.go | Adds CompactChannelHistory to the Principal interface. |
| auth/role.go | Adds roleImpl.CompactChannelHistory and TimedSetHistory.PruneHistoryByKey helper. |
| auth/role_collection_access.go | Adds CollectionAccessHistory type and GetCollectionAccessHistory aggregator across scopes/collections (incl. default). |
| auth/collection_access.go | Extends CollectionChannelAPI with GetCollectionAccessHistory. |
| auth/user_test.go | Unit tests for CompactChannelHistory covering existing/non-existent channels, multiple/default collections, nil history, duplicates. |
| base/audit_events.go | Defines new audit event IDs and metadata for read/compact operations. |
| docs/api/admin.yaml | Registers the two new admin paths. |
| docs/api/paths/admin/db-_user-name-_access_history.yaml | OpenAPI spec for the GET endpoint. |
| docs/api/paths/admin/db-_user-name-_access_history-compact.yaml | OpenAPI spec for the POST compact endpoint. |
| docs/api/components/schemas.yaml | Adds CollectionAccessHistory, UserHistory, CompactedUserHistory schemas. |
| rest/user_api_test.go | REST tests for GET and POST endpoints across single and multiple named collections. |
| rest/upgradetest/user_access_history_test.go | Upgrade-path tests covering default + named collection in default scope. |
| rest/audit_test.go | Audit event coverage for the two new event IDs. |
| rest/revocation_test.go | Asserts that compacting history triggers a _user/<name> change for revocations. |
| // Returns the CollectionAccess map | ||
| GetCollectionsAccess() map[string]map[string]*CollectionAccess | ||
|
|
||
| // Returns the ColelctionAccessHistory map |
| $ref: ../../components/responses.yaml#/Not-found | ||
| tags: | ||
| - Database Security | ||
| operationId: get_db-_user-name-_history |
Comment on lines
+2402
to
+2403
| var reqUserChannelHistory GetUserAccessHistoryResponse | ||
| err := h.readJSONInto(&reqUserChannelHistory) |
Comment on lines
+2418
to
+2433
| colAccessHistoryMap := make(map[string]map[string][]string) | ||
| for scope, cols := range reqUserChannelHistory.Channels { | ||
| colAccessHistoryMap[scope] = make(map[string][]string) | ||
| for col, colVal := range cols { | ||
| colAccessHistoryMap[scope][col] = user.CompactChannelHistory(scope, col, colVal) | ||
| } | ||
| } | ||
|
|
||
| userCompactedChannelHistory := CompactUserAccessHistoryResponse{ | ||
| CompactedChannels: colAccessHistoryMap, | ||
| } | ||
|
|
||
| err = authenticator.Save(user) | ||
| if err != nil { | ||
| return err | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CBG-5396
Describe your PR here...
Pre-review checklist
fmt.Print,log.Print, ...)base.UD(docID),base.MD(dbName))docs/apiDependencies (if applicable)
Integration Tests