Secure ingress/egress with automated certificate management in dstack
Dns01Client::new_cloudflare
method, which initializes the DNS-01 client with the configured Cloudflare zone ID and API token (see source). This enables the gateway to programmatically create and clean up TXT records required for ACME validation, ensuring seamless and secure certificate issuance.
the system can automatically set CAA (Certificate Authority Authorization) records to enhance security, as implemented in certbot/src/bot.rs#L61.
ProxyStateMut
structure (see source). This state includes information about other gateway nodes (nodes
), registered applications (apps
), CVM instances (instances
), allocated network addresses, and additional internal tracking fields. By synchronizing this structured state across the cluster, the gateway ensures consistent knowledge of node membership, application registrations, and CVM instance assignments.
each gateway node tracks other nodes in the cluster using a GatewayNodeInfo
structure (see source), which includes the node’s id, url, WireGuard peer information, and last-seen timestamp.
SyncClient
) initiates connections to peer nodes using a purpose-built RPC client that strictly enforces certificate-based authentication and validates application identity (sync client handshake and validation logic).[core.recycle]
section (see gateway.toml), which sets parameters such as interval
, timeout
, and especially node_timeout
(e.g., node_timeout = "10m"
). the gateway tracks each node’s last-seen timestamp and automatically recycles (removes) nodes that have not been seen within the node_timeout
period. this mechanism is implemented in the gateway service using the GatewayNodeInfo
structure and is part of the cluster state management logic, relying on the gateway’s internal state synchronization and recycling packages.
RegisterCvmRequest
and related types) is responsible for handling CVM registration requests. as part of this process, the endpoint requires the CVM to submit its attestation evidence. the gateway then performs a series of verification steps:
[core.wg]
section. This configuration governs how the gateway manages WireGuard peers, allocates client IPs, and maintains secure connectivity for all registered CVMs.
the following diagram illustrates the CVM registration and secure network setup process: the confidential virtual machine (CVM) first requests attestation from the KMS, which provides the attestation evidence. the CVM then registers with the gateway, submitting its public key and attestation. the gateway verifies the attestation, checks application authorization with the KmsAuth contract, and upon confirmation, allocates a WireGuard IP and configures WireGuard peers. finally, the gateway returns the WireGuard and agent configuration to the CVM, which then establishes a secure WireGuard tunnel with the gateway.
connect_top_n
). this ensures that traffic is routed to peers that are known to be alive and responsive, minimizing latency and avoiding stale or unreachable instances.
the algorithm for sorting and selecting the top N instances is implemented as follows (main_service.rs:329-334):
See implementation in gateway/src/main_service.rs (permalink):
connect_top_n
is set to 0, the system also defaults to random selection. for localhost development, a special case routes traffic directly to 127.0.0.1
.
for implementation details, see select_top_n_hosts
.
main_service.rs
(permalink). this mechanism ensures that applications or operators can always target a particular CVM when needed, without interference from the load balancer.
connect_top_n
is set to 0), the gateway switches to a fallback strategy.
See fallback implementation in gateway/src/main_service.rs (permalink):
[core.recycle]
section. for example: