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

feat(demo-mode): read-only user #79665

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Conversation

obostjancic
Copy link
Member

@obostjancic obostjancic commented Oct 24, 2024

  • Ensures this user can't create/edit organization resources by narrowing down the set of scopes given to the user
  • Ensures this user can't create/edit user resources (API Apps, Auth tokens etc.) by setting the SentryPermission class on User API endpoints
  • Closes: Create a read only member #79006

Context

  • In order to replace Current sandbox, which is a self-hosted instance available at https://try.sentry-demo.com/ we created a SaaS sandbox org https://sandbox.sentry.io/
  • Event data in sandbox org will be synced with demo org through sentry-mirror
  • In order to allow public access to this org we created a Demo User
    • that should have read-only access to only this org. PoC PR
    • that should be able to log in automatically. WIP PR
  • sandbox org and Demo User are behind demo-mode.orgs and demo-mode.users options respectively. Those options are added in PR

@obostjancic obostjancic requested a review from a team October 24, 2024 11:03
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 24, 2024
Copy link

codecov bot commented Oct 24, 2024

Codecov Report

Attention: Patch coverage is 98.16514% with 2 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/api/permissions.py 81.81% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #79665      +/-   ##
==========================================
+ Coverage   84.95%   87.76%   +2.81%     
==========================================
  Files        9487     9341     -146     
  Lines      539524   532799    -6725     
  Branches    21177    20267     -910     
==========================================
+ Hits       458344   467636    +9292     
+ Misses      80739    64781   -15958     
+ Partials      441      382      -59     

@obostjancic obostjancic added the Do Not Merge Don't merge label Oct 24, 2024
@obostjancic obostjancic changed the title feat: readonly user feat(demo-mode): readonly user Oct 29, 2024
@obostjancic obostjancic changed the title feat(demo-mode): readonly user feat(demo-mode): read-only user Oct 29, 2024
@obostjancic obostjancic marked this pull request as ready for review October 29, 2024 15:47
@obostjancic obostjancic requested review from a team as code owners October 29, 2024 15:47
@getsantry
Copy link
Contributor

getsantry bot commented Nov 26, 2024

This pull request has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you add the label WIP, I will leave it alone unless WIP is removed ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@getsantry getsantry bot added the Stale label Nov 26, 2024
@shellmayr shellmayr added the WIP label Nov 26, 2024
Copy link
Member

@leedongwei leedongwei left a comment

Choose a reason for hiding this comment

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

If we're confident that we don't have a GET/HEAD method that modifies data, then the approach seems reasonable to me.

src/sentry/api/permissions.py Outdated Show resolved Hide resolved
@evanpurkhiser
Copy link
Member

Are we planning to clean up all the old sandbox code in sentry?


email = getattr(user, "email", None)

return email in options.get("demo-mode.users")
Copy link
Member

Choose a reason for hiding this comment

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

Is this just a fixed set of demo users that can log in? Can new users sign up for accounts?

@@ -33,7 +33,7 @@ class AcceptProjectTransferEndpoint(Endpoint):
"POST": ApiPublishStatus.PRIVATE,
}
authentication_classes = (SessionAuthentication,)
permission_classes = (IsAuthenticated,)
permission_classes = (SentryPermission,)
Copy link
Member

Choose a reason for hiding this comment

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

We don't usually use SentryPermission directly, it's usually a base class we inherit from and apply scopes to.

It seems like if you use this directly, then no users will have permissions on this api:

allowed_scopes: set[str] = set(self.scope_map.get(request.method, []))
current_scopes = request.auth.get_scopes()
return any(s in allowed_scopes for s in current_scopes)

Since this just defined empty scopes, this any can't return True. Not sure if there's some other piece I'm missing that circumvents this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a read only member
5 participants