Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/network policy sql #30172

Merged
merged 1 commit into from
Nov 1, 2024

Conversation

jubrad
Copy link
Contributor

@jubrad jubrad commented Oct 23, 2024

Motivation

Adds SQL for managing network policies
Part of https://github.com/MaterializeInc/database-issues/issues/4637

Tips for reviewer

syntax discussed here #29814

Checklist

  • This PR has adequate test coverage / QA involvement has been duly considered. (trigger-ci for additional test/nightly runs)
  • This PR has an associated up-to-date design doc, is a design doc (template), or is sufficiently small to not require a design.
  • If this PR evolves an existing $T ⇔ Proto$T mapping (possibly in a backwards-incompatible way), then it is tagged with a T-proto label.
  • If this PR will require changes to cloud orchestration or tests, there is a companion cloud PR to account for those changes that is tagged with the release-blocker label (example).
  • If this PR includes major user-facing behavior changes, I have pinged the relevant PM to schedule a changelog post.

@jubrad jubrad self-assigned this Oct 23, 2024
@jubrad jubrad force-pushed the feature/network-policy-sql branch 8 times, most recently from dee5cb3 to bf15d75 Compare October 29, 2024 15:24
@jubrad jubrad marked this pull request as ready for review October 29, 2024 15:36
@jubrad jubrad requested review from a team as code owners October 29, 2024 15:36
@jubrad jubrad requested a review from jkosh44 October 29, 2024 15:36
@jubrad jubrad force-pushed the feature/network-policy-sql branch from bf15d75 to b91df2d Compare October 29, 2024 15:37
Copy link

shepherdlybot bot commented Oct 29, 2024

Risk Score:80 / 100 Bug Hotspots:7 Resilience Coverage:66%

Mitigations

Completing required mitigations increases Resilience Coverage.

  • (Required) Code Review 🔍 Detected
  • (Required) Feature Flag 🔍 Detected
  • (Required) Integration Test 🔍 Detected
  • (Required) Observability 🔍 Detected
  • (Required) QA Review
  • (Required) Run Nightly Tests
  • Unit Test
Risk Summary:

The pull request presents a high risk with a score of 80, driven by the predictors "Sum Bug Reports Of Files" and "Delta of Executable Lines." Historically, PRs with these predictors are 116% more likely to cause a bug than the repository baseline. Additionally, seven modified files are recent hotspots for bug fixes. The observed bug trend in the repository is increasing, indicating a need for careful review.

Note: The risk score is not based on semantic analysis but on historical predictors of bug occurrence in the repository. The attributes above were deemed the strongest predictors based on that history. Predictors and the score may change as the PR evolves in code, time, and review activity.

Bug Hotspots:
What's This?

File Percentile
../src/parser.rs 98
../catalog/state.rs 92
../defs/statement.rs 98
../src/catalog.rs 93
../coord/ddl.rs 91
../sequencer/inner.rs 97
../statement/ddl.rs 99

@jubrad jubrad force-pushed the feature/network-policy-sql branch from b91df2d to 0596606 Compare October 29, 2024 18:00
@jubrad jubrad requested a review from ParkMyCar October 29, 2024 19:44
@ParkMyCar
Copy link
Member

@jkosh44 I can review this one since I have the context paged in, feel free to unassign yourself!

@jkosh44
Copy link
Contributor

jkosh44 commented Oct 29, 2024

@jkosh44 I can review this one since I have the context paged in, feel free to unassign yourself!

Works for me.

@jkosh44 jkosh44 removed their request for review October 29, 2024 21:17
@jubrad jubrad force-pushed the feature/network-policy-sql branch from 0596606 to f9e585d Compare October 29, 2024 22:48
@jubrad jubrad mentioned this pull request Oct 30, 2024
5 tasks
@jubrad jubrad force-pushed the feature/network-policy-sql branch 2 times, most recently from 9a1519a to 427bc66 Compare October 30, 2024 16:32
Copy link
Member

@ParkMyCar ParkMyCar left a comment

Choose a reason for hiding this comment

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

By and large looks good to me, just some smaller changes I'd love to see before merging.

Btw I looked into the massive diff on the Persist stats snapshot, it's because you added a new variant to the AclMode struct which changed the proptest strategy for generating Datums. So no worries about that!

doc/user/content/sql/system-catalog/mz_internal.md Outdated Show resolved Hide resolved
src/sql-parser/src/ast/defs/statement.rs Outdated Show resolved Hide resolved
src/sql-parser/src/ast/defs/statement.rs Outdated Show resolved Hide resolved
src/sql-parser/src/parser.rs Outdated Show resolved Hide resolved
src/sql-parser/src/parser.rs Outdated Show resolved Hide resolved
src/adapter/src/catalog/transact.rs Outdated Show resolved Hide resolved
Comment on lines 54 to 55
// compute Network Policy
const CREATE_NETWORK_POLICY_CHAR: char = 'P';
Copy link
Member

