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

rbac: add delay_deny implementation in RBAC network filter #33875

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

yangminzhu
Copy link
Contributor

Commit Message: If specified, the RBAC network filter will delay the specified duration before actually closing the connection.
Additional Description: This implements #33771.
Risk Level: Low
Testing: Added Unit Test and Integration Test
Manual Local Test Log:

[2024-04-30 11:03:14.080][22663692][debug][rbac] [source/extensions/filters/network/rbac/rbac_filter.cc:95] checking connection: requestedServerName: , sourceIP: 127.0.0.1:54006, directRemoteIP: 127.0.0.1:54006,remoteIP: 127.0.0.1:54006, localAddress: 127.0.0.1:10000, ssl: none, dynamicMetadata:
[2024-04-30 11:03:14.080][22663692][debug][rbac] [source/extensions/filters/network/rbac/rbac_filter.cc:201] enforced denied, matched policy none
[2024-04-30 11:03:14.080][22663692][debug][rbac] [source/extensions/filters/network/rbac/rbac_filter.cc:129] connection will be delay denied in 1000ms

Docs Changes: N/A
Release Notes: Updated version history
Platform Specific Features: N/A
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]

Copy link

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @wbpcode
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #33875 was opened by yangminzhu.

see: more, trace.

@yangminzhu
Copy link
Contributor Author

cc @kyessenov , @lambdai

If specified, the RBAC network filter will delay the specified duration
before actually closing the connection.

This implements envoyproxy#33771.

Signed-off-by: Yangmin Zhu <ymzhu@uber.com>
Signed-off-by: Yangmin Zhu <ymzhu@uber.com>
@yangminzhu
Copy link
Contributor Author

@wbpcode , @lambdai could you take another look if the api looks good? also wondering who should be reviewing the actual code changes? thanks.

Copy link
Member

@wbpcode wbpcode 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

(PS: sorry for the delay, I was on vacation last days.

@repokitteh-read-only repokitteh-read-only bot removed the api label May 7, 2024
@wbpcode wbpcode assigned yanavlasov and unassigned wbpcode May 7, 2024
Comment on lines +70 to +72
if (is_delay_denied_) {
return Network::FilterStatus::StopIteration;
}
Copy link
Member

Choose a reason for hiding this comment

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

should we drain the data to avoid buffering the data when we wait the timer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it be good enough if we just disable the read after line 123 with callbacks_->connection().readDisable(true);? That way we stop reading any data if we determined the authz result is deny regardless if it is immediate or delay deny? cc @lambdai

@wbpcode
Copy link
Member

wbpcode commented May 7, 2024

@yangminzhu could you merge the main and resolve the conflict? Thanks.

@wbpcode
Copy link
Member

wbpcode commented May 7, 2024

assign this to @yanavlasov for final review and because @yanavlasov is the code owner (and senior maintainer)

Copy link
Contributor

@yanavlasov yanavlasov left a comment

Choose a reason for hiding this comment

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

/wait

// result is DENY. If this is not present, the connection will be closed immediately.
// This is useful to provide a better protection for Envoy against clients that retries
// aggressively when the connection is rejected by the RBAC filter.
google.protobuf.Duration delay_deny = 8;
Copy link
Contributor

Choose a reason for hiding this comment

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

An optional suggestion for a better name. Feel free to ignore.

Suggested change
google.protobuf.Duration delay_deny = 8;
google.protobuf.Duration close_delay = 8;

)EOF");
IntegrationTcpClientPtr tcp_client = makeTcpConnection(lookupPort("listener_0"));
ASSERT_TRUE(tcp_client->write("hello", false, false));
tcp_client->waitForDisconnect();
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not really test that disconnect occurred after configured delay. You can use simulated time for that. Check out MultiplexedIntegrationTestWithSimulatedTime

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yanavlasov I checked MultiplexedIntegrationTestWithSimulatedTime and found it uses the Event::TestUsingSimulatedTime but not quite understand how it works.

The MultiplexedIntegrationTestWithSimulatedTime uses timeSystem().advanceTimeWait in its test case but the same statement doesn't seem working in the RBAC integration:

I subclassed TestUsingSimulatedTime and tried the same but it just never triggers the timer in the RBAC filter as the tcp_client->waitForDisconnect() is blocked forever, also tried simTime().advanceTimeWait but it is still not working.

would you mind expand a little bit how to use the simulated time in the integration test? thanks.

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.

None yet

5 participants