Skip to content

Commit 618bfe2

Browse files
authored
feat: increase max_length for api tokens (#65743)
In support of getsentry/rfcs#32. API Tokens will be prefixed with seven extra characters (ex. `sntryu_`). Eventually these plaintext `token` columns will be dropped, but to maintain backwards compatibility and a smooth transition to fully hashed tokens we'll still want to store them here.
1 parent f52dd18 commit 618bfe2

File tree

5 files changed

+77
-5
lines changed

5 files changed

+77
-5
lines changed

migrations_lockfile.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ To resolve this, rebase against latest master and regenerate your migration. Thi
66
will then be regenerated, and you should be able to merge without conflicts.
77

88
feedback: 0004_index_together
9-
hybridcloud: 0011_add_hybridcloudapitoken_index
9+
hybridcloud: 0012_apitoken_increase_token_length
1010
nodestore: 0002_nodestore_no_dictfield
1111
replays: 0004_index_together
12-
sentry: 0654_rename_priority_sort_to_trends
12+
sentry: 0655_apitoken_increase_token_length
1313
social_auth: 0002_default_auto_field
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Generated by Django 5.0.2 on 2024-02-23 23:26
2+
3+
from django.db import migrations, models
4+
5+
from sentry.new_migrations.migrations import CheckedMigration
6+
7+
8+
class Migration(CheckedMigration):
9+
# This flag is used to mark that a migration shouldn't be automatically run in production. For
10+
# the most part, this should only be used for operations where it's safe to run the migration
11+
# after your code has deployed. So this should not be used for most operations that alter the
12+
# schema of a table.
13+
# Here are some things that make sense to mark as dangerous:
14+
# - Large data migrations. Typically we want these to be run manually by ops so that they can
15+
# be monitored and not block the deploy for a long period of time while they run.
16+
# - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
17+
# have ops run this and not block the deploy. Note that while adding an index is a schema
18+
# change, it's completely safe to run the operation after the code has deployed.
19+
is_dangerous = False
20+
21+
dependencies = [
22+
("hybridcloud", "0011_add_hybridcloudapitoken_index"),
23+
]
24+
25+
operations = [
26+
migrations.AlterField(
27+
model_name="apitokenreplica",
28+
name="token",
29+
field=models.CharField(max_length=71),
30+
),
31+
]

src/sentry/hybridcloud/models/apitokenreplica.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ApiTokenReplica(Model, HasApiScopes):
1717
application_is_active = models.BooleanField(default=False)
1818
user_id = HybridCloudForeignKey("sentry.User", on_delete="CASCADE")
1919
apitoken_id = HybridCloudForeignKey("sentry.ApiToken", null=False, on_delete="CASCADE")
20-
token = models.CharField(max_length=64)
20+
token = models.CharField(max_length=71)
2121
expires_at = models.DateTimeField(null=True)
2222
allowed_origins = models.TextField(blank=True, null=True)
2323
date_added = models.DateTimeField(default=timezone.now)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Generated by Django 5.0.2 on 2024-02-23 23:25
2+
3+
from django.db import migrations, models
4+
5+
import sentry.models.apitoken
6+
from sentry.new_migrations.migrations import CheckedMigration
7+
8+
9+
class Migration(CheckedMigration):
10+
# This flag is used to mark that a migration shouldn't be automatically run in production. For
11+
# the most part, this should only be used for operations where it's safe to run the migration
12+
# after your code has deployed. So this should not be used for most operations that alter the
13+
# schema of a table.
14+
# Here are some things that make sense to mark as dangerous:
15+
# - Large data migrations. Typically we want these to be run manually by ops so that they can
16+
# be monitored and not block the deploy for a long period of time while they run.
17+
# - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
18+
# have ops run this and not block the deploy. Note that while adding an index is a schema
19+
# change, it's completely safe to run the operation after the code has deployed.
20+
is_dangerous = False
21+
22+
dependencies = [
23+
("sentry", "0654_rename_priority_sort_to_trends"),
24+
]
25+
26+
operations = [
27+
migrations.AlterField(
28+
model_name="apitoken",
29+
name="refresh_token",
30+
field=models.CharField(
31+
default=sentry.models.apitoken.generate_token, max_length=71, null=True, unique=True
32+
),
33+
),
34+
migrations.AlterField(
35+
model_name="apitoken",
36+
name="token",
37+
field=models.CharField(
38+
default=sentry.models.apitoken.generate_token, max_length=71, unique=True
39+
),
40+
),
41+
]

src/sentry/models/apitoken.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ class ApiToken(ReplicatedControlModel, HasApiScopes):
4141
application = FlexibleForeignKey("sentry.ApiApplication", null=True)
4242
user = FlexibleForeignKey("sentry.User")
4343
name = models.CharField(max_length=255, null=True)
44-
token = models.CharField(max_length=64, unique=True, default=generate_token)
44+
token = models.CharField(max_length=71, unique=True, default=generate_token)
4545
hashed_token = models.CharField(max_length=128, null=True)
4646
token_type = models.CharField(max_length=7, choices=AuthTokenType, null=True)
4747
token_last_characters = models.CharField(max_length=4, null=True)
48-
refresh_token = models.CharField(max_length=64, unique=True, null=True, default=generate_token)
48+
refresh_token = models.CharField(max_length=71, unique=True, null=True, default=generate_token)
4949
hashed_refresh_token = models.CharField(max_length=128, null=True)
5050
expires_at = models.DateTimeField(null=True, default=default_expiration)
5151
date_added = models.DateTimeField(default=timezone.now)

0 commit comments

Comments
 (0)