mirror of
https://github.com/juanfont/headscale.git
synced 2026-01-11 20:00:28 +01:00
[Bug] OIDC users don't always get a username #901
Closed
opened 2025-12-29 02:25:36 +01:00 by adam
·
42 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#901
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 @ToxicMushroom on GitHub (Jan 8, 2025).
Is this a support request?
Is there an existing issue for this?
Current Behavior
When logging in for the first time with oidc I only got a display_name and no username/name set in headscale.
This can be worked around currently by
docker exec headscale headscale users rename --identifier 1 -r merlijnBut that'd be inconvenient for future users so it should probably get resolved.
Expected Behavior
All the required user fields get set when logging in with oidc,
Steps To Reproduce
Environment
Runtime environment
Anything else?
root@zungenbrecher:/opt/vpn_exit_node# docker exec headscale headscale users list -o jsonoidc claims for my user with "profile", "email", "groups" scopes
config.yaml
@kradalby commented on GitHub (Jan 9, 2025):
which OIDC provider do you use? I noticed that Google for example does not provide a username. If the provider does not provide one, it will not be set.
@ToxicMushroom commented on GitHub (Jan 9, 2025):
I use https://github.com/kanidm/kanidm
@kradalby commented on GitHub (Jan 9, 2025):
Can you provide a the claim json as an example?
@ToxicMushroom commented on GitHub (Jan 9, 2025):
It is in the original post under
anything else ?in theoidc claims for my user with "profile", "email", "groups" scopesblock@ToxicMushroom commented on GitHub (Jan 9, 2025):
I think I found the line here @kradalby
ede4f97a16/hscontrol/types/users.go (L178)The err that is checked does not seem to ever get printed.
I don't think my preferred_username passes the regex check in the FQDN function.
@kradalby commented on GitHub (Jan 9, 2025):
I suppose there should be a logging of that message, but it needs to pass that regex.
@kradalby commented on GitHub (Jan 10, 2025):
What is the username not passing the regex, out of curiosity?
@ToxicMushroom commented on GitHub (Jan 10, 2025):
merlijn@idm.melijn.comI'm curious where the regex comes from tho, what purpose does it serve ?
But kanidm has the option to send the username without the domain part too so I'll configure it to do that.
@kradalby commented on GitHub (Jan 10, 2025):
historically it comes from when our magicdns implementation used the username, so it validates that it is DNS safe. Since this has been removed, it can be removed, I am just a bit cautious opening it completely yet, so keeping it strict initially and being conservative atm feels the best.
Allowing @ would be sensible tho, so I'll update the PR to allow that.
@ToxicMushroom commented on GitHub (Jan 10, 2025):
ooh then it makes sense yeah :)
@suyashFSG commented on GitHub (Jan 18, 2025):
Hey @kradalby I am on v24.0 with AzureAD as OIDC provider and I am noticing that provider id is url instead of preferred_username
On v23.0
headscale users list -o jsonoutputs:v24.0 causes Tailscale client to show the url instead of username
@suyashFSG commented on GitHub (Jan 18, 2025):
Tailscale client shows
provider_idas well instead ofnameordisplay_name@kradalby commented on GitHub (Jan 19, 2025):
@suyashFSG
This happens when preferred username is not valid, and the email is not verified.
Can you send the OIDC claims json sent from azure? I don't have azure so I don't know what they send. Likely there is no username or it contains a invalid character and the email is not marked as verified.
The provider id looks as i expect it, and it would show up in the UI if there is nothing else.
@malonzhao commented on GitHub (Jan 20, 2025):
Hi @kradalby, I meet the same problem that users don't always get a username and picture. I use keycloak as OIDC provider.
User's data in postgres.

