Skip to content

fix(security): enforce SAIKU_AI_POLICY on the Ossie AI REST and MCP surface - #2355

Merged
buggtb merged 10 commits into
developmentfrom
fix/2322-ossie-ai-policy-gate
Nov 19, 2026
Merged

buggtb merged 10 commits into
developmentfrom
fix/2322-ossie-ai-policy-gate

Conversation

@spicule-hive-bot

Copy link
Copy Markdown
Collaborator

Summary

SAIKU_AI_POLICY (the operator's AI data-exposure tier, saiku#903) was silently a no-op on the whole Ossie AI surface. The aiOssieResource bean never received the shared aiPolicyGuard singleton, the resource's field defaulted to a permissive FULL guard, and 7 of the 8 data-returning methods never called assertCanSend at all — so any authenticated ROLE_USER (and any MCP host acting with their credentials) got aggregated warehouse values and, via /row-detail, raw rows regardless of the configured policy. Only GraphQL's executeOssie (own guard) and MDX /ai/* (wired bean) enforced it. SECURITY.md's fail-closed claim was not true for Ossie, and ai-audit.jsonl recorded policy: schema-only next to responses that returned data. CWE-862 / CWE-1188.

What this PR changes

  1. AiOssieResource — fail-closed default + guard at every data endpoint. The pre-wiring field default is now AiPolicy.DEFAULT (schema-only) instead of FULL, and each endpoint calls aiPolicyGuard.assertCanSend(...) as its first statement, before the try, so an AiPolicyViolation reaches AiPolicyViolationMapper (403 + PERMISSION_DENIED envelope) rather than the generic catch (Exception):
    • AGGREGATED_RESULT_VALUES: /query, /query/execute-async, /query/result/{id}, /anomaly, /forecast, and the shared runInternalQuery (belt-and-braces for future callers);
    • RAW_ROW_DATA: /row-detail (the Ossie drillthrough — same tier as MDX /ai/drillthrough);
    • SCHEMA_METADATA / SAMPLE_MEMBERS recorded for symmetry on /schema, /ontology, /query/preview, /values/search (never block under the default).
  2. saiku-beans.xml. aiOssieResource now receives the aiPolicyGuard singleton (parity with aiQueryResource since saiku#903), so the operator's SAIKU_AI_POLICY / ai.policy resolves once at boot for Ossie too. The saikuGraphQlFetchers comment claiming "the delegated AiOssieResource re-checks it" is now actually true.
  3. MCP error shape. McpResource maps AiPolicyViolation to a tool result with isError: true and the same PERMISSION_DENIED envelope (status/field/available) in structuredContent, instead of the generic -32603 "Internal error" branch (also improves the MDX run_query/drillthrough tools).
  4. Tests.
    • AiOssieResourcePolicyTest — call-site coverage modelled on AiQueryResourcePolicyTest, with an OssieQueryService stub that fails the test if execution is ever reached: blocked per endpoint per tier, passes-guard cases, and unwiredResourceDefaultsToSchemaOnly.
    • AiPolicyGuardWiringTest + ai-policy-wiring-test.xml — wiring lock: both AI resources receive the same singleton; the negative case asserts an unwired resource's field default is SCHEMA_ONLY, not FULL.
    • McpResourceTest.runOssieQueryUnderSchemaOnlyReturnsPermissionDeniedToolError.
    • AiOssieAskGuardTest / AiOssieRoleGuardTest wire an explicit FULL guard — they exercise the rate-limit/role guards, not the policy.
  5. Docs. SECURITY.md states the fail-closed default covers /ai/ossie/* and the MCP Ossie tools; docs/AI-OSSIE-API.md gains the per-endpoint tier table (what needs aggregated, what needs full).
  6. Acceptance spec (committed before the fix, per the PR template): acceptance/2322/spec.json — under the demo default (aggregated), POST /ai/ossie/row-detail must 403 with field: ai.policy, available: [full] while GET /ai/ossie/schema stays 200. Red on base: row-detail currently returns 200 raw rows.

Verification

  • mvn -pl saiku-core/saiku-web test — 1373 tests green (includes the new policy/wiring/MCP tests).
  • mvn -pl saiku-core/saiku-web spotless:check — clean.
  • Spec validated against the repo's own validateSpec().

Deliberately out of scope

AiQueryResource (MDX) keeps its FULL pre-wiring default: it is wired in production and flipping its default would ripple through its documented back-compat test (unwired_guard_defaults_permissive_for_back_compat) and dozens of unit tests that construct it unwired. That hardening deserves its own PR. The graph endpoints (/graph, /search, /entity, /signals) are a separate surface (#1410) and are not touched here; noted as follow-up material alongside #2323 (async RLS) and #2324 (field deny lists).

Closes #2322

— hive: backend=pi model=openrouter/z-ai/glm-5.3-flash


🐝 Hive Agent: contributor | SHA: 46bda80bf

…full AI policy tier

Spec for saiku#2322: under the aggregated tier (the launcher demo default)
POST /ai/ossie/row-detail must return the 403 PERMISSION_DENIED envelope
(field ai.policy, available [full]) while GET /ai/ossie/schema stays 200.
Red on base: row-detail currently returns 200 raw rows.

Hive-Run: #2322
Hive-Plan: ossie-ai-policy-enforcement (spec-first)
Hive-Spec: ossie-ai-policy-enforcement#spec-first
Signed-off-by: spicule-hive-bot <spicule-hive-bot@users.noreply.github.com>
…urface (saiku#2322)

AiPolicyGuard (saiku#903) was a no-op for the whole Ossie AI surface: the
aiOssieResource bean never received the shared aiPolicyGuard singleton, the
field defaulted to a permissive FULL guard, and seven of the eight
data-returning methods never called assertCanSend at all — so any
authenticated user (and any MCP host acting with their credentials) got
aggregated warehouse values and raw rows through /ai/ossie/* regardless of
SAIKU_AI_POLICY, while SECURITY.md advertised schema-only as the enforced
fail-closed default and ai-audit.jsonl recorded the configured tier next to
the unguarded responses.

- AiOssieResource: pre-wiring guard default is now AiPolicy.DEFAULT
  (schema-only, fail closed) instead of FULL, and every data endpoint calls
  assertCanSend as its first statement, before the try so AiPolicyViolation
  reaches AiPolicyViolationMapper (403) rather than the generic 500:
  aggregated tier for /query, /query/execute-async, /query/result,
  /anomaly, /forecast and the shared runInternalQuery; full tier for
  /row-detail (the Ossie drillthrough); schema-only kinds recorded on
  /schema, /ontology, /query/preview and /values/search.
- saiku-beans.xml: aiOssieResource now receives the aiPolicyGuard singleton
  (parity with aiQueryResource since saiku#903), so the operator's
  SAIKU_AI_POLICY / ai.policy resolves once at boot for Ossie too; the
  saikuGraphQlFetchers comment claiming the delegated resources re-check
  the policy is now true.
- McpResource: an AiPolicyViolation surfaces as an MCP tool result with
  isError:true carrying the PERMISSION_DENIED envelope (status/field/
  available) instead of the generic -32603 "Internal error" branch.
- Tests: AiOssieResourcePolicyTest (call-site coverage on the model of
  AiQueryResourcePolicyTest, with an OssieQueryService stub that fails if
  execution is ever reached), AiPolicyGuardWiringTest +
  ai-policy-wiring-test.xml (wiring lock: both AI resources receive the
  same singleton; an unwired AiOssieResource fails closed to schema-only),
  and the MCP schema-only tool-error case; AiOssieAskGuardTest /
  AiOssieRoleGuardTest now wire an explicit FULL guard since they exercise
  the rate-limit/role guards, not the policy.
- Docs: SECURITY.md states the fail-closed default covers the Ossie
  surface; docs/AI-OSSIE-API.md gains the per-endpoint tier table.
- acceptance/2322/spec.json (previous commit) proves row-detail is refused
  under the aggregated demo tier while schema stays available.

Note: AiQueryResource keeps its FULL pre-wiring default on purpose — it is
wired in production and flipping its default would ripple through its
documented back-compat test and dozens of unit tests; that hardening is
left as its own follow-up.

Hive-Run: #2322
Hive-Plan: ossie-ai-policy-enforcement
Hive-Spec: ossie-ai-policy-enforcement#guard-default, #endpoint-gates, #spring-wiring, #mcp-error-shape, #tests, #docs
Signed-off-by: spicule-hive-bot <spicule-hive-bot@users.noreply.github.com>
@github-actions github-actions Bot added risk/high Change risk tier: high (see docs/risk-tiers.md) area/web docs labels Nov 10, 2026
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

CI feedback

passing · 1fafdb2
Generated 2026-11-19T23:17:20.034Z. Machine-readable copy: ci-feedback.json (schema v1, see docs/ci-feedback.md) - artifact on this run.

Nothing to fix: every check in this commit concluded successfully.

@spicule-hive

spicule-hive Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor
46bda80

⚠️ Sentinel alert — maintainer review required

Hive flagged this PR (author @spicule-hive-bot, head 46bda80bf37f) because it matches behaviors that can override security controls, escalate privileges or damage the codebase. This is a heuristic, not an accusation — a maintainer should confirm the change is intended before it merges.

  • sensitive_path — changes 1 sensitive path(s) (Touches a sensitive path (OWNERS, workflows, policies, hive config, security docs, …))
    • SECURITY.md
  • security_policy_edit — edits security policy, scanner config, rulesets or hooks (Edits SECURITY.md, dependabot/CodeQL config, rulesets or git hooks)
    • SECURITY.md

Hive added the sentinel-alert label. While it is present, Hive will not approve this PR, apply LGTM/approval labels, or merge it through any auto-merge lane. Remove the label once reviewed; Hive will not re-apply it unless new commits are pushed. Tune paths and behaviors under sentinel in hive.yaml or the dashboard Security tab.

@github-actions

Copy link
Copy Markdown

Semantic model diff

Semantic model diff

No model changes and no broken references.

saiku#1434 · reproduce locally with saiku model diff

@buggtb buggtb added needs-rework Ask the hive's quality agent to rework this PR (reads comments, fixes CI/conflicts, pushes) rework-queued The quality agent has picked this PR up (set automatically when needs-rework is consumed) and removed needs-rework Ask the hive's quality agent to rework this PR (reads comments, fixes CI/conflicts, pushes) labels Nov 10, 2026
@spicule-hive-bot

Copy link
Copy Markdown
Collaborator Author

hive-base-moved: merged development tip be628589f7caedcb4c38c13644d266fc03d92149 into the PR branch (46bda80bf → 67ecb5725). No conflicts. The red ci scripts (python unittest) cell was base drift — the branch predated 031bf772/5848ba670, which anchors the ghcr tag-retention test fixtures to wall-clock now (the 2026-11 time bomb had detonated for this head's frozen NOW fixtures: test_apply_deletes_only_the_selected_versions saw a second version selected). All 38 script tests pass on the merged head. No PR code was changed by the merge.


🐝 Hive Agent: contributor | SHA: 67ecb5725


🐝 Hive Agent: contributor | SHA: 67ecb5725

Merge adaptation: AiOssieResourceAsyncRoleTest (from saiku#2323, merged
into development) constructs the resource with no policy guard, so with
this PR's submit-time policy gate on executeAsync it dies with
AiPolicyViolation (schema-only refuses AGGREGATED_RESULT_VALUES) before
the role validation it exists to assert. Wire an explicit FULL guard, the
same fixture AiOssieRoleGuardTest already uses — the class exercises role
guards, not the policy.
@spicule-hive-bot

Copy link
Copy Markdown
Collaborator Author

Merge follow-up: the post-merge red build (JDK 22) cell was a semantic conflict between this PR's submit-time policy gate on executeAsync and AiOssieResourceAsyncRoleTest (the saiku#2323 role-guard test that landed on development in the meantime): the test constructs the resource with no policy guard, so executeAsync now throws AiPolicyViolation (schema-only refuses AGGREGATED_RESULT_VALUES) before the role validation it exists to assert. Fixed in :new_sha: wire an explicit FULL guard in that test's fixture — the same one AiOssieRoleGuardTest already uses. No production code changed; the PR's fail-closed default is untouched (the test now declares what it always meant: role guards, not policy). No local Maven/JDK in this environment, so CI is the verification.


🐝 Hive Agent: contributor | SHA: :new_sha


🐝 Hive Agent: contributor | SHA: 7be415f62

@spicule-hive-bot

Copy link
Copy Markdown
Collaborator Author

#2355 (comment)


🐝 Hive Agent: contributor | SHA: 7be415f62

@spicule-hive-bot

Copy link
Copy Markdown
Collaborator Author

Merge follow-up: the post-merge red build (JDK 22) cell was a semantic conflict between this PR' submit-time policy gate on executeAsync and AiOssieResourceAsyncRoleTest (the saiku#2323 role-guard test that landed on development in the meantime): the test constructs the resource with no policy guard, so executeAsync now throws AiPolicyViolation (schema-only refuses AGGREGATED_RESULT_VALUES) before the role validation it exists to assert. Fixed in 7be415f62: wire an explicit FULL guard in that test' fixture — the same one AiOssieRoleGuardTest already uses. No production code changed; the fail-closed default is untouched. No local Maven/JDK in this environment, so CI is the verification. (Supersedes my two malformed comments above.)


🐝 Hive Agent: contributor | SHA: 7be415f62


🐝 Hive Agent: contributor | SHA: unknown

@buggtb buggtb added needs-rework Ask the hive's quality agent to rework this PR (reads comments, fixes CI/conflicts, pushes) and removed needs-rework Ask the hive's quality agent to rework this PR (reads comments, fixes CI/conflicts, pushes) labels Nov 12, 2026
spicule-hive-bot and others added 2 commits November 12, 2026 01:54
Signed-off-by: quality <334701613+spicule-hive[bot]@users.noreply.github.com>
@spicule-hive

spicule-hive Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Rework update on the existing branch (head 287556dc6):

  • The earlier collaborator updates are preserved: development was merged at 67ecb5725, and 7be415f62 gives the async role test an explicit FULL policy guard. I checked the newer development tip (e8d7a4d4a) with git merge-tree; it merges cleanly, so no conflict merge was needed.
  • The failing CI feedback identified one Spotless violation in AiOssieResourceAsyncRoleTest. Concurrent commit ff63aef80 made the requested one-line formatting fix before my push. I integrated that commit and pushed the repository session handoff as 287556dc6; no production behavior or test assertion changed, so no additional behavior test was needed. There were no inline review comments or submitted reviews to address.
  • Local checks: JDK 22.0.2 and Maven 3.9.9; mvn -B -ntp -pl saiku-core/saiku-web spotless:check passed (349 Java files clean); ./scripts/check-licence-headers.sh passed (1,311 Java files); git diff --check passed.
  • I attempted the focused Ossie async role, policy, wiring, and MCP tests with mvn -B -ntp -pl saiku-core/saiku-web -am -Dtest=AiOssieResourceAsyncRoleTest,AiOssieResourcePolicyTest,AiPolicyGuardWiringTest,McpResourceTest -Dsurefire.failIfNoSpecifiedTests=false test. Maven stopped before compilation: GitHub Packages returned 401 while resolving Mondrian and olap4j dependencies. The full build and tests therefore need CI's package credentials. CI for the new head was pending when last checked; an automated tool guard rejected further CI polling (ci_watch_blocked), so I cannot report its final result here.

🐝 Hive Agent: quality | Instance: hive-safe-wren | SHA: 287556dc6

— hive: agent=quality backend=codex model=gpt-6-sol codex=0.167.0

@buggtb
buggtb added this pull request to the merge queue Nov 18, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 18, 2026
@buggtb
buggtb added this pull request to the merge queue Nov 19, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 19, 2026
@buggtb
buggtb added this pull request to the merge queue Nov 19, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 19, 2026
@spicule-hive

spicule-hive Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

⚠️ Hold-gate mergeability: this PR has a real conflict with its base

This PR is hold-gated and has fallen behind its base branch. The hive tried to merge the base in to keep it mergeable while it waits on review, but that merge conflicts and the hive cannot resolve it automatically.

It will stay held and will NOT merge on its own even once reviewed — removing hold alone will not be enough. Someone will need to merge or rebase the base branch in by hand (or resolve the conflict another way) before this PR can merge.

@spicule-hive-bot

Copy link
Copy Markdown
Collaborator Author

hive-base-moved: merged current development (230bfb2) into this branch (plus reconciled the prior remote merge bcfa0cc). New head: de8c911. Conflict-free except a .claude/session-summary.md artifact; PR intent (fail-closed SAIKU_AI_POLICY enforcement, #2322) preserved.


🐝 Hive Agent: contributor | SHA: unknown

…uard (merge follow-up)

The error-envelope test (saiku#1920) landed on development after the saiku#2322
policy gate and constructs AiOssieResource with no guard, so the schema-only
policy now rejects executeAi/rowDetail with AiPolicyViolation before the
envelope under test is built. Wire the same explicit FULL guard the async role
test fixture uses; no production code touched.
@spicule-hive-bot

Copy link
Copy Markdown
Collaborator Author

Merge follow-up: the red build (JDK 22) cell on the merged head (de8c911) was the same semantic-conflict pattern as the earlier async-role test — AiOssieResourceErrorEnvelopeTest (saiku#1920) landed on development after this PR's submit-time policy gate and constructs AiOssieResource with no guard, so the schema-only policy rejected executeAi/rowDetail with AiPolicyViolation before the envelope under test was built. Fixed in 1fafdb2: wired the same explicit FULL guard the AiOssieResourceAsyncRoleTest fixture already uses. All 4 tests in the class pass locally; Spotless clean. Note: the semantic model diff cell also went red with spotless-maven-plugin:3.10.4 could not be found in central — the artifact IS on Central (verified HTTP 200) and the pin is identical on development, so that one is a transient resolution failure; gh run rerun is not permitted in this environment, so it needs a CI re-dispatch or will clear on the next head push.


🐝 Hive Agent: contributor | SHA: unknown

@buggtb
buggtb added this pull request to the merge queue Nov 19, 2026
Merged via the queue into development with commit 1179ec7 Nov 19, 2026
28 checks passed
@github-actions

Copy link
Copy Markdown

PR acceptance metric

Acceptance rate: 85.9% — 428 merged / 498 decided PRs (2 still open, excluded from the denominator).

Metric Value
Acceptance rate 85.9%
Accepted / rejected / open 428 / 70 / 2
Median time to first review (merged) 125.1 h
Median time to merge (merged) 14.1 h
Median time open (decided) 18.7 h
Mean review rounds on merged PRs 1.3
Authors with at least one merged PR 8
Author Merged Rejected Acceptance
buggtb 215 19 91.9%
app/dependabot 96 41 70.1%
juanresendiz813 95 1 99.0%
spicule-hive-bot 10 1 90.9%
app/spicule-hive 8 1 88.9%
oiacub1 2 0 100.0%
k-jm 1 3 25.0%
Prithvi1994 1 0 100.0%
laborima 0 3 0.0%
rezamuliawijaya 0 1 0.0%

Generated by scripts/pr-metrics.mjs — see docs/metrics.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-config area/web docs needs-human rework-queued The quality agent has picked this PR up (set automatically when needs-rework is consumed) risk/high Change risk tier: high (see docs/risk-tiers.md) sentinel-alert

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[security] AI data policy (SAIKU_AI_POLICY) is never enforced on Ossie data endpoints — REST and MCP return aggregated and raw rows under schema-only

2 participants