Skip to content

fix: [ocisdev-1433] fix public share, add The grpc clients keepalive and more - #13020

Merged
2403905 merged 7 commits into
stable-8.0from
fix/OCISDEV-1433
Oct 2, 2026
Merged

2403905 merged 7 commits into
stable-8.0from
fix/OCISDEV-1433

Conversation

@2403905

@2403905 2403905 commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Change: Replace GRPC_MAX_CONNECTION_AGE with client keepalive

The grpc clients now send a keepalive ping while a request is in flight and fail
the requests on a connection whose peer stops answering, instead of waiting for
as long as the caller allows. This covers both the reva CS3 clients (gateway,
storage-users, storage-shares, ...) and the go-micro based clients used for
inter-service calls between the other oCIS services. Set GRPC_CLIENT_KEEPALIVE_TIME
and GRPC_CLIENT_KEEPALIVE_TIMEOUT to enable and tune this; leave them unset to keep
grpc's own default (no pings).

GRPC_MAX_CONNECTION_AGE has been removed. It only closed healthy connections on
a timer, never ended a request that was already in flight, and silently did
nothing when its value had no unit suffix.

Enhancement: Make the public share expiry janitor configurable

The sharing service runs a background janitor that permanently deletes
expired public shares. Whether that cleanup runs at all could previously only
be set in the sharing service's yaml config, and how often it ran was fixed
internally with no way to tune it.

Both settings are now exposed as environment variables:
OCIS_SHARING_ENABLE_EXPIRED_SHARES_CLEANUP toggles the cleanup (default:
enabled, expired shares stay hidden from listings even when disabled), and
the new OCIS_SHARING_JANITOR_RUN_INTERVAL sets the interval in seconds
between janitor runs (default: 3600).

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.

Related Riva PR owncloud/reva#748

Change: [OCISDEV-1433] Replace GRPC_MAX_CONNECTION_AGE with client keepalive

The grpc clients can now send a keepalive ping while a request is in flight and
fail the requests on a connection whose peer stops answering, instead of waiting
for as long as the caller allows. Set GRPC_CLIENT_KEEPALIVE_TIME to a duration
such as '20s' to enable this; GRPC_CLIENT_KEEPALIVE_TIMEOUT is how long the
answer to a ping is waited for and defaults to '10s'. Leaving the keepalive time
unset sends no pings at all, which is grpc's own behavior.

GRPC_MAX_CONNECTION_AGE has been removed. It only closed healthy connections on
a timer, never ended a request that was already in flight, and silently did
nothing when its value had no unit suffix.

Bugfix: [OCISDEV-1433] Bound the machine auth call of the metadata storage

The cs3 metadata storage authenticates as a system user before every operation,
and that Authenticate call was issued without a deadline. A gateway that
accepted the connection but never answered it - because it was itself waiting
on a stalled storage provider - therefore parked the calling goroutine for the
lifetime of the process, without any log output. The call now runs with a
timeout and logs a warning when it is exhausted, so a stalled downstream
surfaces as an error instead of a silent, unrecoverable wait.

Bugfix: Harden the json public share manager against races, panics and leaks

The json public share manager (pkg/publicshare/manager/json) and its cs3
persistence backend received a round of concurrency and lifecycle fixes:

The manager's mutex is now a sync.RWMutex, and every read-only operation
(Dump, GetPublicShare, ListPublicShares, GetPublicShareByToken) takes an
RLock instead of a full Lock, so concurrent reads no longer serialize
behind each other.
Every write path (Load, CreatePublicShare, UpdatePublicShare,
RevokePublicShare, the janitor) now mutates its own copy of the share
database instead of the map returned by Read, since that map can alias
the persistence layer's cache and be shared with concurrent readers. The
in-memory and cs3 persistence backends were adjusted to match this
copy-on-write contract.
The cs3 persistence backend's one-time initialization flag is now an
atomic.Bool guarded by its own mutex, so already-initialized callers no
longer contend with each other or with in-flight reads for a single lock.
Its mtime-based read cache is now itself guarded by a mutex, and a
successful Write invalidates that cache so a subsequent Read is forced to
refetch instead of serving a stale entry.
The janitor no longer subscribes to OS signals (SIGHUP/SIGINT/SIGQUIT) to
know when to stop. The manager now exposes a Close(ctx) method
(publicshare.ClosableManager) that cancels the janitor's context and waits
for its goroutine to exit; the publicshareprovider gRPC service calls it
on shutdown with a bounded timeout instead of doing nothing.
GetPublicShare, ListPublicShares and GetPublicShareByToken no longer
revoke an expired share inline while serving a read; they just treat it
as not found/skip it. Actual deletion is left to the janitor, which now
removes expired entries directly instead of recursively calling back into
RevokePublicShare.
Unchecked type assertions on the persisted "share" and "password" fields
(e.g. v.(map[string]interface{})["share"].(string)) were replaced by a
helper that reports failure instead of panicking, so a single malformed
or legacy entry in publicshares.json no longer crash-loops the janitor or
fails a request. The "password" field is treated as optional, since
shares without password protection never had one to begin with.
The default janitor run interval changed from 60 seconds to 1 hour.

@kw-security

kw-security commented Sep 28, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues
✅ Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

2403905 and others added 3 commits September 29, 2026 12:22
The setting closed healthy grpc connections on a timer so that clients would redo
their DNS lookup. It never helped against the failure it was reached for - a
connection whose peer stopped answering - because the age limit is enforced by
the server, the grace period was left at infinity so a request already in flight
was never ended, and any value without a unit suffix silently disabled it again.

Detecting a peer that stops answering is now the job of the grpc clients, which
ping the peer while a request is in flight. The servers here got the matching
enforcement policy so they accept those pings; the client side arrives with the
next reva bump.

Co-Authored-By: Claude Opus 5 <[email protected]>
…TION that disable the resolution of public link shares when answering PROPFIND requests.
@2403905
2403905 marked this pull request as ready for review October 1, 2026 11:15
@2403905
2403905 requested a review from LukasHirt as a code owner October 1, 2026 11:15
@2403905
2403905 force-pushed the fix/OCISDEV-1433 branch 2 times, most recently from f8846c5 to b5cad86 Compare October 1, 2026 13:23

@kobergj kobergj 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.

Reviewed the oCIS side of the pair. Three notes below, none of them blocking. Build is clean and the new keepalive tests pass; the config churn across the service packages is gofmt plus the new fields, with no changed defaults. The propfind flag is plumbed end to end (config -> micro ocdav option -> propfind.go:458).

PublicShareMustHavePassword bool `yaml:"public_sharing_share_must_have_password" env:"OCIS_SHARING_PUBLIC_SHARE_MUST_HAVE_PASSWORD;SHARING_PUBLIC_SHARE_MUST_HAVE_PASSWORD" desc:"Set this to true if you want to enforce passwords on all public shares." introductionVersion:"5.0"`
EnableExpiredSharesCleanup bool `yaml:"enable_expired_shares_cleanup"`
EnableExpiredSharesCleanup bool `yaml:"enable_expired_shares_cleanup" env:"OCIS_SHARING_ENABLE_EXPIRED_SHARES_CLEANUP;SHARING_ENABLE_EXPIRED_SHARES_CLEANUP" desc:"Enable the periodic removal of expired public shares. When disabled, expired shares are still hidden from listings but never actually deleted." introductionVersion:"8.3.0"`
JanitorRunInterval int `yaml:"janitor_run_interval" env:"OCIS_SHARING_JANITOR_RUN_INTERVAL;SHARING_JANITOR_RUN_INTERVAL" desc:"Interval in seconds between two runs of the janitor that permanently deletes expired public shares. Defaults to '3600' (1 hour). Only relevant when OCIS_SHARING_ENABLE_EXPIRED_SHARES_CLEANUP is enabled." introductionVersion:"8.3.0"`

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.

A negative value here takes the process down at startup. commonConfig.init() in the reva json manager substitutes the 3600 default only when the value is exactly 0, so -1 is handed straight to time.NewTicker:

panic: non-positive interval for NewTicker
time.NewTicker(...)
	.../pkg/publicshare/manager/json/json.go:216
created by ...json.New in goroutine 38
	.../pkg/publicshare/manager/json/json.go:142

startJanitorRun runs in its own goroutine, so no caller can recover from this - one typo in the env var puts the instance into a crash loop with a message that does not point at the config. Reproduced on this branch with OCIS_SHARING_JANITOR_RUN_INTERVAL=-1, default driver, cleanup enabled.