@suyashFSG commented on GitHub (Jan 20, 2025):
@kradalby Following is the accessToken returned by AzureAD:
Something I am noticing AzureAD does not include
preferred_usernamein accesstoken and as foremail_verifiedclaim they are not included either.ID Token includes preferred_username:
@GoodiesHQ commented on GitHub (Jan 20, 2025):
@suyashFSG how were you able to pull that information? headscale in debug mode? I am getting this same behavior with Azure. Even if I go add a username to the OIDC user (which has a blank user name and email), the username is ineffectual inside of ACLs. If I use the entire providerId URL in the ACL, it actually works, but is horrendously ugly.
@kradalby commented on GitHub (Jan 20, 2025):
@malonzhao please provide the ID Token JSON, I would not expect profile picture to be included in most OIDC, I would assume that your keycloak does not provide
preferred_username.@suyashFSG I find it strange that the username is not included as the email for the ID Token one, but as the email is not verified, it will not be recorded. You need to get Azure to set the
email_verifiedfield.I am also confused by the first payload you are showing, is that from a different system? are both AzureAD?
Please not that we do not aim to support all the quirks of all the different providers, we are aiming to support the base case, if your provider doesnt provide those fields, we likely wont be able to maintain it.
@malonzhao commented on GitHub (Jan 20, 2025):
Thanks @kradalby , I think I've found the way to resolve this problem.
During debugging, I got a tip like "DBG Username service.system is not valid error="username contains invalid character: '.'".
I will try again after removing the "." character from the username
@kradalby commented on GitHub (Jan 20, 2025):
That is probably a bit strict, I will go over and ensure typical username chars are supported in a upcoming fix release:
.,_,-and@(already handled)@suyashFSG commented on GitHub (Jan 20, 2025):
@kradalby Azure does not have option to add email_verified claim. A lot of apps that i have deployed that has OIDC support for both personal or enterprise lets us admins decide what claim we want to use for specific things.
What was the reason behind making the oidc config very restrictive on headscale. It would be awesome if claim override is an option for username, same with disabling email verified stuff.
Both id token and access token are from same instance of azure and azure app. Azure provide 2 auth tokens when you request one (access an id tokens)
One more question, does headscale use access token or id token or combination of both?
@SamyDjemai commented on GitHub (Jan 21, 2025):
Hi @kradalby,
The v0.24 release breaks Headscale when used with an Okta OIDC integration, since:
preferred_usernamefield contains the user's email address, which contain some of the forbidden characters you mentioned (example:firstname.lastname@company.com)As @suyashFSG mentioned, it would be best to be able to disable
email_verifiedchecking, for the OIDC providers who either don't provide it, or provide it unreliably@kradalby commented on GitHub (Jan 21, 2025):
Noted, please provide an example json payload from your okta, you can anonymise it a bit but preferably as normal as possible so I can write tests against it.
We will per now at least relax the username field, email is undecided.
@SamyDjemai commented on GitHub (Jan 21, 2025):
Here's the ID token:
@Codelica commented on GitHub (Jan 23, 2025):
I see this was part of the release today (v0.24.1), but it seems one regex is still restricting email addresses for me:
It seem like it's getting hung up on the
@during theinvalidCharsInUserRegexcheck ?@kradalby commented on GitHub (Jan 23, 2025):
This regex is not being used, https://github.com/juanfont/headscale/blob/main/hscontrol/util/dns.go#L34 this function is validating it.
Currently this is the passing tests:
https://github.com/juanfont/headscale/blob/main/hscontrol/types/users_test.go#L79 which includes an email on that format.
@Codelica commented on GitHub (Jan 23, 2025):
But on rename user I think that regex is checked, no ?
@kradalby commented on GitHub (Jan 23, 2025):
oh yes, that should be an easy fix, if someone can take a look at that it would be greatly appreciated.
@n-hass commented on GitHub (Feb 3, 2025):
I don’t believe this is resolved on latest v0.24.2.
if a new user logs in from Google oauth using
name@company.com.au, the user created is missing the ‘username’ field.Output of
headscale users ls -o json:then trying
headscale users rename -i 5 -r team@company.com.auresults in:Cannot rename user: DNS segment should only be composed of lowercase ASCII letters numbers, hyphen and dots. team@company.com.au doesn't comply with theses rules: invalid user name, and the user is unchanged.@kradalby commented on GitHub (Feb 3, 2025):
Google doesn’t provide a username, so it will be blank, you have to use the value assigned to the email for things like acl
You should not try to modify users managed by oidc as they will be overwritten on every login, this has been disabled for the next release.
@n-hass commented on GitHub (Feb 3, 2025):
Thank you for the clarification @kradalby, the usage regarding ACLs was my concern as I had thought it is strictly a username that needs to be used in ACLs.
@kradalby commented on GitHub (Feb 3, 2025):
That’s fair. We are working on the docs, but it will resolve in the order of unique id from oidc, email then username.
@vdovhanych commented on GitHub (Feb 12, 2025):
Hey sorry to revive this closed issue. I have a question on this. When i update from 0.23.0 to 0.24.3 and want to do the migration do i also need to change the ACL rules to the email address instead of usernames if i use Google oidc and it does not provide the username property?
Will this mean that if i update my ACL the user won't have access until they go trough the new OIDC flow? Cause i will change it to the email property but user wont have it until he reauthenticates with oidc right?
@kradalby commented on GitHub (Feb 12, 2025):
Technically yes, but also there should not be a problem listing both username and email for a bit, not tested but think it could work
@ssentanoe commented on GitHub (Feb 13, 2025):
hi, similar with the previous question, since I'm also using google oidc which will produce blank on the username, do you have plan to update the
nodes lsto also print the email? right now it is super hard to find nodes that belongs to a user that does not have username.Edit:
I saw there is also
-u, however it does not work with email@vdovhanych commented on GitHub (Feb 18, 2025):
I just want to confirm that this approach works. For now, I will list both types of usernames and emails in the ACL until they all go through the new authentication flow. Thanks for the suggestion.
@Eric-ZhehanZ commented on GitHub (Mar 4, 2025):
How do I create a preauth key for email-only users? It doesn't seem to be possible right now.
@kradalby commented on GitHub (Mar 4, 2025):
Good point, can you create a new issue so we can track the effort to move everything to ID in the cli.
@seeleclover commented on GitHub (Mar 13, 2025):
Hey sorry to revive this closed issue. I am currently using Headscale v0.25.1 version, but I still encounter the issue of OIDC users don‘t get a username.
Environment
config.yamlof Headscaleoidc claims (accessToken returned by Casdoor)
headscale users list
@kradalby commented on GitHub (Mar 13, 2025):
I've added an additional test and it seem to work as expected, please have a look at https://github.com/juanfont/headscale/pull/2474
@DevOpsPop commented on GitHub (Mar 21, 2025):
Headscale v0.25.1the same problem
can't login in tailscale client
log:
@idefixcert commented on GitHub (Apr 3, 2025):
I have the problem in google oauth:
scope: ["openid", "profile", "email"]
the prefered_username is not set
My question is if I could contribute the following change:
-> https://github.com/juanfont/headscale/compare/main...idefixcert:headscale:oidc_username
@malosaaa commented on GitHub (May 9, 2025):
Is this already solved in the future beta ?