Skip to content

[4.0.6 Backport] CBG-5396: User Access history Compaction#8327

Merged
adamcfraser merged 5 commits into
release/4.0.6from
CBG-5396
Jun 4, 2026
Merged

[4.0.6 Backport] CBG-5396: User Access history Compaction#8327
adamcfraser merged 5 commits into
release/4.0.6from
CBG-5396

Conversation

@RIT3shSapata

Copy link
Copy Markdown
Contributor

CBG-5396

Describe your PR here...

  • Backport of user access history compactoin

Pre-review checklist

  • Removed debug logging (fmt.Print, log.Print, ...)
  • Logging sensitive data? Make sure it's tagged (e.g. base.UD(docID), base.MD(dbName))
  • Updated relevant information in the API specifications (such as endpoint descriptions, schemas, ...) in docs/api

Dependencies (if applicable)

  • Link upstream PRs
  • Update Go module dependencies when merged

Integration Tests

Copilot AI review requested due to automatic review settings June 2, 2026 13:51
@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown

Redocly previews

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in routing.go, returning/accepting a per-scope/per-collection channel history shape; default _default._default history is sourced from the principal's top-level ChannelHistory.
  • New Principal.CompactChannelHistory and TimedSetHistory.PruneHistoryByKey helpers, plus CollectionAccessHistory aggregation across collections (including the default collection) on the principal.
  • New audit events AuditIDUserAccessHistoryRead (54105) and AuditIDUserAccessHistoryCompact (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.

Comment thread auth/collection_access.go
// 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 thread rest/admin_api.go
Comment on lines +2402 to +2403
var reqUserChannelHistory GetUserAccessHistoryResponse
err := h.readJSONInto(&reqUserChannelHistory)
Comment thread rest/admin_api.go
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
}

@adamcfraser adamcfraser left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@adamcfraser adamcfraser merged commit 50a1146 into release/4.0.6 Jun 4, 2026
47 checks passed
@adamcfraser adamcfraser deleted the CBG-5396 branch June 4, 2026 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants