[PR #2205] [MERGED] Resolve user to stable unique ID in policy #2547

Closed
opened 2025-12-29 03:21:45 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/juanfont/headscale/pull/2205
Author: @kradalby
Created: 10/22/2024
Status: Merged
Merged: 11/24/2024
Merged by: @kradalby

Base: mainHead: kradalby/acl-user-resolv


📝 Commits (4)

  • 697ec7f resolve user identifier to stable ID
  • c905f04 ensure provider id is found out of order
  • c59144a only set username and email if valid
  • bdcd684 Merge branch 'main' into kradalby/acl-user-resolv

📊 Changes

9 files changed (+507 additions, -145 deletions)

View changed files

📝 hscontrol/app.go (+6 -2)
📝 hscontrol/db/node_test.go (+2 -2)
📝 hscontrol/db/routes.go (+6 -1)
📝 hscontrol/grpcv1.go (+6 -2)
📝 hscontrol/mapper/mapper.go (+16 -3)
📝 hscontrol/mapper/mapper_test.go (+10 -6)
📝 hscontrol/policy/acls.go (+59 -16)
📝 hscontrol/policy/acls_test.go (+388 -101)
📝 hscontrol/types/users.go (+14 -12)

📄 Description

currently, the policy approach node to user matching with a quite naive approach looking at the username provided in the policy and matched it with the username on the nodes. This worked ok as long as usernames were unique and did not change.

As usernames are no longer guarenteed to be unique in an OIDC environment we cant rely on this.

This changes the mechanism that matches the user string (now user token) with nodes:

  • first find all potential users by looking up:
    • database ID
    • provider ID (OIDC)
    • username/email

If more than one user is matching, then the query is rejected, and zero matching nodes are returned.

When a single user is found, the node is matched against the User database ID, which are also present on the actual node.

This means that from this commit, users can use the following to identify users in the policy:

  • provider identity (iss + sub)
  • username
  • email
  • database id

There are more changes coming to this, so it is not recommended to start using any of these new abilities, with the exception of email, which will not change since it includes an @.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/juanfont/headscale/pull/2205 **Author:** [@kradalby](https://github.com/kradalby) **Created:** 10/22/2024 **Status:** ✅ Merged **Merged:** 11/24/2024 **Merged by:** [@kradalby](https://github.com/kradalby) **Base:** `main` ← **Head:** `kradalby/acl-user-resolv` --- ### 📝 Commits (4) - [`697ec7f`](https://github.com/juanfont/headscale/commit/697ec7f46c0feed2de332ea6c52652deb919ea41) resolve user identifier to stable ID - [`c905f04`](https://github.com/juanfont/headscale/commit/c905f0499b86750e88097144dbec524c6273b9c3) ensure provider id is found out of order - [`c59144a`](https://github.com/juanfont/headscale/commit/c59144a287094d167d426e9cbed7c392c455154f) only set username and email if valid - [`bdcd684`](https://github.com/juanfont/headscale/commit/bdcd684a055b2246e3dbba81e4a1419667188829) Merge branch 'main' into kradalby/acl-user-resolv ### 📊 Changes **9 files changed** (+507 additions, -145 deletions) <details> <summary>View changed files</summary> 📝 `hscontrol/app.go` (+6 -2) 📝 `hscontrol/db/node_test.go` (+2 -2) 📝 `hscontrol/db/routes.go` (+6 -1) 📝 `hscontrol/grpcv1.go` (+6 -2) 📝 `hscontrol/mapper/mapper.go` (+16 -3) 📝 `hscontrol/mapper/mapper_test.go` (+10 -6) 📝 `hscontrol/policy/acls.go` (+59 -16) 📝 `hscontrol/policy/acls_test.go` (+388 -101) 📝 `hscontrol/types/users.go` (+14 -12) </details> ### 📄 Description currently, the policy approach node to user matching with a quite naive approach looking at the username provided in the policy and matched it with the username on the nodes. This worked ok as long as usernames were unique and did not change. As usernames are no longer guarenteed to be unique in an OIDC environment we cant rely on this. This changes the mechanism that matches the user string (now user token) with nodes: - first find all potential users by looking up: - database ID - provider ID (OIDC) - username/email If more than one user is matching, then the query is rejected, and zero matching nodes are returned. When a single user is found, the node is matched against the User database ID, which are also present on the actual node. This means that from this commit, users can use the following to identify users in the policy: - provider identity (iss + sub) - username - email - database id There are more changes coming to this, so it is not recommended to start using any of these new abilities, with the exception of email, which will not change since it includes an @. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 03:21:45 +01:00
adam closed this issue 2025-12-29 03:21:45 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/headscale#2547