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

Redesign Scoped Access Tokens #24767

Merged
merged 70 commits into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
ce18b9a
update scopes, replace in tests, api route definitions, WIP on tests,…
jackHay22 May 9, 2023
17663a4
fix some tests
jackHay22 May 9, 2023
2b2cdc9
revert token scope reorg
jackHay22 May 9, 2023
8c0e8dc
split out the token scope check
jackHay22 May 9, 2023
0fc8dd1
add migration, fix integration tests, updates to scopes
jackHay22 May 16, 2023
5bb478d
update access token scope selection
jackHay22 May 16, 2023
3bb330e
fix scope selection logic
jackHay22 May 16, 2023
28c9dcd
update comment
jackHay22 May 16, 2023
5d90011
hide admin section if not admin
jackHay22 May 17, 2023
b439ccf
linting fixes
jackHay22 May 17, 2023
e405ab5
linting fixes
jackHay22 May 17, 2023
8850928
fix test
jackHay22 May 17, 2023
c05d22e
add permissions for gpg test
jackHay22 May 17, 2023
de80a3d
rework checkboxes
jackHay22 May 17, 2023
6df3808
check public org/repo at specific route middleware, fix public option…
jackHay22 May 18, 2023
149cb89
make public/private a radio button
jackHay22 May 18, 2023
21be460
fix test
jackHay22 May 18, 2023
9eca1fe
fix redundant check
jackHay22 May 18, 2023
bb59102
add warning if no scopes selected
jackHay22 May 19, 2023
a077bd0
Fix so that migration doesn't depend on non-migration code
jtran May 24, 2023
c95343c
Fix to initialize capacity
jtran May 24, 2023
2486584
Change public only value to be clearer
jtran May 24, 2023
80772f9
Fix to check type of Data value
jtran May 24, 2023
2216d6b
Change to short-circuit
jtran May 24, 2023
2996b87
Rename variable to be clearer
jtran May 24, 2023
4c406d9
Move early return check to top
jtran May 24, 2023
2bdeac0
Fix to preserve unknown token scopes in the migration
jtran May 24, 2023
cdef14b
Fix formatting
jtran May 24, 2023
be57005
Fix copyright date
jtran May 24, 2023
eff94f1
Add tests that verify that API access tokens deny access
jtran May 25, 2023
94424cb
Fix to not have JS error on other pages
jtran May 26, 2023
75254a0
Remove redundant name field from Vue component
jtran May 26, 2023
5da5715
Change to not display the issue category in the UI
jtran May 26, 2023
80bcbee
Fix public-only in the form
jtran May 26, 2023
b46fd71
Fix to use locale and change "scope" to "permission"
jtran May 26, 2023
bb9ab9c
Fix public-private form UI wording and alignment
jtran May 26, 2023
8fe485b
Remove misleading description text
jtran May 26, 2023
fa903f9
Fix to show public-only access for existing tokens
jtran May 26, 2023
26a4914
Change wording to be clearer about limited visibility access
jtran May 26, 2023
c7ff458
Remove issue category from frontend
jtran May 26, 2023
76b7dbf
Change test order to be alphabetic
jtran May 27, 2023
30faca5
Rename variable to be clearer
jtran May 28, 2023
1ad3b7e
Change formatting to be clearer
jtran May 28, 2023
577673b
Add test that delete scope can also read
jtran May 28, 2023
f932ad8
Change padding based on review
jtran May 28, 2023
2ba71e1
Change to not use inline styles
jtran May 28, 2023
9e7f300
Fix no scope selected warning
kdumontnu May 28, 2023
fcc8595
Add small description
kdumontnu May 28, 2023
b4ad948
Move issue to seperate route
kdumontnu May 29, 2023
4d67b4a
Move repo notifications to seperate route
kdumontnu May 29, 2023
af17f87
Update documentation
kdumontnu May 29, 2023
04f55e1
Add activitypub to documentation
kdumontnu May 29, 2023
24a1a99
apply review feedback
jackHay22 May 30, 2023
67a63fe
revert formatting
jackHay22 May 30, 2023
89c640b
add migration to list, add test for migration
jackHay22 May 31, 2023
f3390f6
add test for idempotent scope conversion
jackHay22 May 31, 2023
d36f036
linting fix
jackHay22 May 31, 2023
a3d67d1
fixes
jackHay22 May 31, 2023
c749400
Merge branch 'main' into jh/feat-redesign-scoped-pats
kdumontnu Jun 1, 2023
d8d1472
apply review feedback
jackHay22 Jun 1, 2023
1c3023e
fix autoformat
jackHay22 Jun 1, 2023
566ea50
Update web_src/js/components/ScopedAccessTokenSelector.vue
silverwind Jun 1, 2023
02a1b03
Update web_src/js/components/ScopedAccessTokenSelector.vue
silverwind Jun 1, 2023
67e1531
Update web_src/js/components/ScopedAccessTokenSelector.vue
silverwind Jun 1, 2023
fccb03e
Merge branch 'main' into jh/feat-redesign-scoped-pats
kdumontnu Jun 2, 2023
cb233ca
merge write and delete scopes
jackHay22 Jun 2, 2023
4d3fea8
update scope selection ui
jackHay22 Jun 2, 2023
a855029
remove delete scopes from documentation
jackHay22 Jun 2, 2023
cb6c9ee
update comment to remove 'delete'
jackHay22 Jun 2, 2023
45e8376
Merge branch 'main' into jh/feat-redesign-scoped-pats
kdumontnu Jun 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 44 additions & 33 deletions docs/content/doc/development/oauth2-provider.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,42 +44,53 @@ To use the Authorization Code Grant as a third party application it is required

## Scopes

Gitea supports the following scopes for tokens:
Gitea supports scoped access tokens, which allow users the ability to restrict tokens to operate only on selected url routes. Scopes are grouped by high-level API routes, and further refined to the following:

- `read`: `GET` routes
- `write`: `POST`, `PUT`, and `PATCH` routes (in addition to `GET`)
- `delete`: `DELETE` routes (in addition to `POST`, `PUT`, `PATCH` and `GET`)
Copy link
Contributor

@wxiaoguang wxiaoguang Jun 2, 2023

Choose a reason for hiding this comment

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

I guess something like "full" or "manage" is a better name than "delete".


For example: IMO "transfer a repo" is "full manage", but not "write" or "delete".


Gitea token scopes are as follows:
Copy link
Contributor

Choose a reason for hiding this comment

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

The "public only" is not mentioned here but appears in code, I still have difficulty to understand what is "public only" or what it affects .....


| Name | Description |
| ---- | ----------- |
| **(no scope)** | Grants read-only access to public user profile and public repositories. |
| **repo** | Full control over all repositories. |
|     **repo:status** | Grants read/write access to commit status in all repositories. |
|     **public_repo** | Grants read/write access to public repositories only. |
| **admin:repo_hook** | Grants access to repository hooks of all repositories. This is included in the `repo` scope. |
|     **write:repo_hook** | Grants read/write access to repository hooks |
|     **read:repo_hook** | Grants read-only access to repository hooks |
| **admin:org** | Grants full access to organization settings |
|     **write:org** | Grants read/write access to organization settings |
|     **read:org** | Grants read-only access to organization settings |
| **admin:public_key** | Grants full access for managing public keys |
|     **write:public_key** | Grant read/write access to public keys |
|     **read:public_key** | Grant read-only access to public keys |
| **admin:org_hook** | Grants full access to organizational-level hooks |
| **admin:user_hook** | Grants full access to user-level hooks |
| **notification** | Grants full access to notifications |
| **user** | Grants full access to user profile info |
|     **read:user** | Grants read access to user's profile |
|     **user:email** | Grants read access to user's email addresses |
|     **user:follow** | Grants access to follow/un-follow a user |
| **delete_repo** | Grants access to delete repositories as an admin |
| **package** | Grants full access to hosted packages |
|     **write:package** | Grants read/write access to packages |
|     **read:package** | Grants read access to packages |
|     **delete:package** | Grants delete access to packages |
| **admin:gpg_key** | Grants full access for managing GPG keys |
|     **write:gpg_key** | Grants read/write access to GPG keys |
|     **read:gpg_key** | Grants read-only access to GPG keys |
| **admin:application** | Grants full access to manage applications |
|     **write:application** | Grants read/write access for managing applications |
|     **read:application** | Grants read access for managing applications |
| **sudo** | Allows to perform actions as the site admin. |
| **(no scope)** | Not supported. A scope is required even for public repositories. |
lunny marked this conversation as resolved.
Show resolved Hide resolved
| **activitypub** |`activitypub` API routes: ActivityPub related operations. |
|     **read:activitypub** | Grants read access for ActivityPub operations. |
|     **write:activitypub** | Grants read/write access for ActivityPub operations. |
|     **delete:activitypub** | Grants read/write/delete access for ActivityPub operations. Currently the same as `write:activitypub`. |
| **admin** | `/admin/*` API routes: Site-wide administrative operations (hidden for non-admin accounts). |
|     **read:admin** | Grants read access for admin operations, such as getting cron jobs or registered user emails. |
|     **write:admin** | Grants read/write access for admin operations, such as running cron jobs or updating user accounts. |
|     **delete:admin** | Grants read/write/delete access for admin operations, such as deleting user accounts. |
| **issue** | `issues/*`, `labels/*`, `milestones/*` API routes: Issue-related operations. |
|     **read:issue** | Grants read access for issues operations, such as getting issue comments, issue attachments, and milestones. |
|     **write:issue** | Grants read/write access for issues operations, such as posting or editing an issue comment or attachment, and updating milestones. |
|     **delete:issue** | Grants read/write/delete access for issues operations, such as deleting comments, labels or issue attachments. |
| **misc** | miscellaneous and settings top-level API routes. |
|     **read:misc** | Grants read access to miscellaneous operations, such as getting label and gitignore templates. |
|     **write:misc** | Grants read/write access to miscellaneous operations, such as markup utility operations. |
|     **delete:misc** | Grants read/write/delete access to miscellaneous operations. Currently the same as `write:misc`. |
| **notification** | `notification/*` API routes: user notification operations. |
|     **read:notification** | Grants read access to user notifications, such as which notifications users are subscribed to and read new notifications. |
|     **write:notification** | Grants read/write access to user notifications, such as marking notifications as read. |
|     **delete:notification** | Grants read/write/delete access to user notifications. Currently the same as `write:notification`. |
| **organization** | `orgs/*` and `teams/*` API routes: Organization and team management operations. |
|     **read:organization** | Grants read access to org and team status, such as listing all orgs a user has visibility to, teams, and team members. |
|     **write:organization** | Grants read/write access to org and team status, such as creating and updating teams and updating org settings. |
|     **delete:organization** | Grants read/write/delete access to org and team status, such as deleting teams and orgs. |
| **package** | `/packages/*` API routes: Packages operations |
|     **read:package** | Grants read access to package operations, such as reading and downloading available packages. |
|     **write:package** | Grants read/write access to package operations. Currently the same as `read:package`. |
|     **delete:package** | Grants read/write/delete access to package operations, such as deleting packages. |
| **repository** | `/repos/*` API routes except `/repos/issues/*`: Repository file, pull-request, and release operations. |
Copy link
Member

