Skip to content
New issue

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

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

Already on GitHub? # to your account

Take expiry timestamp into account in stream connections #10299

Merged
merged 3 commits into from
Jan 22, 2024

Conversation

acogoluegnes
Copy link
Contributor

@acogoluegnes acogoluegnes commented Jan 9, 2024

PR for:

@mergify mergify bot added the bazel label Jan 9, 2024
@acogoluegnes acogoluegnes force-pushed the token-expiration-in-stream-connections branch 5 times, most recently from ea2c944 to 301aeed Compare January 15, 2024 16:51
@acogoluegnes acogoluegnes force-pushed the token-expiration-in-stream-connections branch 3 times, most recently from 32f9db8 to add0eaa Compare January 17, 2024 12:43
@acogoluegnes acogoluegnes marked this pull request as ready for review January 17, 2024 13:10
@acogoluegnes acogoluegnes changed the title Add expiry_timestamp/1 callback to authz backend behavior Take expiry timestamp into account in stream connections Jan 17, 2024
@acogoluegnes acogoluegnes force-pushed the token-expiration-in-stream-connections branch from add0eaa to c69dbd8 Compare January 17, 2024 15:21
@ansd ansd self-requested a review January 18, 2024 11:36
TimerRef =
maybe
rabbit_log:debug("Checking token expiry"),
true ?= rabbit_access_control:permission_cache_can_expire(User),
Copy link
Member

Choose a reason for hiding this comment

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

I wonder whether we can remove function rabbit_access_control:permission_cache_can_expire/1 in future? This function seems to be unnecessary given that we now have rabbit_access_control:expiry_timestamp/1 which will return never if the permission cache cannot expire. Ideally rabbit_channel will use the same new approach as done by Stream connections in this PR. This change doesn't have to be part of this PR though. However, ideally we don't add new calls to rabbit_access_control:permission_cache_can_expire/1 such that we can remove that funtion more easily in the future. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds reasonable. Do we try to remove rabbit_access_control:permission_cache_can_expire/1 in this PR? The sooner, the better.

Copy link
Member

Choose a reason for hiding this comment

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

It's up to you :) I also think, the sooner the better, yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

undefined ->
ok;
_ ->
timer:cancel(Timer)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can use the newer erlang:cancel_timer/2 API instead.

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 ended up using the timer-related functions in erlang instead of timer. I used {async, false} in erlang:cancel_timer/2 to be able to test the cancellation. Asynchronous would be better, but I don't think it makes much of a difference. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, that's perfect, synchronous cancellation (ie. {async, false}) is good enough in this rarely executed code path.

@acogoluegnes acogoluegnes force-pushed the token-expiration-in-stream-connections branch 2 times, most recently from efe3d83 to f3c029a Compare January 19, 2024 10:01
Backends return 'never' or the timestamp of the expiry time
of the credentials. Only the OAuth2 backend returns a timestamp,
other RabbitMQ authz backends return 'never'.

Client code uses rabbit_access_control, so it contains now
a new expiry_timestamp/1 function that returns the earliest
expiry time of the underlying backends.

Fixes #10298
Re-evaluate permissions, cancel publishers and
subscriptions, send metadata update accordingly.

Move record definitions from the stream reader
to a dedicated header file to be able to write
unit tests.

Fixes #10292
Stream write access is already checked when creating the publisher.

Fixes #10371
@acogoluegnes acogoluegnes force-pushed the token-expiration-in-stream-connections branch from f3c029a to 6fc3187 Compare January 19, 2024 13:47
@ansd ansd self-requested a review January 22, 2024 08:47
@ansd ansd added this to the 3.13.0 milestone Jan 22, 2024
@acogoluegnes acogoluegnes merged commit 3bd0fdc into main Jan 22, 2024
16 checks passed
@acogoluegnes acogoluegnes deleted the token-expiration-in-stream-connections branch January 22, 2024 09:23
@acogoluegnes acogoluegnes restored the token-expiration-in-stream-connections branch January 22, 2024 16:25
@acogoluegnes acogoluegnes deleted the token-expiration-in-stream-connections branch January 22, 2024 16:26
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants