Skip to content

Commit 6aebe17

Browse files
authored
Merge pull request #2 from Turbo87/token-scopes-improvements
Improve token scopes proposal
2 parents f5f12a7 + 1d9527e commit 6aebe17

File tree

1 file changed

+26
-54
lines changed

1 file changed

+26
-54
lines changed

text/0000-crates-io-token-scopes.md

Lines changed: 26 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,12 @@ adding the following endpoint scopes:
4242
* **yank**: allows yanking and unyanking existing versions of the user's crates
4343
* **change-owners**: allows inviting new owners or removing existing owners
4444
* **legacy**: allows accessing all the endpoints on crates.io except for
45-
creating new tokens, like tokens created befores the implementation of this
45+
creating new tokens, like tokens created before the implementation of this
4646
RFC.
4747

4848
More endpoint scopes might be added in the future without the need of a
4949
dedicated RFC.
5050

51-
The crates.io UI will pre-select the scopes needed by the `cargo` CLI, which at
52-
the time of writing this RFC are `publish-new`, `publish-update`, `yank` and
53-
`change-owners`. The user will have to explicitly opt into extra scopes or the
54-
legacy permission model.
55-
5651
Tokens created before the implementation of this RFC will default to the legacy
5752
scope.
5853

@@ -61,44 +56,45 @@ scope.
6156
The user will be able to opt into limiting which crates the token can act on by
6257
defining a crates scope.
6358

64-
The crates scope can be left empty to allow the token to act on all the crates
65-
owned by the user, or it can contain the comma-separated list of crate names
66-
the token can interact with. Crate names can contain `*` to match zero or more
67-
characters.
59+
The crates scope can contain a list of crate name patterns the token can
60+
interact with. Crate name patterns can either be regular crate names or they
61+
can end with a `*` character to match zero or more characters.
6862

69-
For example, a crates scope of `lazy_static,serde*` allows the token to act on
70-
the `lazy_static` crate or any present or future crates starting with `serde`
71-
(including `serde` itself), if the user is an owner of those crates.
63+
For example, a crate name pattern of `lazy_static` will only make the token
64+
apply to the corresponding crate, while `serde*` allows the token to act on
65+
any present or future crates starting with `serde` (including `serde` itself),
66+
but only if the user is an owner of those crates.
7267

7368
The crates scope will allow access to all present and future crates matching
7469
it. When an endpoint that doesn't interact with crates is called by a token
7570
with a crates scope, the crates scope will be ignored and the call will be
76-
authorized.
71+
authorized, unless limited by an endpoint scope (see above).
7772

7873
Tokens created before the implementation of this RFC will default to an empty
7974
crate scope filter (equivalent to no restrictions).
8075

8176
# Reference-level explanation
8277
[reference-level-explanation]: #reference-level-explanation
8378

84-
Endpoint scopes and crates scope are two completly separate systems, and can be
85-
used independently from one another. Token scopes will be implemented entirely
86-
on the crates.io side, and there will be no change to `cargo` or alternate
87-
registries.
79+
Endpoint scopes and crates scope are two completely separate systems, and can be
80+
used independently of one another.
81+
82+
Token scopes will be implemented entirely on the crates.io side, and there will
83+
be no change necessary to `cargo` or alternate registries.
8884

8985
## Endpoint scopes
9086

9187
The scopes proposed by this RFC allow access to the following endpoints:
9288

93-
| Endpoint | Required scope |
94-
| --- | --- |
95-
| `PUT /crates/new` (new crates) | **publish-new** |
96-
| `PUT /crates/new` (existing crates) | **publish-update** |
97-
| `DELETE /crates/:crate_id/:version/yank` | **yank** |
98-
| `PUT /crates/:crate_id/:version/unyank` | **yank** |
99-
| `PUT /crates/:crate_id/owners` | **change-owners** |
100-
| `DELETE /crates/:crate_id/owners` | **change-owners** |
101-
| everything except `PUT /me/tokens` | **legacy** |
89+
| Endpoint | Required scope |
90+
|------------------------------------------|--------------------|
91+
| `PUT /crates/new` (new crates) | **publish-new** |
92+
| `PUT /crates/new` (existing crates) | **publish-update** |
93+
| `DELETE /crates/:crate_id/:version/yank` | **yank** |
94+
| `PUT /crates/:crate_id/:version/unyank` | **yank** |
95+
| `PUT /crates/:crate_id/owners` | **change-owners** |
96+
| `DELETE /crates/:crate_id/owners` | **change-owners** |
97+
| everything except `PUT /me/tokens` | **legacy** |
10298

10399
Removing an endpoint from a scope or adding an existing endpoint to an existing
104100
scope will be considered a breaking change. Adding newly created endpoints to
@@ -108,31 +104,7 @@ existing set of endpoints in that scope.
108104

109105
## Crates scope
110106

111-
The pattern for the crate scope is desugared into a regular expression,
112-
following these rules:
113-
114-
* **`^(`** is added at the start of the pattern, and **`)$`** is added at the end of it.
115-
* **`,`** is desugared into `|`, separating multiple patterns.
116-
* **`*`** is desugared into `.*`, matching zero or more characters greedily.
117-
* All other non-alphanumeric characters are quoted to prevent them from having
118-
a special meaning.
119-
120-
As an example, the following pattern:
121-
122-
```
123-
foo,bar-*
124-
```
125-
126-
... is desugared into the following regex:
127-
128-
```
129-
^(foo|bar\-.*)$
130-
```
131-
132-
Any combination of those characters is allowed, but crates.io might define a
133-
complexity limit for the generated regular expressions.
134-
135-
The pattern will be evaluated during each API call, and if no match is found
107+
The patterns will be evaluated during each API call, and if no match is found
136108
the request will be denied. Because it's evaluated every time, a crates scope
137109
will allow interacting with matching crates published after token creation.
138110

@@ -162,7 +134,7 @@ in the RFC author's opinion, are more likely to need crate scopes than a person
162134
with just a few crates), and it wouldn't allow new crates matching the pattern
163135
but uploaded after the token's creation from being accessed.
164136

165-
Finally an alternative could be to do nothing, and encourage users to create
137+
Finally, an alternative could be to do nothing, and encourage users to create
166138
"machine accounts" for each set of crates they own. A drawback of this is that
167139
GitHub's terms of service limit how many accounts a single person could have.
168140

@@ -222,7 +194,7 @@ implementation of solutions that would make the check hard.
222194
To increase the security of CI environments even more, we could implement an
223195
option to require a separate confirmation for the actions executed by tokens.
224196
For example, we could send a confirmation email with a link the owners have to
225-
click to actually publish the crate uploaded by CI, preventing any mailicious
197+
click to actually publish the crate uploaded by CI, preventing any malicious
226198
action with stolen tokens.
227199

228200
To remove the need for machine accounts, a future RFC could propose adding API

0 commit comments

Comments
 (0)