Cheapest fix is upstream, if c.JanitorRunInterval <= 0, which would also match what pool.duration() already does for the keepalive values, where a negative reads as "not configured". Validating in services/sharing/pkg/config/parser would work too.

"service_user_idp": cfg.PublicSharingDrivers.JSONCS3.SystemUserIDP,
"machine_auth_apikey": cfg.PublicSharingDrivers.JSONCS3.SystemUserAPIKey,
"enable_expired_shares_cleanup": cfg.EnableExpiredSharesCleanup,
"janitor_run_interval": cfg.JanitorRunInterval,

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.

These two keys only reach the jsoncs3 driver. The json (file) block at lines 98-101 still passes just file and gateway_addr, and reva's commonConfig has no default for enable_expired_shares_cleanup, so it stays false there. Since the reva side of this pair drops the inline deletion of expired shares on access and leaves everything to the janitor, SHARING_PUBLIC_SHARING_DRIVER=json ends up never deleting expired public shares at all, and both new env vars silently do nothing for it.

I gather a cleanup CLI is planned, so this may be perfectly acceptable - noting it because the desc: on both env vars reads as if they apply to whichever driver is configured. Either pass them through here as well (two lines) or scope the description to the default driver.

The cs3 block below is fine, by the way: it resolves to publicshare/manager/cs3, a different manager that this change does not touch.

// which read them independently of each other but apply the same rules, so both behave
// identically for every input. Keepalive is off unless the time is set to a duration that
// parses; a value without a unit suffix leaves the clients without pings.
GRPCClientKeepaliveTime time.Duration `yaml:"grpc_client_keepalive_time" env:"GRPC_CLIENT_KEEPALIVE_TIME" desc:"How long a grpc client connection with an ongoing request may stay silent before the server is pinged to check whether it is still answering. Set a duration like '20s' to enable detection of unresponsive peers. Leaving it unset, or at '0', sends no pings at all, which is grpc's own default. Values below '10s' are raised to '10s' by grpc. Make sure to include the unit suffix, a bare number is not a valid duration." introductionVersion:"8.3.0"`

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.

The NOTE on line 48 applies to these two fields as well: pool.GetClientKeepaliveParams() reads GRPC_CLIENT_KEEPALIVE_TIME and GRPC_CLIENT_KEEPALIVE_TIMEOUT out of the environment itself, so the CS3 clients never see a value that arrived through yaml. Set grpc_client_options.grpc_client_keepalive_time in a config file rather than as an env var and the go-micro clients get keepalive while every CS3 client gets none - exactly the half-configured state the fallback logic on both sides is written to prevent.

For env input the two implementations really do agree. I checked negative, missing unit suffix, timeout-only, time-only and unset pairwise, and they land on the same parameters in every case. It is only the yaml path that diverges.

Worth either extending the NOTE above to cover these fields, or stating "environment only" in the desc: so it reaches the generated docs.

@2403905
2403905 requested a review from a team October 1, 2026 14:39

@kobergj kobergj 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.

Looks good 👍 Comments are not critical. Will approve once reva is bumped

