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

Add support for autoApprovers ACL #763

Merged
merged 13 commits into from
Sep 23, 2022
Merged

Conversation

tsujamin
Copy link
Contributor

@tsujamin tsujamin commented Aug 24, 2022

  • read the CONTRIBUTING guidelines
  • 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

I've patched in support for AutoApprovers for exit nodes and subnets per https://tailscale.com/blog/auto-approvers/

The behaviour of the code is (currently)

  • Support auto-approving nodes that advertise subnets or exit status by tag, group or namespace
  • Advertised routes can be auto-approved by a overarching autoApproved route (e.g. advertised route 10.10.0.0/16 would be enabled if the node matched autoApproved route 10.0.0.0/8)
  • EnableAutoApprovedRoutes is called in protocol_common_poll.go!handlePollCommon, although I'm not 100% sure if this is the appropriate place within headscale

Let me know what you think, happy to tweak as far as my limited go skills allow

@juanfont
Copy link
Owner

juanfont commented Sep 4, 2022

@tsujamin can you update the PR to fix the conflict and replace inet.af/netaddr with net/netip?

@tsujamin
Copy link
Contributor Author

tsujamin commented Sep 6, 2022

merged and refactored

@tsujamin
Copy link
Contributor Author

tsujamin commented Sep 7, 2022

linting issues fixed

Copy link
Collaborator

@kradalby kradalby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks pretty very good, I would have liked to see these kind of tests for functions like GetRouteApprovers.

We also need a CHANGELOG entry.

}
}

for _, approvedRoute := range approvedRoutes {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have one concern here, but feel free to let me know if I have missed it:

If a node advertise a route, and at the time it is accepted by the ACL autoapprove, what happens if it is removed from the ACL?

I believe the current behaviour would result in the route being left active, which is probably ok since the feature is Auto approve and not implying that it will keep the settings in sync. However we probably should call this out somewhere, not sure where tho.

@juanfont @restanrm

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you're right - if a route advertised by a node is autoApproved under the current policy, and that policy changes, the route will remain approved. As far as I can gather this is similar to the SaaS offering's behaviour: once a route is auto-approved its up to the user to manage it from that point.

Let me know if there's a good place to docco it - another option could be (if my other preauthkey related PR is merged) writing a doc on how to use both features together and call out this behaviour there?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this resembles the upstream behaviour, which the name implies, that it will be approved and is not "state management", then it is fine.

You can document them together.

Another quick question, if a route is already announced by a node, but not approved, and then the autoApprove rule is added, will it get approved? Basically, is this evaluated when a node joins/sends an update, etc.

@tsujamin
Copy link
Contributor Author

awesome - I can add a test like that but since the underlying logic relied on the same expandAlias logic I ommited it for now.

do you want me to do the change-log or is that something the maintainers do as a rollup?

@kradalby
Copy link
Collaborator

awesome - I can add a test like that but since the underlying logic relied on the same expandAlias logic I ommited it for now.

do you want me to do the change-log or is that something the maintainers do as a rollup?

You can add the changelog.

@tsujamin
Copy link
Contributor Author

I've added the changelog - just noting though that there's a merge conflict between this and #767 so #767 would need to be merged first, then I can make the small change to a failing test here

@kradalby kradalby merged commit a507a04 into juanfont:main Sep 23, 2022
return nil, err
}

if autoApprovedPrefix.Bits() >= prefix.Bits() &&
Copy link

@samcday samcday Oct 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this logic might be the wrong way around?

i.e if I have an auto approved prefix of 10.0.0.0/8 and then I try to advertise 10.1.0.0/24, I would expect autoApprovedPrefix.Bits() == 8 and prefix.Bits() == 24, or am I misunderstanding this?

I ask because I tried out the parent prefix thing and it doesn't seem to work for me. For now I'm going to add all 255 /24s I need to my ACL to move on xD. If I get some time later I might try forking and inverting this logic and see if it fixes my issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you're right, bugger but thanks for the find.

@juanfont @kradalby I'll write and submit a PR to fix this with a regression test

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, thanks for the speedy response. And also thanks for shipping this very hype feature :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np, nothing good on tv right now 😂 should be fixed in #862 hopefully

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

Successfully merging this pull request may close these issues.

4 participants