Skip to content

HIVE-29999: HiveCluster CR string fields should be validated before b… - #6802

Merged
ayushtkn merged 4 commits into
apache:masterfrom
tanishq-chugh:op-resc-check
Sep 21, 2026
Merged

ayushtkn merged 4 commits into
apache:masterfrom
tanishq-chugh:op-resc-check

Conversation

@tanishq-chugh

Copy link
Copy Markdown
Contributor

…eing injected into k8s operator generated bash commands

What changes were proposed in this pull request?

Validate HiveCluster CR string fields before adding them into bash commands

Why are the changes needed?

To prevent any additional non-intended values being injected into specific HiveCluster CR string fields

Does this PR introduce any user-facing change?

No

How was this patch tested?

Manual Testing

…eing injected into k8s operator generated bash commands
@tanishq-chugh

Copy link
Copy Markdown
Contributor Author

Hi @ayushtkn
Could you please help with a review on this PR?
Thanks!

Copilot AI 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.

🟡 Changes recommended

One or more issues must be addressed before approval.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds runtime and CRD validation for database settings and external JAR locations, and reports dependent workflow errors in status.

Changes:

  • Validates database types and shell-sensitive values.
  • Validates external JAR URLs before command generation.
  • Adds workflow error status propagation.
File summaries
File Description
packaging/src/kubernetes/src/java/org/apache/hive/kubernetes/operator/reconciler/HiveClusterReconciler.java Updated as part of this pull request.
packaging/src/kubernetes/src/java/org/apache/hive/kubernetes/operator/model/spec/DatabaseConfig.java Updated as part of this pull request.
packaging/src/kubernetes/src/java/org/apache/hive/kubernetes/operator/dependent/HiveDependentResource.java Updated as part of this pull request.
packaging/src/kubernetes/helm/hive-operator/crds/hiveclusters.hive.apache.org-v1.yml Updated as part of this pull request.
Review details

Suppressed comments (4)

packaging/src/kubernetes/src/java/org/apache/hive/kubernetes/operator/dependent/HiveDependentResource.java:384

  • These checks cover only the metastore database fields, but HiveServer2DeploymentDependent also appends the CR-provided metastore.externalUri, llap.serviceHosts, and zookeeper.quorum to the same SERVICE_OPTS string (at its lines 117-139). Values containing whitespace or other rejected characters can therefore still reach the generated startup command, so the stated validation boundary can be bypassed. Route every CR value used to build SERVICE_OPTS through the same validator, or validate them before constructing it.
    validateOptValue("spec.metastore.database.url", db.url());
    validateOptValue("spec.metastore.database.driver", db.driver());
    validateOptValue("spec.metastore.database.username", db.username());

packaging/src/kubernetes/src/java/org/apache/hive/kubernetes/operator/dependent/HiveDependentResource.java:401

  • This accepts an empty string, but callers treat any non-null driverJarUrl as configured and externalJars may also contain empty items. The value then falls through to the non-HTTP branch and generates hadoop fs -copyToLocal '', so malformed input still produces a failing init command instead of being rejected here. Reject empty (and null) locations before building the command.
    if (containsUnsafeShellChars(jarUrl)) {
      throw new IllegalArgumentException("external JAR location must not contain whitespace, quotes, backslashes or "
          + "control characters: " + jarUrl);

packaging/src/kubernetes/src/java/org/apache/hive/kubernetes/operator/dependent/HiveDependentResource.java:407

  • Correct the spelling in this newly added comment: use “spun-up” rather than “spinned up.”
      // and the spinned up pods to enter CrashLoopBackOff.

packaging/src/kubernetes/src/java/org/apache/hive/kubernetes/operator/model/spec/DatabaseConfig.java:30

  • Adding this CRD pattern changes the user-visible behavior: Kubernetes now rejects an invalid database type at admission instead of accepting the CR and letting reconciliation fail later. That conflicts with the PR description's Does this PR introduce any user-facing change? No; please update the description to document the validation behavior.
    @Pattern("^(derby|mysql|postgres|mssql|oracle)$")
  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

One or more issues must be addressed before approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity

Open (2)
Resolved since last review (2)
Previously missed (1)

In code that hasn't changed since last review

Low severity Fix typo and grammar in the new comment

packaging/​src/​kubernetes/​src/​java/​org/​apache/​hive/​kubernetes/​operator/​dependent/​HiveDependentResource.java:407

The new comment has a typo and awkward grammar: “spinned” should be “spun,” and the sentence needs a connector before “preventing.”

Comment on lines +405 to +408
Exception error = workflowResult.get().getErroredDependents().values().iterator().next();
String errorMessage = error.getMessage();
LOG.error("Error reconciling HiveCluster: {}/{} - {}", resource.getMetadata().getNamespace(),
resource.getMetadata().getName(), errorMessage, error);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in commit: 3cb1889

Comment on lines +382 to +384
validateOptValue("spec.metastore.database.url", db.url());
validateOptValue("spec.metastore.database.driver", db.driver());
validateOptValue("spec.metastore.database.username", db.username());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in commit: 3cb1889

Copilot AI 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.

Copilot review overview

🔵 Needs a closer look

The changes require final human review because they are too complex or risky for automated approval.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity

Open (2)

@sonarqubecloud

Copy link
Copy Markdown

@ayushtkn ayushtkn 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.

LGTM

@ayushtkn
ayushtkn merged commit 828f668 into apache:master Sep 21, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants