Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,4 @@ Agent Substrate is built for zero-trust, multi-tenant execution of untrusted act
- **Workload & Storage Isolation**: Actors run strictly inside `gVisor` (`cmd/ateworker-gvisor`) or `Cloud Hypervisor` microVM (`cmd/ateworker-microvm`) sandboxes; plain Linux containers are not supported. `atelet` scrubs actor directories across lifecycle transitions (`resetActorDirs`), and snapshots are stamped with `ActorSandboxRuntime` metadata and transferred via `cmd/objectstore-plugin`.
- **Component & Actor Identity (mTLS, JWTs, and JWKs)**: Inter-component communication uses mTLS backed by `cmd/podcertcontroller` (`podid`, `servicedns`, and `postgres` signers). Actor JWT signing (`internal/localjwtauthority`), verification (`internal/oidcjwt`), and key discovery (served via `cmd/ate-idp-server`) are built on the standard library's crypto packages. Extend those packages rather than adding `go-jose` or another JOSE library, so the code that decides whether a token is valid stays small and supports only the algorithms Substrate uses.
- **Control-Plane Authentication & Authorization**: `ate-api-server` checks every Control RPC against an embedded OpenFGA model (`cmd/ateapi/internal/authz/model.fga`), always enforced. Every served unary RPC needs an entry in `defaultRPCPermissions` (`registry.go`): an RPC without one is denied, and a test fails the build. Access is granted per global scope and atespace through AccessPolicy (`kubectl ate access-policy`); the install's bootstrap owner is the shared `ate-client` ServiceAccount that `kubectl ate` uses. See `docs/guides/authorization.md` for roles and known gaps. Callers are authenticated via `SPIFFE` mTLS or configured OIDC `JWTProvider`s (`cmd/ateapi/internal/apiauthn`).
- **Network Isolation, Ingress, & Egress**: `manifests/ate-install/ate-system-networkpolicies.yaml` enforces default-deny ingress across `ate-system`, and `cmd/atecontroller` reconciles per-`WorkerPool` `NetworkPolicy` objects. Actors run in private `/30` point-to-point veth network namespaces (`internal/ateworker/actornet`) with link-local blocking, policy-enforced DNS filtering (`internal/atunnel/dns`), and zero ambient credentials. Outbound traffic traverses `atunnel` to `atenet-egress`, which enforces per-actor `EgressPolicy` and injects credentials out-of-band via `cmd/credential-provider/kubernetes-secrets` (`k8s-credential-provider`) or actor JWT minting.
- **Network Isolation, Ingress, & Egress**: `manifests/ate-install/ate-system-networkpolicies.yaml` enforces default-deny ingress across `ate-system`, and `cmd/atecontroller` reconciles per-`WorkerPool` `NetworkPolicy` objects. Actors run in private point-to-point veth network namespaces (`internal/ateworker/actornet`), an IPv4 `/30`, an IPv6 `/126`, or both, following the worker pod's IP families, with link-local blocking, policy-enforced DNS filtering (`internal/atunnel/dns`), and zero ambient credentials. Outbound traffic traverses `atunnel` to `atenet-egress`, which enforces per-actor `EgressPolicy` and injects credentials out-of-band via `cmd/credential-provider/kubernetes-secrets` (`k8s-credential-provider`) or actor JWT minting.
8 changes: 6 additions & 2 deletions benchmarking/atunnel/internal/workerhost/workerhost.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ import (
const Atespace = "bench"

// ActorPort is where the ingress actor listens inside each sandbox: the port
// of actornet.ActorHTTPUpstream, which ingress proxies to.
// of families.HTTPUpstream, which ingress proxies to.
const ActorPort = 80

// families are those of an IPv4 cluster's sandboxes.
var families = actornet.Families{IPv4: true}

// Sandbox is one hosted actor, as a process placing an ingress actor in it needs it.
type Sandbox struct {
// Actor is atespace/name, the value of the routing header.
Expand Down Expand Up @@ -76,7 +79,7 @@ type actor struct {
// Start starts atunnel from cfg, as a worker's main does, and hosts actors
// actors whose egress tunnels to gatewayAddress.
func Start(ctx context.Context, cfg atunnel.Config, actors int, gatewayAddress string) (*Host, error) {
t, err := atunnel.Start(ctx, cfg, actornet.ActorHTTPUpstream)
t, err := atunnel.Start(ctx, cfg, families.HTTPUpstream())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -108,6 +111,7 @@ func (h *Host) host(ctx context.Context, attribution resources.ActorAttribution,
session, err := actornet.ServeSandbox(ctx, actornet.SandboxNetworkConfig{
ActorUID: attribution.UID,
Veth: true,
Families: families,
EgressPort: h.tunnel.EgressPort,
DNSPolicy: h.tunnel.ActorEgressPolicy(attribution),
}, h.tunnel.Egress, h.tunnel.DNSRelay)
Expand Down
1 change: 1 addition & 0 deletions cmd/ateworker-gvisor/hosted.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func (s *AteWorkerService) hostActor(ctx context.Context, attribution resources.
session, err := actornet.ServeSandbox(ctx, actornet.SandboxNetworkConfig{
ActorUID: uid,
Veth: true,
Families: s.families,
EgressPort: s.tunnel.EgressPort,
DNSPolicy: s.tunnel.ActorEgressPolicy(attribution),
}, s.tunnel.Egress, s.tunnel.DNSRelay)
Expand Down
22 changes: 15 additions & 7 deletions cmd/ateworker-gvisor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,15 @@ func do(ctx context.Context) error {
}

actorLogger := actorlog.NewActorLogger(syncedWriter, metadata.OnGCE())
tunnel, err := atunnel.Start(ctx, *tunnelConfig, actornet.ActorHTTPUpstream)
families, err := actornet.PodFamilies(register.ParsePodIPs(*podIPs))
if err != nil {
return err
}
ateworkerService := NewService(tunnel, actorLogger, *maxActors, flags, bootID)
tunnel, err := atunnel.Start(ctx, *tunnelConfig, families.HTTPUpstream())
if err != nil {
return err
}
ateworkerService := NewService(tunnel, actorLogger, *maxActors, families, flags, bootID)
ateworkerService.throttleMemory = cgroup.PSIEnabled(defaultCgroupRoot)
if !ateworkerService.throttleMemory {
slog.WarnContext(ctx, "Kernel has no cgroup memory pressure (PSI), so sandboxes keep memory.max and an OOM kill in one can restart the worker")
Expand Down Expand Up @@ -366,6 +370,9 @@ type workloadSession struct {
type AteWorkerService struct {
ateworkerpb.UnimplementedWorkerServer

// families are the IP families each sandbox carries, those of this pod.
families actornet.Families

// Serializes lifecycle RPCs per actor.
locks *actorlock.Locks
// Tracks lifecycle RPCs for shutdown cancellation and draining.
Expand Down Expand Up @@ -428,8 +435,9 @@ type AteWorkerService struct {
var _ ateworkerpb.WorkerServer = (*AteWorkerService)(nil)

// NewService creates a new AteWorkerService.
func NewService(tunnel *atunnel.Tunnel, actorLogger *actorlog.ActorLogger, maxActors int, flags *flagStore, bootID string) *AteWorkerService {
func NewService(tunnel *atunnel.Tunnel, actorLogger *actorlog.ActorLogger, maxActors int, families actornet.Families, flags *flagStore, bootID string) *AteWorkerService {
s := &AteWorkerService{
families: families,
locks: actorlock.New(),
inFlight: actorlock.NewInFlight(),
actors: map[string]*hostedActor{},
Expand Down Expand Up @@ -776,7 +784,7 @@ func (s *AteWorkerService) RunWorkload(ctx context.Context, req *ateworkerpb.Run
return nil, fmt.Errorf("while starting json log pipe for %q: %w", ac.GetName(), err)
}
defer pw.Close()
if err := setupAppRootfs(req.GetActorDirs(), ac.GetName()); err != nil {
if err := setupAppRootfs(req.GetActorDirs(), ac.GetName(), s.families); err != nil {
return nil, fmt.Errorf("while composing %q rootfs: %w", ac.GetName(), err)
}
containersToDelete = append(containersToDelete, ac.GetName())
Expand All @@ -789,7 +797,7 @@ func (s *AteWorkerService) RunWorkload(ctx context.Context, req *ateworkerpb.Run
}

// Block until every wakeup-probe-enabled container reports 200.
if err := wakeupprobe.WaitAll(ctx, req.GetSpec().GetContainers(), actornet.ActorVethIP, wakeupprobe.DialFunc(s.sandboxDialer(req.GetActorUid()))); err != nil {
if err := wakeupprobe.WaitAll(ctx, req.GetSpec().GetContainers(), s.families.ActorIP(), wakeupprobe.DialFunc(s.sandboxDialer(req.GetActorUid()))); err != nil {
return nil, fmt.Errorf("while waiting for container wakeup probe: %w", err)
}
if err := s.tunnel.ActivateIngress(attribution, s.sandboxDialer(req.GetActorUid())); err != nil {
Expand Down Expand Up @@ -1279,7 +1287,7 @@ func (s *AteWorkerService) RestoreWorkload(ctx context.Context, req *ateworkerpb
return nil, fmt.Errorf("while starting json log pipe for %q: %w", ac.GetName(), err)
}
defer pw.Close()
err = setupAppRootfs(req.GetActorDirs(), ac.GetName())
err = setupAppRootfs(req.GetActorDirs(), ac.GetName(), s.families)
timing.appRootfs += lap(&tLast)
if err != nil {
return nil, fmt.Errorf("while composing %q rootfs: %w", ac.GetName(), err)
Expand Down Expand Up @@ -1307,7 +1315,7 @@ func (s *AteWorkerService) RestoreWorkload(ctx context.Context, req *ateworkerpb
}

// Block until every wakeup-probe-enabled container reports 200.
err = wakeupprobe.WaitAll(ctx, containers, actornet.ActorVethIP, wakeupprobe.DialFunc(s.sandboxDialer(req.GetActorUid())))
err = wakeupprobe.WaitAll(ctx, containers, s.families.ActorIP(), wakeupprobe.DialFunc(s.sandboxDialer(req.GetActorUid())))
timing.wakeupProbe = lap(&tLast)
if err != nil {
return nil, fmt.Errorf("while waiting for container wakeup probe: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/ateworker-gvisor/rootfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import (

// setupAppRootfs composes an application container's bundle rootfs, the base
// layer under the sandbox's restored rootfs writes, and writes its /etc files.
func setupAppRootfs(actorDirs *ateworkerpb.ActorDirs, containerName string) error {
func setupAppRootfs(actorDirs *ateworkerpb.ActorDirs, containerName string, families actornet.Families) error {
bundle := ociBundlePath(actorDirs, containerName)
if err := imagecache.SetupBundleRootfs(bundle); err != nil {
return err
}
return actornet.WriteRootfsEtcFiles(filepath.Join(bundle, "rootfs"), ocispec.Hostname)
return actornet.WriteRootfsEtcFiles(filepath.Join(bundle, "rootfs"), ocispec.Hostname, families)
}
1 change: 1 addition & 0 deletions cmd/ateworker-microvm/hosted.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func (s *AteWorkerService) hostActor(ctx context.Context, attribution resources.
// The tap and atunnel share a namespace; the guest owns the other end.
session, err := actornet.ServeSandbox(ctx, actornet.SandboxNetworkConfig{
ActorUID: uid,
Families: s.families,
EgressPort: s.tunnel.EgressPort,
DNSPolicy: s.tunnel.ActorEgressPolicy(attribution),
}, s.tunnel.Egress, s.tunnel.DNSRelay)
Expand Down
4 changes: 2 additions & 2 deletions cmd/ateworker-microvm/internal/kata/agentclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ func (a *AgentClient) UpdateRoutes(ctx context.Context, routes []*agentpb.Route)
return nil
}

// AddARPNeighbors installs static ARP entries in the guest — used to pin the
// gateway (169.254.17.1) to its FIXED MAC so a restored guest's frozen neighbor
// AddARPNeighbors installs static ARP and NDP entries in the guest — used to pin
// the gateway's addresses to its FIXED MAC so a restored guest's frozen neighbor
// entry stays valid across pods. Mirrors grpc.AgentService/AddARPNeighbors.
func (a *AgentClient) AddARPNeighbors(ctx context.Context, neighbors []*agentpb.ARPNeighbor) error {
req := &agentpb.AddARPNeighborsRequest{Neighbors: &agentpb.ARPNeighbors{ARPNeighbors: neighbors}}
Expand Down
14 changes: 11 additions & 3 deletions cmd/ateworker-microvm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,15 @@ func do(ctx context.Context) error {
return fmt.Errorf("while delegating the worker cgroup: %w", err)
}

tunnel, err := atunnel.Start(ctx, *tunnelConfig, actornet.ActorHTTPUpstream)
families, err := actornet.PodFamilies(register.ParsePodIPs(*podIPs))
if err != nil {
return err
}
ateworkerService := NewService(*podUID, *chBinary, *guestDebug, *maxActors, tunnel, actorLogger, bootID)
tunnel, err := atunnel.Start(ctx, *tunnelConfig, families.HTTPUpstream())
if err != nil {
return err
}
ateworkerService := NewService(*podUID, *chBinary, *guestDebug, *maxActors, families, tunnel, actorLogger, bootID)
ateworkerService.throttleMemory = cgroup.PSIEnabled(cgroup.Root)
if !ateworkerService.throttleMemory {
slog.WarnContext(ctx, "Kernel has no cgroup memory pressure (PSI), so actor cgroups get no memory limit and an actor over its booking can restart the worker")
Expand Down Expand Up @@ -362,6 +366,9 @@ const (
type AteWorkerService struct {
ateworkerpb.UnimplementedWorkerServer

// families are the IP families each sandbox carries, those of this pod.
families actornet.Families

// Serializes lifecycle RPCs per actor.
locks *actorlock.Locks
// Tracks lifecycle RPCs for shutdown cancellation and draining.
Expand Down Expand Up @@ -420,8 +427,9 @@ type AteWorkerService struct {
var _ ateworkerpb.WorkerServer = (*AteWorkerService)(nil)

// NewService creates a new AteWorkerService.
func NewService(podUID, chBinary string, guestDebug bool, maxActors int, tunnel *atunnel.Tunnel, actorLogger *actorlog.ActorLogger, bootID string) *AteWorkerService {
func NewService(podUID, chBinary string, guestDebug bool, maxActors int, families actornet.Families, tunnel *atunnel.Tunnel, actorLogger *actorlog.ActorLogger, bootID string) *AteWorkerService {
s := &AteWorkerService{
families: families,
locks: actorlock.New(),
inFlight: actorlock.NewInFlight(),
actors: map[string]*hostedActor{},
Expand Down
16 changes: 9 additions & 7 deletions cmd/ateworker-microvm/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import (
const (
// gatewayMAC is deliberately FIXED (locally administered), unlike
// ateworker-gvisor where a random veth MAC is fine. A CH snapshot freezes the
// guest kernel's ARP cache, including the entry for the gateway
// 169.254.17.1; restoring against a tap with a fresh random MAC would
// blackhole guest egress until that entry expired.
// guest kernel's neighbor cache, including the entries for the gateway's
// addresses; restoring against a tap with a fresh random MAC would
// blackhole guest egress until those entries expired.
gatewayMAC = "02:a8:1e:00:00:01"

// actorGuestMAC is the FIXED MAC for the guest's eth0 (the CH virtio-net).
Expand All @@ -49,9 +49,9 @@ const (

var gatewayHWAddr = actornet.MustParseMAC(gatewayMAC)

// setupActorTap creates the guest's tap with a fixed gateway address and MAC.
// setupActorTap creates the guest's tap with fixed gateway addresses and MAC.
// Returns the FDs cloud-hypervisor adopts on boot or restore.
func setupActorTap(ctx context.Context, actorNetNS netns.Handle, name string, queuePairs int) ([]*os.File, error) {
func setupActorTap(ctx context.Context, actorNetNS netns.Handle, name string, queuePairs int, families actornet.Families) ([]*os.File, error) {
var fds []*os.File
err := netns.Do(ctx, actorNetNS, func(ctx context.Context) error {
if old, lerr := netlink.LinkByName(name); lerr == nil {
Expand Down Expand Up @@ -80,8 +80,10 @@ func setupActorTap(ctx context.Context, actorNetNS netns.Handle, name string, qu
if err := netlink.LinkSetHardwareAddr(link, gatewayHWAddr); err != nil {
return fmt.Errorf("setting the gateway MAC on tap %q: %w", name, err)
}
if err := netlink.AddrReplace(link, actornet.HostVethAddr); err != nil {
return fmt.Errorf("assigning the gateway address to tap %q: %w", name, err)
for _, addr := range families.GatewayAddrs() {
if err := netlink.AddrReplace(link, addr); err != nil {
return fmt.Errorf("assigning the gateway address %s to tap %q: %w", addr, name, err)
}
}
if err := netlink.LinkSetUp(link); err != nil {
return fmt.Errorf("bringing up tap %q: %w", name, err)
Expand Down
44 changes: 33 additions & 11 deletions cmd/ateworker-microvm/net_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestHostActorReplacesSameActor(t *testing.T) {
tunnel: &atunnel.Tunnel{Egress: egressProxy, EgressPort: 15001},
actors: map[string]*hostedActor{},
maxActors: 1,
families: actornet.Families{IPv4: true, IPv6: true},
}
const actorUID = "microvm-network-replace"
t.Cleanup(func() {
Expand Down Expand Up @@ -86,10 +87,23 @@ func tapNetNS(t *testing.T, name string) netns.Handle {
// address and the MAC the guest's snapshot froze into its ARP cache.
func TestSetupActorTap(t *testing.T) {
roottest.Require(t, "creates network namespaces and tap devices")
for _, tc := range []struct {
name string
families actornet.Families
}{
{"ipv4", actornet.Families{IPv4: true}},
{"ipv6", actornet.Families{IPv6: true}},
{"dual", actornet.Families{IPv4: true, IPv6: true}},
} {
t.Run(tc.name, func(t *testing.T) { testSetupActorTap(t, tc.families) })
}
}

func testSetupActorTap(t *testing.T, families actornet.Families) {
ctx := context.Background()
ns := tapNetNS(t, "microvm-tap-test")

fds, err := setupActorTap(ctx, ns, "tap0_kata", 1)
fds, err := setupActorTap(ctx, ns, "tap0_kata", 1, families)
if err != nil {
t.Fatalf("setupActorTap: %v", err)
}
Expand All @@ -116,18 +130,26 @@ func TestSetupActorTap(t *testing.T) {
if got := link.Attrs().MTU; got != actorTapMTU {
t.Errorf("tap MTU = %d, want %d, the value the guest was snapshotted against", got, actorTapMTU)
}
addrs, err := netlink.AddrList(link, netlink.FAMILY_V4)
addrs, err := netlink.AddrList(link, netlink.FAMILY_ALL)
if err != nil {
return err
}
var found bool
for _, a := range addrs {
if a.IPNet.String() == actornet.HostVethAddr.IPNet.String() {
found = true
for _, f := range []struct {
addr *netlink.Addr
want bool
}{
{actornet.HostVethAddr, families.IPv4},
{actornet.HostVethAddrV6, families.IPv6},
} {
var found bool
for _, a := range addrs {
if a.IPNet.String() == f.addr.IPNet.String() {
found = true
}
}
if found != f.want {
t.Errorf("tap addresses = %v, gateway %s present = %v, want %v", addrs, f.addr, found, f.want)
}
}
if !found {
t.Errorf("tap addresses = %v, want the gateway %s the guest routes to", addrs, actornet.HostVethAddr)
}
return nil
}); err != nil {
Expand All @@ -147,15 +169,15 @@ func TestSetupActorTapReplacesALeftover(t *testing.T) {
ctx := context.Background()
ns := tapNetNS(t, "microvm-tap-replace")

first, err := setupActorTap(ctx, ns, "tap0_kata", 1)
first, err := setupActorTap(ctx, ns, "tap0_kata", 1, actornet.Families{IPv4: true, IPv6: true})
if err != nil {
t.Fatalf("first setupActorTap: %v", err)
}
for _, f := range first {
defer f.Close()
}

second, err := setupActorTap(ctx, ns, "tap0_kata", 2)
second, err := setupActorTap(ctx, ns, "tap0_kata", 2, actornet.Families{IPv4: true, IPv6: true})
if err != nil {
t.Fatalf("second setupActorTap over a leftover: %v", err)
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/ateworker-microvm/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"go.ate.dev/substrate/internal/ateworker/phaselog"
"go.ate.dev/substrate/internal/workerstats"

"go.ate.dev/substrate/internal/ateworker/actornet"
"go.ate.dev/substrate/internal/ateworker/cgroup"

"go.ate.dev/substrate/cmd/ateworker-microvm/internal/ch"
Expand Down Expand Up @@ -377,7 +376,7 @@ func (s *AteWorkerService) restoreMemoryFidelity(ctx context.Context, p actorBoo
}
}()
for i, nd := range netDevs {
files, terr := setupActorTap(ctx, s.sandboxNetNS(actorUID), fmt.Sprintf("tap%d_kata", i), nd.QueuePairs)
files, terr := setupActorTap(ctx, s.sandboxNetNS(actorUID), fmt.Sprintf("tap%d_kata", i), nd.QueuePairs, s.families)
if terr != nil {
return fmt.Errorf("while building restore tap for %s: %w", nd.ID, terr)
}
Expand Down Expand Up @@ -481,7 +480,7 @@ func (s *AteWorkerService) restoreMemoryFidelity(ctx context.Context, p actorBoo
tReseeded := time.Now()

// Block until every wakeup-probe-enabled container reports 200.
if err := wakeupprobe.WaitAll(ctx, containers, actornet.ActorVethIP, wakeupprobe.DialFunc(s.sandboxDialer(actorUID))); err != nil {
if err := wakeupprobe.WaitAll(ctx, containers, s.families.ActorIP(), wakeupprobe.DialFunc(s.sandboxDialer(actorUID))); err != nil {
return fmt.Errorf("while waiting for container wakeup probe: %w", err)
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/ateworker-microvm/restore_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/google/uuid"
"go.ate.dev/substrate/cmd/ateworker-microvm/internal/kata"
"go.ate.dev/substrate/internal/ateworker/actornet"
"go.ate.dev/substrate/internal/imagecache"
"go.ate.dev/substrate/internal/proto/ateworkerpb"
"go.ate.dev/substrate/internal/roottest"
Expand Down Expand Up @@ -61,7 +62,7 @@ func failedRestoreRootfs(t *testing.T, actorUID string, overlays bool) *ateworke
// t.TempDir can remove the bundle.
t.Cleanup(func() { _ = imagecache.UnmountAllUnder(dirs.GetOciBundleDir()) })
}
if _, err := (&AteWorkerService{}).buildActorContainers(actorUID, dirs, containers); err != nil {
if _, err := (&AteWorkerService{families: actornet.Families{IPv4: true, IPv6: true}}).buildActorContainers(actorUID, dirs, containers); err != nil {
t.Fatalf("buildActorContainers: %v", err)
}
return dirs
Expand Down
Loading