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

remove expired spaces grants on access #3655

Merged
merged 1 commit into from
Feb 16, 2023
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
1 change: 1 addition & 0 deletions changelog/unreleased/space-member-expiration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ Enhancement: Add expiration date to space memberships

Added an optional expiration date to space memberships to restrict the access in time.

https://github.com/cs3org/reva/pull/3655
https://github.com/cs3org/reva/pull/3628
24 changes: 23 additions & 1 deletion pkg/storage/utils/decomposedfs/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,10 +723,25 @@ func (fs *Decomposedfs) storageSpaceFromNode(ctx context.Context, n *node.Node,
continue
}

grantMap[id] = g.Permissions
if g.Expiration != nil {
// We are doing this check here because we want to remove expired grants "on access".
// This way we don't have to have a cron job checking the grants in regular intervals.
// The tradeof obviously is that this code is here.
if isGrantExpired(g) {
err := fs.RemoveGrant(ctx, &provider.Reference{
ResourceId: &provider.ResourceId{
SpaceId: n.SpaceRoot.SpaceID,
OpaqueId: n.ID},
}, g)
appctx.GetLogger(ctx).Error().Err(err).
Str("space", n.SpaceRoot.ID).
Str("grantee", id).
Msg("failed to remove expired space grant")
continue
}
grantExpiration[id] = g.Expiration
}
grantMap[id] = g.Permissions
}

grantMapJSON, err := json.Marshal(grantMap)
Expand Down Expand Up @@ -881,3 +896,10 @@ func mapHasKey(checkMap map[string]string, keys ...string) bool {
}
return false
}

func isGrantExpired(g *provider.Grant) bool {
if g.Expiration == nil {
return false
}
return time.Now().After(time.Unix(int64(g.Expiration.Seconds), int64(g.Expiration.Nanos)))
}