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

[Feature] Headscale policy set validate ACL before applying? #2044

Closed
2 tasks done
dragon2611 opened this issue Aug 5, 2024 · 12 comments · Fixed by #2089
Closed
2 tasks done

[Feature] Headscale policy set validate ACL before applying? #2044

dragon2611 opened this issue Aug 5, 2024 · 12 comments · Fixed by #2089
Labels
enhancement New feature or request

Comments

@dragon2611
Copy link
Contributor

Use case

Is it possible to have the headscale policy set command run validation before applying the policy and only load the policy if it passed syntax checking.

Description

I accidentally put autogroup:internet instead of autogroup:internet:* and it really didn't like that.

Basically all the clients started throwing back

Could not get the create map update error="strconv.ParseUint: parsing \"internet\": invalid syntax" and I'm pretty sure they all dropped off the tailnet.

Contribution

  • I can write the design doc for this feature
  • I can contribute this feature

How can it be implemented?

No response

@dragon2611 dragon2611 added the enhancement New feature or request label Aug 5, 2024
@dragon2611
Copy link
Contributor Author

dragon2611 commented Aug 5, 2024

Also see #2045 - I'm happy to contribute but writing design docs is rather outside my area of expertise, and you probably wouldn't want any code contributions from me as I'm very much a novice.

@kradalby
Copy link
Collaborator

kradalby commented Aug 6, 2024

Would make sense, @pallabpain are you able to take a look?

@pallabpain
Copy link
Contributor

Would make sense, @pallabpain are you able to take a look?

Yes, I'll take a look. @dragon2611 It'd be great if you could share the policy file you were trying to apply.

Although the SetPolicy API does validate the payload

valid, err := policy.LoadACLPolicyFromBytes([]byte(p))
, maybe it's missing something.

@dragon2611
Copy link
Contributor Author

dragon2611 commented Aug 6, 2024

Whilst I'd rather not post the entire ACL The thing that seemed to trip things up was


 { "action": "accept", "src": ["tag:mobiles"], "dst": ["autogroup:internet"] },
 { "action": "accept", "src": ["tag:pcs"], "dst": ["autogroup:internet"] }

What appeared to work was however

 { "action": "accept", "src": ["tag:mobiles"], "dst": ["autogroup:internet:*"] },
 { "action": "accept", "src": ["tag:pcs"], "dst": ["autogroup:internet:*"] }

@pallabpain
Copy link
Contributor

Whilst I'd rather not post the entire ACL The thing that seemed to trip things up was

{ "action": "accept", "src": ["tag:mobiles"], "dst": ["autogroup:internet"] },
{ "action": "accept", "src": ["tag:pcs"], "dst": ["autogroup:internet"] }

What appeared to work was however

{ "action": "accept", "src": ["tag:mobiles"], "dst": ["autogroup:internet:"] },
{ "action": "accept", "src": ["tag:pcs"], "dst": ["autogroup:internet:
"] }

Thanks. This helps. I'll use this for debugging the issue.

@dragon2611
Copy link
Contributor Author

No problem, just be wary github initially parsed it I think as the * wasn't showing.

Was having a bit of problem with the formatting.

@pallabpain
Copy link
Contributor

pallabpain commented Aug 6, 2024

No problem, just be wary github initially parsed it I think as the * wasn't showing.

Was having a bit of problem with the formatting.

So the issue is that while the policy may be a valid HuJSON/JSON that can be marshaled into the policy struct, it may not have the right values expected in the policy. The current code only ensures format.

@dragon2611
Copy link
Contributor Author

I'm guessing the tailscale client didn't like the lack of a port definition, which is weird as for no TCP/UDP traffic there wouldn't be a port anyways.

@pallabpain
Copy link
Contributor

I'm guessing the tailscale client didn't like the lack of a port definition, which is weird as for no TCP/UDP traffic there wouldn't be a port anyways.

Per Tailscale docs, the port is expected.
https://tailscale.com/kb/1337/acl-syntax#dst

@pallabpain
Copy link
Contributor

Would make sense, @pallabpain are you able to take a look?

@kradalby I couldn't find anything in the tailscale client that I can use to validate the policy. Looks like it has to be implemented in headscale.

@oneingan
Copy link

oneingan commented Aug 6, 2024

Slightly offtopic but in our company we have integration tests for ACL changes using NixOS VMs based testing framework. The misconfiguration were a coomon thing before that. So I can imagine how proper validation tests could help a lot with ACLs.

kradalby added a commit to kradalby/headscale that referenced this issue Aug 30, 2024
this commit aims to improve the feedback of "runtime" policy
errors which would only manifest when the rules are compiled to
filter rules with nodes.

this change will in;

file-based mode load the nodes from the db and try to compile the rules on
start up and return an error if they would not work as intended.

database-based mode prevent a new ACL being written to the database if
it does not compile with the current set of node.

Fixes juanfont#2073
Fixes juanfont#2044

Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
@kradalby
Copy link
Collaborator

I think this is being solved, or at least improved in #2089

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants