Repository navigation
design-proposal: cross-tenant reachability of LoadBalancer public IPs - #92
mattia-eleuteri wants to merge 7 commits into
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
Aleksei Sviridkin (lexfrei)
left a comment
There was a problem hiding this comment.
mattia-eleuteri The core problem is real. With kube-proxy replacement the tenant egress verdict is taken after the LoadBalancer IP is translated, so a pod of tenant A that dials tenant B's public IP is judged against B's backend and dropped. But the problem statement is wider than what main does, and the policy side already has a working precedent in this repo.
The egress policy is more than the own tenant plus world. The <tenant>-egress CCNP in packages/apps/tenant/templates/networkpolicy.yaml also allows the cozystack.io/service: ingress pods in every ancestor namespace. That rule came in with 4dfdbfeb6 for this exact case: a nested cluster in Proxied mode reaching its own domains through the parent's ingress. So a child already reaches its parent's public ingress, and the third bullet of The problem is not true. Every tenant is a descendant of tenant-root, so every tenant reaches the host ingress too, and rollout step 4 has nothing to fix there. The first bullet is narrower as well. With exposeMethod: Proxied, which is the default, B's cluster is published on the controller of its ingress-owning ancestor, and A reaches it whenever A shares that ancestor. What is really broken: ingress controllers of a tenant that is not an ancestor of the client, CCM Services of tenant clusters, and databases with external: true.
The recommended fix does not cover every variant. The isp-slim variants run Cilium L2 announcements instead of MetalLB (values-isp-slim.yaml) and still ship the paas databases. The L4 mode finds its announcer through MetalLB's ServiceL2Status, so it does nothing there, while a toServices rule works on both.
I also think the datapath is out of proportion to what is left. cozy-proxy#25 adds about 5,900 lines: a second stateful L4 balancer next to Cilium, with its own conntrack handling, announcer tracking tied to MetalLB, a measured SYN-ACK loss and several open questions about itself. For Services with a selector the proposal already calls toServices the strongest option, and the ancestor-ingress rule shows its costs are accepted here for ingress pods, which are public on 80/443 anyway. I'd split it. A policy rule for ingress controllers and external databases covers most cases on every variant. The datapath question then shrinks to the CCM Services, and it should wait for open question 5: once HTTP and databases move behind the Gateway, CCM is most of what remains, and a new datapath should be weighed against that.
One more thing: the commit carries a Co-Authored-By line that names a model. This repo merges by rebase, so please make it Assisted-by: LLM.
Assisted-by: LLM Signed-off-by: Mattia Eleuteri <mattia@hidora.io>
26ec189 to
accf6e6
Compare
|
Revised in 06f21ce, and the trailer is now You were right on the problem statement. The ancestor ingress rule from 4dfdbfeb6 is now in Context, and the problem is restated as the three cases that are actually broken: ingress controllers of a non-ancestor tenant, databases with I took the split for Services with a selector. Part A is now a I don't think the CCM part should wait for the Gateway, for two reasons:
So Part B keeps the L4 mode for CCM Services only. That's the case no policy rule can cover without opening every tenant cluster's NodePort range. isp-slim is out of its scope, since it has no iaas and therefore no CCM Services. The variants that do run tenant clusters run MetalLB and kube-ovn. Its costs (size, the SYN-ACK loss under churn, the MetalLB dependency) remain stated and are open questions 1 and 2. |
Aleksei Sviridkin (lexfrei)
left a comment
There was a problem hiding this comment.
mattia-eleuteri The split works for me, and so does keeping Part B for the CCM Services. cloud-config.yaml sets selectorless: true, so every infra Service is selectorless, and a Gateway does not realize the Services a tenant creates inside its own cluster. The ancestor derivation is as you describe too: tenant-foo-bar gets tenant-foo only, so I was wrong that every tenant reaches the host ingress.
One gap is left in Part A. The problem lists "a database of tenant B with external: true", but the table covers only Postgres and MariaDB. On main, kafka, mongodb, nats, opensearch, qdrant, rabbitmq, redis, valkey, openbao, tcp-balancer and vpn also render a public LoadBalancer Service with a selector when external is set. Some of these come from an operator rather than from a template in the app chart (the Strimzi listener for Kafka, the RabbitmqCluster service for RabbitMQ), so the label has to go through each operator's own service settings. Please either list every kind and where its label is set, or narrow case 2 and the Goals to the kinds Part A covers and say what stays broken for the rest.
|
Listed every kind. Part A now has one row per published Service, with where the label is set and the backend ports the rule needs (read on
Ports are the backend ones, since Cilium evaluates the translated destination: tcp-balancer publishes 80/443 on container ports 8080/8443, so its rule lists those. One kind is not covered: rabbitmq. |
|
One correction to the openbao row (453b0ff): with |
|
Hi! We removed Sorry for the extra work, I wanted to mention this now so it doesn't come up late in review. |
Aleksei Sviridkin (lexfrei)
left a comment
There was a problem hiding this comment.
mattia-eleuteri NOT LGTM. The proposal still gives conflicting guarantees about tenant isolation.
The inventory gap from my previous review is fixed. I am not asking for the implementation before accepting the design.
The access guarantee needs a decision. Goals says no tenant gains access to another tenant's ClusterIPs, while Security explicitly accepts that access for labelled backends. Evidence: README lines 146-154 and 342-345 contradict each other, and Cilium converts toServices into a backend selector scoped to the Service's namespace. That grant cannot distinguish the public IP from a ClusterIP or direct backend access on the allowed port. Please make Goals and Non-goals agree with the intended policy. I missed this in the earlier review.
The rejection of policy alternatives is broader than the mechanism supports. Evidence: lines 24-25 say no policy can admit CCM Services without opening the whole NodePort range, but lines 247-250 explain the narrower case of one shared rule with static ports. A rule for an individual Service retains its own toPorts; the converter does not expand it to a range. Please limit the claim to the shared static rule. The shipped agent's lack of pod-CIDR matching remains a valid limitation; no new controller or alternative implementation is needed for this correction.
The public text also needs updating. Evidence: the PR body still recommends the datapath option for selector-based Services, unlike the document's split, and retains the Generated with Claude Code byline. Please sync the body and remove that byline. The current proposal rules require removing the Date and Status headers. The commit bodies saying "The problem statement now accounts" and "Part A now covers" describe revisions; please replace them with the reason for the change, keeping the sign-offs and Assisted-by: LLM.
…only L4 mode Services with a selector can be admitted by a toServices rule in the tenant egress policy, which needs no new datapath and works on every variant. Only the selectorless CCM Services of tenant clusters have no policy route, so the cozy-proxy L4 mode is limited to them. The ancestor ingress rule and the Proxied expose method already cover part of the cross-tenant cases, so the problem statement is restricted to what main leaves broken. Assisted-by: LLM Signed-off-by: Mattia Eleuteri <mattia@hidora.io>
Besides Postgres and MariaDB, every application that publishes a LoadBalancer Service with a selector when external is set is broken the same way, and several get that Service from an operator CR or a nested chart, which is where the label has to be set. rabbitmq has no verified label route and stays as today until one is shown safe. Assisted-by: LLM Signed-off-by: Mattia Eleuteri <mattia@hidora.io>
With more than one replica the openbao chart also renders -active and -standby Services, both enabled by default and both taking server.service.type, so external makes them LoadBalancers as well. The chart reads their labels from server.service.active.extraLabels and server.service.standby.extraLabels, not from server.service.extraLabels, so the row has to name all three. Assisted-by: LLM Signed-off-by: Mattia Eleuteri <mattia@hidora.io>
A toServices grant admits the backends of the matched Services by any address that reaches them on the allowed ports, so Part A cannot promise that their ClusterIPs stay closed, while Part B opens the public IP only. The rejection of policy rules for CCM Services holds for a shared rule with static ports: a rule for one Service keeps its own ports, and what rules it out is the shipped agent's lack of pod-CIDR matching. Proposal status and dates come from the PR history under the current proposal rules. Assisted-by: LLM Signed-off-by: Mattia Eleuteri <mattia@hidora.io>
…l backend With MetalLB in BGP mode and eTP Local, every node with a ready backend advertises the IP and the routers spread flows across them with ECMP. A node that translates only as the L2 announcer sends the flows hashed to the other backend nodes to the default gateway, which drops them. This was seen on a production cluster running MetalLB in L2 and BGP at once, and cozystack/cozy-proxy#25 translates on those nodes as well. Assisted-by: LLM Signed-off-by: Mattia Eleuteri <mattia@hidora.io>
3ed6a41 to
9a367ff
Compare
|
Aleksei Sviridkin (@lexfrei) Revised; the branch is rewritten up to 9a367ff.
One addition, from production: with MetalLB in L2 and BGP at once, eTP |
Aleksei Sviridkin (lexfrei)
left a comment
There was a problem hiding this comment.
NOT LGTM. The three points from my last review are addressed: Goals and Non-goals now match Security, the policy rejection is limited to the shared static rule, and the PR body, header and commit bodies are fixed. What blocks now is that Part B's main reason against a policy rule is out of date. Main ships Cilium 1.20.2, which accepts policy-cidr-match-mode=pods. I believe the rejection still stands for another reason, given inline. The other comments ask to fix the shape of the switches and label keys, decide how loadBalancerSourceRanges is handled, and test the operator-routed labels and the CCM patch.
|
|
||
| A `toServices` rule on a selectorless Service becomes a CIDR selector on its | ||
| EndpointSlice IPs, which matches pods only with `policy-cidr-match-mode=pods`. | ||
| That value is accepted from Cilium 1.20 (cilium/cilium#45194); Cozystack ships |
There was a problem hiding this comment.
This is no longer true on main: since 0f31e7a14 Cozystack ships Cilium 1.20.2 (packages/system/cilium/images/cilium/Dockerfile), and its agent accepts pods (validatePolicyCIDRMatchMode in pkg/option/config.go at v1.20.2). I think the rejection still holds, for a different reason: the mode is agent-wide, and tenants write SecurityGroups whose toCIDR becomes a Cilium CIDR rule (pkg/registry/sdn/securitygroup/cilium.go). With pods enabled, a tenant's toCIDR covering the pod CIDR would match other tenants' pods, so a tenant could grant itself reach into another tenant. Please replace the version argument with that one here, in the Overview (line 22), in Alternatives (line 482) and in the PR body, and say the lab run was on 1.19.5.
There was a problem hiding this comment.
Agreed, fixed in 24ca622. "Why not a policy rule" now rests on the agent-wide mode and the SecurityGroup toCIDR it would widen, and says the lab ran on 1.19.5 before the bump. Overview, Alternatives and the PR body follow.
| - Tenants: the public IP of an opted-in Service becomes reachable from every | ||
| tenant. Under Part A the backend sees the client pod; under Part B it sees | ||
| the translating node's join-network address (`100.64.x` on kube-ovn). | ||
| - Admins: a platform switch per Service type for Part A, and |
There was a problem hiding this comment.
These two switches have no shape yet. Please name each one: the file and key, type and default, and who can set it. For the CCM switch this matters for security: if it is a value of the Kubernetes application, a tenant can turn it on, which contradicts "Opt-in is set by the platform only" (line 152). If that is acceptable because a tenant can only open its own Services, say so in Security.
There was a problem hiding this comment.
Done in 24ca622, new "Switches" section with a table: platform values networking.crossTenantLoadBalancer.kinds (list, []) and networking.crossTenantLoadBalancer.ccmServices (bool, false), carried as _cluster keys, plus l4LoadBalancer.enabled on cozy-proxy. The CCM switch is not a value of the Kubernetes application, and the API refuses _ keys in application values (validateNoInternalKeys), so a tenant cannot turn it on.
| annotation of the tenant Service onto the infra Service, but not its labels, so | ||
| a tenant cannot opt in by itself. | ||
|
|
||
| Both are set by a new CCM patch in |
There was a problem hiding this comment.
Goals promise a per-Service opt-in (line 152), but this patch sets both on every eTP Local Service of a cluster once the switch is on, so the platform's decision is per cluster, and only the rollback is per Service. Note also that the upstream CCM writes metadata only when it creates the infra Service and later updates only the ports (pkg/provider/loadbalancer.go at a0acf33, EnsureLoadBalancer and updateLoadBalancerServicePorts). Please state the real granularity in Goals, and say what the one-shot patch for existing Services is: a platform migration, or a manual runbook step.
There was a problem hiding this comment.
Right. Goals now say it: Part B is switched platform-wide for CCM Services created afterwards, and only the rollback is per Service. Since the CCM writes metadata only at creation, existing infra Services are opted in by a runbook step, Service by Service, not by a platform migration (24ca622).
| `service.cilium.io/type: ClusterIP` without it only makes the tenant's own IP | ||
| dark. A tenant still controls the ports and the eTP of its CCM Service, as | ||
| today. | ||
| - `loadBalancerSourceRanges` is enforced by Cilium on the frontend this mode |
There was a problem hiding this comment.
"Enforce or refuse" leaves a security behavior to the implementation. Please pick one here. Refusing it, like eTP Cluster, is the smaller change and keeps the owner's restriction. Or list it under Open questions as a decision for the cozy-proxy PR.
There was a problem hiding this comment.
Picked refusal (24ca622): the CCM patch does not opt in a Service with loadBalancerSourceRanges, and cozy-proxy refuses one labelled anyway, like eTP Cluster. The owner's restriction stays with Cilium. Enforcing in guard is left for later if someone asks for it.
| 4. **Gateway public IPs.** Once databases and HTTP move behind a Cilium Gateway, | ||
| is the Gateway's public IP reachable across tenants? Part A's rule targets | ||
| the per-release Services and would need its own counterpart there. | ||
| 5. **Label keys.** `networking.cozystack.io/cross-tenant` and |
There was a problem hiding this comment.
The template asks for open questions to be closed before acceptance, and these keys are the API that both parts introduce. Please fix the two keys, and for Part A the label values (the kind names of the table, I assume), in the Design section. If you prefer to settle them on the implementing PRs, say that explicitly here.
There was a problem hiding this comment.
Fixed in the Design section (24ca622): networking.cozystack.io/cross-tenant with the kind names of the table as values, and networking.cozystack.io/lb-proxy: cozy-proxy. The open question is gone.
|
|
||
| ## Testing | ||
|
|
||
| - Part A: chart unit tests, per row of the table, that the label is rendered |
There was a problem hiding this comment.
For the rows that go through an operator or a nested chart (mariadb, mongodb replicaset, kafka, nats, qdrant, openbao), a chart unit test can only check the CR or values field, not that the label reaches the Service. That propagation is exactly what failed for rabbitmq. Please add an e2e assertion per such kind that the published Service carries the label, not a test that parses the operator's code. The same e2e also catches drift between the tenant chart's port map and the app's backend ports, which today only the Postgres e2e would see.
There was a problem hiding this comment.
Added (24ca622): an e2e per kind that asserts the label on every published Service and opens a cross-tenant connection on each declared port. The operator and nested-chart rows are listed explicitly, and the connection also catches port map drift.
| - rabbitmq, before its row is filled: a metadata-only `override.service` on a | ||
| published `RabbitmqCluster`, checked for NodePort churn over several operator | ||
| reconciles. | ||
| - Part B, in cozystack/cozy-proxy#25: unit tests for selection, desired state |
There was a problem hiding this comment.
The CCM patch is the trust anchor of Part B, and Testing does not cover it. Please add unit tests for that patch (the CCM image build already runs the tests of the packages a patch touches): the label and annotation are set only with the switch on and eTP Local, and a copied service.cilium.io/type is overridden on any other Service.
There was a problem hiding this comment.
Added (24ca622): unit tests next to the patched package. Label and annotation only with the switch on, eTP Local and no source ranges; otherwise neither, and a copied service.cilium.io/type is removed.
|
|
||
| #### Datapath | ||
|
|
||
| cozy-proxy gets a second, independent mode behind `--enable-l4-loadbalancer` |
There was a problem hiding this comment.
cozy-proxy#25 now has a fourth step: since a4bdac77, translate rules mark the flow with its VIP and an unnat chain writes the VIP back as the source of replies to non-masqueraded clients. That changes the reply path and adds conntrack marks, so please describe it here next to guard, translate and masq.
There was a problem hiding this comment.
Described next to the other chains (24ca622): the VIP mark set by translate, the unnat chain between conntrack and routing, why replies need it on source-routed nodes, and that pre-upgrade flows carry no mark and keep their path. Also added to Failure cases and the kernel tests.
…e ranges Cozystack now ships Cilium 1.20.2, whose agent accepts pod-CIDR matching, so the version no longer rules out a policy rule for CCM Services. The mode is agent-wide and would let a tenant's SecurityGroup toCIDR match other tenants' pods, which still does. The switches, label keys and handling of loadBalancerSourceRanges are the API and the security behavior both parts introduce, so they belong in the proposal rather than in the implementing PRs. The CCM writes an infra Service's metadata only at creation, so the Part B switch cannot be per Service, and the operator-routed labels and the CCM patch need tests of their own. cozy-proxy#25 added a reply path that the Datapath section did not describe. Assisted-by: LLM Signed-off-by: Mattia Eleuteri <mattia@hidora.io>
Cilium enforces the source ranges on the LoadBalancer frontend that service.cilium.io/type: ClusterIP removes, and the L4 mode does not read them, so programming such a service would lift its owner's restriction. cozystack/community#92 settles on refusing it, like eTP Cluster, and leaving it to Cilium. Assisted-by: LLM Signed-off-by: Mattia Eleuteri <mattia@hidora.io>
Cilium enforces the source ranges on the LoadBalancer frontend that service.cilium.io/type: ClusterIP removes, and the L4 mode does not read them, so programming such a service would lift its owner's restriction. cozystack/community#92 settles on refusing it, like eTP Cluster, and leaving it to Cilium. Assisted-by: LLM Signed-off-by: Mattia Eleuteri <mattia@hidora.io>
A pod of one tenant cannot reach the public IP of another tenant's
LoadBalancerService, although the Internet can. With kube-proxy replacement, Cilium translates the LoadBalancer IP to a backend pod before the tenant egress policy is evaluated, so the verdict is taken against another tenant's pod and the connection is dropped. VMs exposed through cozy-proxy are not affected since026b1c781.The proposal splits the fix by the kind of Service:
external):toServicesrules in the tenant egress policy on platform-labelled Services, with backend ports per kind. No new datapath, works on every variant. The grant covers the backends of opted-in Services on those ports, whatever address reaches them. Every published kind has a label route except RabbitMQ, which stays as today until one is verified. A Service with source ranges (design-proposal: source-IP restriction for externally published applications #87) is not labelled.policy-cidr-match-mode=pods(accepted since the shipped 1.20.2), which would also let a tenant's SecurityGrouptoCIDRreach other tenants' pods, and a single shared rule with static ports would open every tenant cluster's NodePort range. For these only, an opt-in L4 mode in cozy-proxy takes the public IP over from Cilium (service.cilium.io/type: ClusterIPplus a platform-only label), so the client is seen asworldand isolation is not widened. It translates on MetalLB's L2 announcer and on every node with a ready backend, which is what MetalLB in BGP mode advertises from. Prototype: feat: add an L4 LoadBalancer mode for non-VM services cozy-proxy#25, run on a lab with Cilium 1.19.5.It also records why the Part B opt-in is a label rather than
loadBalancerClass(loadbalancer-announcer-neutrality), and that Part B removes the Cilium frontend that enforcesloadBalancerSourceRanges, so a Service that sets it is not opted in and stays with Cilium. The switches (platform-only_clustervalues) and the label keys are fixed in the Design section.