Guest ports
The policy matches guest ports, which are the left side of a Docker Compose port mapping. Forports: ["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 ofrestrict_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 onrestrict_mode and allows:
- every static TCP guest port published in Docker Compose,
- port
8090(guest agent), - port
22when SSH is enabled (dev OS image, SSH keys, or SSH dev box).
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 port8090. Access to port 8090 is controlled by two layers:
- Gateway port policy (this page): Controls whether the gateway forwards port
8090at all. Omitting8090from a restricted policy blocks everyone, including Phala Cloud, and requires explicit confirmation in the console, CLI, and API. - Guest Agent Access: Controls who can reach port
8090while 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.
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 port22 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 with400).
- 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 port8090.
phala.toml
Add a[port_policy] table to phala.toml and run phala deploy:
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
Usephala 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,
allowrequires--proxy-protocolor--no-proxy-protocol, anddenycannot block individual ports (usereplace --restrictinstead). Passingreplace --restrictwith no ports is rejected; use--deny-all. - Scripting and waiting: Changes display a before/after summary and prompt for confirmation. Pass
--yesin non-interactive scripts and--waitto wait until the update finishes. - Closing confirmations: Newly blocking port
8090, newly blocking port22on 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 covers8090and22, and is required when blocking all ports).--yesdoes not satisfy this check. Bothphala port-policyandphala deployvalidate this locally before sending a request. - Unlisted port warnings: Both
phala port-policyandphala deploywarn 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-policyupdates only the CVM, notphala.toml. Copy manual changes into[port_policy]so the nextphala deploydoes not overwrite them. - Concurrent edits: The CLI sends the compose hash it read and rejects stale updates. Re-run
phala port-policy showand retry if someone else modified the CVM.
API
Sendcompose.port_policy in PATCH /cvms/{cvm_id}:
- Merge semantics: Fields inside
port_policymerge by key. Sendingportsreplaces the list; omittingportskeeps the existing list. - Concurrency: Send top-level
expected_compose_hashwith the compose hash you read to reject concurrent changes with409. - Closing port
8090: Omit8090from a restricted policy and include top-level"guest_agent_gateway_access": "closed"in the same request. Without it, Phala Cloud adds8090back automatically. Sending this field while8090is still allowed is rejected. - Unlisted ports: A
202response includesport_policy_unlisted_ports, listing published TCP ports omitted by a restricted policy (env-var ports may be absent).
Troubleshooting
If a port is unreachable through the gateway, check these in order:- Docker Compose mapping: Confirm the port is published (not bound to
127.0.0.1) and the policy lists the guest port (left side). - Allowlist: With
restrict_modeon, confirm the port is listed, especially if it comes from an environment variable like"${PORT}:80". - PROXY protocol mismatch: Confirm PROXY protocol is enabled only when the listener expects a PROXY header, and disabled when it expects plain traffic.
- 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.

