-
Notifications
You must be signed in to change notification settings - Fork 49
Refactor device auth schema #1344
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
Changes from 8 commits
a9e20c5
a195c9e
0af0e27
027d517
c4f4d01
77a0d8c
2b504ca
152fd2a
bf53d38
8ce7e42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1252,37 +1252,36 @@ INSERT INTO omicron.public.user_builtin ( | |
* OAuth 2.0 Device Authorization Grant (RFC 8628) | ||
*/ | ||
|
||
-- Device authorization requests. In theory these records could | ||
-- (and probably should) be short-lived, and removed as soon as | ||
-- a token is granted. | ||
-- TODO-security: We should not grant a token more than once per record. | ||
-- Device authorization requests. These records are short-lived, | ||
-- and removed as soon as a token is granted. This allows us to | ||
-- use the `user_code` as primary key, despite it not having very | ||
-- much entropy. | ||
-- TODO: A background task should remove unused expired records. | ||
CREATE TABLE omicron.public.device_auth_request ( | ||
user_code STRING(20) PRIMARY KEY, | ||
client_id UUID NOT NULL, | ||
device_code STRING(40) NOT NULL, | ||
user_code STRING(63) NOT NULL, | ||
time_created TIMESTAMPTZ NOT NULL, | ||
time_expires TIMESTAMPTZ NOT NULL, | ||
|
||
PRIMARY KEY (client_id, device_code) | ||
time_expires TIMESTAMPTZ NOT NULL | ||
); | ||
|
||
-- Fast lookup by user_code for verification | ||
CREATE INDEX ON omicron.public.device_auth_request (user_code); | ||
|
||
-- Access tokens granted in response to successful device authorization flows. | ||
-- TODO-security: expire tokens. | ||
CREATE TABLE omicron.public.device_access_token ( | ||
token STRING(40) PRIMARY KEY, | ||
client_id UUID NOT NULL, | ||
device_code STRING(40) NOT NULL, | ||
silo_user_id UUID NOT NULL, | ||
time_created TIMESTAMPTZ NOT NULL | ||
time_requested TIMESTAMPTZ NOT NULL, | ||
time_created TIMESTAMPTZ NOT NULL, | ||
time_expires TIMESTAMPTZ | ||
); | ||
|
||
-- Matches the primary key on device authorization records. | ||
-- The UNIQUE constraint is critical for ensuring that at most | ||
-- This UNIQUE constraint is critical for ensuring that at most | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is no longer true (that is, removal from the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But it is still true with respect to this table considered alone. There shouldn't be any code paths now for which this invariant is broken, but it still seems like a good idea to leave it in place for future us (me). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (I wasn't suggesting removing the constraint, just potentially updating the comment, but it's fine as is too) |
||
-- one token is ever created for a given device authorization flow. | ||
CREATE UNIQUE INDEX ON omicron.public.device_access_token (client_id, device_code); | ||
CREATE UNIQUE INDEX ON omicron.public.device_access_token ( | ||
client_id, device_code | ||
); | ||
|
||
/* | ||
* Roles built into the system | ||
|
Uh oh!
There was an error while loading. Please reload this page.