Skip to content

Commit 06bc1da

Browse files
alon-boshiCopilotzeevmoneyclaude
authored
Improve GCP Cloud Run deployment documentation (#601)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Zeev Manilovich <zeevmanilovich@gmail.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Zeev Manilovich <zeevmoney@users.noreply.github.com>
1 parent ed35a4b commit 06bc1da

File tree

1 file changed

+189
-4
lines changed

1 file changed

+189
-4
lines changed

docs/how-to/deploy/cloud-hosts/gcp-cloud-run.mdx

Lines changed: 189 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ The only required environment variable is `PDP_API_KEY`, which is the API key th
4545
See [Get your API Key](/api/api-with-cli) for more information.
4646
Note that you can and should set the environment variables from a secret, using your selected secret store provider.
4747
![Environment Variables](/img/deployments/gcp/5.png)
48+
:::important
49+
Use an Environment-level API key (not Project or Org key) for Cloud Run deployments
50+
:::
4851

4952
### 6. Ready to deploy !
5053

@@ -53,14 +56,196 @@ Click on the "Create" button to deploy the PDP.
5356
You can see the logs of the deployment in the "Logs" tab, and if the deployment succeeded, you will see the URL of the PDP in the top section of the Cloud Run service.
5457
![Deploy](/img/deployments/gcp/6.png)
5558

59+
:::info Signal 6 in Cloud Run
60+
A common misconfiguration issue that can be encountered when deploying the PDP to Google Cloud Run is having the platform unexpectedly terminate the PDP container with a Signal 6 (SIGABRT). This issue stems from Cloud Run's CPU allocation settings, which allow background task processes, such as the PDP, to release CPU resources when idle. Consequently, this results in the container's termination due to insufficient CPU availability.
61+
To address this issue and ensure uninterrupted service, we recommend adding the `run.googleapis.com/cpu-throttling: false` annotation in the YAML configuration.
62+
63+
For a deeper understanding of CPU allocation settings in Cloud Run and how they impact your applications, please refer to the following documentation: [Cloud Run CPU Allocation Settings](https://cloud.google.com/run/docs/configuring/cpu-allocation).
64+
:::
65+
5666
## YAML file
5767

5868
We shared the YAML file that we used to deploy the PDP on GCP Cloud Run.
5969
Take a look at the following [Deployments Github Repository](https://github.com/permitio/permit-pdp-deployments-examples/blob/main/gcp/cloud-run.yaml)
6070

61-
:::info Signal 6 in Cloud Run
62-
A common misconfiguration issue that can be encountered when deploying the PDP to Google Cloud Run is having the platform unexpectedly terminate the PDP container with a Signal 6 (SIGABRT). This issue stems from Cloud Run's CPU allocation settings, which allow background task processes, such as the PDP, to release CPU resources when idle. Consequently, this results in the container's termination due to insufficient CPU availability.
63-
To address this issue and ensure uninterrupted service, we recommend adding the `run.googleapis.com/cpu-throttling: false` annotation in the YAML configuration.
71+
### Known-Good Reference Deployment (YAML / CLI)
72+
73+
The following configuration is known to work on Cloud Run and addresses autoscaling, CPU throttling, startup probes, and environment variables appropriately.
74+
75+
#### Prerequisites
76+
77+
- gcloud installed and authenticated
78+
- Cloud Run and Secret Manager APIs enabled
79+
- Permit Environment API Key stored in Secret Manager
80+
81+
#### Step 1 — Enable Required APIs
82+
```bash
83+
gcloud services enable secretmanager.googleapis.com
84+
gcloud services enable run.googleapis.com
85+
```
86+
87+
#### Step 2: Create a Secret for the API Key
88+
Store your Permit API key securely in GCP Secret Manager:
89+
```bash
90+
echo -n "YOUR_PERMIT_API_KEY" | gcloud secrets create permit-pdp-api-key \
91+
--data-file=- \
92+
--replication-policy=automatic
93+
```
94+
95+
#### Step 3: Grant Secret Access to the Service Account
96+
97+
Get your default compute service account and grant it access to the secret:
98+
99+
```bash
100+
# Get the service account email
101+
SERVICE_ACCOUNT=$(gcloud iam service-accounts list --format="value(email)" | grep compute)
102+
103+
# Grant secret access
104+
gcloud secrets add-iam-policy-binding permit-pdp-api-key \
105+
--member="serviceAccount:${SERVICE_ACCOUNT}" \
106+
--role="roles/secretmanager.secretAccessor"
107+
```
108+
109+
#### Step 4: Create the Cloud Run Service YAML
110+
111+
Create a file named `permit-pdp-service.yaml`:
112+
```yaml
113+
apiVersion: serving.knative.dev/v1
114+
kind: Service
115+
metadata:
116+
name: permit-pdp
117+
labels:
118+
cloud.googleapis.com/location: us-central1
119+
annotations:
120+
run.googleapis.com/client-name: cloud-console
121+
run.googleapis.com/ingress: all
122+
run.googleapis.com/ingress-status: all
123+
spec:
124+
template:
125+
metadata:
126+
labels:
127+
run.googleapis.com/startupProbeType: Default
128+
annotations:
129+
run.googleapis.com/cpu-throttling: "false"
130+
run.googleapis.com/client-name: cloud-console
131+
autoscaling.knative.dev/minScale: "1"
132+
autoscaling.knative.dev/maxScale: "10"
133+
spec:
134+
containerConcurrency: 80
135+
timeoutSeconds: 300
136+
serviceAccountName: YOUR_SERVICE_ACCOUNT_EMAIL
137+
containers:
138+
- image: permitio/pdp-v2:latest
139+
ports:
140+
- name: http1
141+
containerPort: 7000
142+
env:
143+
- name: PDP_API_KEY
144+
valueFrom:
145+
secretKeyRef:
146+
key: latest
147+
name: permit-pdp-api-key
148+
resources:
149+
limits:
150+
cpu: 1000m
151+
memory: 512Mi
152+
startupProbe:
153+
timeoutSeconds: 240
154+
periodSeconds: 240
155+
failureThreshold: 1
156+
tcpSocket:
157+
port: 7000
158+
traffic:
159+
- percent: 100
160+
latestRevision: true
161+
```
162+
163+
**Important Configuration Notes:**
164+
165+
| Setting | Value | Purpose |
166+
|---------|-------|---------|
167+
| `run.googleapis.com/cpu-throttling` | `"false"` | Prevents SIGABRT errors by keeping CPU allocated |
168+
| `autoscaling.knative.dev/minScale` | `"1"` | Avoids cold starts that cause authorization failures |
169+
| `containerPort` | `7000` | Default PDP port |
170+
| `startupProbe.timeoutSeconds` | `240` | Allows time for initial policy sync |
171+
172+
:::note
173+
Replace `YOUR_SERVICE_ACCOUNT_EMAIL` with the service account email obtained in Step 3 (the `$SERVICE_ACCOUNT` variable value).
174+
:::
64175

65-
For a deeper understanding of CPU allocation settings in Cloud Run and how they impact your applications, please refer to the following documentation: [Cloud Run CPU Allocation Settings](https://cloud.google.com/run/docs/configuring/cpu-allocation).
176+
#### Step 5: Deploy the Service
177+
178+
```bash
179+
gcloud run services replace permit-pdp-service.yaml --region=us-central1
180+
```
181+
182+
#### Step 6: Allow Public Access (Optional)
183+
184+
:::warning Security Risk
185+
Exposing the PDP publicly allows anyone to query your authorization decisions. Only use this for development or testing environments. For production, use Cloud Run's IAM authentication or VPC connectors for private access.
186+
:::
187+
188+
If you need unauthenticated access to the PDP:
189+
190+
```bash
191+
gcloud run services add-iam-policy-binding permit-pdp \
192+
--region=us-central1 \
193+
--member="allUsers" \
194+
--role="roles/run.invoker"
195+
```
196+
197+
#### Step 7: Verify the Deployment
198+
199+
Check the health endpoint:
200+
201+
```bash
202+
# Get the service URL
203+
SERVICE_URL=$(gcloud run services describe permit-pdp --region=us-central1 --format="value(status.url)")
204+
205+
# Check health
206+
curl ${SERVICE_URL}/health
207+
```
208+
Expected response:
209+
```json
210+
{
211+
"components": {
212+
"horizon": {
213+
"details": {
214+
"direct_check": "success",
215+
"watchdog": "error"
216+
},
217+
"error": null,
218+
"status": "ok"
219+
},
220+
"opa": {
221+
"error": null,
222+
"status": "ok"
223+
}
224+
},
225+
"status": "ok"
226+
}
227+
```
228+
229+
:::note
230+
The `"watchdog": "error"` in the response is expected behavior in Cloud Run environments due to how Cloud Run handles background processes. As long as `"status": "ok"` appears at the top level, your PDP is healthy and operational.
66231
:::
232+
#### Endpoints
233+
234+
Once deployed, your PDP exposes:
235+
236+
- **Health Check**: `https://YOUR_SERVICE_URL/health`
237+
- **Authorization**: `https://YOUR_SERVICE_URL/allowed`
238+
239+
240+
#### Troubleshooting
241+
242+
##### Signal 6 (SIGABRT) Errors
243+
Ensure `run.googleapis.com/cpu-throttling: "false"` is set in your annotations.
244+
245+
##### Cold Start Authorization Failures
246+
Ensure `autoscaling.knative.dev/minScale: "1"` to keep at least one instance running.
247+
248+
##### Quota Errors
249+
Reduce `autoscaling.knative.dev/maxScale` if you hit CPU/memory quota limits.
250+
251+

0 commit comments

Comments
 (0)