test: [OCISDEV-1516] check vault notifications and access for group members
- Add a scenario outline for a vault resource share to a group: only the group members with the VaultMode permission get an in-app notification and can download the file. The other members get no notification, cannot download the file, and do not see it in the Shares space. - Add a scenario outline for a vault space membership of a group, with the space roles Manager, Space Viewer and Space Editor. Only the group members with the VaultMode permission get the notification and can access the space. The other members cannot download the file and do not see the space in their drive list. - The examples cover the roles Space Admin, Admin, User Light and User. - Assign the role "Space Admin" to Brian in the group share scenario, because the default role has no VaultMode permission. - Add NotificationContext to the apiVault suite. - Fix the pull request number in the changelog. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f456f905c8
commit
f7790d7be5
9 files changed
+215
-8
No files matched your search
@@ -7,5 +7,5 @@ notifications and userlog services now send a vault notification only to the
|
||||
group members who have the permission to use the vault. The other group
|
||||
members get no email and no in-app notification.
|
||||
|
||||
https://github.com/owncloud/ocis/pull/13259
|
||||
https://github.com/owncloud/ocis/pull/13260
|
||||
https://github.com/owncloud/reva/pull/787
|
||||
@@ -67,7 +67,7 @@ require (
|
||||
github.com/open-policy-agent/opa v1.21.1
|
||||
github.com/orcaman/concurrent-map v1.0.0
|
||||
github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245
|
||||
github.com/owncloud/reva/v2 v2.0.0-20261028111744-b8224d25858e
|
||||
github.com/owncloud/reva/v2 v2.0.0-20261028142447-7ce5132a4574
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/pkg/xattr v0.4.12
|
||||
github.com/prometheus/client_golang v1.25.0
|
||||
|
||||
@@ -736,8 +736,8 @@ github.com/orcaman/concurrent-map v1.0.0 h1:I/2A2XPCb4IuQWcQhBhSwGfiuybl/J0ev9HD
|
||||
github.com/orcaman/concurrent-map v1.0.0/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CFcDWnWD9XkenwhI=
|
||||
github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245 h1:JRidLTAKhnvyLMRtVtSF4lhBa0NSAOs6fof+d6JnKII=
|
||||
github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245/go.mod h1:z61VMGAJRtR1nbgXWiNoCkxUXP1B3Je9rMuJbnGd+Og=
|
||||
github.com/owncloud/reva/v2 v2.0.0-20261028111744-b8224d25858e h1:AkjvcOkHg2W4Kin3iMd1rl4/LXSPXkGUeMPUS4cfvhg=
|
||||
github.com/owncloud/reva/v2 v2.0.0-20261028111744-b8224d25858e/go.mod h1:cgqg+UTe4ekjMbJj8hgoXSTxQ9fQramKcOUdvsFUrzc=
|
||||
github.com/owncloud/reva/v2 v2.0.0-20261028142447-7ce5132a4574 h1:BDRlgU05VSMDzQC/7RWKtLHT8VcGxbQ9z0v7ycHQcEI=
|
||||
github.com/owncloud/reva/v2 v2.0.0-20261028142447-7ce5132a4574/go.mod h1:cgqg+UTe4ekjMbJj8hgoXSTxQ9fQramKcOUdvsFUrzc=
|
||||
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
|
||||
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0=
|
||||
github.com/pablodz/inotifywaitgo v0.0.12 h1:DVJJTFMDlSAdO46yisPF2vzozs/r+4k6ih8MVghq78M=
|
||||
|
||||
@@ -503,6 +503,7 @@ default:
|
||||
- SpacesContext:
|
||||
- SharingNgContext:
|
||||
- OCSContext:
|
||||
- NotificationContext:
|
||||
|
||||
cliCommands:
|
||||
paths:
|
||||
|
||||
@@ -1196,6 +1196,7 @@ Feature: vault
|
||||
| groupname |
|
||||
| vault-group |
|
||||
And user "Brian" has been created with default attributes
|
||||
And the administrator has assigned the role "Space Admin" to user "Brian" using the Graph API
|
||||
And user "Brian" has been set up in oCIS
|
||||
And user "Brian" has been added to group "vault-group"
|
||||
And user "Alice" has been set up in oCIS
|
||||
@@ -1214,6 +1215,100 @@ Feature: vault
|
||||
| vaultFile.txt | Viewer | Alice | Personal | vault |
|
||||
|
||||
|
||||
Scenario Outline: only group members with the vault mode permission get a notification and access for a vault share
|
||||
Given these users have been created with default attributes:
|
||||
| username |
|
||||
| Brian |
|
||||
| Carol |
|
||||
And the administrator has assigned the role "<vault-role>" to user "Brian" using the Graph API
|
||||
And the administrator has assigned the role "<no-vault-role>" to user "Carol" using the Graph API
|
||||
And these groups have been created:
|
||||
| groupname |
|
||||
| vault-group |
|
||||
And user "Brian" has been added to group "vault-group"
|
||||
And user "Carol" has been added to group "vault-group"
|
||||
And user "Alice" has been set up in oCIS
|
||||
And user "Brian" has been set up in oCIS
|
||||
And user "Carol" has been set up in oCIS
|
||||
And user "Alice" has uploaded a file inside space "Personal" with content "some content" to "vaultFile.txt" in vault
|
||||
And we save it into "FILEID"
|
||||
When user "Alice" sends the following resource share invitation using the Graph API:
|
||||
| resource | vaultFile.txt |
|
||||
| space | Personal |
|
||||
| sharee | vault-group |
|
||||
| shareType | group |
|
||||
| permissionsRole | Viewer |
|
||||
| storage | vault |
|
||||
Then the HTTP status code should be "200"
|
||||
And user "Brian" should have a share in vault "vaultFile.txt" synced
|
||||
# Check Brian first. The userlog service filters all group members before it stores the
|
||||
# notification for one of them, so the check for Carol cannot run too early.
|
||||
And user "Brian" should get a notification with subject "Resource shared" and message:
|
||||
| message |
|
||||
| Alice Hansen shared vaultFile.txt with you |
|
||||
And user "Carol" should not have any notification
|
||||
When user "Brian" sends HTTP method "GET" to URL "/dav/spaces/<<FILEID>>"
|
||||
Then the HTTP status code should be "200"
|
||||
And the downloaded content should be "some content"
|
||||
When user "Carol" tries to send HTTP method "GET" to URL "/dav/spaces/<<FILEID>>"
|
||||
Then the HTTP status code should be "403" or "404"
|
||||
And for user "Carol" the space "Shares" should not contain these entries:
|
||||
| vaultFile.txt |
|
||||
Examples:
|
||||
| vault-role | no-vault-role |
|
||||
| Space Admin | User Light |
|
||||
| Admin | User |
|
||||
|
||||
|
||||
Scenario Outline: only group members with the vault mode permission get a notification and access for a vault space membership
|
||||
Given these users have been created with default attributes:
|
||||
| username |
|
||||
| Brian |
|
||||
| Carol |
|
||||
And the administrator has assigned the role "<vault-role>" to user "Brian" using the Graph API
|
||||
And the administrator has assigned the role "<no-vault-role>" to user "Carol" using the Graph API
|
||||
And these groups have been created:
|
||||
| groupname |
|
||||
| vault-group |
|
||||
And user "Brian" has been added to group "vault-group"
|
||||
And user "Carol" has been added to group "vault-group"
|
||||
And user "Alice" has been set up in oCIS
|
||||
And user "Brian" has been set up in oCIS
|
||||
And user "Carol" has been set up in oCIS
|
||||
And user "Alice" has created a space "new-space" in vault with the default quota using the Graph API
|
||||
And user "Alice" has uploaded a file inside space "new-space" with content "some content" to "vaultFile.txt" in vault
|
||||
And we save it into "FILEID"
|
||||
When user "Alice" sends the following space share invitation using root endpoint of the Graph API:
|
||||
| space | new-space |
|
||||
| sharee | vault-group |
|
||||
| shareType | group |
|
||||
| permissionsRole | <permissions-role> |
|
||||
| storage | vault |
|
||||
Then the HTTP status code should be "200"
|
||||
# Check Brian first. The userlog service filters all group members before it stores the
|
||||
# notification for one of them, so the check for Carol cannot run too early.
|
||||
And user "Brian" should get a notification with subject "Space shared" and message:
|
||||
| message |
|
||||
| Alice Hansen added you to Space new-space |
|
||||
And user "Carol" should not have any notification
|
||||
And for user "Brian" the space "new-space" in vault should contain these entries:
|
||||
| vaultFile.txt |
|
||||
When user "Brian" sends HTTP method "GET" to URL "/dav/spaces/<<FILEID>>"
|
||||
Then the HTTP status code should be "200"
|
||||
And the downloaded content should be "some content"
|
||||
When user "Carol" tries to send HTTP method "GET" to URL "/dav/spaces/<<FILEID>>"
|
||||
Then the HTTP status code should be "403" or "404"
|
||||
When user "Carol" lists all available spaces via the Graph API
|
||||
Then the HTTP status code should be "200"
|
||||
And the json response should not contain a space with name "new-space"
|
||||
Examples:
|
||||
| permissions-role | vault-role | no-vault-role |
|
||||
| Manager | Space Admin | User Light |
|
||||
| Manager | Admin | User |
|
||||
| Space Viewer | Space Admin | User Light |
|
||||
| Space Editor | Admin | User |
|
||||
|
||||
|
||||
Scenario Outline: server sets a default 30-day expiration when a user share is created without one
|
||||
Given user "Brian" has been created with default attributes
|
||||
And the administrator has assigned the role "Space Admin" to user "Brian" using the Graph API
|
||||
|
||||
+32
@@ -63,6 +63,10 @@ type config struct {
|
||||
UserGroupsCacheSize int `mapstructure:"usergroups_cache_size"`
|
||||
ScopeExpansionCacheSize int `mapstructure:"scope_expansion_cache_size"`
|
||||
MFAEnabled bool `mapstructure:"mfa_enabled"`
|
||||
// VaultModeRequired denies access to users who do not hold the VaultMode permission.
|
||||
VaultModeRequired bool `mapstructure:"vault_mode_required"`
|
||||
VaultModeCacheSize int `mapstructure:"vault_mode_cache_size"`
|
||||
VaultModeCacheSeconds int `mapstructure:"vault_mode_cache_seconds"`
|
||||
}
|
||||
|
||||
func parseConfig(m map[string]interface{}) (*config, error) {
|
||||
@@ -71,6 +75,13 @@ func parseConfig(m map[string]interface{}) (*config, error) {
|
||||
err = errors.Wrap(err, "auth: error decoding conf")
|
||||
return nil, err
|
||||
}
|
||||
if c.VaultModeCacheSize == 0 {
|
||||
c.VaultModeCacheSize = 5000
|
||||
}
|
||||
if c.VaultModeCacheSeconds == 0 {
|
||||
c.VaultModeCacheSeconds = 30
|
||||
}
|
||||
initVaultModeCache(c.VaultModeCacheSize, time.Duration(c.VaultModeCacheSeconds)*time.Second)
|
||||
return c, nil
|
||||
}
|
||||
|
||||
@@ -163,6 +174,16 @@ func NewUnary(m map[string]interface{}, unprotected []string, tp trace.TracerPro
|
||||
return mfaResponse(ctx, req, info)
|
||||
}
|
||||
}
|
||||
if conf.VaultModeRequired && u.Id.Type != userpb.UserType_USER_TYPE_SERVICE {
|
||||
allowed, err := hasVaultMode(ctx, u, conf.GatewayAddr)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("user_id", u.Id.OpaqueId).Msg("could not check the vault mode permission")
|
||||
}
|
||||
if !allowed {
|
||||
log.Debug().Str("user_id", u.Id.OpaqueId).Msg("vault mode permission is required")
|
||||
return denyResponse(ctx, req, info, vaultModeRequiredMsg)
|
||||
}
|
||||
}
|
||||
|
||||
span.SetAttributes(semconv.EnduserIDKey.String(u.Id.OpaqueId))
|
||||
|
||||
@@ -182,6 +203,7 @@ func NewStream(m map[string]interface{}, unprotected []string, tp trace.TracerPr
|
||||
if conf.TokenManager == "" {
|
||||
conf.TokenManager = "jwt"
|
||||
}
|
||||
conf.GatewayAddr = sharedconf.GetGatewaySVC(conf.GatewayAddr)
|
||||
|
||||
if conf.UserGroupsCacheSize == 0 {
|
||||
conf.UserGroupsCacheSize = 10000
|
||||
@@ -260,6 +282,16 @@ func NewStream(m map[string]interface{}, unprotected []string, tp trace.TracerPr
|
||||
return status.Errorf(codes.PermissionDenied, "MFA required to access vault storage")
|
||||
}
|
||||
}
|
||||
if conf.VaultModeRequired && u.Id.Type != userpb.UserType_USER_TYPE_SERVICE {
|
||||
allowed, err := hasVaultMode(ctx, u, conf.GatewayAddr)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("user_id", u.Id.OpaqueId).Msg("could not check the vault mode permission")
|
||||
}
|
||||
if !allowed {
|
||||
log.Debug().Str("user_id", u.Id.OpaqueId).Msg("vault mode permission is required")
|
||||
return status.Errorf(codes.PermissionDenied, vaultModeRequiredMsg)
|
||||
}
|
||||
}
|
||||
wrapped := newWrappedServerStream(ctx, ss)
|
||||
|
||||
span.SetAttributes(semconv.EnduserIDKey.String(u.Id.OpaqueId))
|
||||
|
||||
+7
-3
@@ -12,7 +12,11 @@ import (
|
||||
)
|
||||
|
||||
func mfaResponse(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo) (interface{}, error) {
|
||||
const msg = "MFA required to access vault storage"
|
||||
return denyResponse(ctx, req, info, "MFA required to access vault storage")
|
||||
}
|
||||
|
||||
// denyResponse returns a PERMISSION_DENIED response of the type that matches the request.
|
||||
func denyResponse(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, msg string) (interface{}, error) {
|
||||
switch req.(type) {
|
||||
case *provider.StatRequest:
|
||||
return &provider.StatResponse{Status: rstatus.NewPermissionDenied(ctx, nil, msg)}, nil
|
||||
@@ -67,7 +71,7 @@ func mfaResponse(ctx context.Context, req interface{}, info *grpc.UnaryServerInf
|
||||
case *provider.DeleteStorageSpaceRequest:
|
||||
return &provider.DeleteStorageSpaceResponse{Status: rstatus.NewPermissionDenied(ctx, nil, msg)}, nil
|
||||
default:
|
||||
log.Debug().Str("method", info.FullMethod).Msg("mfa: blocking unknown request type")
|
||||
return nil, grpcstatus.Errorf(codes.PermissionDenied, "mfa: %s: %T", msg, req)
|
||||
log.Debug().Str("method", info.FullMethod).Msg("auth: blocking unknown request type")
|
||||
return nil, grpcstatus.Errorf(codes.PermissionDenied, "auth: %s: %T", msg, req)
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/bluele/gcache"
|
||||
gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
||||
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
||||
permissions "github.com/cs3org/go-cs3apis/cs3/permissions/v1beta1"
|
||||
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
|
||||
"github.com/owncloud/reva/v2/pkg/permission"
|
||||
"github.com/owncloud/reva/v2/pkg/rgrpc/todo/pool"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const vaultModeRequiredMsg = "vault mode permission required to access vault storage"
|
||||
|
||||
var (
|
||||
vaultModeCache gcache.Cache
|
||||
vaultModeCacheTTL time.Duration
|
||||
vaultModeCacheOnce sync.Once
|
||||
|
||||
// getGatewayClient is a variable, so that tests can replace the gateway client.
|
||||
getGatewayClient = func(addr string) (gatewayv1beta1.GatewayAPIClient, error) {
|
||||
return pool.GetGatewayServiceClient(addr)
|
||||
}
|
||||
)
|
||||
|
||||
// initVaultModeCache creates the cache for the VaultMode answers. Only the first call has an effect.
|
||||
func initVaultModeCache(size int, ttl time.Duration) {
|
||||
vaultModeCacheOnce.Do(func() {
|
||||
vaultModeCache = gcache.New(size).LRU().Build()
|
||||
vaultModeCacheTTL = ttl
|
||||
})
|
||||
}
|
||||
|
||||
// hasVaultMode reports whether the user holds the VaultMode permission.
|
||||
// The vault storage provider uses it to deny access to users who cannot use vault mode,
|
||||
// for example group members who received a vault share. A non-nil error means undetermined,
|
||||
// so the caller must deny the request. Only definitive answers are cached.
|
||||
func hasVaultMode(ctx context.Context, u *userpb.User, gatewayAddr string) (bool, error) {
|
||||
id := u.GetId().GetOpaqueId()
|
||||
if v, err := vaultModeCache.Get(id); err == nil {
|
||||
return v.(bool), nil
|
||||
}
|
||||
|
||||
client, err := getGatewayClient(gatewayAddr)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
res, err := client.CheckPermission(ctx, &permissions.CheckPermissionRequest{
|
||||
SubjectRef: &permissions.SubjectReference{
|
||||
Spec: &permissions.SubjectReference_UserId{UserId: u.GetId()},
|
||||
},
|
||||
Permission: permission.VaultMode,
|
||||
})
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "auth: error calling CheckPermission")
|
||||
}
|
||||
|
||||
var allowed bool
|
||||
switch code := res.GetStatus().GetCode(); code {
|
||||
case rpc.Code_CODE_OK:
|
||||
allowed = true
|
||||
case rpc.Code_CODE_PERMISSION_DENIED:
|
||||
allowed = false
|
||||
default:
|
||||
return false, errors.Errorf("auth: vault permission check returned status %q: %s", code, res.GetStatus().GetMessage())
|
||||
}
|
||||
|
||||
_ = vaultModeCache.SetWithExpire(id, allowed, vaultModeCacheTTL)
|
||||
return allowed, nil
|
||||
}
|
||||
Vendored
+1
-1
@@ -1321,7 +1321,7 @@ github.com/orcaman/concurrent-map
|
||||
# github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245
|
||||
## explicit; go 1.18
|
||||
github.com/owncloud/libre-graph-api-go
|
||||
# github.com/owncloud/reva/v2 v2.0.0-20261028111744-b8224d25858e
|
||||
# github.com/owncloud/reva/v2 v2.0.0-20261028142447-7ce5132a4574
|
||||
## explicit; go 1.26.0
|
||||
github.com/owncloud/reva/v2/cmd/revad/internal/grace
|
||||
github.com/owncloud/reva/v2/cmd/revad/runtime
|
||||
|
||||
Reference in new issue
Block a user