[PR #2514] [MERGED] Make matchers part of the Policy interface #2701

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

📋 Pull Request Information

Original PR: https://github.com/juanfont/headscale/pull/2514
Author: @aergus-tng
Created: 4/1/2025
Status: Merged
Merged: 5/1/2025
Merged by: @kradalby

Base: mainHead: regenerate-matches-on-filter-change


📝 Commits (6)

  • 7e63ae3 Make matchers part of the Policy interface
  • c2570a2 Prevent race condition between rules and matchers
  • 56a1f15 Test also matchers in tests for Policy.Filter
  • dfdf048 Compute filterChanged in v2 policy correctly
  • 87784be Fix nil vs. empty list issue in v2 policy test
  • dc79941 policy/v2: always clear ssh map

📊 Changes

12 files changed (+89 additions, -43 deletions)

View changed files

📝 hscontrol/debug.go (+1 -1)
📝 hscontrol/mapper/mapper.go (+2 -2)
📝 hscontrol/policy/matcher/matcher.go (+8 -0)
📝 hscontrol/policy/pm.go (+3 -1)
📝 hscontrol/policy/policy.go (+3 -2)
📝 hscontrol/policy/policy_test.go (+4 -2)
📝 hscontrol/policy/v1/policy.go (+3 -2)
📝 hscontrol/policy/v1/policy_test.go (+24 -2)
📝 hscontrol/policy/v2/policy.go (+16 -10)
📝 hscontrol/policy/v2/policy_test.go (+21 -11)
📝 hscontrol/types/node.go (+1 -9)
📝 hscontrol/types/node_test.go (+3 -1)

📄 Description

This PR makes the Matches that are computed from FilterRules part of the Policy interface, so that they don't have to be recomputed at each call to Node.CanAccess. There have already been some discussion on this approach in #2416.

  • have read the CONTRIBUTING.md file
  • raised a GitHub issue or discussed it on the projects chat beforehand
  • added unit tests
  • added integration tests
  • updated documentation if needed
  • updated CHANGELOG.md

🔄 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/2514 **Author:** [@aergus-tng](https://github.com/aergus-tng) **Created:** 4/1/2025 **Status:** ✅ Merged **Merged:** 5/1/2025 **Merged by:** [@kradalby](https://github.com/kradalby) **Base:** `main` ← **Head:** `regenerate-matches-on-filter-change` --- ### 📝 Commits (6) - [`7e63ae3`](https://github.com/juanfont/headscale/commit/7e63ae337d6da5ec87a5b1e73140ca9a6d981732) Make matchers part of the Policy interface - [`c2570a2`](https://github.com/juanfont/headscale/commit/c2570a2f8a4af66d102254c3e092bf55ccacfbd3) Prevent race condition between rules and matchers - [`56a1f15`](https://github.com/juanfont/headscale/commit/56a1f152c16b503652799b285dd3b542f1eee97f) Test also matchers in tests for Policy.Filter - [`dfdf048`](https://github.com/juanfont/headscale/commit/dfdf048ad7ece383c1f480fdf5ea774799ef9ae2) Compute `filterChanged` in v2 policy correctly - [`87784be`](https://github.com/juanfont/headscale/commit/87784be5c81ab3805078d682687f50bf1c45a97e) Fix nil vs. empty list issue in v2 policy test - [`dc79941`](https://github.com/juanfont/headscale/commit/dc79941746297a192788a5eac56f6e0a3f2a4998) policy/v2: always clear ssh map ### 📊 Changes **12 files changed** (+89 additions, -43 deletions) <details> <summary>View changed files</summary> 📝 `hscontrol/debug.go` (+1 -1) 📝 `hscontrol/mapper/mapper.go` (+2 -2) 📝 `hscontrol/policy/matcher/matcher.go` (+8 -0) 📝 `hscontrol/policy/pm.go` (+3 -1) 📝 `hscontrol/policy/policy.go` (+3 -2) 📝 `hscontrol/policy/policy_test.go` (+4 -2) 📝 `hscontrol/policy/v1/policy.go` (+3 -2) 📝 `hscontrol/policy/v1/policy_test.go` (+24 -2) 📝 `hscontrol/policy/v2/policy.go` (+16 -10) 📝 `hscontrol/policy/v2/policy_test.go` (+21 -11) 📝 `hscontrol/types/node.go` (+1 -9) 📝 `hscontrol/types/node_test.go` (+3 -1) </details> ### 📄 Description This PR makes the `Match`es that are computed from `FilterRule`s part of the `Policy` interface, so that they don't have to be recomputed at each call to `Node.CanAccess`. There have already been some discussion on this approach in #2416. - [x] have read the [CONTRIBUTING.md](./CONTRIBUTING.md) file - [x] raised a GitHub issue or discussed it on the projects chat beforehand - [x] added unit tests - [ ] added integration tests - [ ] updated documentation if needed - [ ] updated CHANGELOG.md --- <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:22:25 +01:00
adam closed this issue 2025-12-29 03:22:25 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/headscale#2701