Skip to content

fix(neutron): carry security groups on the ports, with a network node and a firewall per port (SPEC-033) - #118

Open
uw-sc wants to merge 4 commits into
cobaltcore-dev:mainfrom
uw-sc:bugfix/579-server-security-group-membership-never-reaches-ports-create-os-addremovesecuritygroup-os-interface
Open

uw-sc wants to merge 4 commits into
cobaltcore-dev:mainfrom
uw-sc:bugfix/579-server-security-group-membership-never-reaches-ports-create-os-addremovesecuritygroup-os-interface

Conversation

@uw-sc

@uw-sc uw-sc commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

A server's security groups never reached its ports: create, addSecurityGroup, removeSecurityGroup and
interface attach changed a record the firewall never read. This PR puts the groups on the ports, as upstream does,
and rebuilds real-mode networking around them.

Closes cobaltcore-dev/cloud-storage#579

Spec, plan, tasks and host runbook: docs/specs/033-sg-port-membership/.

What's in it

  • Groups on ports. Every group change, through the compute or the Networking API, changes the ports and is
    applied to the firewall before the answer.
  • Networking API as upstream's. The security-group, subnet, router, floating-IP and port-forwarding answers now
    match upstream: listing filters, revisions with If-Match, stateless groups, allocation pools with one allocator,
    router gateway ports, and administrators reaching every project's resources.
  • Real-mode layout.
    • One network node (neutron.network_node) holds every router (qrouter-<id>) and each network's DHCP and
      metadata (qdhcp-<network>).
    • Every port is firewalled by its own iptables chains on the node it is bound to, in iptables and ebpf mode.
    • A change the holding node cannot apply within one second is undone and answers 500.
    • The reconciler converges both ways and removes the previous layout.
  • Chart and Compose. Mount /run/netns and /lib/modules, run real mode privileged, and refuse a multi-node
    setup without VXLAN and a network node.
  • Schema. Migrations 076 and 077. Group names may repeat, with one default per project.

Operator notes

A clean break; docs/UPGRADING.md has the full tables.

  • Firewall. Every port's chains now end in a drop. Groups created before this release have no egress rules, so
    give them the two shown in UPGRADING. Servers from v0.6.1 or earlier report no groups; add them again.
  • Real mode needs br_netfilter (readiness fails without it) and a privileged pod.
  • Multi-node needs neutron.network_node and VXLAN.

Testing

  • make lint 0 issues; unit tests on PostgreSQL and SQLite 0 failures; helm unittest all pass.
  • Contract suites last run before the second branch review (PostgreSQL 419/0/11, SQLite 392/0/12).
  • Host runbook on one k3s node with real libvirt and Horizon, on 2026-11-25: steps 2.1–2.18 passed.

Not in this PR

  • Two nodes. VXLAN has no flooding destination, so broadcast and DHCP do not cross nodes.
  • DHCPv6, and eBPF, which stays unwired. Other findings are in follow-ups.md.

🤖 Generated with Claude Code

@uw-sc uw-sc self-assigned this Nov 26, 2026
Uwe Schwaeke added 2 commits November 26, 2026 14:55
A server's security groups are now its ports' groups. Create, add and
remove, interface attach and the port API all change the ports; the
node's firewall and floating-IP NAT are applied after each change and
undone compare-and-set if that fails, and the reconciler converges
floating-IP state both ways.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Uwe Schwaeke <uwe.schwaeke@sap.com>
…ixes

Specify, research, plan and break down the second round of SPEC-033.
No code changes; implementation starts at T058.

API, as upstream:
- the security-group listing honours every filter; groups carry a
  revision number (If-Match honoured) and may be stateless
- `default` cannot be deleted by a member, renamed or duplicated; other
  names may repeat, an ambiguous name answering 409 NoUniqueMatch
- subnets store allocation pools; one allocator serves every address
- floating-IP creates no longer race; associations need a router that
  joins the port's subnet to the floating network
- routers get gateway ports with external_fixed_ips
- administrators list, show and write every project's Networking API
  resources

Real-mode layout, as upstream's legacy L3 and iptables drivers:
- one network node holds every router and DHCP namespace; other nodes
  ask it to apply through a bounded node-to-node call
- every port is firewalled on its node, both directions; the
  floating-IP filter is retired
- deletions remove host state before their record; no request path
  logs a failed host step and answers success
- namespaces survive pod restarts; br_netfilter is required

Constitution v1.5.0 is refined in place: the node that holds the state
applies a change, a new exception covers removals applied before their
record, Article V describes the new isolation, and register entry 5 is
narrowed to names.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Uwe Schwaeke <uwe.schwaeke@sap.com>

@senolcolak senolcolak left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Four reproduced findings from a comprehensive review of 066d470. The existing Linux unit suites pass on PostgreSQL and SQLite, but the cases below expose a gateway trust-policy bypass and three networking regressions. I recommend addressing these before merge.

var p routerGatewayPort
err := tx.QueryRow(ctx, `
SELECT id::text, network_id::text, mac_address, fixed_ips, created_at, updated_at FROM ports
WHERE device_id::text = $1 AND device_owner = $2`, routerID, ownerRouterGateway,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P1] Restrict gateway rollback snapshots to the router's real gateway port

This lookup lacks the project_id IS NULL condition used by gatewayPortsOf. A member can create a port on a network they own with device_owner=network:router_gateway and device_id set to their router. If a later gateway update fails host application, undoRouterGateway snapshots that member-created port and recreates it with project_id=NULL. The recovery converge then treats its chosen address as a trusted external gateway and routes/proxies it on the uplink, despite the API returning 500.

I reproduced this on both PostgreSQL and SQLite: after an injected host-apply failure, a member-created 192.0.2.1 port had project_id=NULL and was held as the router gateway. This defeats the administrator-only external-address policy. Please use the canonical gateway ownership predicate for snapshots and restores.

var local []string
for _, b := range bridges {
local = append(local,
"-A "+chainLocal+" -i "+b+" -m physdev --physdev-in tap+ --physdev-is-bridged -j "+chainBoundIn,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P2] Guard orphan TAP traffic that is addressed to the host

Both wildcard guards require --physdev-is-bridged, so host-bound packets entering INPUT do not match them. While a port is present its explicit physdev-in dispatch checks egress, but deleting/unbinding the port removes that dispatch. The packet then falls through the host INPUT policy, allowing traffic that the removed port's groups/source checks previously controlled.

With real Linux bridge/veth devices and FirewallManager, a new ping to the host still succeeded after ConvergePorts(nil). I verified IPv4 with a bridge address and IPv6 with the bridge's automatic link-local address. Please add a managed-bridge TAP guard for INPUT that does not require bridged forwarding.

Comment thread internal/neutron/units.go
if gone(p.id) || len(p.fixedIPs) == 0 {
continue
}
if sub, ok := subnets[p.fixedIPs[0].SubnetID]; ok {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P2] Render every fixed IP of a router interface port

add_router_interface accepts and validates a port with one IPv4 subnet and IPv6 subnets, but this renderer applies only fixed_ips[0]. The API returns 200 while the namespace lacks the remaining addresses and connected routes. Ordering decides which family breaks: an IPv6-first port loses IPv4 routing.

I reproduced the missing second address through the API on PostgreSQL and SQLite; with IPv6 first, only fd00:184::1/64 was converged and 10.184.0.1/24 was omitted. Please carry all fixed IPs into one interface leg's address list and retain all subnet memberships for router checks/removal.

}
}
switch {
case p.DefaultRoute != "" && held.defaultVia != p.DefaultRoute:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P2] Compare the default route's device as well as its next hop

Switching external networks creates a new gateway port/device. If both networks use the same gateway IP, held.defaultVia equals p.DefaultRoute and this skips route replacement. Deleting the old veth subsequently deletes its default route, while ConvergeRouter still returns success. Egress remains broken until another reconciliation pass.

A real namespace reproduction started with default via 198.51.100.1 dev qg-18400001-00; successful convergence to the replacement gateway left the default route listing empty. Please replace the route when the device changes, before deleting the old leg.

Uwe Schwaeke added 2 commits November 26, 2026 15:15
Security groups take every listing filter, revision numbers with
If-Match and stateless groups, refuse changes to default as upstream
does, and may share names. Subnets store their allocation pools, and
one allocator serves ports, router gateways and floating IPs. A
router's gateway is a port holding its address, and a floating IP
finds its router as upstream's lookup does. Only a router's own
records make a port its gateway or interface; a member's port
claiming either is not one. Administrators list, show and change
every project's networking resources.
A port is its project’s and its network owner’s to read, as
upstream’s: a shared network’s other ports stay hidden.
Only an administrator or the network’s project gives a port a
network: owner, as upstream’s policy has it.
A server’s ports are those of its project that name it, for its
group actions and its reported groups.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Uwe Schwaeke <uwe.schwaeke@sap.com>
Round 2 of SPEC-033's real-mode layout, as upstream's: one network node
(neutron.network_node; without VXLAN every node is its own) holds every
router in a qrouter-<id> namespace and each network's DHCP and metadata in
a qdhcp-<network> namespace. Every port is firewalled on the node it is
bound to (binding:host_id) by its own iptables chains, built from its
groups with remote groups resolved to their members, in iptables and ebpf
mode alike. The per-fixed-IP floating-IP filter is retired.

- A request stores its change, has the node that holds the state apply
  it before the answer (a function call there, an authenticated one-second
  node call otherwise), and undoes its own change compare-and-set when
  that fails. A deletion removes the host state before its record and
  re-applies it when the record stays.
- The DHCP port takes the lowest free pool address; dnsmasq serves static
  ranges with option 121; metadata is served in the namespace and
  identifies a guest by network and address. Ports honour fixed_ips.
- Nova binds a port before the guest starts, a revived guest's too, and
  every domain names the guest's TAP for its port.
- Each node's reconciler converges what it holds both ways, removing by
  "no record" only after a complete read; it removes what earlier layouts
  left where it recognises it, the uplink's stray proxy entries, and the
  VXLAN entries and devices no record holds. Teardown and its
  database-less fallback remove the new layout.
- At start, real mode loads br_netfilter and turns on bridge-nf-call-
  iptables and -ip6tables; readiness fails, naming bridge-netfilter,
  while they do not hold.
- The chart's pod and the KVM Compose file mount the host's /run/netns
  both ways and /lib/modules read-only; the teardown purge Job mounts
  /run/netns. The chart runs real mode privileged, as bidirectional
  propagation needs, and refuses multi-node VXLAN without
  neutron.networkNode.
- Removed: TAPDeviceManager and the metadata DNAT remover, which nothing
  called any more, github.com/coreos/go-iptables, which nothing imports,
  and pkg/networking's eBPF wrapper, which lost its last caller with
  Neutron's TAP; pkg/networking/ebpf stays for the separate decision.
- Docs: UPGRADING.md (round 2's answers, the clean break), EBPF_STATUS.md,
  the networking, VXLAN, configuration, troubleshooting, scaling and
  architecture docs, the chart README, CLAUDE.md; the host runbook; the
  Horizon compatibility report, recording instance Edit Security Groups
  as verified.
- A security group rule is checked and stored as upstream's: its
  direction, ethertype, protocol, ports and remote prefix, each refusal
  a 400 under upstream's name. The port firewall writes a rule only as
  it parses it and leaves out what it cannot express: a newline in a
  rule's remote or protocol reached iptables-restore's input, which runs
  as root.
- A subnet's DNS servers are checked as upstream's on create, and the
  DHCP configuration writes a gateway or DNS server only as an IPv4
  address: a newline in one reached dnsmasq's configuration, which
  starts as root.
- The branch review's findings (tasks T169-T239): router ports are the
  router's records, so the port API refuses them (ServicePortInUse) and
  no member's port is routed; a port forwarding finds its router from
  its internal port, as upstream's, and frees it with the last one;
  every undo takes the allocation lock and leaves an address someone
  took meanwhile; a revived guest's TAP is named and filtered; deletions
  re-check under their locks; a subnet's gateway change reaches its
  routers. Answers follow upstream: in-use refusals carry upstream's
  messages, If-Match is read as upstream reads it, a port's and a
  subnet's create and update answer as their show, listings and creates
  ensure the project's default group. The port firewall writes a MAC as
  iptables-save prints it, so an unchanged node is only read, which
  tests now check against captured iptables-save output. The node call
  is served before the users' auth, with plain absent and absent_ids;
  unit locks go with their last user; migration 077 keeps an index on
  security_groups (project_id, name), and its marker is
  "-- lightstack:foreign-keys-off", read on the file's first line only.
- The second branch review's findings (tasks T242-T310): a subnet's
  ip_version must match its CIDR, and DHCP serves IPv4 subnets only, so
  no record stops the reconciler; a deleted port's still-running TAP is
  dropped both ways before any port's chains (ls-bound-in and -out);
  protocols are written as iptables prints them, so vrrp no longer fails
  a node's commit; a rule's delete locks its group first; a server's
  deletion frees its forwardings' floating IPs, and a losing deletion
  binds nothing back; requests waiting on a unit share one converge; one
  request gives each address once, and a gateway keeps the address it is
  not asked to change; a port forwarding's update is checked as its
  create; router:external stays while a gateway uses it; trunks take
  only ports the caller can see; add_router_interface takes a port.
  Answers follow upstream for trusted ports, an empty remote group, the
  rule listing's filters, fixed_ip_address without a port and zoned
  pools.
  The node call bypasses HTTP proxies, network_node is read trimmed, the
  chart refuses multi-node without VXLAN, and the turnkey Compose mounts
  the host's /run/netns.

Run on one Kubernetes node (k3s, real libvirt, Horizon) on 2026-11-23
with the host runbook: every step passed. Two nodes are not supported
yet, so their host run is dropped from the spec and the tasks. Known gap,
outside this change: VXLAN devices have no flooding destination, so
broadcast does not cross nodes and a guest off the network node gets no
DHCP lease (follow-ups.md, 5.1).

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Uwe Schwaeke <uwe.schwaeke@sap.com>
@uw-sc
uw-sc force-pushed the bugfix/579-server-security-group-membership-never-reaches-ports-create-os-addremovesecuritygroup-os-interface branch from 066d470 to 6e3e0ca Compare November 26, 2026 14:16
return nil
}
_, err = tx.Exec(ctx, `
UPDATE floating_ips SET port_id = $1, fixed_ip_address = $2, router_id = $3, status = $4, updated_at = $5

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P2] Revalidate fixed-IP uniqueness before restoring an association

The compare-and-set protects this floating IP's row, but it does not protect the old port/fixed IP from a different floating IP being associated meanwhile. For example: FIP A moves from port P to port Q and commits; another allocation associates FIP B with P's old fixed IP on the same external network; the node call applying A's move fails. This UPDATE blindly puts A back on P, leaving A and B on the same port/fixed IP/external network, contrary to the new uniqueness check.

I reproduced this on SQLite using the API update, an injected host-apply failure, and a competing allocation's committed row during that node call. The update returned 500 and the database contained two matching associations. Reconciliation does not repair the duplicate. This path is unchanged at the current head 6e3e0ca.

Please take the appropriate port/router locks and revalidate the old association before restoring it, preserving the later allocation. keepRestorableAssociation already performs reachability and uniqueness validation for floating-IP deletion restoration; the reassociation undo needs the same protection.

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.

2 participants