Skip to content
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

oidc username/email to create new namespace mapping is broken #365

Closed
kyhwana opened this issue Feb 28, 2022 · 0 comments
Closed

oidc username/email to create new namespace mapping is broken #365

kyhwana opened this issue Feb 28, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@kyhwana
Copy link
Contributor

kyhwana commented Feb 28, 2022

Bug description
When authing a new user via oidc (with email stripping DISABLED, I didn't test with it enabled) the following error occures and the namespace isn't created:

[GIN] 2022/02/27 - 21:54:06 | 302 |     118.701µs | redacated  | GET      "/oidc/register/mkey:redacated"
2022-02-27T21:54:06Z ERR ../home/runner/work/headscale/headscale/oidc.go:319 > could not find or create namespace error="Namespace not found" namespace=redacatednamespace
[GIN] 2022/02/27 - 21:54:06 | 500 |  161.557551ms |  redacated | GET      "/oidc/callback?code=0redacated"
2022-02-27T21:54:09Z WRN Ignoring request, cannot find machine with key mkey:redacated handler=PollNetMap
[GIN] 2022/02/27 - 21:54:09 | 401 |    1.083608ms |   118.92.104.24 | POST     "/machine/redacated/map"


To Reproduce

With email stripping disabled, configure an oidc (tested with azure ad) and have a user attempt to login with [email protected].

Context info

  • 0.15-beta1
  • tailscale client 1.22.0
  • Client OS Windows 11
[GIN] 2022/02/27 - 21:54:06 | 302 |     118.701µs | redacated  | GET      "/oidc/register/mkey:redacated"
2022-02-27T21:54:06Z ERR ../home/runner/work/headscale/headscale/oidc.go:319 > could not find or create namespace error="Namespace not found" namespace=redacatednamespace
[GIN] 2022/02/27 - 21:54:06 | 500 |  161.557551ms |  redacated | GET      "/oidc/callback?code=0redacated"
2022-02-27T21:54:09Z WRN Ignoring request, cannot find machine with key mkey:redacated handler=PollNetMap
[GIN] 2022/02/27 - 21:54:09 | 401 |    1.083608ms |   118.92.104.24 | POST     "/machine/redacated/map"


I fixed and tested this with the following fix:
Line 302 of oidc.go changed from if errors.Is(err, gorm.ErrRecordNotFound) { to if errors.Is(err, errNamespaceNotFound) {
I also had to comment out line 20 of oidc.go "gorm.io/gorm" because the go compiler complained that gorm wasn't being used :)

It looks like getnamespace returns "errNamespaceNotFound" ("Namespace not found") but the if statement on line 302 is just looking for gorm.ErrRecordNotFound and so it falls through to line 317 } else if err != nil { and errors out.

@kyhwana kyhwana added the bug Something isn't working label Feb 28, 2022
kradalby added a commit to kradalby/headscale that referenced this issue Feb 28, 2022
@kradalby kradalby closed this as completed Mar 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants