|
| 1 | +# HTTP Hostname Validation Example |
| 2 | + |
| 3 | +Demonstrates how to make HTTP requests to external APIs from Chainloop policies while maintaining security through hostname allowlisting. |
| 4 | + |
| 5 | +## What This Policy Does |
| 6 | + |
| 7 | +This policy is just an example which validates the Chainloop platform version by making HTTP requests to its external info API. |
| 8 | + |
| 9 | +It demonstrates: |
| 10 | + |
| 11 | +- **HTTP API Integration** - Makes requests to `https://app.chainloop.dev/api/info` |
| 12 | +- **Response validation** - Compares API response against expected version (configurable) |
| 13 | +- **Hostname Security** - Requires explicit hostname allowlisting for HTTP requests |
| 14 | +- **Error Handling** - Gracefully handles network failures and API errors |
| 15 | + |
| 16 | +## Policy Parameters |
| 17 | + |
| 18 | +| Parameter | Description | Required | Default | Example | |
| 19 | +|-----------|-------------|----------|---------|---------| |
| 20 | +| `expected_version` | Expected platform version to validate against | ❌ No | `1.2.3` | `v0.256.0`, `2.0.0` | |
| 21 | + |
| 22 | +## The HTTP Security Challenge |
| 23 | + |
| 24 | +By default, Chainloop policies **block all HTTP requests** for security reasons. This policy will fail with: |
| 25 | + |
| 26 | +``` |
| 27 | +ERR evaluating policy: unallowed host: app.chainloop.dev |
| 28 | +``` |
| 29 | + |
| 30 | +## Solution: Hostname Allowlisting |
| 31 | + |
| 32 | +Use the `--allowed-hostnames` flag to explicitly allow specific hostnames: |
| 33 | + |
| 34 | +```bash |
| 35 | +chainloop policy develop eval \ |
| 36 | + --policy policy.yaml \ |
| 37 | + --material testdata/empty.json \ |
| 38 | + --kind EVIDENCE \ |
| 39 | + --allowed-hostnames app.chainloop.dev |
| 40 | +``` |
| 41 | + |
| 42 | +## Using in Workflow Contracts |
| 43 | + |
| 44 | +Add this policy to your workflow contract: |
| 45 | + |
| 46 | +```yaml |
| 47 | +apiVersion: workflowcontract.chainloop.dev/v1 |
| 48 | +kind: WorkflowContract |
| 49 | +metadata: |
| 50 | + name: platform-validation-workflow |
| 51 | +spec: |
| 52 | + materials: |
| 53 | + - type: EVIDENCE |
| 54 | + name: platform-check |
| 55 | + |
| 56 | + policies: |
| 57 | + - ref: ./http-hostname-validation/policy.yaml |
| 58 | + with: |
| 59 | + expected_version: "2.0.0" # Optional, defaults to "1.2.3" |
| 60 | +``` |
| 61 | +
|
| 62 | +**Note**: When running in production, the Control Plane manages hostname allowlisting through organization settings. The `--allowed-hostnames` flag is only for local development and testing. |
| 63 | + |
| 64 | +## Development & Testing |
| 65 | + |
| 66 | +See [test.sh](test.sh) for the test cases. |
0 commit comments