Skip to content

connect-server, session: a read-only Spark Connect session on request header x-krishiv-read-only (ON-E1) - #1162

Open
techgopal wants to merge 14 commits into
mainfrom
p3/platform3-on-e1-readonly-connect
Open

techgopal wants to merge 14 commits into
mainfrom
p3/platform3-on-e1-readonly-connect

Conversation

@techgopal

Copy link
Copy Markdown
Contributor

What

  • Read-only Spark Connect session (ON-E1). A request with header x-krishiv-read-only: true gets a session that
    only reads. The read-only flag is part of the session key, so the same session id without the header is a different
    session (a writable request for a read-only id gets SESSION_NOT_FOUND). An unreadable header value is refused; it is
    never read as writable.
  • API: Session::new_read_only_session_*, Session::is_read_only, Authenticated::read_only, SessionOwner.read_only;
    the embedded manager builds read-only sessions too.
  • Refusals are all KRISHIV_MCP_STATEMENT_NOT_ALLOWED: non-read SQL, non-read commands (write, register, checkpoint),
    Config Set/Unset (Get still works), DataFrame temp views. A read denial from the inner policy is left unchanged.
  • Design step 4: the check that an analysis only reads moves into krishiv-session (Analysis::check_read_only); the
    MCP gate calls it (allows/allows_parts are removed from krishiv-mcp/src/gate.rs).
  • Fix: a Spark key Krishiv only aliases, with no Krishiv default, now returns Spark's default
    (spark.sql.shuffle.partitions -> 200 for Connect Config Get and SQL SET key; it was SQL_CONF_NOT_FOUND).

Tests

  • krishiv-connect-server/tests/read_only.rs (8 tests: reads pass, every SQL write is refused and changes nothing,
    write/register/checkpoint are refused, config set/unset are refused and get passes, header handling, session-key
    separation, the embedded manager).
  • krishiv-session/tests/sql_commands.rs: the aliased-key default; a read-only child session only reads.
  • Analysis::check_read_only unit tests and a doctest; the krishiv-mcp suite passes.

Notes

  • Pre-existing divergence (not changed here): a ROOT sql relation is lowered as a query, so DDL there is a parse error;
    Spark runs it.
  • Fable review needed: this changes the auth path (security path).

… header x-krishiv-read-only (ON-E1)

Signed-off-by: gopal tathe <44522021+techgopal@users.noreply.github.com>
…adonly-connect

Signed-off-by: gopal tathe <44522021+techgopal@users.noreply.github.com>
…-session (Analysis::check_read_only, ON-E1 step 4); an aliased Spark key with no Krishiv default answers Spark's default (spark.sql.shuffle.partitions = 200)

Signed-off-by: gopal tathe <44522021+techgopal@users.noreply.github.com>
… manager's read-only session and a read-only child session (ON-E1 coverage)

Signed-off-by: gopal tathe <44522021+techgopal@users.noreply.github.com>
…adonly-connect

