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

Prevent alerts to be sent to users who don't have access to the related service #3134

Conversation

thalesmiguel
Copy link
Contributor

What this PR does / why we need it:

This PR updates how we grant the permission to :show AlertRelatedEvents. Right now, any provider on an account has this permission, even though they might not have permissions for a service the alert refers to. With this PR, we're adding a check on service level to prevent the issue reported on the linked ticket.

Which issue(s) this PR fixes

fixes THREESCALE-6318

Verification steps

Verification steps copied from the linked ticket:

  1. As Admin user, create a Product i.e. Test API, an application and application plan. Set a limit of 2 requests per minute.
  2. Create a member i.e “Tom” user with the following rights:
    Accounts – Applications
    Analytics
    Integration & Application Plans
    Disable “All current and future APIs” and check 1 APi, i.e. Test API. 
  1. Sing in at the admin portal as Tom user and enable the following:
    • Go to the Gear icon - Settings > Notification Preferences > Usage Alerts. Check both “Alert usage warning” and “Alert usage violation”. Then Click Update Notificaton Preferences. See screenshot Notification_preferences.png.
    • Go to Product Cars > Applications > Settings - Usage Rules > Alerts, check both “Show Web Alerts to Admins of this Account” and “Send Email Alerts to Admins of this Account”, from 50% to 100%, see screenshot Alerts.png. Both alerts are necessary due to this issue THREESCALE-1870.
  2. Repeat the same steps 2 & 3 for another user, i.e. Marta, however don't allow access to Test API but to another API. See screenshot Marta.png.
  3. Make a request to Test API until hit the limit. Check the emails and you’ll see that Marta has received an alert email regarding Test Api which hasn’t access.

Special notes for your reviewer:

To test this, I ended-up having to run Events.async_fetch_backend_events! on a Rails console to force System to fetch the alert event from Apisonator. This might be happening due to a misconfiguration on my local environment but, just for the sake of sharing, I wanted to add this note to the PR.

@thalesmiguel thalesmiguel self-assigned this Dec 14, 2022
jlledom
jlledom previously approved these changes Dec 19, 2022
@jlledom jlledom requested a review from a team December 19, 2022 09:18
@mayorova
Copy link
Contributor

Looks good and works as expected, but I am wondering - would it make sense to move the check to provider_member.rb instead, as provider admin (not member) by definition has access to all services.

@thalesmiguel
Copy link
Contributor Author

would it make sense to move the check to provider_member.rb instead, as provider admin (not member) by definition has access to all services.

Good question, @mayorova.
This is the only place where we set permissions for events, so it's not clear to me if we could move all of them to be set on provider_member.rb.
By doing so, we'd also need to set those permissions on provider_admin.rb, but without checking for services, so the difference between those roles is clear.
Looks like things work correctly now because has_access_to_service? is able to determinate correctly which services a member or admin has access to 🤔
From what I can gather looking at the current code, I think it makes sense to try and set this permission for any provider, regardless of the role but I might be missing something...
All that to say that I'm not 100% sure one option makes more sense over the other. As a guideline, I try to have permissions set in a less places as possible but, of course, sometimes it makes sense to have it spread.

@mayorova
Copy link
Contributor

Yep, I am not sure whether there would be any benefit in splitting it between the two files (_member and _admin). So let's keep it where it is.

Copy link
Contributor

@akostadinov akostadinov left a comment

Choose a reason for hiding this comment

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

Looks nice!

I have one concern though. Do our users have the use case of a monitoring user that is not allowed to use the APIs? Because such use cases would be broken.

I'm not saying it makes sense. Just asking.

config/abilities/provider_any.rb Show resolved Hide resolved
config/abilities/provider_any.rb Show resolved Hide resolved
config/abilities/provider_any.rb Outdated Show resolved Hide resolved
@thalesmiguel
Copy link
Contributor Author

I have one concern though. Do our users have the use case of a monitoring user that is not allowed to use the APIs? Because such use cases would be broken.

This is interesting @akostadinov and MAYBE 3Scale supports that already.
I think this could be accomplished by saying a member has Access & query analytics of All current and future existing API products (or a set of products) 🤔
Screenshot 2022-12-20 at 10 14 52

If it's something used at all, I guess Product would be able to answer us.

jlledom
jlledom previously approved these changes Dec 20, 2022
mayorova
mayorova previously approved these changes Dec 22, 2022
Copy link
Contributor

@mayorova mayorova left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Copy link
Contributor

@josemigallas josemigallas left a comment

Choose a reason for hiding this comment

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

I only request the commits are rebased properly as discussed

@thalesmiguel
Copy link
Contributor Author

I only request the commits are rebased properly as discussed

@josemigallas My plan was actually to Squash and merge this PR, as I've been doing. Is it really a blocker for this PR not to have the 2 commits as suggested?

@thalesmiguel thalesmiguel dismissed stale reviews from mayorova and jlledom via be44278 December 22, 2022 14:40
@thalesmiguel thalesmiguel force-pushed the THREESCALE-6318-alert-mail-sent-to-unauthorized-users branch from 972db04 to be44278 Compare December 22, 2022 14:40
@thalesmiguel
Copy link
Contributor Author

Force pushed in order to have 2 commits: One for the fix and another one for the Rubocop warnings, as per #3134 (comment)

@thalesmiguel thalesmiguel merged commit b3b774b into 3scale:master Dec 23, 2022
@thalesmiguel thalesmiguel deleted the THREESCALE-6318-alert-mail-sent-to-unauthorized-users branch December 23, 2022 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants