mirror of
https://github.com/juanfont/headscale.git
synced 2026-01-11 20:00:28 +01:00
[Bug] Internal server error when logging in using Google OIDC #970
Closed
opened 2025-12-29 02:26:52 +01:00 by adam
·
23 comments
No Branch/Tag Specified
main
update_flake_lock_action
gh-pages
kradalby/release-v0.27.2
dependabot/go_modules/golang.org/x/crypto-0.45.0
dependabot/go_modules/github.com/opencontainers/runc-1.3.3
copilot/investigate-headscale-issue-2788
copilot/investigate-visibility-issue-2788
copilot/investigate-issue-2833
copilot/debug-issue-2846
copilot/fix-issue-2847
dependabot/go_modules/github.com/go-viper/mapstructure/v2-2.4.0
dependabot/go_modules/github.com/docker/docker-28.3.3incompatible
kradalby/cli-experiement3
doc/0.26.1
doc/0.25.1
doc/0.25.0
doc/0.24.3
doc/0.24.2
doc/0.24.1
doc/0.24.0
kradalby/build-docker-on-pr
topic/docu-versioning
topic/docker-kos
juanfont/fix-crash-node-id
juanfont/better-disclaimer
update-contributors
topic/prettier
revert-1893-add-test-stage-to-docs
add-test-stage-to-docs
remove-node-check-interval
fix-empty-prefix
fix-ephemeral-reusable
bug_report-debuginfo
autogroups
logs-to-stderr
revert-1414-topic/fix_unix_socket
rename-machine-node
port-embedded-derp-tests-v2
port-derp-tests
duplicate-word-linter
update-tailscale-1.36
warn-against-apache
ko-fi-link
more-acl-tests
fix-typo-standalone
parallel-nolint
tparallel-fix
rerouting
ssh-changelog-docs
oidc-cleanup
web-auth-flow-tests
kradalby-gh-runner
fix-proto-lint
remove-funding-links
go-1.19
enable-1.30-in-tests
0.16.x
cosmetic-changes-integration
tmp-fix-integration-docker
fix-integration-docker
configurable-update-interval
show-nodes-online
hs2021
acl-syntax-fixes
ts2021-implementation
fix-spurious-updates
unstable-integration-tests
mandatory-stun
embedded-derp
prtemplate-fix
v0.28.0-beta.1
v0.27.2-rc.1
v0.27.1
v0.27.0
v0.27.0-beta.2
v0.27.0-beta.1
v0.26.1
v0.26.0
v0.26.0-beta.2
v0.26.0-beta.1
v0.25.1
v0.25.0
v0.25.0-beta.2
v0.24.3
v0.25.0-beta.1
v0.24.2
v0.24.1
v0.24.0
v0.24.0-beta.2
v0.24.0-beta.1
v0.23.0
v0.23.0-rc.1
v0.23.0-beta.5
v0.23.0-beta.4
v0.23.0-beta3
v0.23.0-beta2
v0.23.0-beta1
v0.23.0-alpha12
v0.23.0-alpha11
v0.23.0-alpha10
v0.23.0-alpha9
v0.23.0-alpha8
v0.23.0-alpha7
v0.23.0-alpha6
v0.23.0-alpha5
v0.23.0-alpha4
v0.23.0-alpha4-docker-ko-test9
v0.23.0-alpha4-docker-ko-test8
v0.23.0-alpha4-docker-ko-test7
v0.23.0-alpha4-docker-ko-test6
v0.23.0-alpha4-docker-ko-test5
v0.23.0-alpha-docker-release-test-debug2
v0.23.0-alpha-docker-release-test-debug
v0.23.0-alpha4-docker-ko-test4
v0.23.0-alpha4-docker-ko-test3
v0.23.0-alpha4-docker-ko-test2
v0.23.0-alpha4-docker-ko-test
v0.23.0-alpha3
v0.23.0-alpha2
v0.23.0-alpha1
v0.22.3
v0.22.2
v0.23.0-alpha-docker-release-test
v0.22.1
v0.22.0
v0.22.0-alpha3
v0.22.0-alpha2
v0.22.0-alpha1
v0.22.0-nfpmtest
v0.21.0
v0.20.0
v0.19.0
v0.19.0-beta2
v0.19.0-beta1
v0.18.0
v0.18.0-beta4
v0.18.0-beta3
v0.18.0-beta2
v0.18.0-beta1
v0.17.1
v0.17.0
v0.17.0-beta5
v0.17.0-beta4
v0.17.0-beta3
v0.17.0-beta2
v0.17.0-beta1
v0.17.0-alpha4
v0.17.0-alpha3
v0.17.0-alpha2
v0.17.0-alpha1
v0.16.4
v0.16.3
v0.16.2
v0.16.1
v0.16.0
v0.16.0-beta7
v0.16.0-beta6
v0.16.0-beta5
v0.16.0-beta4
v0.16.0-beta3
v0.16.0-beta2
v0.16.0-beta1
v0.15.0
v0.15.0-beta6
v0.15.0-beta5
v0.15.0-beta4
v0.15.0-beta3
v0.15.0-beta2
v0.15.0-beta1
v0.14.0
v0.14.0-beta2
v0.14.0-beta1
v0.13.0
v0.13.0-beta3
v0.13.0-beta2
v0.13.0-beta1
upstream/v0.12.4
v0.12.4
v0.12.3
v0.12.2
v0.12.2-beta1
v0.12.1
v0.12.0-beta2
v0.12.0-beta1
v0.11.0
v0.10.8
v0.10.7
v0.10.6
v0.10.5
v0.10.4
v0.10.3
v0.10.2
v0.10.1
v0.10.0
v0.9.3
v0.9.2
v0.9.1
v0.9.0
v0.8.1
v0.8.0
v0.7.1
v0.7.0
v0.6.1
v0.6.0
v0.5.2
v0.5.1
v0.5.0
v0.4.0
v0.3.6
v0.3.5
v0.3.4
v0.3.3
v0.3.2
v0.3.1
v0.3.0
v0.2.2
v0.2.1
v0.2.0
v0.1.1
v0.1.0
Labels
Clear labels
CLI
DERP
DNS
Nix
OIDC
SSH
bug
database
documentation
duplicate
enhancement
faq
good first issue
grants
help wanted
might-come
needs design doc
needs investigation
no-stale-bot
out of scope
performance
policy 📝
pull-request
question
regression
routes
stale
tags
tailscale-feature-gap
well described ❤️
wontfix
Mirrored from GitHub Pull Request
Milestone
No items
No Milestone
Projects
Clear projects
No project
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: starred/headscale#970
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @adriangoransson on GitHub (Mar 13, 2025).
Is this a support request?
Is there an existing issue for this?
Current Behavior
Similar to https://github.com/juanfont/headscale/issues/2465 which was closed.
An existing (since Headscale 0.23) tried to log in for the first time since upgrading to 0.25, without success.
Even after destroying the user (along with the associated nodes and preauthkeys) and restarting headscale, the issue persists.
I tried to investigate how the OIDC handling has changed over the versions, but from what I could gather most issues seem to stem from the email having possibly changed? This has not happened in our case.
Expected Behavior
The current user should be migrated to the new format.
Steps To Reproduce
Environment
Runtime environment
Anything else?
Thank you for your dedicated work on Headscale!
@kradalby commented on GitHub (Mar 14, 2025):
Can you provide a list of users in the database and their fields and the ones that try to login when you get the error?
I suspect that they might not have migrated from the old "user only" format to the new one, see the changelog for 0.24.
@adriangoransson commented on GitHub (Mar 17, 2025):
Sure, here you go!
User 1 is our subnet router configured as a non-OIDC user. User 15 is an ordinary OIDC user, just with a special email.
Note that the
provider_identifierfor me and user 17 are different. I don't know if they should be.@adriangoransson commented on GitHub (Mar 17, 2025):
Just tried two things:
Reauth
Reauthenticated user 4 (not that the id matters I guess 😅) and encountered an internal server error again.
However, shutting down Tailscale and starting it again worked, so the previous key still seems valid. The output of
headscale users listis unchanged, though I haven't verified the database.Registered new user
Registered a user who has never logged in to Headscale previously. They have a unique first and last name, so there should be no such collisions.
@SeaweedbrainCY commented on GitHub (Apr 2, 2025):
I have the same issue. Even adding new users is creating this behavior. Does anyone has any hint on this ? Any workaround ?
In this state, headscale 0.25 is just unusable
@SeaweedbrainCY commented on GitHub (Apr 2, 2025):
For those having the same issue, I managed to solve the user creation error :
My issue was that even with the migration flag on, my users had a user.name empty,
and most importantly, my OIDC provider was returning an empty username to headscale (I am using authelia).
The UNIQUE constraint were then failing on creating a new user with users.name equals to
''.After digging into the code of headscale, I found that the name (in the DB) is mapped with the
usernamesent by the OIDC provider. And after adjusting the scopes in authelia, allowingprofileandusernameI managed to create a new user account, with a validName, aUsernameandEmail.Bottom line : Destroying and recreating user is possible, but you have to ensure that you're allowing headscale to fetch the user username to avoid duplication of empty value.
It's working for v0.24 and 0.25
@Subito commented on GitHub (Apr 8, 2025):
I'm facing the same problem. I tried the solution mentioned in #2505: https://www.authelia.com/integration/openid-connect/openid-connect-1.0-claims/#restore-functionality-prior-to-claims-parameter, but using the
claims_policyjust gives me the same error. Not using theclaims_policylets me login, but without a proper username.After the successful login the username field is empty and I get
successfully authenticated as https://auth.example.org/{long-uid}in the app. Afterwards it shows this URL instead of the username and none of my other devices.The resulting "user" in the table looks like this:
None of the other users (all use oidc) have the
provider-field set.Using Authelia 4.39.1 and Headscale 0.25.1 might be related to #2516?
@ventsislav-georgiev commented on GitHub (May 5, 2025):
We are experiencing the same error:
creating or updating user: constraint failed: UNIQUE constraint failed: users.name (2067)since updating to v0.24 for creation of new users / new OIDC logins. This error is returned to the user.Updating to v0.25 does not help. The only thing that changes is the error returned to the user is now internal server error. Headscale still logs:
The only way we bypass it is to manually create the user with the cli:
headscale users create ..and use v0.24, since this workaround does not work in v0.25..This is using Google's OAuth 2.0: https://developers.google.com/identity/openid-connect/openid-connect, default scopes (openid, profile, email).
@aronmolnar commented on GitHub (May 8, 2025):
We had a similar issue in
0.24.0-beta.2with Entra ID. The login caused a new user to be created, however, without a user name.The next user who authenticated using SSO violated the UNIQUE constraint because of the empty user name. We could resolve it temporarily by adding a username to the existing user.
@cymonkey commented on GitHub (May 13, 2025):
Same problem here with Google OIDC, I can't even rename or update user since the error
cannot edit OIDC user. Does anyone know any workaround? It's blocking my user registration.@joscdk commented on GitHub (May 14, 2025):
@cymonkey i ended up going into the SQLite database, and update
nameandupdated_atin theuserstable to unblock user creation 🙈@cymonkey commented on GitHub (May 14, 2025):
Thanks @joscdk, tried and it worked, aw the only way I can think of at the this time too
@ventsislav-georgiev commented on GitHub (May 14, 2025):
@kradalby In v0.26.0 it doesn't even create the user in the DB. The server just logs:
ERR http internal server error error="creating or updating user: constraint failed: UNIQUE constraint failed: users.name (2067)" code=500@joscdk @cymonkey what exactly did you need to do to workaround the user creation?
@cymonkey commented on GitHub (May 15, 2025):
@ventsislav-georgiev The
users.nameunique constraint still exists and the OIDC authen function somehow doesn't update the name when user reauthen/register, so it actually can still create one new user via OIDC authen, the user will has ausers.name = nullbut any other user creation attempts after that will raise the error as you've seen.All you need to do is to find the first created user via OIDC auth and update their
users.name:Not really a workaround tbh.
@ventsislav-georgiev commented on GitHub (May 18, 2025):
Possible solution, which I tested working on our setup: https://github.com/juanfont/headscale/pull/2611
@ventsislav-georgiev commented on GitHub (May 21, 2025):
With the help of @kradalby I found that my DB indexes were not up to date with what was expected in v0.26.
I haven't tested from scratch as it is difficult for me to reset or setup a separate test instance.
My issue occurs with existing DB which was gradually updated from version 0.22.1 onward.
These were the indexes:

And it appears this migration hasn't been run or failed silently:
d2879b2b36/hscontrol/db/db.go (L544)despite having it in the migrations table:

After manually fixing my indexes by dumping the DB and running the following script:
All is working properly now with 0.26 and new users logged in from the OIDC are without usernames. They are created successfully on first login.
Here are the new users without usernames as listed by the CLI headscale users list:

@Subito commented on GitHub (May 28, 2025):
Thats a super helpful hint, thank you! Digging into my schema I found that it had some migrations missing, too! Unfortunately its not easy to find out which those are missing and what the sideeffects may be if I apply them now. I'm probably going to wipe my installation and create everything from scratch and see if that helps.
@panteparak commented on GitHub (Jun 1, 2025):
I am getting a similar error too, with Azure EntraID
I have not tried some of the suggested method mentioned above.
@Subito commented on GitHub (Jun 2, 2025):
I got it working again by manually fixing the entries in the
userstable. Settingprovider_identifierto the identifier I found in the Authelia-Logs andprovidertooidclike this:worked for me. Users can login again.
@hafometh88 commented on GitHub (Jun 15, 2025):
Thank you, worked for me!
@kradalby commented on GitHub (Jul 2, 2025):
I'm working on this over in #2617 , more databases to add to the tests would be greatly appreciated. only schema helps, but with data would be even better.
I think we (@nblock) have a script for helping us randomise the data.
@kradalby commented on GitHub (Jul 2, 2025):
As this comment is a bit confusing, I posted a lengthier one here: https://github.com/juanfont/headscale/issues/2597#issuecomment-3028234284
@appleimperio commented on GitHub (Jul 17, 2025):
I'm getting the same issue but with Pocket-id.
ERR http internal server error error="creating or updating user: constraint failed: UNIQUE constraint failed: users.name (2067)" code=500These are my users
I just try the @ventsislav-georgiev and it worked
@kradalby commented on GitHub (Sep 10, 2025):
I'm going to close this as fixed in the upcoming database cleanup for SQLite, no further work will be done for Postgres.