VPC Services are the core building block of Workers VPC. They represent specific resources in your private network that Workers can access through Cloudflare Tunnel.
You can use bindings to connect to VPC Services from Workers. Every request made to a VPC Service using its fetch function will be securely routed to the configured service in the private network.
VPC Services enforce that requests are routed to their intended service without exposing the entire network, securing your workloads and preventing server-side request forgery (SSRF).
Members with the Connectivity Directory Bind role can bind to existing VPC Services from Workers. Creating VPC Services requires the Connectivity Directory Admin role.
A VPC Service consists of:
- Type:
httpfor HTTP/HTTPS services, ortcpfor TCP services (for example, PostgreSQL, MySQL) - Tunnel ID: The Cloudflare Tunnel that provides network connectivity
- Hostname or IPv4/IPv6 addresses: The hostname, or IPv4 and/or IPv6 addresses to use to route to your service from the tunnel in your private network
- Ports: For
httptype, HTTP and/or HTTPS port configuration (optional, defaults to 80/443). Fortcptype, a TCP port (required). - Application protocol (TCP only): Optionally, specify
postgresqlormysqlto indicate the application-layer protocol for the TCP service - TLS settings: Optionally, configure how the connection to the origin verifies TLS certificates, a custom certificate authority (CA) to trust, and a client certificate to present for mutual TLS (mTLS)
- Resolver IPs: Optionally, a specific resolver IP can be provided — when not provided,
cloudflaredwill direct DNS traffic to the currently configured default system resolver.
HTTP VPC Services allow Workers to make fetch() requests to private HTTP/HTTPS endpoints.
Requests are encrypted in flight until they reach your network via a tunnel, regardless of the scheme used in the URL provided to fetch. If the http scheme is used, a plaintext connection is established to the service from the tunnel.
The https scheme can be used for an encrypted connection within your network, between the tunnel and your service. When the https scheme is specified, a hostname provided to the fetch() operation is utilized as the Server Name Indication (SNI) value.
VPC Services default to allowing both http and https schemes to be used. You can provide values for only one of http_port or https_port to enforce the use of a particular scheme.
When Workers VPC is unable to establish a connection to your service, fetch() will throw an exception.
TCP VPC Services allow connections to TCP-based services such as PostgreSQL and MySQL databases. Use the tcp service type with a --tcp-port to expose a TCP service.
You can optionally specify an --app-protocol of postgresql or mysql to indicate the application-layer protocol. This metadata is used by other Cloudflare products, such as Hyperdrive, to locate TCP services using a supported wire protocol.
TCP VPC Services are used with Hyperdrive to connect Workers to private databases. Refer to Connect to a private database using Workers VPC for a complete guide.
When using the https scheme, the tunnel verifies the TLS certificate presented by your origin service. Workers VPC trusts the following certificate types:
- Publicly trusted certificates — Certificates issued by well-known public certificate authorities (for example, Let's Encrypt, DigiCert).
- Cloudflare Origin CA certificates — Free certificates issued by Cloudflare that encrypt traffic between Cloudflare and your origin. Origin CA certificates are not trusted by browsers, but are trusted by Workers VPC when connecting to your private services.
- Certificates issued by your own CA — Certificates signed by a private CA, such as an internal public key infrastructure (PKI) or the Amazon RDS CA. Upload the CA certificate and reference it from the VPC Service. Refer to Custom CA and client certificates.
If your origin service presents a certificate that is not issued by one of these CAs, the TLS handshake will fail and fetch() will throw an exception.
You can configure how the connection to your origin service verifies TLS certificates by setting the --cert-verification-mode option when creating or updating a VPC Service, or by choosing a TLS certificate verification option in the dashboard. This applies to both HTTP and TCP service types.
| Mode | Description |
|---|---|
verify_full |
Verify the full certificate chain and hostname (default) |
verify_ca |
Verify the certificate chain only, skip hostname verification |
disabled |
Do not verify the server certificate |
Private services often use certificates issued by a private certificate authority (CA), or require callers to authenticate with a client certificate (mutual TLS, or mTLS). You can attach both to a VPC Service, so Workers VPC can verify your origin and authenticate to it without weakening the connection with verify_ca or disabled.
- Custom CA (
certificate_authority) — The CA certificate or chain that Workers VPC uses to verify the certificate presented by your origin. - Client certificate (
client_certificate) — The certificate and private key that Workers VPC presents when your origin requests a client certificate.
You can configure a custom CA, a client certificate, or both. For http services, these settings apply to connections that use the https scheme, not plaintext HTTP. For tcp services, they apply to the TLS connection to your service, including PostgreSQL databases used with Hyperdrive.
You can configure custom CA and client certificates in the Cloudflare dashboard ↗︎, with Wrangler, the API, or Terraform.
Upload the CA certificate and the client certificate to your account. Each upload returns a certificate ID that you reference from the VPC Service.
You can upload certificates without leaving the VPC Service form, when you create a VPC Service or edit its TLS settings:
-
In the TLS settings of the VPC Service, select Upload custom CA next to Custom certificate authority, or Upload client certificate next to Client certificate.
-
Enter a Certificate name.
-
Add the certificate file:
- For a custom CA, add a PEM certificate (
.pemor.crtfile). - For a client certificate, add a PEM certificate and its PEM private key (
.pemor.keyfile).
- For a custom CA, add a PEM certificate (
-
Select Upload certificate authority or Upload client certificate.
The dashboard uploads the certificate to your account and selects it in the VPC Service form. Certificates uploaded with Wrangler or the API also appear in the Custom certificate authority and Client certificate lists.
If you do not have permission to upload certificates, the dashboard shows a link to these instructions instead of the upload buttons. You can still select certificates that are already uploaded to the account.
npx wrangler cert upload certificate-authority --ca-cert ./ca.pem --name private-ca
npx wrangler cert upload mtls-certificate --cert ./client.pem --key ./client-key.pem --name private-clientUpload the CA certificate with ca set to true:
Required API token permissions
At least one of the following token permissions is required:Account: SSL and Certificates Write
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/mtls_certificates" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "private-ca",
"ca": true,
"certificates": "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----"
}'Upload the client certificate and its private key with ca set to false:
Required API token permissions
At least one of the following token permissions is required:Account: SSL and Certificates Write
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/mtls_certificates" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "private-client",
"ca": false,
"certificates": "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----",
"private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----"
}'Reference the certificate IDs in the TLS settings of the VPC Service. When you provide a custom CA or a client certificate, you must also set the certificate verification mode explicitly.
To add certificates when you create a VPC Service:
-
In the Cloudflare dashboard, go to the Workers VPC page.
Go to VPC ↗ -
Select the Services tab, then select Create to create a new VPC Service.
-
Enter the service name, tunnel, host, service type, and ports.
-
Under TLS certificate verification, select Full verification (default) or CA verification only. If you only add a client certificate, you can also select Disabled.
-
Select a certificate from Custom certificate authority, Client certificate, or both.
-
Select Create service.
To add or change certificates on an existing VPC Service:
-
In the Cloudflare dashboard, go to the Workers VPC page.
Go to VPC ↗ -
Select the Services tab, then select your VPC Service.
-
Select the Settings tab.
-
In TLS settings, select Edit.
-
Select a verification mode, then select a Custom certificate authority, a Client certificate, or both.
-
Select Save.
The TLS settings section shows the verification mode and the names of the certificates attached to the service.
npx wrangler vpc service create private-api \
--type http \
--https-port 443 \
--hostname api.internal.example \
--tunnel-id <TUNNEL_ID> \
--certificate-authority <CA_CERTIFICATE_ID> \
--client-certificate <CLIENT_CERTIFICATE_ID> \
--cert-verification-mode verify_fullRequired API token permissions
At least one of the following token permissions is required:Connectivity Directory Admin
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/connectivity/directory/services" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"type": "http",
"name": "private-api",
"https_port": 443,
"host": {
"hostname": "api.internal.example",
"resolver_network": {
"tunnel_id": "<TUNNEL_ID>"
}
},
"tls_settings": {
"certificate_authority": "<CA_CERTIFICATE_ID>",
"client_certificate": "<CLIENT_CERTIFICATE_ID>",
"cert_verification_mode": "verify_full"
}
}'The following rules apply:
cert_verification_modeis required whenever you setcertificate_authorityorclient_certificate.- A custom CA cannot be combined with
disabled, because the CA is only used to verify the origin certificate. Useverify_fullorverify_ca. In the dashboard, the Custom certificate authority field is hidden when Disabled is selected. - A client certificate can be used without a custom CA, with any verification mode.
- TLS settings are configured on each VPC Service. The
networkorresolver_networkof the service host has no TLS settings of its own.
To rotate a certificate, upload the new certificate, then update the VPC Service to reference the new certificate ID. Changes can take a few seconds to apply.
-
In the Cloudflare dashboard, go to the Workers VPC page.
Go to VPC ↗ -
Select the Services tab, then select your VPC Service.
-
Select the Settings tab.
-
In TLS settings, select Edit.
-
To rotate a certificate, select the new certificate in Custom certificate authority or Client certificate, or select Upload custom CA or Upload client certificate to upload it. To remove a certificate, clear its field.
-
Select Save.
The dashboard keeps the settings you do not change. For example, replacing the client certificate keeps the custom CA and the verification mode. Editing the name, host, or ports of a VPC Service also keeps its TLS settings.
Updating a VPC Service replaces its complete configuration, including TLS settings. Include every TLS setting the service should keep. Certificate references and the verification mode that you omit are cleared, and an update without TLS settings returns the service to the default verification (verify_full with publicly trusted CAs and Cloudflare Origin CA).
For example, to rotate the client certificate while keeping the custom CA:
npx wrangler vpc service update <SERVICE_ID> \
--name private-api \
--type http \
--https-port 443 \
--hostname api.internal.example \
--tunnel-id <TUNNEL_ID> \
--certificate-authority <CA_CERTIFICATE_ID> \
--client-certificate <NEW_CLIENT_CERTIFICATE_ID> \
--cert-verification-mode verify_fullUpdating a VPC Service with the API replaces its complete configuration, including TLS settings. Send the complete tls_settings object, including the certificate IDs and verification mode the service should keep. Certificate references and the verification mode that you omit are cleared, and an update without tls_settings returns the service to the default verification (verify_full with publicly trusted CAs and Cloudflare Origin CA).
Removing a certificate reference from a VPC Service, or deleting the VPC Service, does not delete the uploaded certificate. To delete it, use wrangler cert delete or the Delete mTLS certificate endpoint.
If a certificate does not match your origin, the connection fails instead of falling back to weaker verification, and fetch() throws an exception that includes the reason, for example CERTIFICATE_VERIFY_FAILED. Refer to Troubleshooting for TLS errors.
These configurations represent the expected contract of the REST API for creating a VPC Service, a type of service within the broader connectivity directory.
The following is an example of an HTTP VPC Service using custom HTTP and HTTPS ports, and both IPv4 and IPv6 addresses.
{
"type": "http",
"name": "human-readable-name",
// Port configuration (optional - defaults to 80/443)
"http_port": 80,
"https_port": 443,
// Host configuration
"host": {
"ipv4": "10.0.0.1",
"ipv6": "fe80::",
"network": {
"tunnel_id": "0191dce4-9ab4-7fce-b660-8e5dec5172da",
},
},
}The following is an example of an HTTP VPC Service using a hostname. When using a hostname, provide a resolver_network that optionally includes resolver_ips.
{
"type": "http",
"name": "human-readable-name",
// Port configuration (optional - defaults to 80/443)
"http_port": 80,
"https_port": 443,
// Hostname Host (with DNS resolver)
"host": {
"hostname": "example.com",
"resolver_network": {
"tunnel_id": "0191dce4-9ab4-7fce-b660-8e5dec5172da",
"resolver_ips": ["10.0.0.1"], // Optional
},
},
}The following is an example of a TCP VPC Service for a PostgreSQL database.
{
"type": "tcp",
"name": "my-postgres-db",
"tcp_port": 5432,
"app_protocol": "postgresql", // Optional: "postgresql" or "mysql"
"host": {
"ipv4": "10.0.0.5",
"network": {
"tunnel_id": "0191dce4-9ab4-7fce-b660-8e5dec5172da",
},
},
}The following example creates a TCP service with verify_ca certificate verification mode.
{
"type": "tcp",
"name": "my-postgres-db",
"tcp_port": 5432,
"app_protocol": "postgresql",
"host": {
"ipv4": "10.0.0.5",
"network": {
"tunnel_id": "0191dce4-9ab4-7fce-b660-8e5dec5172da",
},
},
"tls_settings": {
"cert_verification_mode": "verify_ca",
},
}The following example creates a TCP service for a PostgreSQL database that presents a certificate signed by a private CA and requires a client certificate. The certificate IDs are returned when you upload certificates.
{
"type": "tcp",
"name": "my-postgres-db",
"tcp_port": 5432,
"app_protocol": "postgresql",
"host": {
"hostname": "db.internal.example",
"resolver_network": {
"tunnel_id": "0191dce4-9ab4-7fce-b660-8e5dec5172da",
},
},
"tls_settings": {
"certificate_authority": "705db030-8247-489b-80dd-0d6256e5950d", // Optional: custom CA certificate ID
"client_certificate": "a493fbb4-34bc-4218-a63c-61a9323ac725", // Optional: client certificate ID for mTLS
"cert_verification_mode": "verify_full", // Required when a certificate is set
},
}Once you have created a VPC Service, you can bind it to your Worker:
{
"$schema": "./node_modules/wrangler/config-schema.json",
"name": "my-worker",
"main": "src/index.js",
"upload_source_maps": true,
"vpc_services": [
{
"binding": "PRIVATE_API",
"service_id": "e6a0817c-79c5-40ca-9776-a1c019defe70",
"remote": true // When true, utilizes [remote bindings](/workers/local-development/#remote-bindings) to allow access to the VPC Service during local development.
}
]
}"$schema" = "./node_modules/wrangler/config-schema.json"
name = "my-worker"
main = "src/index.js"
upload_source_maps = true
[[vpc_services]]
binding = "PRIVATE_API"
service_id = "e6a0817c-79c5-40ca-9776-a1c019defe70"
remote = trueYou can have multiple VPC service bindings:
{
"vpc_services": [
{
"binding": "PRIVATE_API",
"service_id": "daf43e8c-a81a-4242-9912-4a2ebe4fdd79",
"remote": true
},
{
"binding": "PRIVATE_DATABASE",
"service_id": "453b6067-1327-420d-89b3-2b6ad16e6551",
"remote": true
},
{
"binding": "INTERNAL_CACHE",
"service_id": "6c39b574-237e-49f4-852a-cea5a93ed8f9",
"remote": true
}
]
}[[vpc_services]]
binding = "PRIVATE_API"
service_id = "daf43e8c-a81a-4242-9912-4a2ebe4fdd79"
remote = true
[[vpc_services]]
binding = "PRIVATE_DATABASE"
service_id = "453b6067-1327-420d-89b3-2b6ad16e6551"
remote = true
[[vpc_services]]
binding = "INTERNAL_CACHE"
service_id = "6c39b574-237e-49f4-852a-cea5a93ed8f9"
remote = trueWorkers VPC uses the following account roles:
Connectivity Directory Readto view Workers VPC Services and Tunnels.Connectivity Directory Bindto list, read, and bind VPC Services in Workers.Connectivity Directory Adminto create, update, and delete VPC Services, and bind directly to tunnels through a VPC Network binding.
For role definitions, refer to Roles.
If your roles were recently updated and commands are still failing, refresh Wrangler authentication:
npx wrangler logout
npx wrangler loginIf you authenticate with an API token (CLOUDFLARE_API_TOKEN), ensure the token belongs to a user with the required roles.
- Configure VPC Services with Terraform for managing VPC Services as infrastructure
- Set up Cloudflare Tunnel for your environment
- Learn about the Service Binding API
- Refer to examples of common use cases