@2403905 2403905 changed the title Fix/ocisdev 1433 fix: [ocisdev-1433] fix public share, add The grpc clients keepalive and more Oct 2, 2026
@2403905
2403905 merged commit 450c414 into stable-8.0 Oct 2, 2026
4 checks passed
@2403905
2403905 deleted the fix/OCISDEV-1433 branch October 2, 2026 08:02
2403905 added a commit that referenced this pull request Oct 2, 2026
…and more (#13020)

* fix: the public share configuration and fixed graceful shutdown

* fix: [OCISDEV-1433] remove GRPC_MAX_CONNECTION_AGE

The setting closed healthy grpc connections on a timer so that clients would redo
their DNS lookup. It never helped against the failure it was reached for - a
connection whose peer stopped answering - because the age limit is enforced by
the server, the grace period was left at infinity so a request already in flight
was never ended, and any value without a unit suffix silently disabled it again.

Detecting a peer that stops answering is now the job of the grpc clients, which
ping the peer while a request is in flight. The servers here got the matching
enforcement policy so they accept those pings; the client side arrives with the
next reva bump.

Co-Authored-By: Claude Opus 5 <[email protected]>

* fix: Added the new variable OCDAV_DISABLE_PROPFIND_PUBLIC_LINK_RESOLUTION that disable the resolution of public link shares when answering PROPFIND requests.

* chore: bump reva

* fix: The keepalive added to grpc clinet

* chore: bump reva

* build(deps): bump go 1.26.8, grpc-go dependency

---------

Co-authored-by: Claude Opus 5 <[email protected]>
2403905 added a commit that referenced this pull request Oct 2, 2026
#13048)

* fix: [ocisdev-1433] fix public share, add The grpc clients keepalive and more (#13020)

* fix: the public share configuration and fixed graceful shutdown

* fix: [OCISDEV-1433] remove GRPC_MAX_CONNECTION_AGE

The setting closed healthy grpc connections on a timer so that clients would redo
their DNS lookup. It never helped against the failure it was reached for - a
connection whose peer stopped answering - because the age limit is enforced by
the server, the grace period was left at infinity so a request already in flight
was never ended, and any value without a unit suffix silently disabled it again.

Detecting a peer that stops answering is now the job of the grpc clients, which
ping the peer while a request is in flight. The servers here got the matching
enforcement policy so they accept those pings; the client side arrives with the
next reva bump.

Co-Authored-By: Claude Opus 5 <[email protected]>

* fix: Added the new variable OCDAV_DISABLE_PROPFIND_PUBLIC_LINK_RESOLUTION that disable the resolution of public link shares when answering PROPFIND requests.

* chore: bump reva

* fix: The keepalive added to grpc clinet

* chore: bump reva

* build(deps): bump go 1.26.8, grpc-go dependency

---------

Co-authored-by: Claude Opus 5 <[email protected]>

* chore: bump pnpm dependencies

* fix: avoid go vet false positive in userlog conversion.go

The go.mod bump to go 1.26.8 made go vet flag loadTemplates' calls to
t.Get(nt.Subject/nt.Message) as non-constant format strings, breaking
the build for services/userlog/pkg/service. These are translation
lookup keys, not printf format strings, so route the call through a
local func value to defeat vet's static trace.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

---------

Co-authored-by: Claude Opus 5 <[email protected]>
2403905 added a commit that referenced this pull request Oct 6, 2026
…and more (#13020) (#13068)

* fix: the public share configuration and fixed graceful shutdown

* fix: [OCISDEV-1433] remove GRPC_MAX_CONNECTION_AGE

The setting closed healthy grpc connections on a timer so that clients would redo
their DNS lookup. It never helped against the failure it was reached for - a
connection whose peer stopped answering - because the age limit is enforced by
the server, the grace period was left at infinity so a request already in flight
was never ended, and any value without a unit suffix silently disabled it again.

Detecting a peer that stops answering is now the job of the grpc clients, which
ping the peer while a request is in flight. The servers here got the matching
enforcement policy so they accept those pings; the client side arrives with the
next reva bump.

* fix: Added the new variable OCDAV_DISABLE_PROPFIND_PUBLIC_LINK_RESOLUTION that disable the resolution of public link shares when answering PROPFIND requests.

* chore: bump reva

* fix: The keepalive added to grpc clinet

* chore: bump reva

* build(deps): bump go 1.26.8, grpc-go dependency

---------

(cherry picked from commit e86eb4d)

For the 9.0 branch, the reva dependency was pointed at reva's main-branch
merge of PR #748 (commit 373f9509a, pseudo-version
v2.0.0-20261005091647-373f9509a363) instead of the 8.2-targeted
e0beaa380005, since the 8.2 merge predates the VaultMode/UploadSessionFilter.Orphaned
APIs already present on the 9.0 reva lineage.

Co-authored-by: Claude Opus 5 <[email protected]>
Co-Authored-By: Claude Sonnet 5 <[email protected]>

# Conflicts:
#	changelog/unreleased/security-bump-grpc.md
#	go.mod
#	go.sum
#	vendor/google.golang.org/grpc/server.go
#	vendor/google.golang.org/grpc/stream.go
#	vendor/google.golang.org/grpc/version.go
#	vendor/modules.txt
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.

4 participants