Repository navigation
fix 371 trino impersonation #397
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
Open
Bohreromir
wants to merge
10
commits into
main
Choose a base branch
from
worktree-fix-371-trino-impersonation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+278
−47
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cbeefd6
fix(auth): restore OIDC username while keeping it read-only (#371)
Bohreromir c75313c
fix(trino): fail instead of impersonating 'anonymous' without a usern…
Bohreromir 07b74cf
test(e2e): assert queries run as the OIDC user (#371)
Bohreromir 4238dba
fix(auth): refresh OIDC username on login, show form error without on…
Bohreromir fec74fa
test(e2e): assert catalog and completion queries run as the OIDC user…
Bohreromir b9e72e4
Merge branch 'main' into worktree-fix-371-trino-impersonation
Bohreromir b62cfcc
Merge branch 'main' into worktree-fix-371-trino-impersonation
Bohreromir 2adba17
refactor: rename user.username to trinoUser
Bohreromir ae5c4f6
Show missing Trino user error in the query editor
Bohreromir bae70ce
Merge branch 'main' into worktree-fix-371-trino-impersonation
Bohreromir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,22 @@ | ||
| import { error } from '@sveltejs/kit'; | ||
|
|
||
| export function getUserId(locals: App.Locals): string { | ||
| return locals.user?.id ?? 'anonymous'; | ||
| } | ||
|
|
||
| /** | ||
| * The user to impersonate in Trino. Without OIDC there is no signed-in user, | ||
| * so queries run as 'anonymous'. A signed-in user without a Trino user means | ||
| * sign-up lost the OIDC claim; return null instead of falling back to 'anonymous'. | ||
| */ | ||
| export function findTrinoUser(locals: App.Locals): string | null { | ||
| if (!locals.user) return 'anonymous'; | ||
| if (locals.user.trinoUser) return locals.user.trinoUser; | ||
| locals.logger.warn({ user_id: locals.user.id }, 'Signed-in user has no Trino user'); | ||
| return null; | ||
| } | ||
|
|
||
| /** Like {@link findTrinoUser}, but fails the request when there is no Trino user. */ | ||
| export function getTrinoUser(locals: App.Locals): string { | ||
| return findTrinoUser(locals) ?? error(500, 'User has no Trino user'); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,39 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { parseUserInput } from 'better-auth/db'; | ||
| import { parseAdditionalUserInputFromProviderProfile } from 'better-auth/db'; | ||
| import { auth } from './auth.js'; | ||
|
|
||
| describe('user.additionalFields.username', () => { | ||
| it('rejects a rewrite through the built-in update-user endpoint', () => { | ||
| expect(() => parseUserInput(auth.options, { username: 'someone-else' }, 'update')).toThrow( | ||
| /username is not allowed to be set/ | ||
| ); | ||
| const hooks = auth.options.databaseHooks!.user!; | ||
| const create = (data: Record<string, unknown>, path: string) => | ||
| hooks.create!.before!(data as never, { path } as never); | ||
| const update = (data: Record<string, unknown>, path: string) => | ||
| hooks.update!.before!(data as never, { path } as never); | ||
|
|
||
| describe('user.additionalFields.trinoUser', () => { | ||
| it('is taken from the OIDC provider profile', () => { | ||
| expect( | ||
| parseAdditionalUserInputFromProviderProfile(auth.options, { trinoUser: 'alice' }, 'create') | ||
| ).toMatchObject({ trinoUser: 'alice' }); | ||
| }); | ||
|
|
||
| it('may be written by the OIDC callback', async () => { | ||
| await expect( | ||
| create({ email: 'alice@example.com', trinoUser: 'alice' }, '/oauth2/callback/:providerId') | ||
| ).resolves.toBeUndefined(); | ||
| }); | ||
|
|
||
| it('rejects a rewrite smuggled in at sign-up', () => { | ||
| expect(() => parseUserInput(auth.options, { username: 'someone-else' }, 'create')).toThrow( | ||
| /username is not allowed to be set/ | ||
| it('rejects a rewrite through the built-in update-user endpoint', async () => { | ||
| await expect(update({ trinoUser: 'someone-else' }, '/update-user')).rejects.toThrow( | ||
| /trinoUser is not allowed to be set/ | ||
| ); | ||
| }); | ||
|
|
||
| it('is still declared, so the OIDC claim can populate it', () => { | ||
| expect(auth.options.user?.additionalFields?.username).toMatchObject({ type: 'string' }); | ||
| it('rejects a rewrite smuggled in at sign-up', async () => { | ||
| await expect( | ||
| create({ email: 'eve@example.com', trinoUser: 'someone-else' }, '/sign-up/email') | ||
| ).rejects.toThrow(/trinoUser is not allowed to be set/); | ||
| }); | ||
|
|
||
| it('leaves other user updates alone', async () => { | ||
| await expect(update({ emailVerified: true }, '/update-user')).resolves.toBeUndefined(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.