Skip to main content
A gateway port policy controls which ports on your CVM receive traffic from the gateway, and which of those ports get a PROXY protocol header. Restrictive policies and PROXY protocol require dstack OS 0.5.9 or later. Phala Cloud rejects them on older images; upgrade the OS image first.

Guest ports

The policy matches guest ports, which are the left side of a Docker Compose port mapping. For ports: ["8080:80"], Nginx listens on container port 80 and Docker publishes it on guest port 8080, so the policy lists 8080.
  • Ports bound only to loopback (such as 127.0.0.1:8080:80) cannot be reached from the gateway regardless of policy.
  • The policy does not publish container ports, does not affect host-mapped ports, and has no effect when the gateway is disabled for the CVM.

Policy modes

A policy consists of restrict_mode and a list of ports.
New CVMs enable restrict_mode by default and automatically populate the port policy from your Docker Compose ports mappings. GPU rental orders are the exception: they forward all ports unless you set a policy. If the generated policy is inaccurate or misses a port, update it manually.

Default policy for new CVMs

When you create a CVM without declaring a policy, Phala Cloud turns on restrict_mode and allows:
  • every static TCP guest port published in Docker Compose,
  • port 8090 (guest agent),
  • port 22 when SSH is enabled (dev OS image, SSH keys, or SSH dev box).
Phala Cloud skips the default policy (forwarding all ports) when the OS image is older than dstack OS 0.5.9, the CVM uses the Bash runner, or a service uses host or another non-default network mode. GPU rental orders also skip it; the launch form’s Gateway port policy field forwards all ports by default. Ports set via environment variables (such as "${PORT}:80") cannot be resolved statically, so they are left out of the generated allowlist and stay closed until you add them manually.

Special ports: 8090 and 22

Guest agent (port 8090)

Phala Cloud reads CVM logs and attestation data through the guest agent on port 8090. Access to port 8090 is controlled by two layers:
  1. Gateway port policy (this page): Controls whether the gateway forwards port 8090 at all. Omitting 8090 from a restricted policy blocks everyone, including Phala Cloud, and requires explicit confirmation in the console, CLI, and API.
  2. Guest Agent Access: Controls who can reach port 8090 while the port policy allows it. By default, only Phala Cloud can reach it; you can open it publicly when third parties need to verify attestation.
In the console, choose who can reach the guest agent under the app’s Networking → Dstack Guest Agent → Access: Choosing No one removes 8090 from the port policy and restarts the app’s instances after you confirm. The Port policy card always keeps 8090, so close it here instead. With the CLI or API, leave 8090 out of a restricted policy and confirm the closure (see below). To block public access without breaking logs or attestation, choose Phala Cloud. See Guest Agent Access.

SSH (port 22)

Omitting port 22 from a restricted policy blocks SSH through the gateway. Keep 22 in the policy if you connect over SSH; see Enable SSH Access.

PROXY protocol

Enable PROXY protocol on a port only when the service listening on it expects a PROXY header before application data. Listeners expecting plain HTTP, TLS, or SSH reject connections that start with a PROXY header (HTTP servers typically reply with 400).
  • The gateway writes PROXY protocol v2 headers, or passes through an upstream load balancer’s header (which may be v1). Configure listeners to accept both versions.
  • Update the listener and the port policy in the same deployment so both sides agree.

Restarts and multi-instance apps

  • Restarts: Effective policy changes restart a running CVM; a stopped CVM picks up the new policy on its next start. No-op updates (same forwarded ports and PROXY settings) do not restart the CVM.
  • On-chain KMS: Register the new compose hash on-chain before applying the change. See Updating with Onchain KMS.
  • Multiple instances: Policies are per-instance. For any given port, the gateway only routes traffic to instances whose policy allows it, so keep policies in sync across instances.

Configure a policy

Console

Open the app, go to Networking → Access control, and edit the Port policy card: toggle Restrict mode, click Add port to add guest ports, and use the Proxy protocol (pp) switch on each row as needed. Saving applies the policy to every instance of the app and restarts the running ones after you confirm. On the GPU rental launch form, the Gateway port policy field defaults to forwarding all ports and asks for confirmation before closing port 8090.

phala.toml

Add a [port_policy] table to phala.toml and run phala deploy:
Both restrict_mode and ports are required. Each entry takes a guest port and an optional pp = true to turn on PROXY protocol. To block every port, set restrict_mode = true with ports = [] and apply with phala deploy --confirm-close all. phala deploy replaces the CVM’s entire policy rather than merging. If you omit [port_policy], existing CVMs keep their current policy and new CVMs get the default policy. See the phala.toml reference for other keys.

CLI

Use phala port-policy to inspect or change a single CVM’s policy. Pass --cvm-id <id>, or omit it to target the CVM linked in phala.toml.
  • Command constraints: When a policy already forwards all ports, allow requires --proxy-protocol or --no-proxy-protocol, and deny cannot block individual ports (use replace --restrict instead). Passing replace --restrict with no ports is rejected; use --deny-all.
  • Scripting and waiting: Changes display a before/after summary and prompt for confirmation. Pass --yes in non-interactive scripts and --wait to wait until the update finishes.
  • Closing confirmations: Newly blocking port 8090, newly blocking port 22 on an existing CVM, or blocking every port requires a separate confirmation, interactively or via --confirm-close 8090, --confirm-close 22, or --confirm-close all (which covers 8090 and 22, and is required when blocking all ports). --yes does not satisfy this check. Both phala port-policy and phala deploy validate this locally before sending a request.
  • Unlisted port warnings: Both phala port-policy and phala deploy warn when a restricted policy omits a port published in Docker Compose (env-var ports may not be detected). Ignore the warning if intentional.
  • Sync with phala.toml: phala port-policy updates only the CVM, not phala.toml. Copy manual changes into [port_policy] so the next phala deploy does not overwrite them.
  • Concurrent edits: The CLI sends the compose hash it read and rejects stale updates. Re-run phala port-policy show and retry if someone else modified the CVM.

API

Send compose.port_policy in PATCH /cvms/{cvm_id}:
  • Merge semantics: Fields inside port_policy merge by key. Sending ports replaces the list; omitting ports keeps the existing list.
  • Concurrency: Send top-level expected_compose_hash with the compose hash you read to reject concurrent changes with 409.
  • Closing port 8090: Omit 8090 from a restricted policy and include top-level "guest_agent_gateway_access": "closed" in the same request. Without it, Phala Cloud adds 8090 back automatically. Sending this field while 8090 is still allowed is rejected.
  • Unlisted ports: A 202 response includes port_policy_unlisted_ports, listing published TCP ports omitted by a restricted policy (env-var ports may be absent).
See Update a CVM for full request details.

Troubleshooting

If a port is unreachable through the gateway, check these in order:
  1. Docker Compose mapping: Confirm the port is published (not bound to 127.0.0.1) and the policy lists the guest port (left side).
  2. Allowlist: With restrict_mode on, confirm the port is listed, especially if it comes from an environment variable like "${PORT}:80".
  3. PROXY protocol mismatch: Confirm PROXY protocol is enabled only when the listener expects a PROXY header, and disabled when it expects plain traffic.
  4. Older OS image: On images older than dstack OS 0.5.9, the gateway forwards all ports, so the cause is elsewhere. See Networking Troubleshooting.