Skip to content

[SPARK-59118][SQL][4.x] Warn when doAs is enabled but not enforced - #58438

Closed
holdenk wants to merge 6 commits into
apache:branch-4.xfrom
holdenk:SPARK-59118-doAs-warn-4.x-r2
Closed

holdenk wants to merge 6 commits into
apache:branch-4.xfrom
holdenk:SPARK-59118-doAs-warn-4.x-r2

Conversation

@holdenk

@holdenk holdenk commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This is a softer follow on of #58414 for 4.X branch which warns when doAs is enabled but not enforced. We should log rather than fail a previously running job.

Why are the changes needed?

People might expect doAs to run as a different user, which is not supported.

Does this PR introduce any user-facing change?

The Spark Thrift Server logs a startup warning when hive.server2.enable.doAs is enabled with an authenticating auth type, unless the new static conf spark.sql.hive.thriftServer.allowIneffectiveDoAs is set to true.

How was this patch tested?

New unit test.

Was this patch authored or co-authored using generative AI tooling?

Yes, claude

hive.server2.enable.doAs is accepted and HiveSessionProxy does impersonate
the connecting user for metastore calls, but queries and the storage access
they perform run as the service identity (SPARK-5159), so storage ACLs are
checked against the wrong principal. Warn at startup rather than look like
we enforce something we do not.

Warn rather than refuse, because refusing breaks deployments that have been
accepted for years and this is a minor release. Spark 5.0 refuses instead
and adds an escape-hatch conf, which the message points at.

The warning does not tell operators to just set doAs=false: that also drops
metastore impersonation, so it is not a no-op.

Auth types that never establish a user identity have nothing to impersonate,
so NONE and NOSASL stay quiet -- which is also the stock Hive config, since
Hive defaults doAs to true.

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


Co-authored-by: Holden Karau <[email protected]>
@dongjoon-hyun dongjoon-hyun changed the title [SPARK-59118][SQL] Warn when doAs is enabled but not enforced [SPARK-59118][SQL][4.x] Warn when doAs is enabled but not enforced Sep 1, 2026

@HyukjinKwon HyukjinKwon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 blocking, 2 non-blocking, 0 nits.
Clean, well-tested backport with no production-behavior defects. The auth-vs-doAs guard is correctly null-safe and the new suite covers both inverting config axes. Two non-blocking points remain: uros-b's existing note that the warning hardcodes the not-yet-merged 5.0 config name, and a stale 'user-facing change' field in the PR description.

Already raised in existing discussion (1)

  • The warning hardcodes the config name spark.sql.hive.thriftServer.allowIneffectiveDoAs, which does not exist on 4.x -- it is the Spark 5.0 opt-out from SPARK-58414. A maintenance-branch message that names an unmerged config can drift silently: if the 5.0 config lands under a different name, this 4.x warning keeps pointing users at a name that never shipped, and nothing here fails when that happens. Since 4.x cannot reference the (nonexistent) config constant, the more robust option is to not name the specific future config in this branch -- e.g. drop the final sentence, or point to the migration guide / SPARK-59118 -- so the 4.x text cannot go stale independently of 5.0. -- existing discussion

Design / architecture (1)

  • General: The PR description's "Does this PR introduce any user-facing change?" answer reads "Explicit error unless config flag is disabled", but this 4.x change only emits a startup warning and adds no config flag -- the explicit-error/opt-out behavior is the Spark 5.0 behavior that the warning text itself points to. The answer looks copied from the master PR (SPARK-58414) and would generate an inaccurate release note. Please update it to describe the actual user-facing change: a new startup warning when hive.server2.enable.doAs is enabled under an authenticating auth type.

Verification

Independently confirmed: the auth comparison is null-safe (constant-on-left equalsIgnoreCase, so an explicitly-emptied auth conf does not NPE); NONE/NOSASL are the only exempted auth types; init is the sole production caller of the helper and is reached from startWithSparkSession; no production subclass overrides init; and the new suite exercises both inverting axes (doAs on/off, verifying vs non-verifying auth) plus untouched and unrecognized configs. All changed lines are within 100 chars and the text/contract/efficiency scanners returned no findings.

@HyukjinKwon HyukjinKwon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One follow-up on the doAs warning for the maintenance branch (see inline).

// Constant on the left: authType is null when explicitly set empty, and this must not NPE.
val authVerifiesUser = !unverifiedAuthTypes.exists(_.equalsIgnoreCase(authType))
if (authVerifiesUser && hiveConf.getBoolVar(ConfVars.HIVE_SERVER2_ENABLE_DOAS)) {
logWarning(log"${MDC(CONFIG, ConfVars.HIVE_SERVER2_ENABLE_DOAS.varname)} is set to true, " +

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warn-only is the right call for a maintenance branch -- it surfaces the SPARK-5159 impersonation gap without breaking servers that are running today, and pointing at the 5.0 escape hatch (allowIneffectiveDoAs) in the message is a nice touch. One fix: the PR description still answers the user-facing-change question with "Explicit error unless config flag is disabled" (copied from #58414), but this variant only logs a warning and never fails startup -- please update it so the 4.x behavior isn't misread as a hard failure.

@jzhan-2026 jzhan-2026 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.

+1 on the feedback from other reviewers. The PR description still says "Explicit error" — worth updating to reflect that this variant only warns.

@holdenk

holdenk commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

Good point updated the PR description

@dongjoon-hyun

Copy link
Copy Markdown
Member

Thank you for making a softer version for branch-4.x, @holdenk.

Since this is the branch-4.x counterpart of #58414, it would be great to keep the two consistent. Currently there are a few divergences:

  1. Unrecognized auth types: [SPARK-59118][SQL] Error when doAs is used and not supported #58414 uses an allow-list (LDAP/KERBEROS/CUSTOM/PAM) and leaves unknown values to HiveAuthFactory's own error, while this PR uses a deny-list (everything except NONE/NOSASL), and the test an unrecognized auth type warns pins the opposite behavior. 4.x should warn on exactly the configurations that 5.0 will reject.
  2. Message accuracy: [SPARK-59118][SQL] Error when doAs is used and not supported #58414 says impersonation applies on the driver (metastore calls and driver-side file system access) and executor-side access runs as the service identity. This PR says only metastore calls are impersonated.
  3. Null comment: authType is null when explicitly set empty contradicts [SPARK-59118][SQL] Error when doAs is used and not supported #58414 (getVar returns "", never null). With the allow-list approach, this comment becomes unnecessary.
  4. PR description: It says "Explicit warning unless config flag is disabled", but there is no such flag in this PR. The only way to silence it is doAs=false, which also disables metastore impersonation. Do we want to add the same static conf to 4.x (e.g., default true) so that users can acknowledge the limitation without changing behavior?

Also, the warning message is quite long for a single log line. It might be better to keep it concise and move the details to the migration guide.

@holdenk

holdenk commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

Yup I'll update this one shortly since it seems like we've largely settled on the master/5.X version :)

@dongjoon-hyun

Copy link
Copy Markdown
Member

BTW, for master PR, I approved it.

…e silenced

The warning told operators to set
spark.sql.hive.thriftServer.allowIneffectiveDoAs=true, but nothing defined
that conf: an unknown spark.sql.* key is accepted silently, so following the
advice did nothing and the operator got no feedback either way. Worse, the
name ships in a released binary, so if 5.0 lands the gate under a different
name the log line points at a key that never existed.

Define it here and honor it today. Setting it acknowledges the limitation and
silences the warning; 5.0 is expected to refuse to start on the same
configuration unless it is set, so the key an operator sets now carries
forward. Versioned 4.3.0 -- it ships in 4.3.0 via RC2, not in the 4.3.1
that branch-4.3's pom currently reads between RCs.

Also test that init() actually emits the warning, since deleting the call
left every unit test green, and that the warning names the conf that
silences it -- which is what would have caught the missing conf.

Operation logging is off in that test: init() boots Hive's service graph,
and OperationManager.init attaches an appender to the root logger that
nothing ever removes.

Co-authored-by: Holden Karau <[email protected]>

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@holdenk

holdenk commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

I'm going back and forth on if the config flag is worth it since it would just gate a warning but it does let people proactively see how to opt out of enforcement.

@holdenk
holdenk marked this pull request as draft September 24, 2026 05:01
@holdenk

holdenk commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

Moved to draft while I update it based on the master approved one

…JVM logging state

CI runs the hive-thriftserver module in a single forked JVM
(SERIAL_SBT_TESTS=1 disables the dedicated-JVM test grouping), so
SparkExecuteStatementOperationSuite's init test ran in the same JVM as
HiveThriftServer2DoAsSuite. The init test attached an appender to the
HiveThriftServer2 logger by name; log4j2's addLoggerAppender permanently
registers an exact-name LoggerConfig for it, copying the root config's
additivity (false). Cleanup removes the appender but not the LoggerConfig,
so every later event from that logger was swallowed - never reaching the
console or any root-attached appender - and the doAs suite's log-capture
assertions failed.

Two changes:

- Split warnIfIneffectiveDoAs into ineffectiveDoAsWarning, which returns
  the warning as an Option[LogEntry], and a one-line wrapper that logs it.
  The doAs suite now asserts on the returned entry instead of capturing
  log output, mirroring how the master version asserts on the thrown
  exception.
- The init test attaches its appender to the root logger instead of the
  named logger, so it no longer leaves the non-additive LoggerConfig
  behind. It still covers end-to-end emission through init().

Co-authored-by: Cursor <[email protected]>

Co-Authored-By: Holden Karau <[email protected]>
@holdenk
holdenk marked this pull request as ready for review September 25, 2026 00:55
@cloud-fan

Copy link
Copy Markdown
Contributor

the master pr is merged, is this one ready to go?

cloud-fan and others added 2 commits October 27, 2026 03:44
This change missed 4.3.0: neither 4.3.0-rc2 nor 4.3.0-rc3 includes it, and
branch-4.x is the 4.4.0 line. Version
spark.sql.hive.thriftServer.allowIneffectiveDoAs 4.4.0 and move the migration
note to the 4.3 to 4.4 section, matching the master guide's "Spark 4.4 logs a
warning for the same configuration".

Co-authored-by: Isaac <[email protected]>
@cloud-fan

Copy link
Copy Markdown
Contributor

@holdenk I pushed two commits to retarget this at 4.4. It missed 4.3.0: neither 4.3.0-rc2 nor 4.3.0-rc3 includes it, and branch-4.x is now the 4.4.0 line.

  • 9c9befc: merged the current branch-4.x into this branch. It was based on an Aug 12 branch-4.x, and the "Upgrading from Spark SQL 4.3 to 4.4" section has since grown on both sides of its only entry, so moving the migration note there would otherwise conflict. The merge itself had no conflicts.
  • f918b8e: spark.sql.hive.thriftServer.allowIneffectiveDoAs is now .version("4.4.0"), and the migration note moved from the 4.2 to 4.3 section to the end of the 4.3 to 4.4 section ("Since Spark 4.4"). This matches master's migration guide, which already says "Spark 4.4 logs a warning for the same configuration."

No code or test changes; the PR still touches the same 5 files. I also fixed the user-facing-change line in the PR description, which said the warning is silenced by disabling a flag; it is silenced by setting allowIneffectiveDoAs to true.

After this merges, master needs a one-line follow-up to change the same conf's .version("5.0.0") to "4.4.0", since it will first ship in 4.4.0.

@holdenk

holdenk commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Yeah 4.4.0 makes sense

@cloud-fan

Copy link
Copy Markdown
Contributor

tests actually passed, thanks, merging to 4.x!

cloud-fan added a commit that referenced this pull request Oct 27, 2026
### What changes were proposed in this pull request?

This is a softer follow on of #58414 for 4.X branch which warns when doAs is enabled but not enforced. We should log rather than fail a previously running job.

### Why are the changes needed?

People might expect doAs to run as a different user, which is not supported.

### Does this PR introduce _any_ user-facing change?

The Spark Thrift Server logs a startup warning when `hive.server2.enable.doAs` is enabled with an authenticating auth type, unless the new static conf `spark.sql.hive.thriftServer.allowIneffectiveDoAs` is set to `true`.

### How was this patch tested?

New unit test.

### Was this patch authored or co-authored using generative AI tooling?
Yes, claude

Closes #58438 from holdenk/SPARK-59118-doAs-warn-4.x-r2.

Lead-authored-by: Holden Karau <[email protected]>
Co-authored-by: Holden Karau <[email protected]>
Co-authored-by: Wenchen Fan <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
@cloud-fan cloud-fan closed this Oct 27, 2026
@cloud-fan

Copy link
Copy Markdown
Contributor

Merge Summary:

Posted by merge_spark_pr.py

cloud-fan added a commit that referenced this pull request Oct 28, 2026
….4 migration note with branch-4.x

### What changes were proposed in this pull request?

A follow-up to #58414, now that its `branch-4.x` backport #58438 has shipped `spark.sql.hive.thriftServer.allowIneffectiveDoAs` in 4.4.0 (as a warn-only gate):

- Change the conf's `.version("5.0.0")` to `.version("4.4.0")`, since 4.4.0 is the first release with this key.
- Add the backport's 4.4 migration note to the "Upgrading from Spark SQL 4.3 to 4.4" section, at the same position as on `branch-4.x`. That section is otherwise identical between `master` and `branch-4.x`, and the 5.0 note added by #58414 already says "Spark 4.4 logs a warning for the same configuration."

### Why are the changes needed?

A conf's version should record the first release that has it, and master's 4.3 to 4.4 migration section should match `branch-4.x`'s.

### Does this PR introduce _any_ user-facing change?

No. Behavior is unchanged; the generated conf docs list the conf as available since 4.4.0 instead of 5.0.0.

### How was this patch tested?

No new tests: the change is a version string and one documentation line. Checked that master's "Upgrading from Spark SQL 4.3 to 4.4" section is now identical to `branch-4.x`'s.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Isaac (Claude Opus 5.5)

This pull request and its description were written by Isaac.

Closes #59831 from cloud-fan/wenchen/spark-59118-doas-version-4.4.

Authored-by: Wenchen Fan <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
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.

7 participants