You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: text/0032-improved-api-tokens.md
+8-10Lines changed: 8 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -133,9 +133,9 @@ Second, we will need to secure the tokens. This involves four primary goals.
133
133
- Newly created user API application tokens have the `sntrya_` prefix
134
134
- We encourage users in the UI via a notification/banner to recreate their tokens in order to get new ones with a prefix
135
135
136
-
1. Nullable `hashed_token` and `hashed_refresh_token` fields are added to the `ApiToken` model
137
-
2. The `save()` method on `ApiToken` is updated to calculate and store the token's SHA-256 hash in `hashed_token`.
138
-
3. Update the `UserAuthTokenAuthentication` middleware to:
136
+
1. Nullable `hashed_token` and `hashed_refresh_token` fields are added to the `ApiToken` model[#65300](https://github.com/getsentry/sentry/pull/65300)[#66679](https://github.com/getsentry/sentry/pull/66679)
137
+
2. The `save()` method on `ApiToken` is updated to calculate and store the token's SHA-256 hash in `hashed_token`.[#67969](https://github.com/getsentry/sentry/pull/67969)
138
+
3. Update the `UserAuthTokenAuthentication` middleware to:[#67969](https://github.com/getsentry/sentry/pull/67969)
139
139
140
140
1. Caculate the SHA-256 hash and use the hash value for the table lookup on the `hashed_token` or `hashed_refresh_token` column.
141
141
2. If the hash is not found, use the plaintext token for the table lookup on the `token` or `refresh_token` column.
@@ -147,16 +147,14 @@ Second, we will need to secure the tokens. This involves four primary goals.
147
147
> _It's important to note that this does not update the token to the new prefixed format._
148
148
149
149
4. A nullable `token_type` field is added to the `ApiToken` model. It should accept a limited set of choices to indicate whether the token is `sntryu_`, `sntrya_`, etc. A _null_
150
-
value would indicate a legacy token that is not prefixed regardless of whether it is a user or application token.
151
-
5. A new _class method_ named `create_token(..)` is created on the `ApiToken` model. This method will return the plaintext token, plaintext refresh token, and `ApiToken`
152
-
instance to the caller. The plaintext token will be needed to display to the user temporarily in the UI.
153
-
6. Calls to `ApiToken.objects.create(..)` should be replaced with the new `ApiToken.create_token(..)` method.
154
-
7. API endpoints that retrieve the full plaintext token value should be updated to no longer do so. This should only be available on creation.
155
-
8. A notification/banner in the UI should be displayed recommending users recreate their tokens, resulting in the new token version.
150
+
value would indicate a legacy token that is not prefixed regardless of whether it is a user or application token. [#65684](https://github.com/getsentry/sentry/pull/65684)
151
+
5. Adjust `create(...)` method on the `ApiToken` model to hash the plaintext token values and temporary access to the plaintext values. [#68148](https://github.com/getsentry/sentry/pull/68148)
152
+
6. API endpoints that retrieve the full plaintext token value should be updated to no longer do so. This should only be available on creation. [#68148](https://github.com/getsentry/sentry/pull/68148)
153
+
7. A notification/banner in the UI should be displayed recommending users recreate their tokens, resulting in the new token version.
156
154
157
155
Next, any remaining legacy tokens that do not have hashed values will need to be handled:
158
156
159
-
1. As a Django migration, a bulk operation is executed to update all remaining legacy tokens in the database.
157
+
1. As a Django migration, a bulk operation is executed to update all remaining legacy tokens in the database.[#71728](https://github.com/getsentry/sentry/pull/71728)
160
158
- This operation will hash the legacy `token` and `refresh_token` values and store them in the database.
161
159
- It does **not** update the tokens to the new format.
0 commit comments