|
3 | 3 | A library to access reCAPTCHA Enterprise via [Google Cloud Load Balancing Callouts](https://cloud.google.com/service-extensions/docs/callouts-overview).
|
4 | 4 |
|
5 | 5 | ## Usage
|
6 |
| -This is experimental and in active development. More info to come. |
| 6 | +This project is a full implementation of an [Envoy External Processing server](https://www.envoyproxy.io/docs/envoy/latest/api-v3/service/ext_proc/v3/external_processor.proto) for use with Google Cloud Load Balancing callouts and reCAPTCHA. |
| 7 | + |
| 8 | +### Building and hosting a container image |
| 9 | +Callouts supports serveral backend service types and typical service deployment will rely on building and hosting a container image. For this purpose, this respository contains the following files: |
| 10 | +- [xlb.Dockerfile](../../xlb.Dockerfile) |
| 11 | +- [xlb.cloudbuild.yaml](../../xlb.cloudbuild.yaml) |
| 12 | + |
| 13 | +These deployment files assume that Docker format [Google Cloud Artifact Registry](https://cloud.google.com/artifact-registry/docs/repositories/create-repos) repository named 'recaptcha-edge-repo' has been created in your project. Deploying a container image to the respository may be done with the following command from the repository root: |
| 14 | + |
| 15 | +``` |
| 16 | +gcloud builds submit --region={region} --config xlb.cloudbuild.yaml |
| 17 | +``` |
| 18 | + |
| 19 | +Running this command will, by default, create an image in this location: `{region}-docker.pkg.dev/{my-project}/recaptcha-edge-repo/recaptcha-edge:latest` |
| 20 | + |
| 21 | +### Manually deploying to Google Cloud Load Balancer |
| 22 | +Your load balancer can be configured with the reCAPTCHA External Processing server image by following the [Callouts documentation](https://cloud.google.com/service-extensions/docs/configure-callout-backend-service). |
| 23 | + |
| 24 | +### Deploying to Google Cloud Load Balancer with Terraform |
| 25 | +Terraform may also be used to deploy the cloud resources requried to configure the load balancer callout. A simple [terraform module](./terraform/) which deploys the Callout backend on Cloud Run and configures the Load Balancer has been provided for this purpose. |
| 26 | + |
| 27 | +<b>Usage Example:</b> |
| 28 | +``` |
| 29 | +module "recaptcha_lb_extension" { |
| 30 | + # The module source. This can be local or github. |
| 31 | + source = "path/to/terraform/module" |
| 32 | +
|
| 33 | + # Basic deployment information. |
| 34 | + project_id = "my-project-id" |
| 35 | + region = "us-central1" |
| 36 | +
|
| 37 | + # Identify the type of load balancer we're attaching to. |
| 38 | + load_balancing_scheme = "EXTERNAL_MANAGED" |
| 39 | +
|
| 40 | + # Identify the load balancer front end |
| 41 | + lb_frontend = "https://www.googleapis.com/compute/v1/projects/my-project-id/regions/us-central1/forwardingRules/my-lb-frontend" |
| 42 | +
|
| 43 | + # The match condition that causes traffic to be forwareded to the recaptcha edge callout. |
| 44 | + extension_cel_match = "request.path.startsWith('/callout')" |
| 45 | +
|
| 46 | + # Callout server configs |
| 47 | + edge_container = "us-central1-docker.pkg.dev/my-project-id/recaptcha-edge-repo/recaptcha-edge:label" |
| 48 | +
|
| 49 | + callout_config = { |
| 50 | + project_number = 123456789 |
| 51 | + api_key = "my-api-key" |
| 52 | + action_site_key = "my-action-site-key" |
| 53 | + challenge_page_site_key = "my-challenge-site-key" |
| 54 | + session_site_sey = "my-session-site-key" |
| 55 | +
|
| 56 | + session_js_install_path = "/callout/session.html;/anotherPage.html" |
| 57 | + debug = true |
| 58 | + } |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +### Callout server configuration |
| 63 | +The callout server needs several pieces of information in order to interact with the reCAPTCHA. These are configured via environment variables (ex. [Cloud Run](https://cloud.google.com/run/docs/configuring/services/environment-variables.)) and convieniently in the terraform module noted above. |
| 64 | + |
| 65 | +- `API_KEY`: The Google Cloud API key you created for authentication. |
| 66 | +- `PROJECT_NUMBER`: Your Google Cloud project number. |
| 67 | +- `EXPRESS_SITE_KEY`: The express key if you are using reCAPTCHA express. |
| 68 | +- `SESSION_SITE_KEY`: The session-token key if you are using reCAPTCHA session-token. |
| 69 | +- `ACTION_SITE_KEY`: The action-token key if you are using reCAPTCHA action-token. |
| 70 | +- `CHALLENGE_SITE_KEY`: The challenge-page key if you are using reCAPTCHA challenge page. |
| 71 | +- `SESSION_JS_INSTALL_PATH`: URLs of the pages where you want the Callouts server to install the reCAPTCHA JavaScript using the session-token key. Specify the paths as a glob pattern and use ; as the delimiter. This option is available only for reCAPTCHA session-token. Note that Javascript injection cannot be injected on pages larger than 128KB (see [docs](https://cloud.google.com/service-extensions/docs/callouts-overview)). |
7 | 72 |
|
8 | 73 | ## Contribution
|
9 | 74 |
|
|
0 commit comments