feat: [OCISDEV-1433] The public link resolution flag and the context timeout added to PROPFIND request

Adds the config field, env var binding, and option wiring for disabling
public link share resolution on PROPFIND requests. Requires bumping the
vendored reva dependency to the fix/OCISDEV-1433-prppfind branch
for ocdav.DisablePropfindPublicLinkResolution to exist.
This commit is contained in:
Roman Perekhod committed 2026-09-30 14:45:00 +02:00
1 parent dbfd742112
commit ce396b1bcb
12 files changed
+145 -62

No files matched your search

@@ -0,0 +1,12 @@
Enhancement: The public link resolution flag added to PROPFIND
The public link resolution flag and the context timeout added to PROPFIND request
The ocdav PROPFIND handler resolves public link shares to populate the oc:share-type property.
A new toggle for skipping that lookup. The toggle is now exposed as
OCDAV_DISABLE_PROPFIND_PUBLIC_LINK_RESOLUTION, which can be set to reduce load
on services for large collections.
Also, the bounded context was added for least public share request. Since this property is needed only
to display an icon next to files in the list, indicating that a public link exists,
it can be omitted if the ListPublicShares request is slow.
https://github.com/owncloud/ocis/pull/13031
+1 -1
View File
@@ -65,7 +65,7 @@ require (
github.com/open-policy-agent/opa v1.19.0
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-20260910093159-40663c5bb3cb
github.com/owncloud/reva/v2 v2.0.0-20260930102649-8627a367787a
github.com/pkg/errors v0.9.1
github.com/pkg/xattr v0.4.12
github.com/prometheus/client_golang v1.24.1
+2 -2
View File
@@ -735,8 +735,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-20260910093159-40663c5bb3cb h1:pbFDeaDFhJ5dJF/ZYOyRf/FtD6MbG5BIPlOUeoh1vIs=
github.com/owncloud/reva/v2 v2.0.0-20260910093159-40663c5bb3cb/go.mod h1:LSXqMWTC7Ya6uxmqp1ksrWYZXBuZ6PhcmVimxyG8U5o=
github.com/owncloud/reva/v2 v2.0.0-20260930102649-8627a367787a h1:fOgWtuGNLctt2DIGiGamcq65RpHY3yqHhSUEWnV5cts=
github.com/owncloud/reva/v2 v2.0.0-20260930102649-8627a367787a/go.mod h1:LSXqMWTC7Ya6uxmqp1ksrWYZXBuZ6PhcmVimxyG8U5o=
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=
+1
View File
@@ -71,6 +71,7 @@ func Server(cfg *config.Config) *cli.Command {
ocdav.WebdavNamespace(cfg.WebdavNamespace),
ocdav.OCMNamespace(cfg.OCMNamespace),
ocdav.AllowDepthInfinity(cfg.AllowPropfindDepthInfinity),
ocdav.DisablePropfindPublicLinkResolution(cfg.DisablePropfindPublicLinkResolution),
ocdav.SharesNamespace(cfg.SharesNamespace),
ocdav.Timeout(cfg.Timeout),
ocdav.Insecure(cfg.Insecure),
+2
View File
@@ -38,6 +38,8 @@ type Config struct {
Status Status `yaml:"-"`
AllowPropfindDepthInfinity bool `yaml:"allow_propfind_depth_infinity" env:"OCDAV_ALLOW_PROPFIND_DEPTH_INFINITY" desc:"Allow the use of depth infinity in PROPFINDS. When enabled, a propfind will traverse through all subfolders. If many subfolders are expected, depth infinity can cause heavy server load and/or delayed response times." introductionVersion:"pre5.0"`
DisablePropfindPublicLinkResolution bool `yaml:"disable_propfind_public_link_resolution" env:"OCDAV_DISABLE_PROPFIND_PUBLIC_LINK_RESOLUTION" desc:"Disable the resolution of public link shares when answering PROPFIND requests. When disabled, the oc:share-type property will not be populated with public link share information, which can reduce load on services for large collections." introductionVersion:"8.3.0"`
}
type Log struct {
@@ -21,17 +21,18 @@ type Config struct {
Timeout int64 `mapstructure:"timeout"`
Insecure bool `mapstructure:"insecure"`
// If true, HTTP COPY will expect the HTTP-TPC (third-party copy) headers
EnableHTTPTpc bool `mapstructure:"enable_http_tpc"`
PublicURL string `mapstructure:"public_url"`
FavoriteStorageDriver string `mapstructure:"favorite_storage_driver"`
FavoriteStorageDrivers map[string]map[string]interface{} `mapstructure:"favorite_storage_drivers"`
Version string `mapstructure:"version"`
VersionString string `mapstructure:"version_string"`
Edition string `mapstructure:"edition"`
Product string `mapstructure:"product"`
ProductName string `mapstructure:"product_name"`
ProductVersion string `mapstructure:"product_version"`
AllowPropfindDepthInfinitiy bool `mapstructure:"allow_depth_infinity"`
EnableHTTPTpc bool `mapstructure:"enable_http_tpc"`
PublicURL string `mapstructure:"public_url"`
FavoriteStorageDriver string `mapstructure:"favorite_storage_driver"`
FavoriteStorageDrivers map[string]map[string]interface{} `mapstructure:"favorite_storage_drivers"`
Version string `mapstructure:"version"`
VersionString string `mapstructure:"version_string"`
Edition string `mapstructure:"edition"`
Product string `mapstructure:"product"`
ProductName string `mapstructure:"product_name"`
ProductVersion string `mapstructure:"product_version"`
AllowPropfindDepthInfinitiy bool `mapstructure:"allow_depth_infinity"`
DisablePropfindPublicLinkResolution bool `mapstructure:"disable_propfind_public_link_resolution"`
TransferSharedSecret string `mapstructure:"transfer_shared_secret"`
@@ -22,6 +22,7 @@ import (
"context"
"encoding/json"
"encoding/xml"
stderr "errors"
"fmt"
"io"
"net/http"
@@ -454,42 +455,9 @@ func (p *Handler) propfindResponse(ctx context.Context, w http.ResponseWriter, r
defer span.End()
var linkshares map[string]struct{}
// public link access does not show share-types
// oc:share-type is not part of an allprops response
if namespace != "/public" {
// only fetch this if property was queried
for _, prop := range pf.Prop {
if prop.Space == net.NsOwncloud && (prop.Local == "share-types" || prop.Local == "permissions") {
filters := make([]*link.ListPublicSharesRequest_Filter, 0, len(resourceInfos))
for i := range resourceInfos {
// FIXME this is expensive
// the filters array grow by one for every file in a folder
// TODO store public links as grants on the storage, reassembling them here is too costly
// we can then add the filter if the file has share-types=3 in the opaque,
// same as user / group shares for share indicators
filters = append(filters, publicshare.ResourceIDFilter(resourceInfos[i].Id))
}
client, err := p.selector.Next()
if err != nil {
log.Error().Err(err).Msg("error getting grpc client")
w.WriteHeader(http.StatusInternalServerError)
return
}
listResp, err := client.ListPublicShares(ctx, &link.ListPublicSharesRequest{Filters: filters})
if err == nil {
linkshares = make(map[string]struct{}, len(listResp.Share))
for i := range listResp.Share {
linkshares[listResp.Share[i].ResourceId.OpaqueId] = struct{}{}
}
} else {
log.Error().Err(err).Msg("propfindResponse: couldn't list public shares")
span.SetStatus(codes.Error, err.Error())
}
break
}
}
if !p.c.DisablePropfindPublicLinkResolution {
linkshares = p.resolveLinkshares(ctx, w, namespace, pf, resourceInfos, log)
}
prefer := net.ParsePrefer(r.Header.Get(net.HeaderPrefer))
returnMinimal := prefer[net.HeaderPreferReturn] == "minimal"
@@ -522,6 +490,58 @@ func (p *Handler) propfindResponse(ctx context.Context, w http.ResponseWriter, r
}
}
// resolveLinkshares resolves the link shares for the given resource infos
func (p *Handler) resolveLinkshares(ctx context.Context, w http.ResponseWriter, namespace string, pf XML, resourceInfos []*provider.ResourceInfo, log zerolog.Logger) map[string]struct{} {
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "resolveLinkshares")
defer span.End()
var linkshares map[string]struct{}
// public link access does not show share-types
// oc:share-type is not part of an allprops response
if namespace != "/public" {
localCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
// only fetch this if property was queried
for _, prop := range pf.Prop {
if err := localCtx.Err(); err != nil {
if stderr.Is(err, context.DeadlineExceeded) {
log.Info().Err(err).Msg("resolveLinkshares: deadline exceeded")
span.SetStatus(codes.Error, err.Error())
}
break
}
if prop.Space == net.NsOwncloud && (prop.Local == "share-types" || prop.Local == "permissions") {
filters := make([]*link.ListPublicSharesRequest_Filter, 0, len(resourceInfos))
for i := range resourceInfos {
// FIXME this is expensive
// the filters array grow by one for every file in a folder
// TODO store public links as grants on the storage, reassembling them here is too costly
// we can then add the filter if the file has share-types=3 in the opaque,
// same as user / group shares for share indicators
filters = append(filters, publicshare.ResourceIDFilter(resourceInfos[i].Id))
}
client, err := p.selector.Next()
if err != nil {
log.Error().Err(err).Msg("error getting grpc client")
w.WriteHeader(http.StatusInternalServerError)
return nil
}
listResp, err := client.ListPublicShares(ctx, &link.ListPublicSharesRequest{Filters: filters})
if err == nil {
linkshares = make(map[string]struct{}, len(listResp.Share))
for i := range listResp.Share {
linkshares[listResp.Share[i].ResourceId.OpaqueId] = struct{}{}
}
} else {
log.Error().Err(err).Msg("propfindResponse: couldn't list public shares")
span.SetStatus(codes.Error, err.Error())
}
break
}
}
}
return linkshares
}
// TODO this is just a stat -> rename
func (p *Handler) statSpace(ctx context.Context, ref *provider.Reference, metadataKeys, fieldMaskPaths []string) (*provider.ResourceInfo, *rpc.Status, error) {
client, err := p.selector.Next()
+15 -7
View File
@@ -64,13 +64,14 @@ type Options struct {
MetricsSubsystem string
// ocdav.* is internal so we need to set config options individually
config config.Config
lockSystem ocdav.LockSystem
AllowCredentials bool
AllowedOrigins []string
AllowedHeaders []string
AllowedMethods []string
AllowDepthInfinity bool
config config.Config
lockSystem ocdav.LockSystem
AllowCredentials bool
AllowedOrigins []string
AllowedHeaders []string
AllowedMethods []string
AllowDepthInfinity bool
DisablePropfindPublicLinkResolution bool
RegisterTTL time.Duration
RegisterInterval time.Duration
@@ -114,6 +115,13 @@ func AllowDepthInfinity(val bool) Option {
}
}
// DisablePropfindPublicLinkResolution provides a function to set the DisablePropfindPublicLinkResolution option.
func DisablePropfindPublicLinkResolution(val bool) Option {
return func(o *Options) {
o.DisablePropfindPublicLinkResolution = val
}
}
// JWTSecret provides a function to set the jwt secret option.
func JWTSecret(s string) Option {
return func(o *Options) {
+5 -4
View File
@@ -22,6 +22,10 @@ import (
"net/http"
"strings"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
httpServer "github.com/go-micro/plugins/v4/server/http"
"github.com/owncloud/ocis/v2/ocis-pkg/registry"
"github.com/owncloud/reva/v2/internal/http/interceptors/appctx"
"github.com/owncloud/reva/v2/internal/http/interceptors/auth"
cors2 "github.com/owncloud/reva/v2/internal/http/interceptors/cors"
@@ -31,10 +35,6 @@ import (
"github.com/owncloud/reva/v2/pkg/rhttp/global"
"github.com/owncloud/reva/v2/pkg/storage/favorite/memory"
rtrace "github.com/owncloud/reva/v2/pkg/trace"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
httpServer "github.com/go-micro/plugins/v4/server/http"
"github.com/owncloud/ocis/v2/ocis-pkg/registry"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
@@ -154,6 +154,7 @@ func setDefaults(sopts *Options) error {
}
sopts.config.AllowPropfindDepthInfinitiy = sopts.AllowDepthInfinity
sopts.config.DisablePropfindPublicLinkResolution = sopts.DisablePropfindPublicLinkResolution
return nil
}
@@ -523,6 +523,14 @@ func (m *manager) ListPublicShares(ctx context.Context, u *user.User, filters []
continue
}
if local.ResourceId == nil {
log.Warn().
Str("share_id", local.PublicShare.GetId().GetOpaqueId()).
Str("share_token", local.Token).
Msg("ListPublicShares: skipping share with nil resource_id")
continue
}
key := strings.Join([]string{local.ResourceId.StorageId, local.ResourceId.OpaqueId}, "!")
if _, hit := cache[key]; !hit && !publicshare.IsCreatedByUser(&local.PublicShare, u) {
sRes, err := client.Stat(ctx, &provider.StatRequest{Ref: &provider.Reference{ResourceId: local.ResourceId}})
+31 -1
View File
@@ -52,6 +52,12 @@ func init() {
tracer = otel.Tracer("github.com/owncloud/reva/pkg/storage/utils/metadata")
}
// defaultAuthRPCTimeout bounds the machine auth Authenticate call made for
// every metadata operation. It only has to cover a token mint, so it is
// generous - its purpose is to turn a stalled gateway into an error instead of
// a goroutine that waits for the lifetime of the process.
const defaultAuthRPCTimeout = 10 * time.Second
// CS3 represents a metadata storage with a cs3 storage backend
type CS3 struct {
SpaceRoot *provider.ResourceId
@@ -61,6 +67,7 @@ type CS3 struct {
useSystemUser bool
serviceUser *user.User
machineAuthAPIKey string
authRPCTimeout time.Duration
dataGatewayClient *http.Client
}
@@ -71,6 +78,7 @@ func NewCS3(gwAddr, providerAddr string) (s *CS3) {
return &CS3{
providerAddr: providerAddr,
gatewayAddr: gwAddr,
authRPCTimeout: defaultAuthRPCTimeout,
dataGatewayClient: http.DefaultClient,
}
}
@@ -573,12 +581,34 @@ func (cs3 *CS3) getAuthContext(ctx context.Context) (context.Context, error) {
}
authCtx = ctxpkg.ContextSetUser(authCtx, cs3.serviceUser)
authRes, err := client.Authenticate(authCtx, &gateway.AuthenticateRequest{
// The Authenticate call gets a context of its own: a gateway that is stuck
// on a downstream storage provider accepts the connection and then never
// answers, and there is nothing else that would ever end the wait. The
// deadline cannot live on authCtx, because the caller runs its own RPC on
// the context we return here.
timeout := cs3.authRPCTimeout
if timeout <= 0 {
timeout = defaultAuthRPCTimeout
}
rpcCtx, cancel := context.WithTimeout(authCtx, timeout)
defer cancel()
start := time.Now()
authRes, err := client.Authenticate(rpcCtx, &gateway.AuthenticateRequest{
Type: "machine",
ClientId: "userid:" + cs3.serviceUser.Id.OpaqueId,
ClientSecret: cs3.machineAuthAPIKey,
})
if err != nil {
// this used to fail silently by never returning at all, so make sure
// an exhausted deadline is visible at production log level
appctx.GetLogger(ctx).Warn().
Err(err).
Str("gateway_addr", cs3.gatewayAddr).
Dur("elapsed", time.Since(start)).
Dur("timeout", timeout).
Msg("cs3: machine authentication failed")
return nil, err
}
if authRes.GetStatus().GetCode() != rpc.Code_CODE_OK {
+1 -1
View File
@@ -1325,7 +1325,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-20260910093159-40663c5bb3cb
# github.com/owncloud/reva/v2 v2.0.0-20260930102649-8627a367787a
## explicit; go 1.24.0
github.com/owncloud/reva/v2/cmd/revad/internal/grace
github.com/owncloud/reva/v2/cmd/revad/runtime