chore(connlib): use proxy ip to match filters instead of translated#6960
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
I manually tested this with the local docker-compose as it's hard to do automated testing until we do non-icmp packets in proptests |
thomaseizinger
left a comment
There was a problem hiding this comment.
Left some comments with ideas.
| fn ensure_allowed_dst(&mut self, packet: &IpPacket) -> anyhow::Result<()> { | ||
| let dst = packet.destination(); | ||
|
|
||
| // Note a Gateway with Internet resource should never get packets for other resources |
There was a problem hiding this comment.
Can you open an issue where we can brainstorm design ideas how we can model this better?
| ipv4: Ipv4Addr, | ||
| ipv6: Ipv6Addr, | ||
| resources: HashMap<ResourceId, ResourceOnGateway>, | ||
| internet_resource_enabled: bool, |
There was a problem hiding this comment.
Isn't this implicit from having an Internet Resource in the hash map? Why track this separately?
There was a problem hiding this comment.
If this is just a cache, let's document that. Plus, should we have a follow-up to make it an either resources or Internet resource in here once Internet Sites are released?
|
|
||
| debug_assert!(resource.is_dns()); | ||
|
|
||
| let mut filter_engine = FilterEngine::empty(); |
There was a problem hiding this comment.
Is there a way we can de-duplicate this with the above bit?
There was a problem hiding this comment.
LMK what you think now
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { |
There was a problem hiding this comment.
Would it be very difficult to at least add a unit-test? I think some kind of automated test would be good, doesn't have to be a proptest.
There was a problem hiding this comment.
I can do it, I'd need to replicate the whole proxy-ips thingy to have it mean something. Let me take another look at this.
There was a problem hiding this comment.
I can do it, I'd need to replicate the whole proxy-ips thingy to have it mean something. Let me take another look at this.
It shouldn't be that difficult, should it? All we need is to define a few IP addresses, doesn't have to be 8, 1 proxy IP should be enough, right?
I think doing a TCP handshake in the proptests should be pretty easy now that we have |
yeah, I'd like to do that. But why do you think adding filters would be hard? It's encoding the expected packets? |
I think so yes. If we randomly sample the filters, I think we will need to essentially re-build the filter matching engine in the tests to compute, whether the packet will make it through. What we can do is perhaps make a simpler model by only adding resources with certain filters, like HTTP, HTTPS, SSH etc. If there is only a certain list to choose from, we can for example easily test that packets on other ports don't go through. That would still have the benefit of checking what we fix in this PR I think. We do still miss out on some of the overlapping filters logic then but perhaps that is a good trade-off? Similarly to DNS names where we only use 1 level of subdomains for wildcard resources, the proptest could only use a certain subset of the filter features and we leave the rest to more specific unit tests. |
| tracing::trace!(%addr, filters = ?filter_engine, "Installing new filters"); | ||
| self.filters.insert(*addr, filter_engine); |
There was a problem hiding this comment.
Could we deduplicate this too? I think it should be possible to have have a function that takes ip and list of filters, creates a filter engine, logs it and inserts it, right?
There was a problem hiding this comment.
It's possible but I'd need a wrapper for the network table so it can be done by self.filter or a static function. Otherwise the borrow checker won't allow to take self as mutable as I'm already holding self.resources as immutable.
I could also just clone self.resources but would require making ResourceOnGateway clonable.
There was a problem hiding this comment.
updated with the static function version
|
@thomaseizinger added some unit-test! With this it should be ready for merge |
thomaseizinger
left a comment
There was a problem hiding this comment.
Awesome, thanks for adding tests!
Previously, when a gateway checked if a packet was allowed through, it used the real IP of the DNS resource that the client was trying to communicate with.
The problem with this was that if there's an overlapping CIDR resource with the real IP this would allow a user to send packets using the filters for that resource instead of the DNS resource filters.
This can be confusing for users as packet can flow unexpectedly to the resources even if the filter doesn't permit it, so we use the IP of the packet before we translate it to the real IP to match the filters.
This doesn't change the security of this feature as a user can just change the IP of the packet with the dst of the DNS or the cidr resource according to what they need.
Fixes #6806