MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / RevokedCollectionChannels

Method RevokedCollectionChannels

auth/user.go:292–404  ·  view source on GitHub ↗

RevokedCollectionChannels returns a map of revoked channels for the collection => most recent sequence at which access to that channel was lost Steps: Get revoked roles and for each: - Revoke the current channels if the role is deleted - Revoke the role revoked channels Get current roles and for ea

(scope string, collection string, since uint64, lowSeq uint64, triggeredBy uint64)

Source from the content-addressed store, hash-verified

290// Get user:
291// - Revoke users revoked channels
292func (user *userImpl) RevokedCollectionChannels(scope string, collection string, since uint64, lowSeq uint64, triggeredBy uint64) (RevokedChannels, error) {
293 // checkSeq represents the value that we use to 'diff' against ie. What channels did the user have at checkSeq but
294 // no longer has.
295 // In the event we have a lowSeq that will be used.
296 // In the event we do not have a lowSeq but have a triggeredBy that will be used.
297 // In the event we have neither lowSeq or triggeredBy the 'regular' seq value will be used.
298 var checkSeq uint64
299 if lowSeq > 0 {
300 checkSeq = lowSeq
301 } else if triggeredBy > 0 {
302 checkSeq = triggeredBy
303 } else {
304 checkSeq = since
305 }
306
307 // Note
308 // entry.EndSeq > checkSeq || entry.EndSeq == triggeredBy
309 // The above check is used in a number of places and represents:
310 // If there has been a revocation somewhere after the since value or we're in an interrupted revocation backfill
311 // at the point a revocation occurred we should return this as a channel to revoke.
312
313 accessibleChannels, err := user.InheritedCollectionChannels(scope, collection)
314 if err != nil {
315 return nil, err
316 }
317 // Get revoked roles
318 rolesToRevoke := map[string]uint64{}
319 roleHistory := user.RoleHistory()
320 for roleName, history := range roleHistory {
321 if !user.RoleNames().Contains(roleName) {
322 for _, entry := range history.Entries {
323 if entry.EndSeq > checkSeq || entry.EndSeq == triggeredBy {
324 mostRecentEndSeq := history.Entries[len(history.Entries)-1]
325 rolesToRevoke[roleName] = mostRecentEndSeq.EndSeq
326 }
327 }
328 }
329 }
330
331 // Store revoked channels to return
332 // addToCombined adds to this return map or updates if required based on requirement to have largest triggeredBy val
333 combinedRevokedChannels := RevokedChannels{}
334
335 // revokeChannelHistoryProcessing iterates over a principals channel history and if not accessible add to combined
336 revokeChannelHistoryProcessing := func(princ Principal) {
337 for chanName, history := range princ.CollectionChannelHistory(scope, collection) {
338 if !accessibleChannels.Contains(chanName) {
339 for _, entry := range history.Entries {
340 if entry.EndSeq > checkSeq || entry.EndSeq == triggeredBy {
341 mostRecentEndSeq := history.Entries[len(history.Entries)-1]
342 combinedRevokedChannels.add(chanName, mostRecentEndSeq.EndSeq)
343 }
344 }
345 }
346 }
347 }
348
349 // Iterate over revoked roles and revoke ALL channels (current and previous) from revoked roles that we don't have

Callers 1

revokedChannelsMethod · 0.95

Calls 13

RoleHistoryMethod · 0.95
RoleNamesMethod · 0.95
addMethod · 0.95
GetRolesIncDeletedMethod · 0.95
WarnfCtxFunction · 0.92
UDFunction · 0.92
GetRoleIncDeletedMethod · 0.80
AllKeysMethod · 0.80
ContainsMethod · 0.65
IsDeletedMethod · 0.65

Tested by

no test coverage detected