Signed-off-by: gopal tathe <44522021+techgopal@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Signed-off-by: gopal tathe <44522021+techgopal@users.noreply.github.com>
…under 2,000 lines (file-size gate on #1162)

Signed-off-by: gopal tathe <44522021+techgopal@users.noreply.github.com>
@techgopal

Copy link
Copy Markdown
Contributor Author

Diff review of 1b89271 (full): changes requested.

  1. Flight SQL is untested: ON-E1 is the Flight SQL session. The header reaches Flight SQL through the shared auth layer, but no test runs a statement, a DoPut update, a prepared statement or SetSessionOptions in a read-only Flight SQL session, or shows that a cookie issued with the header and presented without it gets a fresh writable session (and the reverse). Add those tests and say in the changelog and crate CLAUDE.md files that the header applies to Flight SQL.
  2. A path read is not refused: the spec lists it as refused. SELECT * FROM parquet.\/dir`andspark.read.parquet(path)` are READ, and ReadOnlyPolicy passes Select on a Path to the inner policy, so a role that may read paths reads any path from the read-only session. Refuse Select on Securable::Path in a read-only session (in the session's wrapper, not in ReadOnlyPolicy, which the MCP setup lock also uses), with tests; or get the spec row changed.
  3. Refusals that reach the policy keep KRISHIV_INSUFFICIENT_PERMISSIONS: the class check is only in ran.rs, so Catalog::authorize_as paths (Connect dropGlobalTempView) and READ statements needing Monitor/Usage are refused with 42501. The spec maps them to KRISHIV_MCP_STATEMENT_NOT_ALLOWED. Move the check into Session::authorize_statement and map ReadOnlyPolicy's own denials; test dropGlobalTempView of another session's view.
  4. Analysis::check_read_only is moved but never called for the read-only session. Either call it per statement or document which layer covers partial, privileges and user code at analysis.
  5. Connect paths refused by different layers have no test: local CreateDataframeView, an inline Python UDF in a plan, AddArtifacts, AnalyzePlan persist, and catalog createTable / setCurrentDatabase / cacheTable / dropGlobalTempView / refreshByPath. Assert the error class and that nothing changed.

Nits: use an added changelog fragment for the read-only session; the shuffle.partitions default would be better as its own PR; asks could return an enum instead of Result<bool, ()>.

…usals at authorize_statement, path reads refused, the read-only class for the rule's own 42501s, Flight SQL and Connect tests

- authorize_statement (Session::sql and the catalog API) refuses a non-READ class or a target outside READ_ONLY_PRIVILEGES; the ran.rs check is gone (finding 3)
- ReadOnlyPolicy::for_session also refuses every privilege on a path (finding 2)
- Session::read_only_refusal maps the read-only rule's own 42501 to KRISHIV_MCP_STATEMENT_NOT_ALLOWED; a read the inner policy denies stays 42501 (finding 3)
- Catalog::drop_global_temp_view refuses in a read-only session before its existence check
- which layer covers each condition of the MCP gate's analysis check, in the session CLAUDE.md (finding 4)
- tests: Flight SQL statements, updates, prepared statements, path read, SetSessionOptions, cookies both ways (finding 1); Connect path reads, dropGlobalTempView, catalog calls, CreateDataframeView, inline Python UDF, AnalyzePlan persist, AddArtifacts (finding 5); session path read and inner denials
- nits: read_only::Asked enum; changelog split into added and fixed

Signed-off-by: gopal tathe <44522021+techgopal@users.noreply.github.com>
…adonly-connect

Signed-off-by: gopal tathe <44522021+techgopal@users.noreply.github.com>

# Conflicts:
#	crates/krishiv-session/CLAUDE.md
#	crates/krishiv-session/src/session.rs
@techgopal

Copy link
Copy Markdown
Contributor Author

Diff review of 767db6a (full diff against main): changes requested. The five findings of 1b89271 are closed, and the session cannot be left (flag in every session constructor and in the session owner, header fail closed, every command through enforce, persisted UDFs not loaded). Two findings remain:

  1. [P2] The refusal text is wrong for a read (krishiv-session/src/access.rs:430-437 authorize_statement, :448 read_only_refusal; krishiv-connect-server/src/auth.rs:176). statementClass is filled with the class name only, so SELECT * FROM parquet./p`` (and spark.read.parquet(p), or a read whose target needs another privilege) answers "...this statement is of class READ." A caller cannot tell what to change. The check moved to `analyze/read_only.rs` names the reason ("READ, but it needs MONITOR"); the session's refusals should too: "READ, but it needs ``" and "READ, but it reads by path", the bare class name only when the class is not `READ`. The unreadable-header refusal ("of class unreadable x-krishiv-read-only header") is the same defect. Assert the text in the two path-read tests and the header test.
  2. [P2] SetSessionOptions of catalog and schema has no read-only test (krishiv-flight-sql/tests/service/read_only.rs:191-236). set_option (session_options.rs:188) sends these two names to Catalog::set_current_catalog / set_current_database, never authorize_set_key; they are refused only because those run USE through Session::sql. The test sets spark.sql.shuffle.partitions alone, which takes the other path. Add both names to the request, assert both are in errors and that the current catalog and schema did not move.

Nits (not blocking): Catalog::drop_temp_view has no read-only refusal (nothing can be there today); read_only_refusal matches the path ' prefix of Securable's Display, worth a line at the Display; the header is read before authentication, so a bad header without a token is not answered as unauthenticated.

Nothing was built or run for this review.

…ry's session read-only

A read-only session's KRISHIV_MCP_STATEMENT_NOT_ALLOWED now says 'READ, but it needs <privilege>'
or 'READ, but it reads by path' instead of the bare class, and an unreadable x-krishiv-read-only
header says what the header must be. The header is read after the caller is authenticated.

SessionManager applies the caller's read-only flag after any SessionFactory, so a factory that
does not read it (an embedder's own) still gives a read-only session; found by the new
SetSessionOptions test of catalog and schema. Catalog::drop_temp_view drops nothing in a
read-only session. Review of 767db6a (Fable).

Signed-off-by: gopal tathe <44522021+techgopal@users.noreply.github.com>
…nly: applied, so a client fails closed on a server that ignored the header

AuthLayer stamps the header on the response (initial metadata: streams, replies and refusals) when the
caller's read-only header was applied. Tests over Spark Connect and Flight SQL; guide section in
docs/guides/access-control.md.

Signed-off-by: gopal tathe <44522021+techgopal@users.noreply.github.com>
@techgopal

Copy link
Copy Markdown
Contributor Author

Diff review passed (ffce13d)

Scope: the delta since 767db6a (refusal text for a refused read, the catalog / schema session options test, the manager making a factory's session read-only, the header read after authentication). Both earlier findings are closed; four non-blocking nits are in the review file.

@techgopal

Copy link
Copy Markdown
Contributor Author

Reviewed-by: Fable
Diff review passed (ffce13d)

Delta since 767db6a: findings none; four nits (record ops/reviews/review-p3-platform3-on-e1-readonly-connect-ffce13d63.md). The nits and the read-only confirmation header (x-krishiv-read-only: applied, for AO1-4's fail-closed client) follow as the next delta.

… function with a test of its text; SessionFactory says what the read-only copy drops; the path-read and SetSessionOptions tests check the reason

Signed-off-by: gopal tathe <44522021+techgopal@users.noreply.github.com>
@techgopal

Copy link
Copy Markdown
Contributor Author

New head e28aba9 (delta since ffce13d, Fable requested):

  • 1b402d8: every response to a read-only request carries x-krishiv-read-only: applied (AuthLayer; streams, replies, refusals), so a client (AO1-4's platformd) fails closed on an engine that ignored the header. Tests over Connect and Flight SQL; guide docs/guides/access-control.md "Read-only sessions".
  • e28aba9: the four nits of the ffce13d review.
    Scoped diff-coverage 93.0% (279/300).

@techgopal

Copy link
Copy Markdown
Contributor Author

Reviewed-by: Fable
Diff review passed (e28aba9)

Delta since ffce13d: findings none, one nit (record ops/reviews/review-p3-platform3-on-e1-readonly-connect-e28aba9b1.md); its fix follows.

…l metadata only (a status from the trailers does not repeat it; e28aba9 review nit)

Signed-off-by: gopal tathe <44522021+techgopal@users.noreply.github.com>
@techgopal

Copy link
Copy Markdown
Contributor Author

Reviewed-by: Opus
Diff review passed (50f2563)

Delta since e28aba9 (test only): findings none. Record ops/reviews/review-p3-platform3-on-e1-readonly-connect-50f256393.md. The chain of passes: 1b89271 -> 767db6a -> ffce13d -> e28aba9 (Fable) -> 50f2563.

@techgopal
techgopal marked this pull request as ready for review December 6, 2026 02:58
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 6, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-12-06T03:48:20.366232Z
We couldn’t complete this review. Comment @codex review to try again.
50f2563 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@codecov

codecov Bot commented Dec 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@techgopal

Copy link
Copy Markdown
Contributor Author

@codex review

@techgopal

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Dec 6, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited. More included reviews will be available in 17 minutes.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

This branch has not been deployed

No deployments
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.

1 participant