Choose a reason for hiding this comment

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

how did you select P, feels like something we should run by the sql council? Also note the comment on the other consts capitalizes the letter in the resource that we're using here, e.g. this comment should be // network Policy if we use P

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, well it is the P in network Policy, whether that's good enough justification IDK, but it seems as reasonable as anything I can think of.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah it seems quite reasonable, we could also do n but that might confuse users with N, sticking with P sounds good to me

src/catalog/src/durable/transaction.rs Outdated Show resolved Hide resolved
doc/user/sql-grammar/sql-grammar.bnf Show resolved Hide resolved
Comment on lines 35 to 39
SHOW NETWORK POLICIES
----
np
(empty)
Copy link
Member

Choose a reason for hiding this comment

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

should SHOW NETWORK POLICIES include more info? maybe the rules that are in the policy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated this to include rules, for better or worse, I went with a similar model to how we display replicas on clusters. The downside to this is that one could create a policy with 25 rules, leading to a rather long value.

Copy link
Member

Choose a reason for hiding this comment

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

That looks good to me!

@jubrad jubrad force-pushed the feature/network-policy-sql branch 3 times, most recently from c74e4e5 to 4851fc5 Compare October 31, 2024 04:57
@jubrad jubrad force-pushed the feature/network-policy-sql branch from 4851fc5 to d15206a Compare October 31, 2024 14:51
@jubrad jubrad requested a review from ParkMyCar October 31, 2024 15:05
@jubrad jubrad force-pushed the feature/network-policy-sql branch 5 times, most recently from e360c89 to 5bfe9cd Compare October 31, 2024 18:50
Copy link
Member

@ParkMyCar ParkMyCar left a comment

Choose a reason for hiding this comment

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

Thanks for working through this one, looks great!

@jubrad jubrad merged commit 289410e into MaterializeInc:main Nov 1, 2024
83 checks passed
ParkMyCar added a commit that referenced this pull request Nov 11, 2024
<!--
Describe the contents of the PR briefly but completely.

If you write detailed commit messages, it is acceptable to copy/paste
them
here, or write "see commit messages for details." If there is only one
commit
in the PR, GitHub will have already added its commit message above.
-->

### Motivation
- adds a new predefined network policy
- removes the allow list based policy system var
  in favor of a new `network_policy` system var
- swaps policy enforcement to use the default policy.

stacked on #30172
part of MaterializeInc/database-issues#4637

<!--
Which of the following best describes the motivation behind this PR?

  * This PR fixes a recognized bug.

    [Ensure issue is linked somewhere.]

  * This PR adds a known-desirable feature.

    [Ensure issue is linked somewhere.]

  * This PR fixes a previously unreported bug.

    [Describe the bug in detail, as if you were filing a bug report.]

  * This PR adds a feature that has not yet been specified.

[Write a brief specification for the feature, including justification
for its inclusion in Materialize, as if you were writing the original
     feature specification.]

   * This PR refactors existing code.

[Describe what was wrong with the existing code, if it is not obvious.]
-->

### Tips for reviewer

If you are reviewing this prior to #30172 going in, you should only look
at the `add predefined network policy and system var` commit.

<!--
Leave some tips for your reviewer, like:

    * The diff is much smaller if viewed with whitespace hidden.
    * [Some function/module/file] deserves extra attention.
* [Some function/module/file] is pure code movement and only needs a
skim.

Delete this section if no tips.
-->

### Checklist

- [ ] This PR has adequate test coverage / QA involvement has been duly
considered. ([trigger-ci for additional test/nightly
runs](https://trigger-ci.dev.materialize.com/))
- [ ] This PR has an associated up-to-date [design
doc](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/design/README.md),
is a design doc
([template](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/design/00000000_template.md)),
or is sufficiently small to not require a design.
  <!-- Reference the design in the description. -->
- [ ] If this PR evolves [an existing `$T ⇔ Proto$T`
mapping](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/command-and-response-binary-encoding.md)
(possibly in a backwards-incompatible way), then it is tagged with a
`T-proto` label.
- [ ] If this PR will require changes to cloud orchestration or tests,
there is a companion cloud PR to account for those changes that is
tagged with the release-blocker label
([example](MaterializeInc/cloud#5021)).
<!-- Ask in #team-cloud on Slack if you need help preparing the cloud
PR. -->
- [ ] If this PR includes major [user-facing behavior
changes](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/guide-changes.md#what-changes-require-a-release-note),
I have pinged the relevant PM to schedule a changelog post.

---------

Co-authored-by: Parker Timmerman <[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.

4 participants