|
| 1 | +# Kernel Browser - Cloud Run Deployment Guide |
| 2 | + |
| 3 | +This guide explains how to deploy the Kernel Browser to Google Cloud Run with secure Twilio credential management. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Google Cloud SDK (`gcloud`) installed |
| 8 | +- Docker installed |
| 9 | +- Git installed |
| 10 | +- A Google Cloud Project with billing enabled |
| 11 | +- Twilio account with API credentials (for WebRTC TURN servers) |
| 12 | + |
| 13 | +## Quick Start |
| 14 | + |
| 15 | +### 1. Clone the repository |
| 16 | +```bash |
| 17 | +git clone <repository-url> |
| 18 | +cd browser-web-agent |
| 19 | +git submodule update --init --recursive |
| 20 | +``` |
| 21 | + |
| 22 | +### 2. Set up Twilio credentials |
| 23 | +```bash |
| 24 | +# Copy the example environment file |
| 25 | +cp .env.example .env |
| 26 | + |
| 27 | +# Edit .env and add your Twilio credentials |
| 28 | +# Get these from https://console.twilio.com/ > Account > API Keys & Tokens |
| 29 | +``` |
| 30 | + |
| 31 | +Your `.env` file should contain: |
| 32 | +``` |
| 33 | +TWILIO_ACCOUNT_SID=SK...your_api_key_sid_here |
| 34 | +TWILIO_AUTH_TOKEN=your_api_key_secret_here |
| 35 | +``` |
| 36 | + |
| 37 | +### 3. Deploy to Cloud Run |
| 38 | +```bash |
| 39 | +./deploy.sh |
| 40 | +``` |
| 41 | + |
| 42 | +The script will: |
| 43 | +- Load credentials from `.env` |
| 44 | +- Create/update secrets in Google Secret Manager |
| 45 | +- Build and deploy the container to Cloud Run |
| 46 | +- Configure all necessary permissions |
| 47 | + |
| 48 | +## Deployment Options |
| 49 | + |
| 50 | +### Using Cloud Build (recommended) |
| 51 | +```bash |
| 52 | +./deploy.sh |
| 53 | +``` |
| 54 | + |
| 55 | +### Using local Docker build |
| 56 | +```bash |
| 57 | +./deploy.sh --local |
| 58 | +``` |
| 59 | + |
| 60 | +### Specify project and region |
| 61 | +```bash |
| 62 | +./deploy.sh --project YOUR_PROJECT_ID --region us-central1 |
| 63 | +``` |
| 64 | + |
| 65 | +## How It Works |
| 66 | + |
| 67 | +### Credential Management |
| 68 | + |
| 69 | +1. **Local Development**: Credentials are stored in `.env` file (gitignored) |
| 70 | +2. **Secret Manager**: Deploy script automatically creates/updates secrets in Google Secret Manager |
| 71 | +3. **Cloud Run**: Service uses `secretKeyRef` to securely access credentials at runtime |
| 72 | +4. **Dynamic TURN**: Container fetches fresh TURN credentials from Twilio on startup |
| 73 | + |
| 74 | +### Security Features |
| 75 | + |
| 76 | +- Credentials never appear in code or logs |
| 77 | +- Secrets are encrypted at rest and in transit |
| 78 | +- Service account has minimal required permissions |
| 79 | +- Automatic credential rotation support |
| 80 | + |
| 81 | +### Files Overview |
| 82 | + |
| 83 | +- `.env.example` - Template for environment variables |
| 84 | +- `.env` - Your local credentials (gitignored) |
| 85 | +- `deploy.sh` - Main deployment script with Secret Manager integration |
| 86 | +- `service-secrets.yaml` - Cloud Run config with secret references |
| 87 | +- `service.yaml` - Fallback config (for deployments without secrets) |
| 88 | +- `cloudbuild.yaml` - Cloud Build configuration |
| 89 | +- `twilio/` - Twilio credential management scripts |
| 90 | + |
| 91 | +## Updating Credentials |
| 92 | + |
| 93 | +To update Twilio credentials: |
| 94 | + |
| 95 | +1. Update `.env` with new credentials |
| 96 | +2. Run `./deploy.sh` again |
| 97 | +3. Script will update secrets and redeploy |
| 98 | + |
| 99 | +## Manual Secret Management |
| 100 | + |
| 101 | +If you need to manage secrets manually: |
| 102 | + |
| 103 | +```bash |
| 104 | +# Create secrets |
| 105 | +echo -n "YOUR_SID" | gcloud secrets create twilio-account-sid --data-file=- |
| 106 | +echo -n "YOUR_TOKEN" | gcloud secrets create twilio-auth-token --data-file=- |
| 107 | + |
| 108 | +# Update secrets |
| 109 | +echo -n "NEW_SID" | gcloud secrets versions add twilio-account-sid --data-file=- |
| 110 | +echo -n "NEW_TOKEN" | gcloud secrets versions add twilio-auth-token --data-file=- |
| 111 | + |
| 112 | +# Grant access to service account |
| 113 | +gcloud secrets add-iam-policy-binding twilio-account-sid \ |
| 114 | + --member="serviceAccount:kernel-browser-sa@PROJECT_ID.iam.gserviceaccount.com" \ |
| 115 | + --role="roles/secretmanager.secretAccessor" |
| 116 | +``` |
| 117 | + |
| 118 | +## Service Endpoints |
| 119 | + |
| 120 | +After deployment, you'll have access to: |
| 121 | + |
| 122 | +- **Main Interface**: `https://SERVICE_URL/` |
| 123 | +- **WebRTC Client**: `https://SERVICE_URL/` |
| 124 | +- **Chrome DevTools**: `https://SERVICE_URL/devtools/` |
| 125 | +- **DevTools WebSocket**: `wss://SERVICE_URL/cdp/ws` |
| 126 | +- **Recording API**: `https://SERVICE_URL/api` |
| 127 | +- **Health Check**: `https://SERVICE_URL/health` |
| 128 | + |
| 129 | +## Troubleshooting |
| 130 | + |
| 131 | +### Deployment fails |
| 132 | +- Check that all prerequisites are installed |
| 133 | +- Ensure billing is enabled on your GCP project |
| 134 | +- Verify you have sufficient quota in your region |
| 135 | + |
| 136 | +### WebRTC not working |
| 137 | +- Ensure Twilio credentials are correct |
| 138 | +- Check Cloud Run logs: `gcloud run services logs read kernel-browser --region=us-central1` |
| 139 | +- Verify TURN servers are accessible from your network |
| 140 | + |
| 141 | +### Secrets not found |
| 142 | +- Run `gcloud secrets list` to verify secrets exist |
| 143 | +- Check service account permissions |
| 144 | +- Ensure Secret Manager API is enabled |
| 145 | + |
| 146 | +## Architecture |
| 147 | + |
| 148 | +``` |
| 149 | +┌─────────────┐ ┌──────────────────┐ ┌─────────────────┐ |
| 150 | +│ Client │────▶│ Cloud Run │────▶│ Secret Manager │ |
| 151 | +│ (Browser) │ │ (Container) │ │ (Credentials) │ |
| 152 | +└─────────────┘ └──────────────────┘ └─────────────────┘ |
| 153 | + │ |
| 154 | + ▼ |
| 155 | + ┌──────────────────┐ |
| 156 | + │ Twilio API │ |
| 157 | + │ (TURN Servers) │ |
| 158 | + └──────────────────┘ |
| 159 | +``` |
| 160 | + |
| 161 | +## Support |
| 162 | + |
| 163 | +For issues or questions: |
| 164 | +- Check logs: `gcloud run services logs read kernel-browser --region=us-central1` |
| 165 | +- Review service status: `gcloud run services describe kernel-browser --region=us-central1` |
| 166 | +- File an issue on GitHub |
0 commit comments