-
Notifications
You must be signed in to change notification settings - Fork 15
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
chore(backend): force token expire #969
Conversation
e592fc6
to
e37576b
Compare
/e2e --tests=substrafl,mnist,camelyon,frontend --refs=substra-frontend=chore/disable-never-expiring-token |
End to end tests: ✔️ SUCCESS |
5722f0c
to
2489bd4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One question, otherwise LGTM.
I don't know enough about the OIDC implementation to know if it will work without issues there.
And we have to keep in mind at the next upgrade that all tokens will be revoked.
migrations.AlterField( | ||
model_name="bearertoken", | ||
name="expires_at", | ||
field=models.DateTimeField(default=django.utils.timezone.now), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default, all existing tokens will expire immediately at the time of the migration. Is that what you want?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the idea was rather to set an immediate expiration date for token that does not have one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, thank you
backend/users/models/token.py
Outdated
@@ -10,7 +10,7 @@ | |||
|
|||
class BearerToken(Token): | |||
note = models.TextField(null=True) | |||
expires_at = models.DateTimeField(null=True) | |||
expires_at = models.DateTimeField(null=False, default=timezone.now) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand, does that mean that by default it expires instantly ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for asking, I am not sure I remember the rational behind this particular change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may have been that all already existing tokens are revoked
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really want a default value or do we want to force the user to provide it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What it means is that if no value is provided, the token will be created with instant expire. Note that the fronted will disable the possibility to create token with a null expires_at
field. One other option is to remove the default ; meaning that creating a token with a null expires_at
field will raise the following error:
django.db.utils.IntegrityError: null value in column "expires_at" of relation "users_bearertoken" violates not-null constraint
Not sure of what would be the best behavior, but happy to rework this if we think it's worth.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really want a default value or do we want to force the user to provide it
Did not refresh, sorry. Obviously better if we force the user to provide it indeed. Is there a clean way to do so?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did you get this IntegrityError
? The serializer should have returned an error when receiving an empty field for expires_at
(and if I recall correctly, DRF does not emit DB django error)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the error when running tests that rely on instantiating tokens with null expires_at
(eg here) and setting either:
required=True
in theBearerTokenSerializer
blank=False
in theBearerToken
model
2489bd4
to
d987c1c
Compare
/e2e --tests=sdk,substrafl,mnist,camelyon,frontend |
End to end tests: ✔️ SUCCESS |
response = authenticated_client.post(url, payload) | ||
|
||
assert response.json() == {"expires_at": ["This field is required."]} | ||
assert response.status_code == status.HTTP_400_BAD_REQUEST |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work!
Signed-off-by: Thibault Camalon <135698225+thbcmlowk@users.noreply.github.com>
Signed-off-by: Thibault Camalon <135698225+thbcmlowk@users.noreply.github.com>
Signed-off-by: Thibault Camalon <135698225+thbcmlowk@users.noreply.github.com>
Signed-off-by: Thibault Camalon <135698225+thbcmlowk@users.noreply.github.com>
Signed-off-by: Thibault Camalon <135698225+thbcmlowk@users.noreply.github.com>
Signed-off-by: Thibault Camalon <135698225+thbcmlowk@users.noreply.github.com>
Signed-off-by: Thibault Camalon <135698225+thbcmlowk@users.noreply.github.com>
Signed-off-by: Thibault Camalon <135698225+thbcmlowk@users.noreply.github.com>
Signed-off-by: Thibault Camalon <135698225+thbcmlowk@users.noreply.github.com>
40b7d8d
to
716c064
Compare
/e2e --tests=sdk,substrafl,mnist,camelyon,frontend |
Description
Part of FL-1656
Disable never expiring
BearerToken
Companion
Substra/substra-frontend#385
How has this been tested?
On dev by:
Creating tokens
Applying migration
I have no name!@substra-backend-substra-backend-server-5674697f78-ds9nk:/usr/src/app$ ./manage.py migrate users Operations to perform: Apply all migrations: users Running migrations: Applying users.0008_alter_bearertoken_expires_at... OK
Checklist