Choose a reason for hiding this comment

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

I have a slight feeling that this is precisely the category we should split up into distinct categories as those are again completely different subcategories - typically, you either want the whole package, or you only want to interact with 2-3 parts of the API, i.e. pulling all issues and PRs, perhaps writing back to them or creating a new release.
At best, you don't want to touch file states or even releases.

|     **read:repository** | Grants read access to repository operations, such as getting repository files, releases, collaborators. |
|     **write:repository** | Grants read/write access to repository operations, such as getting updating repository files, creating pull requests, updating collaborators. |
|     **delete:repository** | Grants read/write/delete access to repository operations, such as getting deleting repository file, delete pull-request, removing collaborators. |
| **user** | `/user/*` and `/users/*` API routes: User-related operations. |
|     **read:user** | Grants read access to user operations, such as getting user repo subscriptions and user settings. |
|     **write:user** | Grants read/write access to user operations, such as updating user repo subscriptions, followed users, and user settings. |
|     **delete:user** | Grants read/write/delete access to user operations, such as removing user repo subscriptions. |

## Client types

Expand Down
9 changes: 9 additions & 0 deletions models/auth/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ func NewAccessToken(t *AccessToken) error {
return err
}

// DisplayPublicOnly whether to display this as a public-only token.
func (t *AccessToken) DisplayPublicOnly() bool {
publicOnly, err := t.Scope.PublicOnly()
if err != nil {
return false
}
return publicOnly
}

func getAccessTokenIDFromCache(token string) int64 {
if successfulAccessTokenCache == nil {
return 0
Expand Down
Loading