Skip to content

Conversation

@beliefer
Copy link
Contributor

What changes were proposed in this pull request?

The current implementation of persistent view is create hive table with view text.
The view text is just a query string, so the hackers may tamper with it through various means.
Such as, select * from tab1 tampered with drop table tab1.

Why are the changes needed?

First, the view text is query string, parser.parsePlan(viewText) occurs more overhead than parser.parseQuery(viewText).
Second, the view text can be tampered by hackers and issue security vulnerabilities.

Does this PR introduce any user-facing change?

'No'. Unless hackers tamper view text, user will not see any change.

How was this patch tested?

New tests.

@github-actions github-actions bot added the SQL label Nov 10, 2021
@SparkQA
Copy link

SparkQA commented Nov 10, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/49524/

@SparkQA
Copy link

SparkQA commented Nov 10, 2021

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/49524/

@SparkQA
Copy link

SparkQA commented Nov 10, 2021

Test build #145054 has finished for PR 34543 at commit dc46ba4.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Nov 10, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/49534/

@SparkQA
Copy link

SparkQA commented Nov 10, 2021

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/49534/

@SparkQA
Copy link

SparkQA commented Nov 10, 2021

Test build #145064 has finished for PR 34543 at commit b3f898c.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@beliefer
Copy link
Contributor Author

ping @MaxGekk @gengliangwang
cc @cloud-fan

parser.parseQuery(viewText)
} catch {
case _: ParseException => throw new AnalysisException(
s"Invalid view text of view ${metadata.qualifiedName}, it may have been tampered with")
Copy link
Contributor

Choose a reason for hiding this comment

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

shall we display the view sql text as wel?

Copy link
Contributor

Choose a reason for hiding this comment

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

and let's move the error to QueryCompilationErrors.scala

parser.parseQuery(viewText)
} catch {
case _: ParseException => throw new AnalysisException(
s"Invalid view text of view ${metadata.qualifiedName}, it may have been tampered with")
Copy link
Contributor

Choose a reason for hiding this comment

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

and let's move the error to QueryCompilationErrors.scala


test("SPARK-37266: Optimize the analysis for view text of persistent view and" +
" fix security vulnerabilities caused by sql tampering") {
val table = hiveContext.sessionState.catalog.getTableMetadata(TableIdentifier("parquet_view1"))
Copy link
Contributor

Choose a reason for hiding this comment

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

can we create a new view to test it instead of altering an existing view?

@SparkQA
Copy link

SparkQA commented Nov 11, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/49583/

@SparkQA
Copy link

SparkQA commented Nov 11, 2021

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/49583/

@SparkQA
Copy link

SparkQA commented Nov 11, 2021

Test build #145113 has finished for PR 34543 at commit a51a184.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Nov 12, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/49597/

@SparkQA
Copy link

SparkQA commented Nov 12, 2021

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/49597/

// Simulate the behavior of hackers
val tamperedViewText = "drop view parquet_view2"
val tamperedTable = table.copy(viewText = Some(tamperedViewText))
hiveContext.sessionState.catalog.alterTable(tamperedTable)
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like we can run this test in sql/core, as it does not rely on hive. Can we move it to PersistedViewTestSuite?


test("SPARK-37266: Optimize the analysis for view text of persistent view and" +
" fix security vulnerabilities caused by sql tampering") {
sql("CREATE VIEW parquet_view2 as select * from parquet_tab4")
Copy link
Contributor

Choose a reason for hiding this comment

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

can be simpler CREATE VIEW v AS SELECT 1

@SparkQA
Copy link

SparkQA commented Nov 12, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/49608/

test("SPARK-37266: Optimize the analysis for view text of persistent view and" +
" fix security vulnerabilities caused by sql tampering") {
sql("CREATE VIEW v AS SELECT 1")
val table = spark.sessionState.catalog.getTableMetadata(TableIdentifier("v"))
Copy link
Contributor

Choose a reason for hiding this comment

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

let's wrap the test with withView

}

test("SPARK-37266: Optimize the analysis for view text of persistent view and" +
" fix security vulnerabilities caused by sql tampering") {
Copy link
Contributor

Choose a reason for hiding this comment

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

we can shorten the test name: SPARK-37266: view text can only be SELECT queries

@SparkQA
Copy link

SparkQA commented Nov 12, 2021

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/49608/

@SparkQA
Copy link

SparkQA commented Nov 12, 2021

Test build #145126 has finished for PR 34543 at commit 81f0ba1.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Nov 12, 2021

Test build #145137 has finished for PR 34543 at commit 1d8495c.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@beliefer beliefer changed the title [SPARK-37266][SQL] Optimize the analysis for view text of persistent view and fix security vulnerabilities caused by sql tampering [SPARK-37266][SQL] View text can only be SELECT queries Nov 12, 2021
@SparkQA
Copy link

SparkQA commented Nov 12, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/49639/

@SparkQA
Copy link

SparkQA commented Nov 12, 2021

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/49639/

@SparkQA
Copy link

SparkQA commented Nov 12, 2021

Test build #145169 has finished for PR 34543 at commit 77cbbdf.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Nov 13, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/49647/

@SparkQA
Copy link

SparkQA commented Nov 13, 2021

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/49647/

@SparkQA
Copy link

SparkQA commented Nov 13, 2021

Test build #145178 has finished for PR 34543 at commit 0f46831.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

cloud-fan commented Nov 15, 2021

thanks, merging to master!

@cloud-fan cloud-fan closed this in 6391655 Nov 15, 2021
@beliefer
Copy link
Contributor Author

@cloud-fan Thank you for your review.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants