Skip to content

fix(workspaces): legacy resources grant at most EDIT; settings load once and revalidate - #1322

Merged
ginccc merged 6 commits into
mainfrom
fix/workspace-legacy-access
Nov 12, 2026
Merged

ginccc merged 6 commits into
mainfrom
fix/workspace-legacy-access

Conversation

@ginccc

@ginccc ginccc commented Nov 6, 2026

Copy link
Copy Markdown
Member

Any user could own every pre-workspace resource

With eddi.workspaces.enabled=true and the default legacy-visibility=shared,
DescriptorAccess.effectiveLevel returned OWN for any caller on a descriptor with no
owner and no space, which is what every resource created before the upgrade looks like.
OWN is the gate for delete, share, revoke, visibility and move, so on an upgraded
deployment a plain eddi-editor named bob could:

  • PUT .../shares/visibility a colleague's pre-upgrade agent to published, exposing it
    to anonymous callers on the production chat endpoints;
  • move it to user:bob. The descriptor then has a space, so it is no longer "unowned".
    Bob keeps EDIT through the space branch and everyone else loses access;
  • share it with himself at OWN, which survives a later switch to admin-only;
  • delete it, or cascade-delete its config graph.

With enforcement off, the same answer fed mayReadGrants' structural fallback, so any
user could read the grant audience (principal and team names) of a legacy resource.

That contradicted the rest of the code and the docs. A resource with no descriptor at
all
is already capped below EDIT (ResourceAccessGuard.requireLegacyFallback), and
docs/workspaces.md says an absent owner record "must not grant authority". The comment
justifying OWN cited OwnershipValidator.requireOwnerOrAdmin, which has no production
caller outside its strict variant.

The fix

DescriptorAccess: the legacy contribution is now EDIT, not OWN. Under shared
everyone can still read, use, edit and deploy pre-existing resources, so an upgrade hides
nothing and stops nobody's work. The OWN acts are admin-only until an owner is assigned
(PUT /descriptorstore/descriptors/{id}/shares/owner, already admin-only). Explicit grants
on a legacy resource still count in full: a user granted OWN holds it. The access index
is unchanged, because it only decides whether a caller is admitted at all, and that
answer did not change.

The same PR fixes three smaller things in the workspace settings that every access check
reads:

WorkspaceSettings no longer blocks access checks on a store read. When the 5-second
cache expired, snapshot() re-read Mongo/Postgres inside synchronized(this). That
read has no timeout of its own, so every request whose guard asked admitsLegacy()
queued on the monitor for the whole read: at every expiry under load, and for the whole
of a database stall. It is now stale-while-revalidate, with no executor:

Situation Before After
Fresh snapshot served served
Expired, nobody refreshing caller reads under the lock, others wait the caller that wins an AtomicBoolean reads; others are served the stale snapshot at once
adopt() lands while a re-read is in flight blocked on the monitor until the read finished wins: every read is numbered when it starts and every adopt when it lands, and the higher number stays served
Two re-reads overlap (an access check and the settings page) serialised on the monitor the one that started later stays served, whichever answers first
No snapshot yet (first read) waits still waits (synchronized firstLoad): there is nothing to serve, and the defaults would open legacy data

refresh() (the forced re-read behind GET /workspaces/settings) installs the same
way, so it cannot overwrite a write adopted while it was reading, and an older
access-check re-read that answers after it cannot put the older values back. A re-read
that fails keeps what is served when it fails, not what was served when it began.

A corrupt stored legacy-visibility is validated once, at load.
effectiveLegacyVisibility() re-validated the stored value and logged a WARN on
every call. That meant one WARN per access check per request for as long as a bad
row (only a direct DB write can create one) stayed. Now the value is checked when it is
read: a valid one is stored trimmed and lower-case, an invalid one is dropped (the
default shared applies, as before). The WARN is logged once per distinct bad value, not
at every 5-second re-read. GET /workspaces/settings now reports such a value as
DEFAULT, the value that actually applies, where it used to say STORED next to an
effective shared.

PUT /workspaces/settings stamps updatedAt to the millisecond. The new parity test
showed Mongo keeps milliseconds and Postgres microseconds, so what this instance adopted
(Instant.now(), sub-microsecond on Windows) differed from what any replica read back.

New WorkspaceSettingsStoreParityTest. Neither settings store had a test. The two
encode "not set" differently: Mongo drops the key in a replaced document, Postgres writes
NULL through ON CONFLICT ... EXCLUDED. PUT relies on a write clearing an omitted
field. The test runs both real adapters (Testcontainers, the TenantQuotaStoreParityTest
pattern) through: unknown tenant, full round trip, unset fields read back as null,
writing null clears a stored value, tenant isolation, and timestamp precision.

Decisions

Choice Rejected Why
Cap legacy at EDIT VIEW/USE (the no-descriptor cap) Editing pre-existing agents is the upgrade path people rely on. Losing it would break every team on upgrade, and the harm was in the OWN acts, not in editing
Cap legacy at EDIT keep OWN, guard each OWN act separately Five call sites plus delete plus grant disclosure; one policy line covers them all and keeps index and decision in one place
Stale-while-revalidate inline a refresh executor / @Scheduled No thread to own, nothing to shut down; only the first-ever read still waits, which is unavoidable
Order snapshots by a start sequence (install) plain set in refresh() (the plan); compareAndSet against the snapshot seen at read start set lets a read that began before an adopt() overwrite it; the start-time CAS let an older re-read that landed first make the settings page's newer read lose its swap. A sequence taken when each read starts orders all three cases correctly
Drop an invalid stored value at load keep it and validate per call Validation was the per-call cost and the per-call WARN; DEFAULT is the honest report
WARN once per distinct bad value WARN at every load Every 5 s per node forever is still log spam; a new bad value is still reported
Truncate updatedAt at the write boundary truncate in each store The stores should persist what they are given; the endpoint is the one place an Instant.now() enters

What changes for users and operators

  • Upgraded deployments with enforcement on: non-admins can no longer delete, share,
    revoke, publish (change visibility), move, or read the grants of a resource created
    before ownership was recorded. The Manager already gates those buttons on callerLevel,
    which now says EDIT for such resources, so it stops offering them. Admins are
    unaffected. Assign owners to resources that someone other than an admin should
    manage. This is written up in docs/workspaces.md (new "Resources that predate
    ownership" section and upgrade steps 4 and 5) and in docs/configuration-reference.md.
  • Enforcement off: only the grant list of legacy resources is now hidden from
    non-admins, matching owned resources.
  • REST shapes, stored configs, MCP, /v1, properties: unchanged. No new property,
    no new endpoint. The Platform Operator's prompt does not cover legacy visibility, so
    it needs no change and no revision bump.

Where to look hardest

  1. WorkspaceSettings.snapshot() and install(): the flag and the ordering. The
    finally resets the flag; the re-check after winning it avoids a redundant read;
    install keeps whichever snapshot's read (or adopt) began last. A failed re-read
    keeps the values served at the moment it fails, with a new timestamp, so an outage
    retries once per TTL, from one thread.
  2. DescriptorAccess.effectiveLevel: confirm that nothing in production relied on legacy
    OWN for a non-admin. grep -rn "AccessLevel.OWN" src/main/java lists the gates:
    RestVersionInfo delete/requireOwnAccess, ResourceSharingService
    share/revoke/visibility/move and cascade (canAccess(..., OWN)), and grant disclosure.
    All of them should now refuse a non-admin on legacy data. transferOwnership is the
    admin recovery path.

Verification

All runs offline, unit tests only (-DskipUi=true):

  • ./mvnw -o -DskipUi=true test -Dtest='DescriptorAccessTest,ResourceAccessGuardTest'
    before the fix: 6 failures, each for the expected reason (legacy level OWN where
    EDIT is expected; requireAccess(OWN) admitted bob; bob could read legacy grants
    with enforcement off). After the fix: 77 tests, 0 failures.
  • RuntimeWorkspaceSettingsTest against the origin/main versions of
    WorkspaceSettings and RestWorkspaces: 6 failures. The two concurrency cases hit the
    1-second assertTimeoutPreemptively, the WARN count was 100 instead of 1 and 3 instead
    of 2, a corrupt value was reported as stored, and updatedAt had sub-millisecond
    digits. With the fix: 19 tests, 0 failures.
  • Mutation run on the fixed code, with three lines reverted together (compareAndSet ->
    set in snapshot(), the WARN dedupe disabled, legacy_visibility = EXCLUDED.legacy_visibility removed from the Postgres UPSERT): exactly
    adoptDuringRereadWins, corruptStoredLegacyWarnsOnChangeOnly and
    overwritingWithNullClears[postgres] failed. The other 28 cases passed, including the
    parity cases on both backends (Docker was available locally).
  • Final run: ./mvnw -o -DskipUi=true test -Dtest='ai/labs/eddi/engine/security/spaces/**/*Test,ListingRedactionWiringTest,ConversationReviewTest,RestVersionInfoTest,ImportStyleTest,BuildQualityGatesTest,ChangelogRotationTest,ChangelogFragmentTest,DocumentationLinksTest,DocumentationAccuracyTest,DocumentedRestPathsTest,DeploymentManifestsTest' gave 570 tests, 0 failures, 0 errors, 1 skipped (a skip inside DeploymentManifestsTest), BUILD SUCCESS. That is the whole engine.security.spaces package (35 report files), the other tests that build a real WorkspaceSettings, and the repo-wide guards. A surefire report was confirmed for every class named.

Review pass (independent reviewer, after the three implementation commits):

  • New olderRereadDoesNotUndoNewerOne: red against the implementation as first
    committed (expected finance, was engineering: the settings page's newer read lost its
    swap to an older access-check read), green after install().
  • New failedRereadKeepsLatestValues: mutation (capture the fallback snapshot at read
    start) turns it red; green with the fix.
  • Mutation: disabling the sequence comparison in install() turns
    adoptDuringRereadWins red.
  • Mutation: restoring best = AccessLevel.OWN in DescriptorAccess turns 6 tests red
    across DescriptorAccessTest and ResourceAccessGuardTest.
  • Final run, same command as above: 572 tests, 0 failures, 0 errors, 1 skipped,
    BUILD SUCCESS, 35 report files, a report for every named class.

Not run locally: the full unit suite, verify, integration tests (*IT) and the
Manager/Chat UI suites. CI covers those. No UI code changed.

Follow-ups (out of scope)

  • OwnershipValidator.requireOwnerOrAdmin still treats an unowned resource as owned. It
    has no production caller outside the strict variant (tracked separately as
    NEW-sec-authz-1).
  • The legacy level is the same EDIT for an anonymous caller. Anonymous callers cannot
    reach the edit endpoints (role-gated), but a later tightening could cap anonymous at
    USE.

A descriptor with no owner and no space gave every caller OWN under
legacy-visibility=shared, so any user could delete, share, publish or move
a pre-workspace resource, and moving it into their own space took it from
everyone else. With enforcement off the same answer disclosed its grant
list. The legacy contribution is now EDIT: reading, using, editing and
deploying keep working after an upgrade, while the OWN acts are admin-only
until an owner is assigned. Explicit grants still count in full, matching
the no-descriptor fallback in ResourceAccessGuard.
WorkspaceSettings re-read the stored settings inside synchronized(this)
when its 5-second cache expired, so every access check queued behind a
database read with no timeout of its own. It is now stale-while-revalidate:
one caller re-reads while the others are served the last values, and a
write adopted meanwhile is not overwritten by the older read. Only the
first read, with nothing to serve, is still waited for.

A stored legacy-visibility is validated once at load instead of on every
access check, where an invalid value logged a WARN per call; it is now
dropped (the default applies and the settings report DEFAULT) and logged
once per distinct value. PUT /workspaces/settings stamps updatedAt to the
millisecond both stores keep.
Neither settings store had a test, and they encode "not set" differently
(an absent key against a NULL column) while PUT /workspaces/settings relies
on a write clearing an omitted field. The new parity test runs both real
adapters through the same cases, including the timestamp precision each
keeps. Adds the changelog fragment for the branch.
The stale-while-revalidate install compared against the snapshot seen when
a read started, so a forced re-read (GET /workspaces/settings) that answered
after an older access-check re-read lost its swap and left the older values
served. Each store read is now numbered as it starts, and each adopted write
as it lands; the higher number stays served, whichever answers first. A
failed re-read keeps what is served when it fails rather than what was
served when it began.

The changelog fragment no longer says a resource with no descriptor gets the
same level as a legacy descriptor: that fallback stops at read and use.
@ginccc
ginccc requested a review from rolandpickl as a code owner November 6, 2026 16:10
@vercel

vercel Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
eddi-docs Ignored Ignored Preview Nov 6, 2026 6:12pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Next included review available in 16 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between fdd9b34 and a327075.

Files selected for processing: 10

  • docs/changelog.d/2026-11-06-workspace-legacy-access.md
  • docs/configuration-reference.md
  • docs/workspaces.md
  • src/main/java/ai/labs/eddi/engine/security/spaces/DescriptorAccess.java
  • src/main/java/ai/labs/eddi/engine/security/spaces/WorkspaceSettings.java
  • src/main/java/ai/labs/eddi/engine/security/spaces/rest/RestWorkspaces.java
  • src/test/java/ai/labs/eddi/engine/security/spaces/DescriptorAccessTest.java
  • src/test/java/ai/labs/eddi/engine/security/spaces/ResourceAccessGuardTest.java
  • src/test/java/ai/labs/eddi/engine/security/spaces/RuntimeWorkspaceSettingsTest.java
  • src/test/java/ai/labs/eddi/engine/security/spaces/settings/WorkspaceSettingsStoreParityTest.java
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@ginccc
ginccc merged commit 8176edb into main Nov 12, 2026
48 checks passed
ginccc added a commit that referenced this pull request Nov 23, 2026
…plete the release docs (#1518)

* fix(workspaces): legacy resources grant at most EDIT; settings load once and revalidate (#1322)

* fix(workspaces): legacy resources grant at most EDIT

A descriptor with no owner and no space gave every caller OWN under
legacy-visibility=shared, so any user could delete, share, publish or move
a pre-workspace resource, and moving it into their own space took it from
everyone else. With enforcement off the same answer disclosed its grant
list. The legacy contribution is now EDIT: reading, using, editing and
deploying keep working after an upgrade, while the OWN acts are admin-only
until an owner is assigned. Explicit grants still count in full, matching
the no-descriptor fallback in ResourceAccessGuard.

* fix(workspaces): settings load once and revalidate without blocking

WorkspaceSettings re-read the stored settings inside synchronized(this)
when its 5-second cache expired, so every access check queued behind a
database read with no timeout of its own. It is now stale-while-revalidate:
one caller re-reads while the others are served the last values, and a
write adopted meanwhile is not overwritten by the older read. Only the
first read, with nothing to serve, is still waited for.

A stored legacy-visibility is validated once at load instead of on every
access check, where an invalid value logged a WARN per call; it is now
dropped (the default applies and the settings report DEFAULT) and logged
once per distinct value. PUT /workspaces/settings stamps updatedAt to the
millisecond both stores keep.

* test(workspaces): Mongo and Postgres settings store parity

Neither settings store had a test, and they encode "not set" differently
(an absent key against a NULL column) while PUT /workspaces/settings relies
on a write clearing an omitted field. The new parity test runs both real
adapters through the same cases, including the timestamp precision each
keeps. Adds the changelog fragment for the branch.

* fix(workspaces): order settings snapshots by when their read began

The stale-while-revalidate install compared against the snapshot seen when
a read started, so a forced re-read (GET /workspaces/settings) that answered
after an older access-check re-read lost its swap and left the older values
served. Each store read is now numbered as it starts, and each adopted write
as it lands; the higher number stays served, whichever answers first. A
failed re-read keeps what is served when it fails rather than what was
served when it began.

The changelog fragment no longer says a resource with no descriptor gets the
same level as a legacy descriptor: that fallback stops at read and use.

* fix(workspaces): rewrap two test comments the formatter split mid-sentence

* test(workspaces): null-guard the reader threads in two finally blocks

(cherry picked from commit 8176edb)

* fix(ingestion): fetchable crawl URLs, bounded markdown prefixes, at-block hiding rules (#1339)

* fix(ingestion): fetchable crawl URLs, bounded markdown prefixes, at-block hiding rules

- WebCrawler fetched the raw abs:href, so href="my doc.html" failed in the
  fetcher's URI.create on every run as an inconclusive error, which also
  blocked deletion reconciliation. CrawlUrls.fetchable strips the fragment
  and encodes through the same tolerant parser as canonicalize; links and
  sitemap URLs use it for the fetch, the length bound and the frontier cost.
- HtmlToMarkdownConverter copied every line once per enclosing blockquote
  or re-indented list item, so 90 nested quotes in a 236 KB mail allocated
  339 MB. At most MAX_PREFIXED_NESTING = 8 such containers stack, counted
  on the per-conversion Walk; deeper ones are written in place.
- HiddenStylesheetRules skipped every at-block, so a hiding rule inside
  @media screen hid text from readers and still reached the model. @layer,
  @supports and screen-wide @media blocks are entered in the same forward
  scan; viewport and device queries stay skipped.

* fix(ingestion): keep the walk's prefix-nesting counter private like its other counters

* fix(ingestion): state the at-block hiding rules in security.md without nested dashes

(cherry picked from commit 7d65ba2)

* fix(nlp): an unknown word drops * as well, so it cannot act as the wildcard

A lone * typed by a user became unknown(*). Expression.equals treats * as
a wildcard, so that expression matched every behavior rule written as
unknown(x). Unknown now strips * together with ( ) and ,.

* docs(release): complete the 6.7.1 behaviour changes and record the review additions

The upgrade notes gain the workspace, ingestion, import and sync, and Helm
Keycloak digest changes, the price gap for GPT-6.2 and Gemini 4, and the
expression injection the unknown(...) change closes. The Vertex picker
never offered gemini-2.5-*, so that claim goes. Release-notes row dated
2026-11-22. OpenAiPermitModeAuthMechanism is @SInCE 6.7.1, and the
Java4ShellMitigationTest Javadoc no longer contradicts itself.

* fix(ingestion,workspaces): address review of the 6.7.1 backports

- WorkspaceSettings: a failed re-read keeps the sequence of the snapshot it
  keeps, so an earlier-started read that answers later is not refused; the
  fail-closed snapshot of a never-read store ranks below every read.
- WebCrawler: a held document linked only through a URL too long to fetch is
  reported after the crawl as content unknown (recorded unreachable, not
  missed) instead of being skipped silently. CrawlSink.holds says which
  documents the source holds.
- HiddenStylesheetRules: a comment in an @media prelude separates tokens, so
  @media only/**/screen is entered.
- CrawlUrls.encodeIllegal encodes by code point: an emoji is %F0%9F%98%80,
  not %3F%3F.
- HtmlToMarkdownConverterSalvageTest: allocation tests also assume the
  counters are enabled.

* fix(ingestion): bound and narrow the oversized-link report

- reportOversized skips documents already visited or delivered, so a page
  reached through a redirect is not also reported as content unknown.
- At most MAX_OVERSIZED_LINKS (1,000) documents are remembered; past that,
  discovery is incomplete. The report runs only after a crawl that completed
  with discovery complete, and stops on cancellation, interruption or the
  time budget, leaving discovery incomplete.
- Collector.holds treats a failing state-store lookup as held, so it cannot
  fail a finished crawl.
- A sitemap URL dropped for exceeding MAX_SITEMAP_URL_LENGTH marks the
  sitemap incomplete, so a page listed only that way is not tombstoned.

* fix(ingestion): keep the oversized-link report from failing or flooding a run

- Revert the sitemap change from the previous commit: a <loc> longer than
  MAX_SITEMAP_URL_LENGTH is dropped silently again. The check runs before the
  scheme and scope checks, so any long line disabled deletion reconciliation
  for the source for good; it stays a known gap.
- Collector.onError: a failing recordUnreachable is caught and logged at
  debug, as ownershipUnverified does, so it cannot fail a finished crawl.
- Collector.holds: after the first failing lookup it warns once and answers
  "held" for the rest of the run without asking the store again.
- reportOversized: the queued/visited/delivered and robots skips come first;
  cancellation, interruption and the time budget are checked just before
  each lookup.
- The skip log says "discovery was incomplete" rather than "incomplete
  sitemap discovery", which no longer covers every cause.
- Tests: RecordingSink counts holds calls; a crawl past MAX_OVERSIZED_LINKS
  makes none, and exactly MAX_OVERSIZED_LINKS stays complete. A pipeline test
  covers a failing lookup: the run completes, looks up once, and tombstones
  nothing.

* fix(ingestion): let a failed unreachable mark fail the run again

- Collector.onError: the try/catch around recordUnreachable is removed. A
  swallowed failure let the run end covered and reconcile, so pages that
  merely answered an error counted as missed and could be tombstoned. The
  holds once-only failure flag stays; its comment now says what happens.
- reportOversized Javadoc: names the queued/visited/delivered (redirect)
  skips, MAX_OVERSIZED_LINKS and the cancel/deadline stop.
- Test: a store that cannot record an unreachable page fails the run and
  tombstones nothing.
- docs: the overlong-link behaviour in "Behaviour changes in 6.7.1"; the
  silent drop of over-long sitemap <loc> entries recorded as a known gap.

* fix(ingestion): admit only unreached oversized links; ignore robots in the report

- noteOversized skips ids already visited or delivered, so overlong links
  to redirect targets the crawl reached no longer fill MAX_OVERSIZED_LINKS
  and disable reconciliation. reportOversized keeps its skips for links
  seen before their target was reached.
- reportOversized no longer consults robots.txt. It matched rules against
  the canonical id, which has lost the link's tracking parameters, so a
  held document the real link reaches could be skipped and then deleted.
  Reported instead, it is kept.
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.

2 participants