Skip to content

feat(auth): add scopes and org selection to ApiApplication#76974

Merged
sentaur-athena merged 3 commits into
masterfrom
athena/org-socpe-api-application
Sep 6, 2024
Merged

feat(auth): add scopes and org selection to ApiApplication#76974
sentaur-athena merged 3 commits into
masterfrom
athena/org-socpe-api-application

Conversation

@sentaur-athena

Copy link
Copy Markdown
Member

We want to be able to provides scopes for each application and store it in the model. Today the application requests the scope which is too loose.

The second change is to be able to limit the application scope to one org at a time. Basically if requires_org_level_access is true the user has to give the app permission twice to give the app access to 2 orgs.

@sentaur-athena sentaur-athena requested a review from a team as a code owner September 4, 2024 23:35
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Sep 4, 2024
@sentaur-athena sentaur-athena requested review from a team and mdtro September 4, 2024 23:36
@codecov

codecov Bot commented Sep 4, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff             @@
##           master   #76974       +/-   ##
===========================================
+ Coverage   57.14%   78.18%   +21.03%     
===========================================
  Files        6902     6912       +10     
  Lines      306931   307293      +362     
  Branches    50305    50350       +45     
===========================================
+ Hits       175408   240242    +64834     
+ Misses     126725    60605    -66120     
- Partials     4798     6446     +1648     

@sentaur-athena sentaur-athena force-pushed the athena/org-socpe-api-application branch from ac88332 to 5b346b8 Compare September 4, 2024 23:53
@github-actions

github-actions Bot commented Sep 4, 2024

Copy link
Copy Markdown
Contributor

This PR has a migration; here is the generated SQL for src/sentry/migrations/0754_add_scopes_to_apiapplication.py ()

--
-- Custom state/database change combination
--

                    ALTER TABLE "sentry_apiapplication"
                    ADD COLUMN "scopes" TEXT[] NULL,
                    ADD COLUMN "requires_org_level_access" BOOLEAN DEFAULT FALSE;

Comment on lines +51 to +56
migrations.AddField(
model_name="apiapplication",
name="scopes",
field=sentry.db.models.fields.array.ArrayField(null=True),
),
],

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.

Jfyi, you can just include this as a separate operation outside of the SeparateDatabaseAndState. It's safe to create a nullable column

@sentaur-athena sentaur-athena force-pushed the athena/org-socpe-api-application branch 2 times, most recently from 21d9641 to ef46622 Compare September 5, 2024 20:19
@github-actions

github-actions Bot commented Sep 5, 2024

Copy link
Copy Markdown
Contributor

This PR has a migration; here is the generated SQL for src/sentry/migrations/0755_add_scopes_to_apiapplication.py ()

--
-- Custom state/database change combination
--

                    ALTER TABLE "sentry_apiapplication"
                    ADD COLUMN "scopes" TEXT[] NULL,
                    ADD COLUMN "requires_org_level_access" BOOLEAN DEFAULT FALSE;

@markstory

Copy link
Copy Markdown
Member

We want to be able to provides scopes for each application and store it in the model. Today the application requests the scope which is too loose.

What will happen if an apiapplication has scopes stored in the database and a different set of scopes is provided during the authorization flow?

@sentaur-athena

Copy link
Copy Markdown
Member Author

@markstory we respect data base if it's tighter than what the app is asking for. For now though it's nullable and if it's null we don't change behavior at all.

@sentaur-athena sentaur-athena force-pushed the athena/org-socpe-api-application branch from 4c62545 to 7663f7d Compare September 6, 2024 19:41
@github-actions

github-actions Bot commented Sep 6, 2024

Copy link
Copy Markdown
Contributor

This PR has a migration; here is the generated SQL for src/sentry/migrations/0757_add_scopes_to_apiapplication.py ()

--
-- Custom state/database change combination
--

                    ALTER TABLE "sentry_apiapplication"
                    ADD COLUMN "scopes" TEXT[] NULL,
                    ADD COLUMN "requires_org_level_access" BOOLEAN DEFAULT FALSE;

@sentaur-athena sentaur-athena force-pushed the athena/org-socpe-api-application branch from 7663f7d to 2b5c428 Compare September 6, 2024 20:35
@sentaur-athena sentaur-athena merged commit 62eb4b4 into master Sep 6, 2024
@sentaur-athena sentaur-athena deleted the athena/org-socpe-api-application branch September 6, 2024 21:18
c298lee pushed a commit that referenced this pull request Sep 10, 2024
We want to be able to provides scopes for each application and store it
in the model. Today the application requests the scope which is too
loose.

The second change is to be able to limit the application scope to one
org at a time. Basically if `requires_org_level_access` is true the user
has to give the app permission twice to give the app access to 2 orgs.
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants