Skip to content

rbac: add matching range of destination ports#17356

Merged
htuch merged 14 commits intoenvoyproxy:mainfrom
zhxie:rbac-dport-range
Aug 1, 2021
Merged

rbac: add matching range of destination ports#17356
htuch merged 14 commits intoenvoyproxy:mainfrom
zhxie:rbac-dport-range

Conversation

@zhxie
Copy link
Copy Markdown
Contributor

@zhxie zhxie commented Jul 15, 2021

Signed-off-by: Xie Zhihao zhihao.xie@intel.com

Commit Message: rbac: add matching range of destination ports
Additional Description: use one destination port range rule to cover thousands of port rules in RBAC permissions, adding convenience for writing configuration and making matching quicker
Risk Level: Low
Testing: Unit
Docs Changes: N/A
Release Notes: Added
Platform Specific Features: N/A
Fixes #16039

@repokitteh-read-only
Copy link
Copy Markdown

Hi @zhxie, welcome and thank you for your contribution.

We will try to review your Pull Request as quickly as possible.

In the meantime, please take a look at the contribution guidelines if you have not done so already.

🐱

Caused by: #17356 was opened by zhxie.

see: more, trace.

@repokitteh-read-only
Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to api/envoy/.
envoyproxy/api-shepherds assignee is @adisuissa
CC @envoyproxy/api-watchers: FYI only for changes made to api/envoy/.

🐱

Caused by: #17356 was opened by zhxie.

see: more, trace.

@leyao-daily
Copy link
Copy Markdown
Member

please rebase and sign all your commits with git commit -s to pass DCO check.

@zhxie zhxie force-pushed the rbac-dport-range branch 2 times, most recently from 9b62ded to f4a7842 Compare July 15, 2021 12:45
Copy link
Copy Markdown
Contributor

@adisuissa adisuissa 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 on this!
Left a few API questions.

zhxie added 5 commits July 19, 2021 09:10
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
@zhxie zhxie force-pushed the rbac-dport-range branch from 9b0b76b to 33c9d44 Compare July 19, 2021 05:44
@zhxie zhxie changed the title [WIP] rbac: add matching range of destination ports rbac: add matching range of destination ports Jul 19, 2021
@zhxie zhxie marked this pull request as ready for review July 19, 2021 07:19
Copy link
Copy Markdown
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

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

/lgtm api

@zhxie
Copy link
Copy Markdown
Contributor Author

zhxie commented Jul 20, 2021

/retest

@repokitteh-read-only
Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #17356 (comment) was created by @zhxie.

see: more, trace.

@zhxie zhxie requested review from adisuissa and htuch July 21, 2021 01:37
@htuch
Copy link
Copy Markdown
Member

htuch commented Jul 23, 2021

@adisuissa could you also take a look at the first pass for implementation review when you're back? Thanks!

Copy link
Copy Markdown
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

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

Implementation and tests look good overall, thanks!
Left a couple of nits.

Comment on lines +109 to +110
perm->mutable_destination_port_range()->set_start(123);
perm->mutable_destination_port_range()->set_end(456);
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.

nit: why not copy range into destination_port_range?

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.

That's right. Unused variable has been removed.

checkMatcher(PortMatcher(456), false, conn, headers, info);
}

TEST(PortRangeMatcher, PortRangeMatcher) {
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.

Please add a short comment stating what the test validates.

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.

Ok, comment added.

@htuch htuch self-assigned this Jul 25, 2021
zhxie added 2 commits July 26, 2021 10:23
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
@zhxie zhxie force-pushed the rbac-dport-range branch from 41b6e39 to 1e9c882 Compare July 26, 2021 02:24
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
@zhxie zhxie requested a review from adisuissa July 27, 2021 02:11
adisuissa
adisuissa previously approved these changes Jul 27, 2021
Copy link
Copy Markdown
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM.
@htuch for the next pass

class PortRangeMatcher : public Matcher {
public:
PortRangeMatcher(const ::envoy::type::v3::Int32Range& range)
: start_(range.start()), end_(range.end()) {}
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.

Arguably we should reject negative and OOB values here for ports.

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.

To validate the range of ports, we are better to add a validation rule in RBAC proto.

// A port number range that describes a range of destination ports connecting to.
type.v3.Int32Range destination_port_range = 11;

But the type type.v3.Int32Range does not have any validation rules, and only certain types have validation rules that is located in validate.proto, which belongs to another repo envoyproxy/protoc-gen-validate. As a result, we are not easy to reject invalid or illegal values.

In addition, type.v3.Int32Range is also used in destination port matching in listener filter, but the ListenerFilterDstPortMatcher does not check its input.

// Match destination port. Particularly, the match evaluation must use the recovered local port if
// the owning listener filter is after :ref:`an original_dst listener filter <config_listener_filters_original_dst>`.
type.v3.Int32Range destination_port_range = 5;

/**
* Destination port matcher.
*/
class ListenerFilterDstPortMatcher final : public ListenerFilterMatcher {
public:
explicit ListenerFilterDstPortMatcher(const ::envoy::type::v3::Int32Range& range)
: start_(range.start()), end_(range.end()) {}

So I think maybe we do not have to add a check?

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.

Yes, this is a limit of PGV annotations and proto typing, I don't think it can be done cleanly at the proto annotation level. I think both ListenerFilterDstPortMatcher and your code could share a common utility that at config ingestion time, checks the port range and throws if invalid; this is the next best thing.

Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

LGTM modulo small ask.
/wait

zhxie added 3 commits July 30, 2021 10:04
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
@zhxie
Copy link
Copy Markdown
Contributor Author

zhxie commented Jul 30, 2021

/retest

@repokitteh-read-only
Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #17356 (comment) was created by @zhxie.

see: more, trace.

@zhxie
Copy link
Copy Markdown
Contributor Author

zhxie commented Jul 30, 2021

/retest

@repokitteh-read-only
Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #17356 (comment) was created by @zhxie.

see: more, trace.

@zhxie zhxie requested a review from htuch July 30, 2021 11:37
Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@htuch htuch merged commit 0d2418e into envoyproxy:main Aug 1, 2021
leyao-daily pushed a commit to leyao-daily/envoy that referenced this pull request Sep 30, 2021
use one destination port range rule to cover thousands of port rules in RBAC permissions, adding convenience for writing configuration and making matching quicker

Risk Level: Low
Testing: Unit
Docs Changes: N/A
Release Notes: Added
Platform Specific Features: N/A

Fixes envoyproxy#16039

Signed-off-by: Xie Zhihao <zhihao.xie@intel.com>
@zhxie zhxie deleted the rbac-dport-range branch September 7, 2022 08:27
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.

Support destination port range in config.rbac.Permission

4 participants