Rasmus
07/11/2025, 8:03 AMMarvin
07/11/2025, 8:03 AMMarvin
07/11/2025, 8:04 AMRasmus
07/11/2025, 8:05 AMMarvin
07/11/2025, 8:05 AMMarvin
07/11/2025, 8:06 AMbash
gcloud compute networks vpc-access connectors create [CONNECTOR_NAME] \
--region=[REGION] \
--range=[IP_RANGE] \
--network=[VPC_NAME]
2. Configure the Work Pool:
- In the Prefect UI: Create a new Cloud Run work pool
- Or via CLI:
bash
prefect work-pool create my-cloud-run-pool --type cloud-run
3. Add VPC Configuration:
- In the work pool settings, go to the "Advanced" tab
- Update the job configuration JSON to include the VPC connector in the correct location:
json
{
"job_configuration": {
"command": "{{ command }}",
"env": "{{ env }}",
"labels": "{{ labels }}",
"name": "{{ name }}",
"region": "{{ region }}",
"credentials": "{{ credentials }}",
"job_body": {
"apiVersion": "<http://run.googleapis.com/v1|run.googleapis.com/v1>",
"kind": "Job",
"metadata": {
"name": "{{ name }}",
"annotations": {
"<http://run.googleapis.com/launch-stage|run.googleapis.com/launch-stage>": "BETA"
}
},
"spec": {
"template": {
"metadata": {
"annotations": {
"<http://run.googleapis.com/vpc-access-connector|run.googleapis.com/vpc-access-connector>": "{{ vpc_connector_name }}"
}
}
}
}
}
}
}
4. Set the VPC Connector Name:
- In the work pool configuration UI, you can set the VPC connector name either:
- In the standard configuration menu
- Or in the advanced configuration options
Important Notes:
- Make sure your VPC connector is in the same region as your Cloud Run service
- The VPC connector name should be in the format: projects/[PROJECT_ID]/locations/[REGION]/connectors/[CONNECTOR_NAME]
- Your service account needs appropriate IAM permissions to use the VPC connector
- The VPC connector allows your Cloud Run jobs to access resources in your VPC, such as databases or other internal services
This configuration will ensure your Cloud Run workers can securely access resources within your VPC network while maintaining the serverless benefits of Cloud Run.Rasmus
07/11/2025, 8:14 AMMarvin
07/11/2025, 8:14 AMMarvin
07/11/2025, 8:15 AMvpc_connector_name
- This should be specified in the format: projects/[PROJECT_ID]/locations/[REGION]/connectors/[CONNECTOR_NAME]
2. Via CLI:
bash
prefect work-pool create my-cloud-run-pool \
--type cloud-run \
--vpc-connector-name "projects/[PROJECT_ID]/locations/[REGION]/connectors/[CONNECTOR_NAME]"
3. Or using the Base Job Configuration:
You can also set this in the base job configuration during creation:
json
{
"vpc_connector_name": "projects/[PROJECT_ID]/locations/[REGION]/connectors/[CONNECTOR_NAME]"
}
Important Notes:
- The VPC connector must exist before you create the work pool
- The connector must be in the same region where your Cloud Run jobs will run
- You can modify the VPC connector settings after creation by updating the work pool configuration
- Make sure your service account has the necessary permissions to use the VPC connector
Would you like me to provide more details about any of these configuration methods or about the required permissions?Rasmus
07/11/2025, 10:14 AMMarvin
07/11/2025, 10:14 AMMarvin
07/11/2025, 10:16 AMjson
{
"job_configuration": {
"command": "{{ command }}",
"env": "{{ env }}",
"labels": "{{ labels }}",
"name": "{{ name }}",
"region": "{{ region }}",
"credentials": "{{ credentials }}",
"job_body": {
"apiVersion": "<http://run.googleapis.com/v1|run.googleapis.com/v1>",
"kind": "Job",
"metadata": {
"name": "{{ name }}",
"annotations": {
"<http://run.googleapis.com/launch-stage|run.googleapis.com/launch-stage>": "BETA"
}
},
"spec": {
"template": {
"metadata": {
"annotations": {
"<http://run.googleapis.com/vpc-access-connector|run.googleapis.com/vpc-access-connector>": "{{ vpc_connector_name }}",
"<http://run.googleapis.com/vpc-access-egress|run.googleapis.com/vpc-access-egress>": "all-traffic",
"<http://run.googleapis.com/ingress|run.googleapis.com/ingress>": "internal"
}
},
"spec": {
"containers": [{
"image": "{{ image }}",
"env": "{{ env }}",
"resources": {
"limits": {
"cpu": "{{ cpu }}",
"memory": "{{ memory }}"
}
}
}]
}
}
}
}
}
}
Key changes and annotations explained:
1. "<http://run.googleapis.com/vpc-access-connector|run.googleapis.com/vpc-access-connector>": "{{ vpc_connector_name }}"
- Connects the service to your VPC using the specified connector
2. "<http://run.googleapis.com/vpc-access-egress|run.googleapis.com/vpc-access-egress>": "all-traffic"
- Routes all egress traffic through the VPC
- This ensures no direct internet access
3. "<http://run.googleapis.com/ingress|run.googleapis.com/ingress>": "internal"
- Restricts the service to internal access only
- Prevents external IP assignment
Important Notes:
- Make sure your VPC connector is properly configured before deploying
- The service account used needs appropriate IAM permissions
- You'll need to configure Private Service Connect or Internal Load Balancing if you need to access this service from within your VPC
- Remember to set the vpc_connector_name
in your work pool configuration using the format: projects/[PROJECT_ID]/locations/[REGION]/connectors/[CONNECTOR_NAME]
This configuration ensures that your Cloud Run jobs:
- Run within your VPC network
- Have no external IP addresses
- Route all traffic through your VPC
- Can only be accessed internally
Would you like me to explain any of these settings in more detail or provide information about the required IAM permissions?Rasmus
07/11/2025, 10:43 AMMarvin
07/11/2025, 10:43 AMMarvin
07/11/2025, 10:44 AMbash
PREFECT_API_URL=<https://your-prefect-server-url/api>
PREFECT_API_USERNAME=your-username
PREFECT_API_PASSWORD=your-password
2. Add these to your Work Pool Configuration:
In the work pool settings, you can add these environment variables in one of two ways:
a. Through the UI:
- Go to your work pool settings
- Add the environment variables in the "Base Job Configuration" section
b. Or in the Advanced configuration:
json
{
"job_configuration": {
"env": [
{
"name": "PREFECT_API_URL",
"value": "<https://your-prefect-server-url/api>"
},
{
"name": "PREFECT_API_USERNAME",
"value": "your-username"
},
{
"name": "PREFECT_API_PASSWORD",
"value": "your-password"
}
]
}
}
Important Security Notes:
- Consider using Google Cloud Secret Manager to store sensitive credentials
- If using Secret Manager, you can reference secrets in your environment variables:
json
{
"name": "PREFECT_API_PASSWORD",
"valueFrom": {
"secretKeyRef": {
"name": "prefect-password",
"key": "latest"
}
}
}
- Ensure your VPC and network settings are properly configured to allow the worker to reach your self-hosted Prefect server
- Make sure the URL includes the /api
suffix in the PREFECT_API_URL
Would you like me to provide more details about setting up Secret Manager integration or any other aspects of the configuration?Rasmus
07/11/2025, 10:45 AMMarvin
07/11/2025, 10:45 AMMarvin
07/11/2025, 10:45 AMPREFECT_API_URL
with the credentials embedded in the URL format:
bash
PREFECT_API_URL=<https://username:password@your-prefect-server-url/api>
So in your Cloud Run work pool configuration, you would just need:
json
{
"job_configuration": {
"env": [
{
"name": "PREFECT_API_URL",
"value": "<https://username:password@your-prefect-server-url/api>"
}
]
}
}
That's all you need - no separate username and password environment variables required. The basic auth credentials are passed directly in the URL as per HTTP Basic Auth standards.
Remember to:
- URL encode any special characters in your username or password
- Ensure the /api
suffix is included in the URL
- Consider using Secret Manager for the entire URL if you want to keep the credentials more secureRasmus
07/11/2025, 10:46 AMMarvin
07/11/2025, 10:46 AMMarvin
07/11/2025, 10:46 AMjson
{
"job_configuration": {
"env": [
{
"name": "PREFECT_API_URL",
"value": "<https://your-prefect-server-url/api>"
},
{
"name": "PREFECT_API_AUTH_CREDENTIALS",
"value": "username:password"
}
]
}
}
This exactly mirrors the Helm chart's behavior where:
- enabled: true
is handled by setting the auth credentials
- authString: "username:password"
is directly set in PREFECT_API_AUTH_CREDENTIALS
The worker will use these credentials to authenticate with your self-hosted Prefect server, just like it would in the Kubernetes deployment.
Note: Make sure to replace "username:password" with your actual credentials. As before, you might want to consider using Secret Manager for storing these credentials securely.Rasmus
07/11/2025, 10:48 AMMarvin
07/11/2025, 10:48 AMMarvin
07/11/2025, 10:48 AMPREFECT_SERVER_API_AUTH_STRING
on the server side, you should use the same environment variable name for consistency on the worker side.
Here's the correct configuration for your Cloud Run work pool:
json
{
"job_configuration": {
"env": [
{
"name": "PREFECT_API_URL",
"value": "<https://your-prefect-server-url/api>"
},
{
"name": "PREFECT_SERVER_API_AUTH_STRING",
"value": "username:password"
}
]
}
}
This matches exactly with your server configuration, using PREFECT_SERVER_API_AUTH_STRING
for both server and worker. The worker will now use the same authentication mechanism as configured on your server.