← Back to Pull requests

feat(webhook): add sparkConf key validation #3043

Closed
unknown closed this pull request without merging on Jul 16, 2026 16:00 UTC
View on GitHub
unknown unknown commented on Jul 14, 2026 14:26 UTC
Author

Blocks dangerous sparkConf keys in the validating webhook to prevent security-sensitive overrides due to last-value-wins in spark-submit. Applied to SparkApplication, ScheduledSparkApplication, and SparkConnect validators
This addresses #3006.

<!-- Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, check our contributor guidelines: https://www.kubeflow.org/docs/about/contributing
2. To know more about how to develop with the Spark operator, check the developer guide: https://spark.kubeflow.org/en/latest/contributor-guide/
3. If you want faster PR reviews, check how: https://git.k8s.io/community/contributors/guide/pull-requests.md#best-practices-for-faster-reviews
4. Please open an issue to discuss significant work before you start. We appreciate your contributions and don't want your efforts to go to waste!
-->

Purpose of this PR

<!-- Provide a clear and concise description of the changes. Explain the motivation behind these changes and link to relevant issues or discussions. -->
The operator builds spark-submit arguments in a fixed order (defined in submission.go), which is last-value-wins. The user could set entries in sparkConf that applied after the operator-set values like namespace, service account setup, and container image config. Therefore, a tenant could silently override these by setting the same key in sparkConf (e.g. a user could escalate privileges with just a config change in sparkConf).

This PR adds key-level validation to the webhook so these keys are rejected at admission before they reach the controller. Every blocked key already has a dedicated CRD field alternative, and the error message tells the user exactly which one to use. This is applied to SparkApplication, ScheduledSparkApplication, and SparkConnect, none of which had this validation before.

Proposed changes:

  • Add validateSparkConf to block 14 sparkConf keys that can override operator-managed values due to spark-submit argument ordering

  • Blocked keys: service account names (driver, executor), OAuth token/tokenFile (submission client, driver, executor), master URLs, container image keys, and namespace (pinned to app namespace)

  • Wire validation into all three CRD validators

  • Unit tests covering all 14 attack vectors, update rejection, and benign-key pass-through across all three CRDs

  • E2E tests verify the webhook rejects a denied key and accepts a safe key against a live cluster.
  • Change Category

    <!-- Indicate the type of change by marking the applicable boxes. -->

  • Bugfix (non-breaking change which fixes an issue)

  • Feature (non-breaking change which adds functionality)

  • Breaking change (fix or feature that could affect existing functionality)

  • Documentation update
  • Users who currently set any of these keys via sparkConf will need to move the value to the corresponding CRD field (a one-line manifest change per key, with clear instructions in the error msg), but allowing these keys to pass through is the vulnerability itself, so a breaking change seems to be the only way to fix it.

    Rationale

    <!-- Provide reasoning for the changes if not already covered in the description above. -->
    The vulnerability exists because sparkConfOption runs after the namespaceOption (in position 6), imageOption(position 7), and other operator-related options in optionFuncs. The denylist uses specific key enumeration instead of prefix matching to avoid blocking cert-related authenticate keys that would not have a CRD alternative. SSL blocking was excluded dude Istio users would need to legitimately disable the built-in SSL, so it wouldn't fit into this current architecture.

    Checklist

    <!-- Before submitting your PR, please review the following: -->

  • I have conducted a self-review of my own code.

  • I have updated documentation accordingly.

  • I have added tests that prove my changes are effective or that my feature works.

  • Existing unit tests pass locally with my changes.
  • Additional Notes

    <!-- Include any additional notes or context that could be helpful for the reviewers here. -->
    Denylist:

  • spark.kubernetes.authenticate.driver.serviceAccountName / executor.serviceAccountName - SA override (use spec.driver.serviceAccount)

  • spark.kubernetes.authenticate.oauthToken / oauthTokenFile (submission, driver, executor variants) - credential injection (use Kubernetes service accounts)

  • spark.master / spark.kubernetes.driver.master - cluster redirect (managed by operator)

  • spark.kubernetes.container.image / driver / executor variants - image override (use spec.image)

  • spark.kubernetes.namespace - value allowed only if value matches the app's namespace
  • Diff: 596 lines (+447 / -149) across 7 files Reviewer: vjanelle Review duration: 2974m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 596 lines diff across 7 files
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.382
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3043"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 50% (MEDIUM) · Higher = larger blast radius
    50%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.8% · Safe to merge
    19.8%