Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

Add Terraform modules for S3 and GCS object storage forwarding

shukieshah17791acfddd4
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 78e53ba9..6a643b58 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -289,6 +289,29 @@ jobs:
go vet ./...
go test ./...
+ terraform:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: hashicorp/setup-terraform@v3
+ with:
+ terraform_version: 1.14.3
+ terraform_wrapper: false
+ # Hermetic: the tests mock the AWS and Google providers, so no cloud account or
+ # credentials are involved. Only the provider downloads reach the network.
+ - name: Check Terraform modules
+ run: |
+ terraform fmt -check -recursive -diff terraform
+ for module in terraform/aws-s3 terraform/gcs; do
+ terraform -chdir="$module" init -backend=false -input=false
+ terraform -chdir="$module" validate
+ terraform -chdir="$module" test
+ done
+ for example in terraform/*/examples/*/; do
+ terraform -chdir="$example" init -backend=false -input=false
+ terraform -chdir="$example" validate
+ done
+
cross-build:
runs-on: ubuntu-latest
strategy:
diff --git a/CLAUDE.md b/CLAUDE.md
index 95b0e7bd..403260e7 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -18,6 +18,7 @@ Beacon Endpoint Agent is a local-only endpoint telemetry agent for AI runtimes.
- `spec/lenses`: the Lenses format — single-file HTML views of one trace that the local dashboard runs in a sandboxed, network-less frame and feeds once through `window.beacon.getTrace()`. The contract types (`LensManifestV1`, `LensDataV1`) live in `pkg/asymptoteobserve/lens.go`, and `lens_test.go` pins the spec's examples and manifest schema to them. The dashboard builds the data in `BuildLensData` (`/api/lens-data`), lists lenses at `/api/lenses`, and serves each lens at `/lenses/frame/<id>` under the spec's CSP with `lenses/prelude.js` (which defines `window.beacon`) injected ahead of it; that route is the only one that may be framed. Built-in lenses are `cli/beacon/internal/endpoint/dashboard/lenses/*.lens.html`, and `activity` is byte-identical to the spec example (a test enforces it). The session page (`static/session.html`, `initLensTabs` in `app.js`) shows lenses as tabs fed by `/api/lens-data?session=`, which projects exactly the events that page lists; it is the host half of the protocol and closes a lens that errors, stalls, or navigates its own frame. Trust model (SPEC "Trust model"): the opaque origin, sandbox and CSP keep a lens from touching Beacon or the dashboard and block ordinary network APIs, but cannot fully prevent a lens from sending trace data out through browser features no CSP governs (WebRTC, resource hints, speculative loading), so an installed lens is code the person trusts with the trace data it is shown; never describe the sandbox as making exfiltration impossible. `prelude.js` removes the `RTC*` globals and guards the document (refuses creating, inserting or parsing in nested frames, `<link>` elements and `<script type=speculationrules>`, parsing markup in the real call's document and context and inserting exactly the checked nodes so `<noscript>`/foreign-content parser differentials cannot slip through, refuses `document.write` and `execCommand("insertHTML")`, and a mutation observer removes those from the file's own markup); that is best-effort hardening, not a boundary, and the hostile `probe` fixture in `testdata/lens-e2e` pins each covered path. Installed lenses live in the lens store (`cli/beacon/internal/endpoint/lensstore`, `<BaseDir>/lenses/<id>.lens.html`, 0600 under 0700), written only by `beacon lenses add|remove` (`cli/beacon/cmd/lenses.go`; `add` prints the trust warning and confirms on a TTY, and refuses without one or in CI unless `--yes`); the dashboard rescans it per request and never writes it, and a store lens can never shadow a built-in. `asymptoteobserve.CheckLensFile` is the one file check every installer, server and linter uses. User docs are `docs/concepts/lenses.mdx` and `docs/cli/lenses.mdx`; keep them in sync with the commands and built-in lenses. The authoring loop is `beacon lenses spec` (the spec carried in the binary as `dashboard/lenses/SPEC.md`, kept byte-identical to `spec/lenses/SPEC.md` by a test), `beacon lenses data` (the exact `LensDataV1` for a session), `beacon lenses lint` (`lensstore.Lint`; built-ins must lint clean) and `beacon lenses preview` (the dashboard with `Options.LensFiles`, re-read per reload).
- `beacon-sandbox`: harness that runs a real Claude Code session in a disposable sandbox and checks what Beacon captured. See `beacon-sandbox/AGENTS.md`.
- `packaging`: macOS, Linux, and Windows packaging and deployment assets.
+- `terraform`: customer-run Terraform modules for the cloud side of object storage forwarding. `aws-s3` creates the bucket (hardened, skipped with `create_bucket = false`), the put-only `beacon-endpoint-writer` IAM user, and optionally `beacon-s3-reader` for Beacon Cloud's S3 data connector, which reads with an access key because ClickPipes on the GCP-hosted ClickHouse rejects IAM roles. `gcs` creates the bucket, a `beacon-endpoint-writer` service account with `objectCreator` limited to the prefix by an IAM condition, an optional reader, and an optional `objectViewer` grant for Beacon's `beacon-clickpipes-reader`. Neither creates keys unless asked (`create_access_keys`, `create_writer_key`), so no secret lands in state by default. Resource names and the `forwarder_settings` output match the packaged `install-forwarder.sh` helpers and the manual guides. The AWS module needs provider 6.0+ for the per-data-source `region` that finds an existing bucket in another region. Docs are `docs/log-forwarding/{aws-s3,gcs}-terraform.mdx`, mirrored in beacon-mdr's docs, with the module pinned to a release tag; keep both in sync with the variables.
- `docs`: the published documentation site (docs.asymptotelabs.ai).
Do not recreate or depend on removed `asymptote` mirror trees. Keep new work focused on the Beacon paths above.
@@ -132,6 +133,13 @@ cd pkg/asymptoteobserve
go test ./...
```
+Run the Terraform module tests (the providers are mocked, so no cloud account is needed):
+
+```bash
+cd terraform/aws-s3 && terraform init -backend=false && terraform test
+cd ../gcs && terraform init -backend=false && terraform test
+```
+
Run the managed runtime plugin/extension checks (each verifies the checked-in copy matches its embedded twin, then runs its tests):
```bash
@@ -560,6 +568,7 @@ unpacked through Chrome's developer mode.
- `browser-extension` (Node 22, matrix over `chromium` and `msedge`): `npm run check`, `npm run test:unit`, `npm run build`, a check that the build is a loadable MV3 extension, `npm run lint:firefox` (the Firefox build plus `addons-linter --warnings-as-errors`), and the Playwright replay e2e running the real extension headless in that leg's browser (`BROWSER_CHANNEL`) against a local HTTPS replay server; the HTML report and traces upload on failure. Brave, Opera, Vivaldi and Arc have no Playwright channel; `BROWSER_EXECUTABLE` runs the same e2e against their binaries for the manual checklist in `docs/runtimes/browser-extension-chromium.mdx`.
- `lens-e2e` (ubuntu): runs the real dashboard handler with hostile fixture lenses and the full `rules/` corpus installed (`cli/beacon/internal/endpoint/dashboard/e2eserver`, `testdata/lens-e2e`) and drives the session page in headless Chromium. Every escape from the lens sandbox must be refused, and a lens that throws, stalls or navigates must give way to the full session.
- `beacon-sandbox` (ubuntu): `go build`, `go vet`, and `go test` for the verification harness. Hermetic — no Modal account, no API key, no paid resources.
+- `terraform` (ubuntu): `terraform fmt -check`, `validate`, and `terraform test` (mocked providers) for `terraform/aws-s3` and `terraform/gcs`, and `validate` for each example.
- `cross-build` (ubuntu): builds all five release targets and asserts the Linux binaries are statically linked (no `PT_INTERP`).
- `package-smoke` (macOS): `packaging/macos/test-endpoint-scripts.sh`, a `build-pkg.sh` payload check, and `packaging/macos/smoke-endpoint.sh`.
- `linux-systemd-smoke` and `linux-package-smoke` (ubuntu): the real systemd install path, and installing the built `.deb` in a systemd container.
diff --git a/docs/cli/gcs.mdx b/docs/cli/gcs.mdx
index d8c59a52..c373e442 100644
--- a/docs/cli/gcs.mdx
+++ b/docs/cli/gcs.mdx
@@ -201,6 +201,9 @@ list or read the objects it successfully uploads.
## Related
<Columns cols={2}>
+ <Card title="Google Cloud Storage with Terraform" icon="cloud" href="/log-forwarding/gcs-terraform">
+ Create the bucket and create-only service account with Terraform.
+ </Card>
<Card title="Object storage forwarding" icon="chart-line" href="/guides/macos-object-storage-system">
Configure Vector forwarding from Beacon JSONL into Google Cloud Storage.
</Card>
diff --git a/docs/cli/s3.mdx b/docs/cli/s3.mdx
index 09065f25..018061e3 100644
--- a/docs/cli/s3.mdx
+++ b/docs/cli/s3.mdx
@@ -179,6 +179,9 @@ Supported provider-chain variables include `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCE
## Related
<Columns cols={2}>
+ <Card title="AWS S3 with Terraform" icon="bucket" href="/log-forwarding/aws-s3-terraform">
+ Create the bucket and write-only IAM user with Terraform.
+ </Card>
<Card title="Beacon with Fleet and S3" icon="bucket" href="/guides/fleet-s3-mdm">
Fleet software install, self-updates, and Vector forwarding to S3.
</Card>
diff --git a/docs/docs.json b/docs/docs.json
index 183b6830..79368b67 100644
--- a/docs/docs.json
+++ b/docs/docs.json
@@ -505,7 +505,9 @@
"group": "Object Storage",
"expanded": true,
"pages": [
- "guides/macos-object-storage-system"
+ "guides/macos-object-storage-system",
+ "log-forwarding/aws-s3-terraform",
+ "log-forwarding/gcs-terraform"
]
},
{
diff --git a/docs/guides/fleet-s3-mdm.mdx b/docs/guides/fleet-s3-mdm.mdx
index f10408f6..b0579517 100644
--- a/docs/guides/fleet-s3-mdm.mdx
+++ b/docs/guides/fleet-s3-mdm.mdx
@@ -79,28 +79,52 @@ You can leave this Mac as it is. When Fleet installs the same package on it late
**Pick a prefix** such as `beacon-prod`. Beacon adds `runtime/` and `inventory/` under it, so don't put either in the prefix.
-**Create an IAM user for Beacon** with this policy. Replace the bucket and prefix with yours:
+<Tabs>
+ <Tab title="AWS console or CLI">
+ **Create an IAM user for Beacon** with this policy. Replace the bucket and prefix with yours:
-```json title="IAM policy for the Beacon writer"
-{
- "Version": "2012-10-17",
- "Statement": [
+ ```json title="IAM policy for the Beacon writer"
{
- "Effect": "Allow",
- "Action": ["s3:PutObject"],
- "Resource": "arn:aws:s3:::example-security-logs/beacon-prod/*"
+ "Version": "2012-10-17",
+ "Statement": [
+ {
+ "Effect": "Allow",
+ "Action": ["s3:PutObject"],
+ "Resource": "arn:aws:s3:::example-security-logs/beacon-prod/*"
+ }
+ ]
}
- ]
-}
-```
+ ```
+
+ **Create an access key** for that user. Use a long-lived key, which starts with `AKIA`. Temporary credentials stop working when they expire, and uploads that fail after that point are lost.
-**Create an access key** for that user. Use a long-lived key, which starts with `AKIA`. Temporary credentials stop working when they expire, and uploads that fail after that point are lost.
+ Three things about the bucket:
-Three things about the bucket:
+ - **Startup check.** When the forwarder starts, it checks that it can reach the bucket, which needs `s3:ListBucket` on `arn:aws:s3:::example-security-logs`. Without it, uploads still work, but the forwarder's log shows a health-check error at startup. Add the permission if you'd rather not see that error.
+ - **KMS.** If the bucket's default encryption uses a customer managed KMS key, also allow `kms:GenerateDataKey` on that key.
+ - **Encryption headers.** Beacon doesn't send encryption headers or ACLs, so the bucket's default encryption applies. A bucket policy that requires an encryption header on every upload will reject Beacon's uploads.
+ </Tab>
+ <Tab title="Terraform">
+ Beacon's [Terraform module](/log-forwarding/aws-s3-terraform) creates the bucket and an IAM user with the policy from the other tab, plus `s3:ListBucket` for the forwarder's startup check. Add it to a configuration whose AWS provider uses the region you want the bucket in:
+
+ ```hcl
+ module "beacon_s3" {
+ source = "github.com/asymptote-labs/agent-beacon//terraform/aws-s3?ref=v1.3.38"
-- **Startup check.** When the forwarder starts, it checks that it can reach the bucket, which needs `s3:ListBucket` on `arn:aws:s3:::example-security-logs`. Without it, uploads still work, but the forwarder's log shows a health-check error at startup. Add the permission if you'd rather not see that error.
-- **KMS.** If the bucket's default encryption uses a customer managed KMS key, also allow `kms:GenerateDataKey` on that key.
-- **Encryption headers.** Beacon doesn't send encryption headers or ACLs, so the bucket's default encryption applies. A bucket policy that requires an encryption header on every upload will reject Beacon's uploads.
+ bucket_name = "example-security-logs"
+ prefix = "beacon-prod"
+ }
+ ```
+
+ Run `terraform apply`. Then **create an access key** with the AWS CLI, which keeps the secret out of your Terraform state:
+
+ ```bash
+ aws iam create-access-key --user-name beacon-endpoint-writer --output json
+ ```
+
+ The key starts with `AKIA` and doesn't expire. To use a bucket you already have or your own KMS key, see the [module's options](/log-forwarding/aws-s3-terraform#options).
+ </Tab>
+</Tabs>
## 3. Set up Fleet
diff --git a/docs/guides/jamf-anthropic-openai-cursor-mdm.mdx b/docs/guides/jamf-anthropic-openai-cursor-mdm.mdx
index 54b4b56a..38d544f7 100644
--- a/docs/guides/jamf-anthropic-openai-cursor-mdm.mdx
+++ b/docs/guides/jamf-anthropic-openai-cursor-mdm.mdx
@@ -85,6 +85,10 @@ BEACON_S3_PREFIX="beacon-prod/runtime" # avoid
## AWS permission
+<Tip>
+ Managing AWS with Terraform? [AWS S3 with Terraform](/log-forwarding/aws-s3-terraform) creates the bucket and an IAM user with this policy. Create its access key with the AWS CLI, then continue here.
+</Tip>
+
Scope write access to the Beacon prefix:
```json
diff --git a/docs/guides/jamf-gcs-mdm.mdx b/docs/guides/jamf-gcs-mdm.mdx
index 83f3df41..88dba57d 100644
--- a/docs/guides/jamf-gcs-mdm.mdx
+++ b/docs/guides/jamf-gcs-mdm.mdx
@@ -30,59 +30,113 @@ deployments should use the root layout.
## 1. Prepare Google Cloud
-Set placeholders in an administrator shell:
-
-```bash
-export GCP_PROJECT="<project-id>"
-export GCP_REGION="<region>" # for example us-central1
-export BEACON_GCS_BUCKET="<globally-unique-bucket>"
-export BEACON_GCS_PREFIX="beacon-prod"
-export BEACON_GCS_WRITER="beacon-endpoint-writer"
-export BEACON_GCS_READER="beacon-endpoint-reader"
-```
-
-Create the bucket and writer service account:
-
-```bash
-gcloud services enable storage.googleapis.com iam.googleapis.com \
- --project "$GCP_PROJECT"
-
-gcloud storage buckets create "gs://${BEACON_GCS_BUCKET}" \
- --project "$GCP_PROJECT" \
- --location "$GCP_REGION" \
- --uniform-bucket-level-access
-
-gcloud iam service-accounts create "$BEACON_GCS_WRITER" \
- --project "$GCP_PROJECT" \
- --display-name "Beacon endpoint GCS writer"
-
-export BEACON_GCS_WRITER_EMAIL="${BEACON_GCS_WRITER}@${GCP_PROJECT}.iam.gserviceaccount.com"
-
-gcloud storage buckets add-iam-policy-binding "gs://${BEACON_GCS_BUCKET}" \
- --member "serviceAccount:${BEACON_GCS_WRITER_EMAIL}" \
- --role roles/storage.objectCreator
-```
-
-`roles/storage.objectCreator` can create objects but cannot list, read, overwrite,
-or delete them. A successful writer therefore cannot validate delivery by
-running `gcloud storage ls` or `cat`.
-
-Create a separate read-only identity for validation and downstream consumers:
-
-```bash
-gcloud iam service-accounts create "$BEACON_GCS_READER" \
- --project "$GCP_PROJECT" \
- --display-name "Beacon endpoint GCS reader"
-
-export BEACON_GCS_READER_EMAIL="${BEACON_GCS_READER}@${GCP_PROJECT}.iam.gserviceaccount.com"
-
-gcloud storage buckets add-iam-policy-binding "gs://${BEACON_GCS_BUCKET}" \
- --member "serviceAccount:${BEACON_GCS_READER_EMAIL}" \
- --role roles/storage.objectViewer
-```
-
-Apply lifecycle, retention, logging, and CMEK controls in Google Cloud according
-to your organization's policy.
+<Tabs>
+ <Tab title="gcloud">
+ Set placeholders in an administrator shell:
+
+ ```bash
+ export GCP_PROJECT="<project-id>"
+ export GCP_REGION="<region>" # for example us-central1
+ export BEACON_GCS_BUCKET="<globally-unique-bucket>"
+ export BEACON_GCS_PREFIX="beacon-prod"
+ export BEACON_GCS_WRITER="beacon-endpoint-writer"
+ export BEACON_GCS_READER="beacon-endpoint-reader"
+ ```
+
+ Create the bucket and writer service account:
+
+ ```bash
+ gcloud services enable storage.googleapis.com iam.googleapis.com \
+ --project "$GCP_PROJECT"
+
+ gcloud storage buckets create "gs://${BEACON_GCS_BUCKET}" \
+ --project "$GCP_PROJECT" \
+ --location "$GCP_REGION" \
+ --uniform-bucket-level-access
+
+ gcloud iam service-accounts create "$BEACON_GCS_WRITER" \
+ --project "$GCP_PROJECT" \
+ --display-name "Beacon endpoint GCS writer"
+
+ export BEACON_GCS_WRITER_EMAIL="${BEACON_GCS_WRITER}@${GCP_PROJECT}.iam.gserviceaccount.com"
+
+ gcloud storage buckets add-iam-policy-binding "gs://${BEACON_GCS_BUCKET}" \
+ --member "serviceAccount:${BEACON_GCS_WRITER_EMAIL}" \
+ --role roles/storage.objectCreator
+ ```
+
+ `roles/storage.objectCreator` can create objects but cannot list, read, overwrite,
+ or delete them. A successful writer therefore cannot validate delivery by
+ running `gcloud storage ls` or `cat`.
+
+ Create a separate read-only identity for validation and downstream consumers:
+
+ ```bash
+ gcloud iam service-accounts create "$BEACON_GCS_READER" \
+ --project "$GCP_PROJECT" \
+ --display-name "Beacon endpoint GCS reader"
+
+ export BEACON_GCS_READER_EMAIL="${BEACON_GCS_READER}@${GCP_PROJECT}.iam.gserviceaccount.com"
+
+ gcloud storage buckets add-iam-policy-binding "gs://${BEACON_GCS_BUCKET}" \
+ --member "serviceAccount:${BEACON_GCS_READER_EMAIL}" \
+ --role roles/storage.objectViewer
+ ```
+
+ Apply lifecycle, retention, logging, and CMEK controls in Google Cloud according
+ to your organization's policy.
+ </Tab>
+ <Tab title="Terraform">
+ Beacon's [Terraform module](/log-forwarding/gcs-terraform) creates the bucket, the
+ writer, and the read-only service account, with the same roles as the gcloud steps.
+ The writer is also limited to the Beacon prefix:
+
+ ```hcl title="main.tf"
+ module "beacon_gcs" {
+ source = "github.com/asymptote-labs/agent-beacon//terraform/gcs?ref=v1.3.38"
+
+ project = "<project-id>"
+ location = "<region>" # for example us-central1
+ bucket_name = "<globally-unique-bucket>"
+ prefix = "beacon-prod"
+ create_reader = true
+ }
+
+ output "bucket_name" {
+ value = module.beacon_gcs.bucket_name
+ }
+
+ output "prefix" {
+ value = module.beacon_gcs.prefix
+ }
+
+ output "writer_email" {
+ value = module.beacon_gcs.writer_email
+ }
+
+ output "reader_email" {
+ value = module.beacon_gcs.reader_email
+ }
+ ```
+
+ Apply it and save the outputs for the next steps:
+
+ ```bash
+ terraform init
+ terraform apply
+
+ export GCP_PROJECT="<project-id>"
+ export BEACON_GCS_BUCKET="$(terraform output -raw bucket_name)"
+ export BEACON_GCS_PREFIX="$(terraform output -raw prefix)"
+ export BEACON_GCS_WRITER_EMAIL="$(terraform output -raw writer_email)"
+ export BEACON_GCS_WRITER="${BEACON_GCS_WRITER_EMAIL%%@*}"
+ export BEACON_GCS_READER_EMAIL="$(terraform output -raw reader_email)"
+ ```
+
+ For lifecycle rules, CMEK, or an existing bucket, see the
+ [module's options](/log-forwarding/gcs-terraform#options).
+ </Tab>
+</Tabs>
## 2. Deliver the writer credential
diff --git a/docs/guides/jamf-s3-mdm.mdx b/docs/guides/jamf-s3-mdm.mdx
index f3bc92b4..13e18fbc 100644
--- a/docs/guides/jamf-s3-mdm.mdx
+++ b/docs/guides/jamf-s3-mdm.mdx
@@ -54,6 +54,10 @@ The helper normalizes old prefixes ending in `/runtime` or `/inventory`, but new
## AWS permission
+<Tip>
+ Managing AWS with Terraform? [AWS S3 with Terraform](/log-forwarding/aws-s3-terraform) creates the bucket and an IAM user with this policy. Create its access key with the AWS CLI, then continue here.
+</Tip>
+
Use a bucket policy or IAM policy scoped to the Beacon prefix. Example:
```json
diff --git a/docs/guides/macos-object-storage-system.mdx b/docs/guides/macos-object-storage-system.mdx
index 7ef9cd06..cc3d1ef6 100644
--- a/docs/guides/macos-object-storage-system.mdx
+++ b/docs/guides/macos-object-storage-system.mdx
@@ -97,67 +97,123 @@ Use a root prefix such as `beacon-prod`. Do not include `runtime` or
### AWS S3
-You need an AWS account where your current AWS CLI identity can create an S3
-bucket, IAM user, and inline policy. Confirm the identity before making changes:
-
-```bash
-aws sts get-caller-identity
-```
-
-Choose globally unique bucket and writer names:
-
-```bash
-export AWS_REGION="us-west-2"
-export BEACON_S3_BUCKET="<globally-unique-bucket>"
-export BEACON_S3_PREFIX="beacon-prod"
-export BEACON_S3_STORAGE_CLASS="STANDARD"
-export BEACON_S3_WRITER="beacon-endpoint-writer"
-```
-
-Create the bucket. AWS requires a different command shape for `us-east-1`:
-
-```bash
-if [ "$AWS_REGION" = "us-east-1" ]; then
- aws s3api create-bucket \
- --bucket "$BEACON_S3_BUCKET" \
- --region "$AWS_REGION"
-else
- aws s3api create-bucket \
- --bucket "$BEACON_S3_BUCKET" \
- --region "$AWS_REGION" \
- --create-bucket-configuration "LocationConstraint=$AWS_REGION"
-fi
-```
-
-Create a dedicated writer and grant only `s3:PutObject` below the Beacon root
-prefix:
-
-```bash
-aws iam create-user --user-name "$BEACON_S3_WRITER"
-
-aws iam put-user-policy \
- --user-name "$BEACON_S3_WRITER" \
- --policy-name BeaconEndpointWriteOnly \
- --policy-document "$(cat <<EOF
-{
- "Version": "2012-10-17",
- "Statement": [{
- "Effect": "Allow",
- "Action": ["s3:PutObject"],
- "Resource": "arn:aws:s3:::${BEACON_S3_BUCKET}/${BEACON_S3_PREFIX}/*"
- }]
-}
-EOF
-)"
-```
-
-Create an access key:
-
-```bash
-aws iam create-access-key \
- --user-name "$BEACON_S3_WRITER" \
- --output json
-```
+<Tabs>
+ <Tab title="AWS CLI">
+ You need an AWS account where your current AWS CLI identity can create an S3
+ bucket, IAM user, and inline policy. Confirm the identity before making changes:
+
+ ```bash
+ aws sts get-caller-identity
+ ```
+
+ Choose globally unique bucket and writer names:
+
+ ```bash
+ export AWS_REGION="us-west-2"
+ export BEACON_S3_BUCKET="<globally-unique-bucket>"
+ export BEACON_S3_PREFIX="beacon-prod"
+ export BEACON_S3_STORAGE_CLASS="STANDARD"
+ export BEACON_S3_WRITER="beacon-endpoint-writer"
+ ```
+
+ Create the bucket. AWS requires a different command shape for `us-east-1`:
+
+ ```bash
+ if [ "$AWS_REGION" = "us-east-1" ]; then
+ aws s3api create-bucket \
+ --bucket "$BEACON_S3_BUCKET" \
+ --region "$AWS_REGION"
+ else
+ aws s3api create-bucket \
+ --bucket "$BEACON_S3_BUCKET" \
+ --region "$AWS_REGION" \
+ --create-bucket-configuration "LocationConstraint=$AWS_REGION"
+ fi
+ ```
+
+ Create a dedicated writer and grant only `s3:PutObject` below the Beacon root
+ prefix:
+
+ ```bash
+ aws iam create-user --user-name "$BEACON_S3_WRITER"
+
+ aws iam put-user-policy \
+ --user-name "$BEACON_S3_WRITER" \
+ --policy-name BeaconEndpointWriteOnly \
+ --policy-document "$(cat <<EOF
+ {
+ "Version": "2012-10-17",
+ "Statement": [{
+ "Effect": "Allow",
+ "Action": ["s3:PutObject"],
+ "Resource": "arn:aws:s3:::${BEACON_S3_BUCKET}/${BEACON_S3_PREFIX}/*"
+ }]
+ }
+ EOF
+ )"
+ ```
+
+ Create an access key:
+
+ ```bash
+ aws iam create-access-key \
+ --user-name "$BEACON_S3_WRITER" \
+ --output json
+ ```
+ </Tab>
+ <Tab title="Terraform">
+ Beacon's [Terraform module](/log-forwarding/aws-s3-terraform) creates the bucket and
+ the write-only IAM user. Use a configuration whose AWS provider uses the region you
+ want the bucket in:
+
+ ```hcl title="main.tf"
+ module "beacon_s3" {
+ source = "github.com/asymptote-labs/agent-beacon//terraform/aws-s3?ref=v1.3.38"
+
+ bucket_name = "<globally-unique-bucket>"
+ prefix = "beacon-prod"
+ }
+
+ output "bucket_name" {
+ value = module.beacon_s3.bucket_name
+ }
+
+ output "region" {
+ value = module.beacon_s3.region
+ }
+
+ output "prefix" {
+ value = module.beacon_s3.prefix
+ }
+
+ output "writer_user_name" {
+ value = module.beacon_s3.writer_user_name
+ }
+ ```
+
+ Apply it and save the outputs for the commands below:
+
+ ```bash
+ terraform init
+ terraform apply
+
+ export BEACON_S3_BUCKET="$(terraform output -raw bucket_name)"
+ export AWS_REGION="$(terraform output -raw region)"
+ export BEACON_S3_PREFIX="$(terraform output -raw prefix)"
+ export BEACON_S3_STORAGE_CLASS="STANDARD"
+ export BEACON_S3_WRITER="$(terraform output -raw writer_user_name)"
+ ```
+
+ Create the access key with the AWS CLI, which keeps the secret out of your Terraform
+ state:
+
+ ```bash
+ aws iam create-access-key \
+ --user-name "$BEACON_S3_WRITER" \
+ --output json
+ ```
+ </Tab>
+</Tabs>
AWS displays the secret only once. Store both values in your password manager
or endpoint secret tooling, then export them without committing them or placing
@@ -191,56 +247,100 @@ in Beacon.
### Google Cloud Storage
-You need a Google Cloud project where your current `gcloud` identity can enable
-APIs, create a bucket, create a service account, and manage bucket IAM. Confirm
-the active identity and project:
-
-```bash
-gcloud auth list --filter=status:ACTIVE
-gcloud config get-value project
-```
-
-Choose the project, bucket, location, prefix, and writer name:
-
-```bash
-export GCP_PROJECT="<project-id>"
-export GCP_LOCATION="us-west1"
-export BEACON_GCS_BUCKET="<globally-unique-bucket>"
-export BEACON_GCS_PREFIX="beacon-prod"
-export BEACON_GCS_STORAGE_CLASS="STANDARD"
-export BEACON_GCS_WRITER="beacon-endpoint-writer"
-export BEACON_GCS_WRITER_EMAIL="${BEACON_GCS_WRITER}@${GCP_PROJECT}.iam.gserviceaccount.com"
-```
-
-Enable the APIs and create a uniform-access bucket:
-
-```bash
-gcloud services enable storage.googleapis.com iam.googleapis.com \
- --project "$GCP_PROJECT"
-
-gcloud storage buckets create "gs://${BEACON_GCS_BUCKET}" \
- --project "$GCP_PROJECT" \
- --location "$GCP_LOCATION" \
- --default-storage-class "$BEACON_GCS_STORAGE_CLASS" \
- --uniform-bucket-level-access
-```
-
-Create the writer service account:
-
-```bash
-gcloud iam service-accounts create "$BEACON_GCS_WRITER" \
- --project "$GCP_PROJECT" \
- --display-name "Beacon endpoint GCS writer"
-```
-
-Grant it write-only access to the bucket:
-
-```bash
-gcloud storage buckets add-iam-policy-binding \
- "gs://${BEACON_GCS_BUCKET}" \
- --member "serviceAccount:${BEACON_GCS_WRITER_EMAIL}" \
- --role roles/storage.objectCreator
-```
+<Tabs>
+ <Tab title="gcloud">
+ You need a Google Cloud project where your current `gcloud` identity can enable
+ APIs, create a bucket, create a service account, and manage bucket IAM. Confirm
+ the active identity and project:
+
+ ```bash
+ gcloud auth list --filter=status:ACTIVE
+ gcloud config get-value project
+ ```
+
+ Choose the project, bucket, location, prefix, and writer name:
+
+ ```bash
+ export GCP_PROJECT="<project-id>"
+ export GCP_LOCATION="us-west1"
+ export BEACON_GCS_BUCKET="<globally-unique-bucket>"
+ export BEACON_GCS_PREFIX="beacon-prod"
+ export BEACON_GCS_STORAGE_CLASS="STANDARD"
+ export BEACON_GCS_WRITER="beacon-endpoint-writer"
+ export BEACON_GCS_WRITER_EMAIL="${BEACON_GCS_WRITER}@${GCP_PROJECT}.iam.gserviceaccount.com"
+ ```
+
+ Enable the APIs and create a uniform-access bucket:
+
+ ```bash
+ gcloud services enable storage.googleapis.com iam.googleapis.com \
+ --project "$GCP_PROJECT"
+
+ gcloud storage buckets create "gs://${BEACON_GCS_BUCKET}" \
+ --project "$GCP_PROJECT" \
+ --location "$GCP_LOCATION" \
+ --default-storage-class "$BEACON_GCS_STORAGE_CLASS" \
+ --uniform-bucket-level-access
+ ```
+
+ Create the writer service account:
+
+ ```bash
+ gcloud iam service-accounts create "$BEACON_GCS_WRITER" \
+ --project "$GCP_PROJECT" \
+ --display-name "Beacon endpoint GCS writer"
+ ```
+
+ Grant it write-only access to the bucket:
+
+ ```bash
+ gcloud storage buckets add-iam-policy-binding \
+ "gs://${BEACON_GCS_BUCKET}" \
+ --member "serviceAccount:${BEACON_GCS_WRITER_EMAIL}" \
+ --role roles/storage.objectCreator
+ ```
+ </Tab>
+ <Tab title="Terraform">
+ Beacon's [Terraform module](/log-forwarding/gcs-terraform) creates the bucket and
+ the create-only service account:
+
+ ```hcl title="main.tf"
+ module "beacon_gcs" {
+ source = "github.com/asymptote-labs/agent-beacon//terraform/gcs?ref=v1.3.38"
+
+ project = "<project-id>"
+ location = "us-west1"
+ bucket_name = "<globally-unique-bucket>"
+ prefix = "beacon-prod"
+ }
+
+ output "bucket_name" {
+ value = module.beacon_gcs.bucket_name
+ }
+
+ output "prefix" {
+ value = module.beacon_gcs.prefix
+ }
+
+ output "writer_email" {
+ value = module.beacon_gcs.writer_email
+ }
+ ```
+
+ Apply it and save the outputs for the commands below:
+
+ ```bash
+ terraform init
+ terraform apply
+
+ export GCP_PROJECT="<project-id>"
+ export BEACON_GCS_BUCKET="$(terraform output -raw bucket_name)"
+ export BEACON_GCS_PREFIX="$(terraform output -raw prefix)"
+ export BEACON_GCS_STORAGE_CLASS="STANDARD"
+ export BEACON_GCS_WRITER_EMAIL="$(terraform output -raw writer_email)"
+ ```
+ </Tab>
+</Tabs>
The packaged Vector 0.56 service on macOS needs a service-account JSON file. If
your organization allows service-account keys, create one in a temporary
diff --git a/docs/guides/rippling-gcs-mdm.mdx b/docs/guides/rippling-gcs-mdm.mdx
index 575aaa08..4948e727 100644
--- a/docs/guides/rippling-gcs-mdm.mdx
+++ b/docs/guides/rippling-gcs-mdm.mdx
@@ -70,63 +70,117 @@ Prepare:
## 1. Prepare Google Cloud
-Set administrator-shell placeholders:
+<Tabs>
+ <Tab title="gcloud">
+ Set administrator-shell placeholders:
-```bash
-export GCP_PROJECT="<project-id>"
-export GCP_REGION="<region>" # for example us-central1
-export BEACON_GCS_BUCKET="<globally-unique-bucket>"
-export BEACON_GCS_PREFIX="beacon-prod"
-export BEACON_GCS_WRITER="beacon-endpoint-writer"
-export BEACON_GCS_READER="beacon-endpoint-reader"
-```
+ ```bash
+ export GCP_PROJECT="<project-id>"
+ export GCP_REGION="<region>" # for example us-central1
+ export BEACON_GCS_BUCKET="<globally-unique-bucket>"
+ export BEACON_GCS_PREFIX="beacon-prod"
+ export BEACON_GCS_WRITER="beacon-endpoint-writer"
+ export BEACON_GCS_READER="beacon-endpoint-reader"
+ ```
-Enable APIs and create the bucket:
+ Enable APIs and create the bucket:
-```bash
-gcloud services enable storage.googleapis.com iam.googleapis.com \
- --project "$GCP_PROJECT"
+ ```bash
+ gcloud services enable storage.googleapis.com iam.googleapis.com \
+ --project "$GCP_PROJECT"
-gcloud storage buckets create "gs://${BEACON_GCS_BUCKET}" \
- --project "$GCP_PROJECT" \
- --location "$GCP_REGION" \
- --uniform-bucket-level-access
-```
+ gcloud storage buckets create "gs://${BEACON_GCS_BUCKET}" \
+ --project "$GCP_PROJECT" \
+ --location "$GCP_REGION" \
+ --uniform-bucket-level-access
+ ```
-Create the endpoint writer:
+ Create the endpoint writer:
-```bash
-gcloud iam service-accounts create "$BEACON_GCS_WRITER" \
- --project "$GCP_PROJECT" \
- --display-name "Beacon endpoint GCS writer"
+ ```bash
+ gcloud iam service-accounts create "$BEACON_GCS_WRITER" \
+ --project "$GCP_PROJECT" \
+ --display-name "Beacon endpoint GCS writer"
-export BEACON_GCS_WRITER_EMAIL="${BEACON_GCS_WRITER}@${GCP_PROJECT}.iam.gserviceaccount.com"
+ export BEACON_GCS_WRITER_EMAIL="${BEACON_GCS_WRITER}@${GCP_PROJECT}.iam.gserviceaccount.com"
-gcloud storage buckets add-iam-policy-binding "gs://${BEACON_GCS_BUCKET}" \
- --member "serviceAccount:${BEACON_GCS_WRITER_EMAIL}" \
- --role roles/storage.objectCreator
-```
+ gcloud storage buckets add-iam-policy-binding "gs://${BEACON_GCS_BUCKET}" \
+ --member "serviceAccount:${BEACON_GCS_WRITER_EMAIL}" \
+ --role roles/storage.objectCreator
+ ```
-`roles/storage.objectCreator` permits new object creation but not listing,
-reading, overwriting, or deleting objects. This limits the endpoint credential,
-but it also means that credential cannot validate uploads.
+ `roles/storage.objectCreator` permits new object creation but not listing,
+ reading, overwriting, or deleting objects. This limits the endpoint credential,
+ but it also means that credential cannot validate uploads.
-Create a separate read-only identity:
+ Create a separate read-only identity:
-```bash
-gcloud iam service-accounts create "$BEACON_GCS_READER" \
- --project "$GCP_PROJECT" \
- --display-name "Beacon endpoint GCS reader"
+ ```bash
+ gcloud iam service-accounts create "$BEACON_GCS_READER" \
+ --project "$GCP_PROJECT" \
+ --display-name "Beacon endpoint GCS reader"
-export BEACON_GCS_READER_EMAIL="${BEACON_GCS_READER}@${GCP_PROJECT}.iam.gserviceaccount.com"
+ export BEACON_GCS_READER_EMAIL="${BEACON_GCS_READER}@${GCP_PROJECT}.iam.gserviceaccount.com"
-gcloud storage buckets add-iam-policy-binding "gs://${BEACON_GCS_BUCKET}" \
- --member "serviceAccount:${BEACON_GCS_READER_EMAIL}" \
- --role roles/storage.objectViewer
-```
+ gcloud storage buckets add-iam-policy-binding "gs://${BEACON_GCS_BUCKET}" \
+ --member "serviceAccount:${BEACON_GCS_READER_EMAIL}" \
+ --role roles/storage.objectViewer
+ ```
+
+ Apply lifecycle, retention, access logging, and CMEK controls according to your
+ organization's Google Cloud policy.
+ </Tab>
+ <Tab title="Terraform">
+ Beacon's [Terraform module](/log-forwarding/gcs-terraform) creates the bucket, the
+ writer, and the read-only service account, with the same roles as the gcloud steps.
+ The writer is also limited to the Beacon prefix:
+
+ ```hcl title="main.tf"
+ module "beacon_gcs" {
+ source = "github.com/asymptote-labs/agent-beacon//terraform/gcs?ref=v1.3.38"
+
+ project = "<project-id>"
+ location = "<region>" # for example us-central1
+ bucket_name = "<globally-unique-bucket>"
+ prefix = "beacon-prod"
+ create_reader = true
+ }
+
+ output "bucket_name" {
+ value = module.beacon_gcs.bucket_name
+ }
+
+ output "prefix" {
+ value = module.beacon_gcs.prefix
+ }
+
+ output "writer_email" {
+ value = module.beacon_gcs.writer_email
+ }
+
+ output "reader_email" {
+ value = module.beacon_gcs.reader_email
+ }
+ ```
+
+ Apply it and save the outputs for the next steps:
+
+ ```bash
+ terraform init
+ terraform apply
+
+ export GCP_PROJECT="<project-id>"
+ export BEACON_GCS_BUCKET="$(terraform output -raw bucket_name)"
+ export BEACON_GCS_PREFIX="$(terraform output -raw prefix)"
+ export BEACON_GCS_WRITER_EMAIL="$(terraform output -raw writer_email)"
+ export BEACON_GCS_WRITER="${BEACON_GCS_WRITER_EMAIL%%@*}"
+ export BEACON_GCS_READER_EMAIL="$(terraform output -raw reader_email)"
+ ```
-Apply lifecycle, retention, access logging, and CMEK controls according to your
-organization's Google Cloud policy.
+ For lifecycle rules, CMEK, or an existing bucket, see the
+ [module's options](/log-forwarding/gcs-terraform#options).
+ </Tab>
+</Tabs>
## 2. Create and deliver the writer credential
diff --git a/docs/log-forwarding/aws-s3-terraform.mdx b/docs/log-forwarding/aws-s3-terraform.mdx
new file mode 100644
index 00000000..ee264465
--- /dev/null
+++ b/docs/log-forwarding/aws-s3-terraform.mdx
@@ -0,0 +1,273 @@
+---
+title: "AWS S3 with Terraform"
+description: "Create the S3 bucket and write-only IAM user for Beacon forwarding with Beacon's Terraform module."
+---
+
+Use this page if you manage AWS with Terraform. It covers the AWS side of S3 forwarding: the bucket, the identity your Macs upload with, and the values your rollout needs. When you finish, continue with your rollout guide from the step after its AWS setup.
+
+The AWS CLI steps in the rollout guides create the same resources. Follow either one.
+
+## What you'll set up
+
+- **An S3 bucket** with public access blocked, ACLs disabled, HTTPS required, default encryption (SSE-S3, or SSE-KMS with your key), and versioning.
+- **`beacon-endpoint-writer`**, an IAM user that can upload objects below your Beacon prefix and can't read or delete them.
+- **Optionally, `beacon-s3-reader`**, a read-only IAM user for [Beacon Cloud's S3 data connector](/manage/configure-s3-data-connector).
+
+Every Mac's forwarder writes both of Beacon's logs to the bucket:
+
+```text
+s3://<bucket>/<prefix>/runtime/date=YYYY-MM-DD/<time>-<id>.jsonl.gz
+s3://<bucket>/<prefix>/inventory/date=YYYY-MM-DD/<time>-<id>.jsonl.gz
+```
+
+The module is in the Beacon repository at [`terraform/aws-s3`](https://github.com/asymptote-labs/agent-beacon/tree/main/terraform/aws-s3).
+
+## Before you start
+
+| You need | Why |
+| --- | --- |
+| Terraform 1.5 or later | Runs the module. |
+| AWS provider 6.0 or later | Terraform installs it during `terraform init`. |
+| An AWS identity that can create S3 buckets, IAM users, and IAM user policies | Used by `terraform apply`. |
+| The AWS CLI, signed in as that identity | Creates the writer's access key in step 3. |
+| A bucket name nobody else uses | S3 bucket names are global across all AWS accounts. |
+
+## 1. Add the module
+
+Pick a root prefix such as `beacon-prod`. Beacon adds `runtime/` and `inventory/` below it, so don't put either in the prefix.
+
+Create a `main.tf` in a new directory, or add these blocks to your existing configuration. Change the region, bucket name, and prefix:
+
+```hcl title="main.tf"
+provider "aws" {
+ region = "us-west-2"
+}
+
+module "beacon_s3" {
+ source = "github.com/asymptote-labs/agent-beacon//terraform/aws-s3?ref=v1.3.38"
+
+ bucket_name = "acme-beacon-telemetry"
+ prefix = "beacon-prod"
+}
+
+output "bucket_name" {
+ value = module.beacon_s3.bucket_name
+}
+
+output "region" {
+ value = module.beacon_s3.region
+}
+
+output "prefix" {
+ value = module.beacon_s3.prefix
+}
+
+output "writer_user_name" {
+ value = module.beacon_s3.writer_user_name
+}
+```
+
+The bucket is created in the provider's region. `ref` pins the module to a Beacon release. The module first shipped in `v1.3.38`, and any later release tag works too.
+
+## 2. Create the bucket and writer
+
+```bash
+terraform init
+terraform apply
+```
+
+Review the plan and type `yes`. It's working when the apply ends with:
+
+```text
+Apply complete! Resources: 9 added, 0 changed, 0 destroyed.
+
+Outputs:
+
+bucket_name = "acme-beacon-telemetry"
+prefix = "beacon-prod"
+region = "us-west-2"
+writer_user_name = "beacon-endpoint-writer"
+```
+
+Save the values as shell variables for the next steps. The rollout guides use the same names:
+
+```bash
+export BEACON_S3_BUCKET="$(terraform output -raw bucket_name)"
+export AWS_REGION="$(terraform output -raw region)"
+export BEACON_S3_PREFIX="$(terraform output -raw prefix)"
+export BEACON_S3_STORAGE_CLASS="STANDARD"
+export BEACON_S3_WRITER="$(terraform output -raw writer_user_name)"
+```
+
+## 3. Create the writer's access key
+
+The module doesn't create access keys by default, because Terraform would store the secret in its state file. Create the key with the AWS CLI:
+
+```bash
+aws iam create-access-key --user-name "$BEACON_S3_WRITER" --output json
+```
+
+AWS shows the secret only once. Store `AccessKeyId` and `SecretAccessKey` in your password manager or MDM secret store. The key starts with `AKIA` and doesn't expire, so the forwarder keeps uploading without anyone renewing a credential.
+
+## 4. Give the values to your rollout
+
+| Value | Fleet admin helper | Jamf script parameter | `install-forwarder.sh` |
+| --- | --- | --- | --- |
+| `bucket_name` | `BEACON_S3_BUCKET` | 4 | `BEACON_S3_BUCKET` |
+| `region` | `AWS_REGION` | 5 | `AWS_REGION` |
+| `prefix` | `BEACON_S3_PREFIX` | 6 | `BEACON_S3_PREFIX` |
+| Storage class (`STANDARD`) | `BEACON_S3_STORAGE_CLASS` | 7 | `BEACON_S3_STORAGE_CLASS` |
+| Access key from step 3 | `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` | Your Jamf secret injection | `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` |
+
+Then continue with your rollout:
+
+| Rollout | Continue at |
+| --- | --- |
+| Fleet | [Beacon with Fleet and S3, step 3](/guides/fleet-s3-mdm#3-set-up-fleet) |
+| Jamf Pro | [Claude with Jamf and S3, Jamf policy setup](/guides/jamf-s3-mdm#jamf-policy-setup) |
+| One Mac without MDM | [macOS object storage forwarding](/guides/macos-object-storage-system), the `install-forwarder.sh` command under AWS S3 |
+| Linux | [`beacon endpoint s3 install-pack`](/cli/s3#beacon-endpoint-s3-install-pack) |
+
+## 5. Confirm delivery
+
+After the forwarder is running on a Mac, write a test event there:
+
+```bash
+sudo /opt/beacon/bin/beacon endpoint s3 validate --system
+```
+
+The forwarder uploads in batches, so allow up to five minutes. Then list the objects with your own AWS identity, because the writer can't read the bucket:
+
+```bash
+aws s3 ls "s3://${BEACON_S3_BUCKET}/${BEACON_S3_PREFIX}/runtime/" --recursive --region "$AWS_REGION"
+```
+
+## Options
+
+Set any of these in the `module "beacon_s3"` block and run `terraform apply` again. Every input is described in [`variables.tf`](https://github.com/asymptote-labs/agent-beacon/blob/main/terraform/aws-s3/variables.tf).
+
+<AccordionGroup>
+ <Accordion title="Use a bucket you already have">
+ ```hcl
+ create_bucket = false
+ bucket_name = "acme-security-logs"
+ existing_bucket_region = "us-east-1" # only if it differs from the provider's region
+ ```
+
+ The module then creates only the IAM users and changes nothing on the bucket. Two bucket settings can block uploads:
+
+ - **Customer managed KMS key.** Set `kms_key_arn` to the bucket's key so the writer gets `kms:GenerateDataKey`.
+ - **A bucket policy that requires encryption headers.** The forwarder sends none and relies on the bucket's default encryption, so such a policy rejects every upload.
+ </Accordion>
+ <Accordion title="Encrypt with your own KMS key">
+ ```hcl
+ kms_key_arn = "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"
+ ```
+
+ The bucket uses SSE-KMS with an S3 Bucket Key. The writer gets `kms:GenerateDataKey` and the Beacon reader gets `kms:Decrypt` on the key. The key's own policy must allow IAM policies in your account to grant access, which the default key policy does.
+ </Accordion>
+ <Accordion title="Delete old objects">
+ ```hcl
+ expiration_days = 365
+ ```
+
+ Objects below the prefix are deleted a year after upload. Versioning is on by default, so a deleted or replaced object stays recoverable for `noncurrent_version_expiration_days` (default 30). Set `versioning_enabled = false` to turn versioning off.
+ </Accordion>
+ <Accordion title="Let Beacon Cloud read the bucket">
+ ```hcl
+ create_beacon_reader = true
+ ```
+
+ This adds `beacon-s3-reader`, which can list the bucket and read objects below the prefix. Create its key the same way as the writer's:
+
+ ```bash
+ aws iam create-access-key --user-name beacon-s3-reader --output json
+ ```
+
+ Send Beacon the key and the `beacon_reader_source_url` output. See [Configure S3 Data Connector](/manage/configure-s3-data-connector).
+ </Accordion>
+ <Accordion title="Create the access keys with Terraform">
+ ```hcl
+ create_access_keys = true
+ ```
+
+ Terraform creates the writer's key, and the reader's when you have one. Read the secret with `terraform output -raw writer_secret_access_key` after adding a matching `output` block. The secret is stored in Terraform state, so use this only when your state is encrypted and access is restricted.
+ </Accordion>
+ <Accordion title="Match your organization's IAM rules">
+ - `writer_user_name` and `beacon_reader_user_name` rename the users.
+ - `iam_path` puts them under a path such as `/beacon/`.
+ - `permissions_boundary_arn` attaches a permissions boundary.
+ - `tags` tags every resource the module creates.
+ </Accordion>
+ <Accordion title="Drop the health-check permission">
+ ```hcl
+ allow_writer_healthcheck = false
+ ```
+
+ By default the writer also has `s3:ListBucket`, which the forwarder's startup check needs. Without it, uploads still work, but the forwarder logs a health-check error each time it starts. `s3:ListBucket` lets the writer see object names, never their contents.
+ </Accordion>
+</AccordionGroup>
+
+## Outputs
+
+| Output | What it is |
+| --- | --- |
+| `bucket_name`, `region`, `prefix`, `storage_class` | The forwarder settings, also together as `forwarder_settings` |
+| `writer_user_name`, `writer_user_arn` | The IAM user every Mac uploads as |
+| `beacon_reader_user_name`, `beacon_reader_user_arn` | The Beacon reader, when `create_beacon_reader = true` |
+| `beacon_reader_source_url` | The location to send Beacon for the S3 data connector |
+| `writer_access_key_id`, `writer_secret_access_key` | Only with `create_access_keys = true` |
+
+## Rotate the writer key
+
+Rotation happens outside Terraform. IAM allows two keys per user, so the old key keeps working while you roll out the new one.
+
+1. Create a second key: `aws iam create-access-key --user-name "$BEACON_S3_WRITER"`.
+2. Give the new key to your rollout and rerun its forwarder setup on every Mac. In Fleet, update the two secret variables and rerun `beacon-configure-s3-forwarding.sh`.
+3. When every Mac has the new key, delete the old one: `aws iam delete-access-key --user-name "$BEACON_S3_WRITER" --access-key-id <old key id>`.
+
+## Remove
+
+1. Remove the forwarder from your Macs. Uninstalling Beacon removes it.
+2. Delete the access keys you created with the AWS CLI. IAM refuses to delete a user that still has keys:
+
+ ```bash
+ aws iam list-access-keys --user-name "$BEACON_S3_WRITER"
+ aws iam delete-access-key --user-name "$BEACON_S3_WRITER" --access-key-id <key id>
+ ```
+
+3. Run `terraform destroy`. It stops at a bucket that still holds objects. To delete the telemetry too, set `force_destroy = true`, run `terraform apply`, and then destroy.
+
+## Troubleshooting
+
+<AccordionGroup>
+ <Accordion title="Error: reading S3 Bucket (...): empty result">
+ With `create_bucket = false`, the bucket is in a different region from the provider. Set `existing_bucket_region` to the bucket's region.
+ </Accordion>
+ <Accordion title="BucketAlreadyExists">
+ Someone else, in any AWS account, already has a bucket with that name. Choose another `bucket_name`.
+ </Accordion>
+ <Accordion title="DeleteConflict: Cannot delete entity, must delete access keys first">
+ `terraform destroy` or a rename is trying to delete an IAM user that still has a key you created with the AWS CLI. Delete the key first. See [Remove](#remove).
+ </Accordion>
+ <Accordion title="Uploads fail with AccessDenied">
+ Check that the forwarder's bucket, region, and prefix match the Terraform outputs exactly. The writer can only upload below `<prefix>/`. For an existing bucket with a customer managed KMS key, set `kms_key_arn`.
+ </Accordion>
+</AccordionGroup>
+
+## Related
+
+<Columns cols={2}>
+ <Card title="Beacon with Fleet and S3" icon="bucket" href="/guides/fleet-s3-mdm">
+ Roll out Beacon with Fleet and forward to S3.
+ </Card>
+ <Card title="Claude with Jamf and S3" icon="bucket" href="/guides/jamf-s3-mdm">
+ Roll out Beacon with Jamf Pro and forward to S3.
+ </Card>
+ <Card title="Google Cloud Storage with Terraform" icon="cloud" href="/log-forwarding/gcs-terraform">
+ The same setup for a Cloud Storage bucket.
+ </Card>
+ <Card title="Configure S3 Data Connector" icon="database" href="/manage/configure-s3-data-connector">
+ Let Beacon Cloud read the telemetry in your bucket.
+ </Card>
+</Columns>
diff --git a/docs/log-forwarding/gcs-terraform.mdx b/docs/log-forwarding/gcs-terraform.mdx
new file mode 100644
index 00000000..7a16c836
--- /dev/null
+++ b/docs/log-forwarding/gcs-terraform.mdx
@@ -0,0 +1,256 @@
+---
+title: "Google Cloud Storage with Terraform"
+description: "Create the Cloud Storage bucket and create-only service account for Beacon forwarding with Beacon's Terraform module."
+---
+
+Use this page if you manage Google Cloud with Terraform. It covers the Google Cloud side of GCS forwarding: the bucket, the service account your Macs upload with, and the values your rollout needs. When you finish, continue with your rollout guide from the step after its Google Cloud setup.
+
+The gcloud steps in the rollout guides create the same resources. Follow either one.
+
+## What you'll set up
+
+- **A Cloud Storage bucket** with uniform bucket-level access, public access prevention enforced, versioning, and optionally your Cloud KMS key.
+- **`beacon-endpoint-writer`**, a service account that can create objects below your Beacon prefix and can't list, read, or delete them.
+- **`beacon-endpoint-reader`**, a read-only service account for checking uploads.
+- **Optionally, read access for Beacon Cloud**, so Beacon can ingest the telemetry you store.
+
+Every Mac's forwarder writes both of Beacon's logs to the bucket:
+
+```text
+gs://<bucket>/<prefix>/runtime/date=YYYY-MM-DD/<time>-<id>.jsonl
+gs://<bucket>/<prefix>/inventory/date=YYYY-MM-DD/<time>-<id>.jsonl
+```
+
+The module is in the Beacon repository at [`terraform/gcs`](https://github.com/asymptote-labs/agent-beacon/tree/main/terraform/gcs).
+
+## Before you start
+
+| You need | Why |
+| --- | --- |
+| Terraform 1.5 or later | Runs the module. |
+| Google provider 5.0 or later | Terraform installs it during `terraform init`. |
+| A Google Cloud project, and an identity that can enable APIs, create buckets and service accounts, and set bucket IAM | Used by `terraform apply`. Terraform reads Application Default Credentials (`gcloud auth application-default login`). |
+| gcloud, signed in as that identity | Creates the writer's key in step 3. |
+| Permission to create service-account keys | The packaged forwarder authenticates with a JSON key. If your organization policy blocks keys (`iam.disableServiceAccountKeyCreation`), Beacon's GCS forwarder can't run on your Macs. |
+| A bucket name nobody else uses | Bucket names are global across Google Cloud. |
+
+## 1. Add the module
+
+Pick a root prefix such as `beacon-prod`. Beacon adds `runtime/` and `inventory/` below it, so don't put either in the prefix.
+
+Create a `main.tf` in a new directory, or add these blocks to your existing configuration. Change the project, location, bucket name, and prefix:
+
+```hcl title="main.tf"
+provider "google" {
+ project = "acme-security"
+}
+
+module "beacon_gcs" {
+ source = "github.com/asymptote-labs/agent-beacon//terraform/gcs?ref=v1.3.38"
+
+ project = "acme-security"
+ location = "us-west1"
+ bucket_name = "acme-beacon-telemetry"
+ prefix = "beacon-prod"
+ create_reader = true
+}
+
+output "bucket_name" {
+ value = module.beacon_gcs.bucket_name
+}
+
+output "prefix" {
+ value = module.beacon_gcs.prefix
+}
+
+output "writer_email" {
+ value = module.beacon_gcs.writer_email
+}
+
+output "reader_email" {
+ value = module.beacon_gcs.reader_email
+}
+```
+
+`ref` pins the module to a Beacon release. The module first shipped in `v1.3.38`, and any later release tag works too.
+
+## 2. Create the bucket and service accounts
+
+```bash
+terraform init
+terraform apply
+```
+
+Review the plan and type `yes`. It's working when the apply ends with:
+
+```text
+Apply complete! Resources: 7 added, 0 changed, 0 destroyed.
+
+Outputs:
+
+bucket_name = "acme-beacon-telemetry"
+prefix = "beacon-prod"
+reader_email = "[email protected]"
+writer_email = "[email protected]"
+```
+
+The module enables the Cloud Storage and IAM APIs on the project if they're off, and leaves them on if you destroy it later.
+
+Save the values as shell variables for the next steps. The rollout guides use the same names:
+
+```bash
+export GCP_PROJECT="acme-security"
+export BEACON_GCS_BUCKET="$(terraform output -raw bucket_name)"
+export BEACON_GCS_PREFIX="$(terraform output -raw prefix)"
+export BEACON_GCS_STORAGE_CLASS="STANDARD"
+export BEACON_GCS_WRITER_EMAIL="$(terraform output -raw writer_email)"
+export BEACON_GCS_WRITER="${BEACON_GCS_WRITER_EMAIL%%@*}"
+export BEACON_GCS_READER_EMAIL="$(terraform output -raw reader_email)"
+```
+
+## 3. Create the writer's key
+
+The module doesn't create keys by default, because Terraform would store the private key in its state file. Create the key with gcloud:
+
+```bash
+umask 077
+gcloud iam service-accounts keys create "./${BEACON_GCS_WRITER}.json" \
+ --project "$GCP_PROJECT" \
+ --iam-account "$BEACON_GCS_WRITER_EMAIL"
+```
+
+Deliver the JSON file to each Mac with your MDM's secret or file delivery, to a root-owned path outside Beacon's directories, with mode `0600`. Your rollout guide covers this step for your MDM. Then delete the local copy.
+
+## 4. Give the values to your rollout
+
+| Value | Jamf script parameter | `install-forwarder.sh` |
+| --- | --- | --- |
+| `bucket_name` | 4 | `BEACON_GCS_BUCKET` |
+| `prefix` | 5 | `BEACON_GCS_PREFIX` |
+| Storage class (`STANDARD`) | 6 | `BEACON_GCS_STORAGE_CLASS` |
+| Path of the key file on the Mac | 8 | `GOOGLE_APPLICATION_CREDENTIALS` |
+
+Then continue with your rollout:
+
+| Rollout | Continue at |
+| --- | --- |
+| Jamf Pro | [Claude with Jamf and GCS, step 2](/guides/jamf-gcs-mdm#2-deliver-the-writer-credential) |
+| Rippling | [Claude with Rippling and GCS, step 2](/guides/rippling-gcs-mdm#2-create-and-deliver-the-writer-credential), from "Use this endpoint path" |
+| One Mac without MDM | [macOS object storage forwarding](/guides/macos-object-storage-system), from "Install the JSON outside Beacon-managed directories" under Google Cloud Storage |
+| Linux | [`beacon endpoint gcs install-pack`](/cli/gcs) |
+
+## 5. Confirm delivery
+
+After the forwarder is running on a Mac, write a test event there:
+
+```bash
+sudo /opt/beacon/bin/beacon endpoint gcs validate --system
+```
+
+The forwarder uploads in batches, so allow up to five minutes. Then list the objects as the reader, because the writer can't list the bucket. Impersonating the reader needs `roles/iam.serviceAccountTokenCreator` on it; you can also list with your own identity if it can read the bucket.
+
+```bash
+gcloud storage ls "gs://${BEACON_GCS_BUCKET}/${BEACON_GCS_PREFIX}/runtime/**" \
+ --impersonate-service-account "$BEACON_GCS_READER_EMAIL"
+```
+
+## Options
+
+Set any of these in the `module "beacon_gcs"` block and run `terraform apply` again. Every input is described in [`variables.tf`](https://github.com/asymptote-labs/agent-beacon/blob/main/terraform/gcs/variables.tf).
+
+<AccordionGroup>
+ <Accordion title="Use a bucket you already have">
+ ```hcl
+ create_bucket = false
+ bucket_name = "acme-security-logs"
+ ```
+
+ The module then creates only the service accounts and their bucket IAM bindings, and changes nothing else on the bucket. The writer's binding uses an IAM condition, which needs uniform bucket-level access. If the bucket still uses fine-grained ACLs, set `scope_writer_to_prefix = false`; the writer can then create objects anywhere in the bucket.
+ </Accordion>
+ <Accordion title="Encrypt with your own Cloud KMS key">
+ ```hcl
+ kms_key_name = "projects/acme-security/locations/us-west1/keyRings/beacon/cryptoKeys/telemetry"
+ ```
+
+ The key becomes the bucket's default encryption. Cloud Storage encrypts with its own service agent, so the module grants that agent `roles/cloudkms.cryptoKeyEncrypterDecrypter` on the key. Set `grant_kms_to_storage_agent = false` if you manage the key's IAM elsewhere. The writer needs no KMS permission.
+ </Accordion>
+ <Accordion title="Delete old objects">
+ ```hcl
+ expiration_days = 365
+ ```
+
+ Objects below the prefix are deleted a year after upload. Versioning is on by default, so a deleted or replaced object stays recoverable for `noncurrent_version_expiration_days` (default 30). Set `versioning_enabled = false` to turn versioning off.
+ </Accordion>
+ <Accordion title="Let Beacon Cloud read the bucket">
+ ```hcl
+ grant_beacon_read_access = true
+ ```
+
+ This grants `roles/storage.objectViewer` on the bucket to Beacon's reader, `[email protected]`. No key is involved. Then send Beacon the bucket name and prefix.
+ </Accordion>
+ <Accordion title="Create the writer's key with Terraform">
+ ```hcl
+ create_writer_key = true
+ ```
+
+ Read it with `terraform output -raw writer_private_key | base64 --decode > beacon-gcs-writer.json` after adding a matching `output` block. The private key is stored in Terraform state, so use this only when your state is encrypted and access is restricted.
+ </Accordion>
+ <Accordion title="Match your organization's naming">
+ - `writer_account_id` and `reader_account_id` rename the service accounts.
+ - `labels` labels the bucket.
+ - `enable_apis = false` skips enabling the APIs, for projects where they're managed elsewhere.
+ </Accordion>
+</AccordionGroup>
+
+## Outputs
+
+| Output | What it is |
+| --- | --- |
+| `bucket_name`, `prefix`, `storage_class` | The forwarder settings, also together as `forwarder_settings` |
+| `bucket_url` | `gs://<bucket>/<prefix>/` |
+| `writer_email` | The service account every Mac uploads as |
+| `reader_email` | The read-only service account, when `create_reader = true` |
+| `writer_private_key` | Only with `create_writer_key = true` |
+
+## Rotate the writer key
+
+Rotation happens outside Terraform. Create a new key, deliver it to every Mac, restart the forwarder, confirm a new object arrives, and then delete the old key. Your rollout guide has the exact commands under credential rotation.
+
+## Remove
+
+1. Remove the forwarder from your Macs. Uninstalling Beacon removes it.
+2. Run `terraform destroy`. Deleting the writer service account also deletes its keys. Destroy stops at a bucket that still holds objects. To delete the telemetry too, set `force_destroy = true`, run `terraform apply`, and then destroy.
+
+## Troubleshooting
+
+<AccordionGroup>
+ <Accordion title="location is required when create_bucket = true">
+ Set `location` to a region such as `us-west1` or a multi-region such as `US`.
+ </Accordion>
+ <Accordion title="The bucket name is already taken">
+ Someone else, in any project, already has a bucket with that name. Choose another `bucket_name`.
+ </Accordion>
+ <Accordion title="Terraform can't add the writer's IAM binding to an existing bucket">
+ An existing bucket without uniform bucket-level access can't hold the writer's IAM condition. Turn on uniform access for the bucket, or set `scope_writer_to_prefix = false`.
+ </Accordion>
+ <Accordion title="Uploads fail with 403">
+ Check that the forwarder's bucket and prefix match the Terraform outputs exactly. The writer can only create objects below `<prefix>/`.
+ </Accordion>
+</AccordionGroup>
+
+## Related
+
+<Columns cols={2}>
+ <Card title="Claude with Jamf and GCS" icon="bucket" href="/guides/jamf-gcs-mdm">
+ Roll out Beacon with Jamf Pro and forward to Cloud Storage.
+ </Card>
+ <Card title="Claude with Rippling and GCS" icon="bucket" href="/guides/rippling-gcs-mdm">
+ Roll out Beacon with Rippling and forward to Cloud Storage.
+ </Card>
+ <Card title="AWS S3 with Terraform" icon="bucket" href="/log-forwarding/aws-s3-terraform">
+ The same setup for an S3 bucket.
+ </Card>
+ <Card title="Object storage forwarding" icon="chart-line" href="/guides/macos-object-storage-system">
+ Forward to S3, Cloud Storage, or both from one Mac.
+ </Card>
+</Columns>
diff --git a/docs/log-forwarding/index.mdx b/docs/log-forwarding/index.mdx
index f5e3487a..2f9fc650 100644
--- a/docs/log-forwarding/index.mdx
+++ b/docs/log-forwarding/index.mdx
@@ -103,6 +103,12 @@ Use these paths when Beacon JSONL should land in a customer-managed bucket for a
<Card title="Claude with Jamf and S3" icon="bucket" href="/guides/jamf-s3-mdm">
The same Vector S3 path, installed with Jamf Pro.
</Card>
+ <Card title="AWS S3 with Terraform" icon="bucket" href="/log-forwarding/aws-s3-terraform">
+ Create the S3 bucket and write-only IAM user with Terraform.
+ </Card>
+ <Card title="Google Cloud Storage with Terraform" icon="cloud" href="/log-forwarding/gcs-terraform">
+ Create the Cloud Storage bucket and create-only service account with Terraform.
+ </Card>
</Columns>
### Local
@@ -244,7 +250,8 @@ beacon endpoint s3 install-pack --system --output ./beacon-s3-pack
The generated pack includes setup guidance, a Vector `aws_s3` sink template, a one-shot AWS CLI smoke-test script, and sample events. AWS credentials, bucket policy, lifecycle, retention, encryption, and object ownership stay in AWS, Vector, endpoint-management tooling, or your secret store rather tha Beacon endpoint configuration.
See [macOS System-Mode Object Storage Forwarding](/guides/macos-object-storage-system)
-for bucket creation, IAM, credentials, Vector setup, and validation.
+for bucket creation, IAM, credentials, Vector setup, and validation. To create the
+bucket and IAM user with Terraform, see [AWS S3 with Terraform](/log-forwarding/aws-s3-terraform).
### Google Cloud Storage
diff --git a/docs/manage/configure-s3-data-connector.mdx b/docs/manage/configure-s3-data-connector.mdx
index 46d705a5..c230f20d 100644
--- a/docs/manage/configure-s3-data-connector.mdx
+++ b/docs/manage/configure-s3-data-connector.mdx
@@ -5,106 +5,102 @@ description: "Configure read-only S3 access for Beacon ingestion."
## Overview
-Beacon can ingest customer-hosted event files from a private AWS S3 bucket or prefix. Grant Beacon's ingestion worker read-only access to the bucket that contains the event files.
+Beacon can ingest customer-hosted event files from a private AWS S3 bucket or prefix. Beacon reads them with the access key of a read-only IAM user you create. That user can list the bucket and read objects below the prefix you choose, and nothing else.
+
+Beacon can't assume an IAM role in your account for this connector, so use an IAM user's access key.
Do not make the bucket public. Do not grant write or delete permissions.
-At the end of setup, send Beacon the full IAM role ARN for the role you create.
-
-## Customer steps
-
-1. Send Beacon the S3 location details.
-
- Include:
-
- - AWS account ID
- - S3 bucket name
- - AWS region
- - Prefix/path for the event files, such as `s3://your-bucket/asymptote/events/`
- - File format, ideally JSONL or JSONEachRow
- - Delivery cadence and approximate event volume
- - Encryption type, either SSE-S3 or SSE-KMS
- - KMS key ARN, only if SSE-KMS is enabled
-
-2. Create a dedicated IAM role in AWS.
-
- Sign in to the AWS account that owns the S3 bucket with an IAM user that can create and manage IAM roles. Open the IAM service console, then create a new role named something like `asymptote-s3-read`.
-
-3. Configure the role trust policy.
-
- Use the IAM ARN Beacon gives you as the trusted principal. Replace `ASYMPTOTE_IAM_ARN` with that ARN.
-
- ```json title="IAM role trust policy"
- {
- "Version": "2012-10-17",
- "Statement": [
- {
- "Effect": "Allow",
- "Principal": {
- "AWS": "ASYMPTOTE_IAM_ARN"
- },
- "Action": "sts:AssumeRole"
- }
- ]
- }
- ```
-
-4. Attach a read-only S3 policy.
-
- ```json title="Read-only S3 policy"
- {
- "Version": "2012-10-17",
- "Statement": [
- {
- "Effect": "Allow",
- "Action": [
- "s3:GetBucketLocation",
- "s3:ListBucket"
- ],
- "Resource": [
- "arn:aws:s3:::YOUR_BUCKET_NAME"
- ]
- },
- {
- "Effect": "Allow",
- "Action": [
- "s3:Get*",
- "s3:List*"
- ],
- "Resource": [
- "arn:aws:s3:::YOUR_BUCKET_NAME/*"
- ]
- }
- ]
- }
- ```
-
- Replace `YOUR_BUCKET_NAME` with the name of the S3 bucket that contains the event files.
-
-5. Add KMS decrypt permission if needed.
-
- If the bucket uses SSE-KMS, add this statement to the role policy:
-
- ```json title="SSE-KMS decrypt statement"
- {
- "Sid": "DecryptEventObjects",
- "Effect": "Allow",
- "Action": "kms:Decrypt",
- "Resource": "YOUR_KMS_KEY_ARN"
- }
- ```
-
- The KMS key policy must also allow this IAM role to use `kms:Decrypt`.
-
-6. Send Beacon the final onboarding details.
-
- Send:
-
- - IAM role ARN for the role you created
- - S3 URL/prefix
- - AWS region
- - KMS key ARN, if applicable
- - A small sample event file or example JSONL row
+## Create the read-only user
+
+<Tabs>
+ <Tab title="Terraform">
+ If you created the bucket with [AWS S3 with Terraform](/log-forwarding/aws-s3-terraform), turn on the reader in the module block and apply:
+
+ ```hcl
+ module "beacon_s3" {
+ # ...your existing settings...
+ create_beacon_reader = true
+ }
+ ```
+
+ The module creates `beacon-s3-reader` with the policy shown in the other tab, including `kms:Decrypt` when you set `kms_key_arn`. Create its access key:
+
+ ```bash
+ aws iam create-access-key --user-name beacon-s3-reader --output json
+ ```
+ </Tab>
+ <Tab title="AWS CLI">
+ Set the bucket and the prefix that holds the event files:
+
+ ```bash
+ export BEACON_S3_BUCKET="<bucket>"
+ export BEACON_S3_PREFIX="beacon-prod"
+ ```
+
+ Create the user and give it read-only access to that prefix:
+
+ ```bash
+ aws iam create-user --user-name beacon-s3-reader
+
+ aws iam put-user-policy \
+ --user-name beacon-s3-reader \
+ --policy-name BeaconTelemetryReadOnly \
+ --policy-document "$(cat <<EOF
+ {
+ "Version": "2012-10-17",
+ "Statement": [
+ {
+ "Effect": "Allow",
+ "Action": ["s3:ListBucket", "s3:GetBucketLocation"],
+ "Resource": "arn:aws:s3:::${BEACON_S3_BUCKET}"
+ },
+ {
+ "Effect": "Allow",
+ "Action": "s3:GetObject",
+ "Resource": "arn:aws:s3:::${BEACON_S3_BUCKET}/${BEACON_S3_PREFIX}/*"
+ }
+ ]
+ }
+ EOF
+ )"
+ ```
+
+ If the bucket uses SSE-KMS, also allow `kms:Decrypt` on the key, and make sure the key policy lets IAM policies in your account grant it:
+
+ ```json title="SSE-KMS decrypt statement"
+ {
+ "Effect": "Allow",
+ "Action": "kms:Decrypt",
+ "Resource": "YOUR_KMS_KEY_ARN"
+ }
+ ```
+
+ Create the access key:
+
+ ```bash
+ aws iam create-access-key --user-name beacon-s3-reader --output json
+ ```
+ </Tab>
+</Tabs>
+
+AWS shows the secret only once. Keep it in your password manager until you send it to Beacon.
+
+## Send Beacon the details
+
+Send these through the secure channel your Beacon contact gives you. Don't send the secret access key by email or chat.
+
+- S3 bucket name and AWS region
+- Prefix for the event files, such as `s3://your-bucket/beacon-prod/`
+- The access key ID and secret access key
+- KMS key ARN, only if SSE-KMS is enabled
+- For files that Beacon's forwarder didn't write: the file format (ideally JSONL), delivery cadence, approximate event volume, and a small sample file or example JSONL row
+
+To rotate the key later, create a second key for `beacon-s3-reader`, send it to Beacon, and delete the old key once Beacon confirms the switch.
+
+## Using Google Cloud Storage
+
+For a Cloud Storage bucket, no key is involved. Grant `roles/storage.objectViewer` on the bucket to `[email protected]`, or set `grant_beacon_read_access = true` in the [Terraform module](/log-forwarding/gcs-terraform). Then send Beacon the bucket name and prefix.
## Event file requirements
@@ -112,19 +108,21 @@ Use newline-delimited JSON, with one complete JSON object per line. Each event s
Share a representative sample file before production ingestion. The sample should show realistic field names and value shapes, but should not include secrets.
+Beacon's own S3 forwarder already writes this format, as gzip-compressed JSONL below `<prefix>/runtime/` and `<prefix>/inventory/`.
+
## Related
<Columns cols={2}>
<Card title="Beacon Cloud" icon="cloud" href="/deployment/managed">
Review managed visibility, governance, and investigation workflows.
</Card>
- <Card title="Endpoint Event Schema" icon="code" href="/telemetry-schema/event-schema">
- Review normalized event fields and example payloads.
+ <Card title="AWS S3 with Terraform" icon="bucket" href="/log-forwarding/aws-s3-terraform">
+ Create the bucket, writer, and Beacon reader with Terraform.
</Card>
<Card title="Object Storage Forwarding" icon="bucket" href="/guides/macos-object-storage-system">
Configure customer-managed Beacon event forwarding into S3.
</Card>
- <Card title="Data Inventory" icon="table-list" href="/security/data-inventory">
- Review the endpoint event fields Beacon can write.
+ <Card title="Endpoint Event Schema" icon="code" href="/telemetry-schema/event-schema">
+ Review normalized event fields and example payloads.
</Card>
</Columns>
diff --git a/terraform/.gitignore b/terraform/.gitignore
new file mode 100644
index 00000000..db2a2c6f
--- /dev/null
+++ b/terraform/.gitignore
@@ -0,0 +1,6 @@
+.terraform/
+.terraform.lock.hcl
+*.tfstate
+*.tfstate.*
+*.tfvars
+crash.log
diff --git a/terraform/README.md b/terraform/README.md
new file mode 100644
index 00000000..d70e531e
--- /dev/null
+++ b/terraform/README.md
@@ -0,0 +1,39 @@
+# Terraform for Beacon object storage forwarding
+
+These modules create the cloud side of Beacon's object storage forwarding: the bucket
+your Macs upload to, and the narrowly scoped identity their forwarder uses. You run
+them in your own cloud account. Beacon itself never runs Terraform and never needs
+your cloud credentials.
+
+| Module | Creates | Guide |
+| --- | --- | --- |
+| [`aws-s3`](aws-s3) | An S3 bucket, a write-only IAM user, and optionally a read-only user for Beacon Cloud | [AWS S3 with Terraform](https://docs.beacon.sh/log-forwarding/aws-s3-terraform) |
+| [`gcs`](gcs) | A Cloud Storage bucket, a create-only service account, and optionally read access for Beacon Cloud | [Google Cloud Storage with Terraform](https://docs.beacon.sh/log-forwarding/gcs-terraform) |
+
+Use a module from your own configuration and pin it to a Beacon release:
+
+```hcl
+module "beacon_s3" {
+ source = "github.com/asymptote-labs/agent-beacon//terraform/aws-s3?ref=<release tag>"
+
+ bucket_name = "acme-beacon-telemetry"
+ prefix = "beacon-prod"
+}
+```
+
+Neither module creates keys unless you ask it to (`create_access_keys`,
+`create_writer_key`), so by default no secret is written to Terraform state. The
+guides show how to create the key with the AWS CLI or gcloud instead.
+
+## Development
+
+The tests mock the cloud providers, so they need no account:
+
+```bash
+cd terraform/aws-s3 # or terraform/gcs
+terraform init -backend=false
+terraform test
+```
+
+CI runs `terraform fmt -check`, `validate` and `test` for both modules, and
+`validate` for each example.
diff --git a/terraform/aws-s3/README.md b/terraform/aws-s3/README.md
new file mode 100644
index 00000000..47d2da36
--- /dev/null
+++ b/terraform/aws-s3/README.md
@@ -0,0 +1,50 @@
+# Beacon AWS S3 module
+
+Creates the AWS side of Beacon's S3 forwarding:
+
+- an S3 bucket with public access blocked, ACLs disabled, TLS required, default
+ encryption (SSE-S3, or SSE-KMS with `kms_key_arn`), versioning, and a lifecycle rule
+ scoped to the Beacon prefix (skipped with `create_bucket = false`);
+- `beacon-endpoint-writer`, an IAM user that can only `s3:PutObject` below the prefix
+ (plus `s3:ListBucket` for the forwarder's startup health check);
+- optionally `beacon-s3-reader`, a read-only IAM user for Beacon Cloud's S3 data
+ connector (`create_beacon_reader = true`).
+
+```hcl
+provider "aws" {
+ region = "us-west-2"
+}
+
+module "beacon_s3" {
+ source = "github.com/asymptote-labs/agent-beacon//terraform/aws-s3?ref=<release tag>"
+
+ bucket_name = "acme-beacon-telemetry"
+ prefix = "beacon-prod"
+}
+
+output "forwarder_settings" {
+ value = module.beacon_s3.forwarder_settings
+}
+```
+
+After `terraform apply`, create the writer's access key outside Terraform, so its
+secret never enters state:
+
+```bash
+aws iam create-access-key --user-name beacon-endpoint-writer
+```
+
+`forwarder_settings` holds the non-secret values the packaged forwarder helper reads
+(`BEACON_S3_BUCKET`, `AWS_REGION`, `BEACON_S3_PREFIX`, `BEACON_S3_STORAGE_CLASS`).
+
+The module needs Terraform 1.5 or later and the AWS provider 6.0 or later. A new bucket
+is created in the provider's region. For an existing bucket in another region, set
+`existing_bucket_region`.
+
+Before `terraform destroy`, delete the access keys you created with the AWS CLI. IAM
+refuses to delete a user that still has keys, which keeps a rename or replace from
+cutting off every Mac at once.
+
+Every input is described in [`variables.tf`](variables.tf), and every output in
+[`outputs.tf`](outputs.tf). The full walkthrough, including Fleet, Jamf and
+single-Mac handoff, is [AWS S3 with Terraform](https://docs.beacon.sh/log-forwarding/aws-s3-terraform).
diff --git a/terraform/aws-s3/examples/basic/main.tf b/terraform/aws-s3/examples/basic/main.tf
new file mode 100644
index 00000000..189c6bc3
--- /dev/null
+++ b/terraform/aws-s3/examples/basic/main.tf
@@ -0,0 +1,62 @@
+# A new, dedicated bucket for Beacon telemetry and the write-only IAM user the forwarder uses.
+#
+# terraform init
+# terraform apply -var region=us-west-2 -var bucket_name=<globally-unique-name>
+# aws iam create-access-key --user-name "$(terraform output -raw writer_user_name)"
+#
+# Outside this repository, point source at a release:
+# source = "github.com/asymptote-labs/agent-beacon//terraform/aws-s3?ref=<release tag>"
+
+terraform {
+ required_version = ">= 1.5.0"
+
+ required_providers {
+ aws = {
+ source = "hashicorp/aws"
+ version = ">= 6.0"
+ }
+ }
+}
+
+variable "region" {
+ description = "AWS region for the bucket."
+ type = string
+}
+
+variable "bucket_name" {
+ description = "Globally unique name for the new bucket."
+ type = string
+}
+
+variable "prefix" {
+ description = "Root prefix for Beacon objects."
+ type = string
+ default = "beacon-prod"
+}
+
+provider "aws" {
+ region = var.region
+}
+
+module "beacon_s3" {
+ source = "../.."
+
+ bucket_name = var.bucket_name
+ prefix = var.prefix
+}
+
+output "bucket_name" {
+ value = module.beacon_s3.bucket_name
+}
+
+output "region" {
+ value = module.beacon_s3.region
+}
+
+output "prefix" {
+ value = module.beacon_s3.prefix
+}
+
+output "writer_user_name" {
+ value = module.beacon_s3.writer_user_name
+}
diff --git a/terraform/aws-s3/iam.tf b/terraform/aws-s3/iam.tf
new file mode 100644
index 00000000..0a0fae47
--- /dev/null
+++ b/terraform/aws-s3/iam.tf
@@ -0,0 +1,104 @@
+locals {
+ writer_statements = concat(
+ [
+ {
+ Sid = "WriteBeaconObjects"
+ Effect = "Allow"
+ Action = "s3:PutObject"
+ Resource = local.beacon_objects_arn
+ },
+ ],
+ var.allow_writer_healthcheck ? [
+ {
+ Sid = "ForwarderHealthCheck"
+ Effect = "Allow"
+ Action = "s3:ListBucket"
+ Resource = local.bucket_arn
+ },
+ ] : [],
+ var.kms_key_arn == null ? [] : [
+ {
+ Sid = "EncryptBeaconObjects"
+ Effect = "Allow"
+ Action = "kms:GenerateDataKey"
+ Resource = var.kms_key_arn
+ },
+ ],
+ )
+
+ reader_statements = concat(
+ [
+ {
+ Sid = "ListBeaconBucket"
+ Effect = "Allow"
+ Action = ["s3:ListBucket", "s3:GetBucketLocation"]
+ Resource = local.bucket_arn
+ },
+ {
+ Sid = "ReadBeaconObjects"
+ Effect = "Allow"
+ Action = "s3:GetObject"
+ Resource = local.beacon_objects_arn
+ },
+ ],
+ var.kms_key_arn == null ? [] : [
+ {
+ Sid = "DecryptBeaconObjects"
+ Effect = "Allow"
+ Action = "kms:Decrypt"
+ Resource = var.kms_key_arn
+ },
+ ],
+ )
+}
+
+# The identity every Mac's forwarder uses. It can create objects below the Beacon prefix, and it
+# cannot read or delete them.
+resource "aws_iam_user" "writer" {
+ name = var.writer_user_name
+ path = var.iam_path
+ permissions_boundary = var.permissions_boundary_arn
+ tags = var.tags
+}
+
+resource "aws_iam_user_policy" "writer" {
+ name = "BeaconEndpointWriteOnly"
+ user = aws_iam_user.writer.name
+ policy = jsonencode({
+ Version = "2012-10-17"
+ Statement = local.writer_statements
+ })
+}
+
+resource "aws_iam_access_key" "writer" {
+ count = var.create_access_keys ? 1 : 0
+
+ user = aws_iam_user.writer.name
+}
+
+# Beacon Cloud's S3 data connector reads with an access key; it cannot assume a role in your account.
+resource "aws_iam_user" "beacon_reader" {
+ count = var.create_beacon_reader ? 1 : 0
+
+ name = var.beacon_reader_user_name
+ path = var.iam_path
+ permissions_boundary = var.permissions_boundary_arn
+ tags = var.tags
+}
+
+resource "aws_iam_user_policy" "beacon_reader" {
+ count = var.create_beacon_reader ? 1 : 0
+
+ name = "BeaconTelemetryReadOnly"
+ user = aws_iam_user.beacon_reader[0].name
+ policy = jsonencode({
+ Version = "2012-10-17"
+ Statement = local.reader_statements
+ })
+}
+
+resource "aws_iam_access_key" "beacon_reader" {
+ count = var.create_beacon_reader && var.create_access_keys ? 1 : 0
+
+ user = aws_iam_user.beacon_reader[0].name
+}
diff --git a/terraform/aws-s3/main.tf b/terraform/aws-s3/main.tf
new file mode 100644
index 00000000..f4a603e6
--- /dev/null
+++ b/terraform/aws-s3/main.tf
@@ -0,0 +1,139 @@
+data "aws_partition" "current" {}
+
+# Only read for an existing bucket: it confirms the bucket exists and reports its region. The lookup
+# runs in the provider's region unless existing_bucket_region names another.
+data "aws_s3_bucket" "existing" {
+ count = var.create_bucket ? 0 : 1
+
+ bucket = var.bucket_name
+ region = var.existing_bucket_region
+}
+
+locals {
+ bucket_arn = "arn:${data.aws_partition.current.partition}:s3:::${var.bucket_name}"
+
+ # Beacon writes <prefix>/runtime/date=YYYY-MM-DD/... and <prefix>/inventory/date=YYYY-MM-DD/...
+ beacon_objects_arn = "${local.bucket_arn}/${var.prefix}/*"
+
+ bucket_region = var.create_bucket ? aws_s3_bucket.this[0].region : data.aws_s3_bucket.existing[0].region
+}
+
+resource "aws_s3_bucket" "this" {
+ count = var.create_bucket ? 1 : 0
+
+ bucket = var.bucket_name
+ force_destroy = var.force_destroy
+ tags = var.tags
+
+ lifecycle {
+ precondition {
+ condition = var.existing_bucket_region == null
+ error_message = "existing_bucket_region applies only with create_bucket = false. A new bucket is created in the provider's region."
+ }
+ }
+}
+
+resource "aws_s3_bucket_public_access_block" "this" {
+ count = var.create_bucket ? 1 : 0
+
+ bucket = aws_s3_bucket.this[0].id
+ block_public_acls = true
+ block_public_policy = true
+ ignore_public_acls = true
+ restrict_public_buckets = true
+}
+
+# ACLs off: every object belongs to the bucket owner. The forwarder sends no ACL.
+resource "aws_s3_bucket_ownership_controls" "this" {
+ count = var.create_bucket ? 1 : 0
+
+ bucket = aws_s3_bucket.this[0].id
+
+ rule {
+ object_ownership = "BucketOwnerEnforced"
+ }
+}
+
+# The forwarder sends no encryption headers, so the bucket default decides how objects are encrypted.
+resource "aws_s3_bucket_server_side_encryption_configuration" "this" {
+ count = var.create_bucket ? 1 : 0
+
+ bucket = aws_s3_bucket.this[0].id
+
+ rule {
+ apply_server_side_encryption_by_default {
+ sse_algorithm = var.kms_key_arn == null ? "AES256" : "aws:kms"
+ kms_master_key_id = var.kms_key_arn
+ }
+ bucket_key_enabled = var.kms_key_arn != null
+ }
+}
+
+resource "aws_s3_bucket_versioning" "this" {
+ count = var.create_bucket && var.versioning_enabled ? 1 : 0
+
+ bucket = aws_s3_bucket.this[0].id
+
+ versioning_configuration {
+ status = "Enabled"
+ }
+}
+
+resource "aws_s3_bucket_lifecycle_configuration" "this" {
+ count = var.create_bucket ? 1 : 0
+
+ bucket = aws_s3_bucket.this[0].id
+
+ rule {
+ id = "beacon-telemetry"
+ status = "Enabled"
+
+ filter {
+ prefix = "${var.prefix}/"
+ }
+
+ abort_incomplete_multipart_upload {
+ days_after_initiation = 7
+ }
+
+ dynamic "expiration" {
+ for_each = var.expiration_days == null ? [] : [var.expiration_days]
+ content {
+ days = expiration.value
+ }
+ }
+
+ dynamic "noncurrent_version_expiration" {
+ for_each = var.versioning_enabled ? [var.noncurrent_version_expiration_days] : []
+ content {
+ noncurrent_days = noncurrent_version_expiration.value
+ }
+ }
+ }
+
+ depends_on = [aws_s3_bucket_versioning.this]
+}
+
+resource "aws_s3_bucket_policy" "this" {
+ count = var.create_bucket ? 1 : 0
+
+ bucket = aws_s3_bucket.this[0].id
+ policy = jsonencode({
+ Version = "2012-10-17"
+ Statement = [
+ {
+ Sid = "DenyInsecureTransport"
+ Effect = "Deny"
+ Principal = "*"
+ Action = "s3:*"
+ Resource = [local.bucket_arn, "${local.bucket_arn}/*"]
+ Condition = {
+ Bool = { "aws:SecureTransport" = "false" }
+ }
+ },
+ ]
+ })
+
+ # S3 rejects a bucket policy written while the public access block is still being applied.
+ depends_on = [aws_s3_bucket_public_access_block.this]
+}
diff --git a/terraform/aws-s3/outputs.tf b/terraform/aws-s3/outputs.tf
new file mode 100644
index 00000000..66b2dd38
--- /dev/null
+++ b/terraform/aws-s3/outputs.tf
@@ -0,0 +1,81 @@
+output "bucket_name" {
+ description = "Bucket Beacon writes to."
+ value = var.create_bucket ? aws_s3_bucket.this[0].bucket : data.aws_s3_bucket.existing[0].bucket
+}
+
+output "bucket_arn" {
+ description = "ARN of the bucket."
+ value = local.bucket_arn
+}
+
+output "region" {
+ description = "Region of the bucket (AWS_REGION for the forwarder)."
+ value = local.bucket_region
+}
+
+output "prefix" {
+ description = "Root prefix Beacon writes below (BEACON_S3_PREFIX)."
+ value = var.prefix
+}
+
+output "storage_class" {
+ description = "Storage class the forwarder writes objects with (BEACON_S3_STORAGE_CLASS)."
+ value = var.storage_class
+}
+
+output "forwarder_settings" {
+ description = "The non-secret settings Beacon's S3 forwarder helper reads, keyed by environment variable name."
+ value = {
+ BEACON_S3_BUCKET = var.create_bucket ? aws_s3_bucket.this[0].bucket : data.aws_s3_bucket.existing[0].bucket
+ AWS_REGION = local.bucket_region
+ BEACON_S3_PREFIX = var.prefix
+ BEACON_S3_STORAGE_CLASS = var.storage_class
+ }
+}
+
+output "writer_user_name" {
+ description = "IAM user the forwarder authenticates as. Create its access key with: aws iam create-access-key --user-name <this value>"
+ value = aws_iam_user.writer.name
+}
+
+output "writer_user_arn" {
+ description = "ARN of the writer IAM user."
+ value = aws_iam_user.writer.arn
+}
+
+output "writer_access_key_id" {
+ description = "Writer access key ID, when create_access_keys = true."
+ value = try(aws_iam_access_key.writer[0].id, null)
+}
+
+output "writer_secret_access_key" {
+ description = "Writer secret access key, when create_access_keys = true. Read it with terraform output -raw writer_secret_access_key."
+ value = try(aws_iam_access_key.writer[0].secret, null)
+ sensitive = true
+}
+
+output "beacon_reader_user_name" {
+ description = "Read-only IAM user for Beacon Cloud's S3 data connector, when create_beacon_reader = true."
+ value = try(aws_iam_user.beacon_reader[0].name, null)
+}
+
+output "beacon_reader_user_arn" {
+ description = "ARN of the Beacon reader IAM user, when create_beacon_reader = true."
+ value = try(aws_iam_user.beacon_reader[0].arn, null)
+}
+
+output "beacon_reader_access_key_id" {
+ description = "Beacon reader access key ID, when create_beacon_reader and create_access_keys are both true."
+ value = try(aws_iam_access_key.beacon_reader[0].id, null)
+}
+
+output "beacon_reader_secret_access_key" {
+ description = "Beacon reader secret access key, when create_beacon_reader and create_access_keys are both true."
+ value = try(aws_iam_access_key.beacon_reader[0].secret, null)
+ sensitive = true
+}
+
+output "beacon_reader_source_url" {
+ description = "The location to give Beacon for the S3 data connector."
+ value = "https://${var.bucket_name}.s3.${local.bucket_region}.amazonaws.com/${var.prefix}"
+}
diff --git a/terraform/aws-s3/tests/module.tftest.hcl b/terraform/aws-s3/tests/module.tftest.hcl
new file mode 100644
index 00000000..40a76d21
--- /dev/null
+++ b/terraform/aws-s3/tests/module.tftest.hcl
@@ -0,0 +1,391 @@
+# Hermetic: the AWS provider is mocked, so these runs need no account or credentials.
+
+mock_provider "aws" {
+ mock_data "aws_partition" {
+ defaults = {
+ partition = "aws"
+ }
+ }
+
+ mock_data "aws_s3_bucket" {
+ defaults = {
+ bucket = "acme-security-logs"
+ region = "eu-west-1"
+ }
+ }
+
+ mock_resource "aws_s3_bucket" {
+ defaults = {
+ bucket = "acme-beacon-telemetry"
+ region = "us-west-2"
+ }
+ }
+}
+
+variables {
+ bucket_name = "acme-beacon-telemetry"
+ prefix = "beacon-prod"
+}
+
+run "writer_can_only_put_below_the_prefix" {
+ command = plan
+
+ assert {
+ condition = jsondecode(aws_iam_user_policy.writer.policy).Statement == [
+ {
+ Sid = "WriteBeaconObjects"
+ Effect = "Allow"
+ Action = "s3:PutObject"
+ Resource = "arn:aws:s3:::acme-beacon-telemetry/beacon-prod/*"
+ },
+ {
+ Sid = "ForwarderHealthCheck"
+ Effect = "Allow"
+ Action = "s3:ListBucket"
+ Resource = "arn:aws:s3:::acme-beacon-telemetry"
+ },
+ ]
+ error_message = "The writer policy must grant only s3:PutObject below the prefix and the health-check s3:ListBucket."
+ }
+
+ assert {
+ condition = aws_iam_user_policy.writer.name == "BeaconEndpointWriteOnly" && aws_iam_user.writer.name == "beacon-endpoint-writer"
+ error_message = "The writer keeps the names the manual guides use."
+ }
+}
+
+run "no_access_keys_by_default" {
+ command = plan
+
+ assert {
+ condition = length(aws_iam_access_key.writer) == 0 && length(aws_iam_access_key.beacon_reader) == 0
+ error_message = "Access keys, whose secrets would land in state, must be opt-in."
+ }
+
+ assert {
+ condition = length(aws_iam_user.beacon_reader) == 0
+ error_message = "The Beacon reader must be opt-in."
+ }
+}
+
+run "new_bucket_is_hardened" {
+ command = plan
+
+ assert {
+ condition = (
+ aws_s3_bucket_public_access_block.this[0].block_public_acls
+ && aws_s3_bucket_public_access_block.this[0].block_public_policy
+ && aws_s3_bucket_public_access_block.this[0].ignore_public_acls
+ && aws_s3_bucket_public_access_block.this[0].restrict_public_buckets
+ )
+ error_message = "A new bucket must block all public access."
+ }
+
+ assert {
+ condition = one(aws_s3_bucket_ownership_controls.this[0].rule).object_ownership == "BucketOwnerEnforced"
+ error_message = "A new bucket must disable ACLs."
+ }
+
+ assert {
+ condition = one(one(aws_s3_bucket_server_side_encryption_configuration.this[0].rule).apply_server_side_encryption_by_default).sse_algorithm == "AES256"
+ error_message = "Without a KMS key the bucket defaults to SSE-S3."
+ }
+
+ assert {
+ condition = one(aws_s3_bucket_versioning.this[0].versioning_configuration).status == "Enabled"
+ error_message = "Versioning is on by default."
+ }
+
+ assert {
+ condition = aws_s3_bucket.this[0].force_destroy == false
+ error_message = "A bucket holding telemetry must not be force-destroyed by default."
+ }
+
+ assert {
+ condition = jsondecode(aws_s3_bucket_policy.this[0].policy).Statement == [
+ {
+ Sid = "DenyInsecureTransport"
+ Effect = "Deny"
+ Principal = "*"
+ Action = "s3:*"
+ Resource = ["arn:aws:s3:::acme-beacon-telemetry", "arn:aws:s3:::acme-beacon-telemetry/*"]
+ Condition = { Bool = { "aws:SecureTransport" = "false" } }
+ },
+ ]
+ error_message = "A new bucket must refuse requests that are not over TLS."
+ }
+
+ assert {
+ condition = one(aws_s3_bucket_lifecycle_configuration.this[0].rule[0].filter).prefix == "beacon-prod/"
+ error_message = "The lifecycle rule applies only to the Beacon prefix."
+ }
+
+ assert {
+ condition = length(aws_s3_bucket_lifecycle_configuration.this[0].rule[0].expiration) == 0
+ error_message = "Objects are kept forever unless expiration_days is set."
+ }
+
+ assert {
+ condition = one(aws_s3_bucket_lifecycle_configuration.this[0].rule[0].noncurrent_version_expiration).noncurrent_days == 30
+ error_message = "Noncurrent versions expire after 30 days by default."
+ }
+}
+
+run "forwarder_settings_match_the_helper" {
+ command = apply
+
+ assert {
+ condition = output.forwarder_settings == {
+ BEACON_S3_BUCKET = "acme-beacon-telemetry"
+ AWS_REGION = "us-west-2"
+ BEACON_S3_PREFIX = "beacon-prod"
+ BEACON_S3_STORAGE_CLASS = "STANDARD"
+ }
+ error_message = "forwarder_settings must carry exactly the variables install-forwarder.sh reads."
+ }
+
+ assert {
+ condition = output.beacon_reader_source_url == "https://acme-beacon-telemetry.s3.us-west-2.amazonaws.com/beacon-prod"
+ error_message = "The data connector URL is the bucket's regional endpoint plus the prefix."
+ }
+}
+
+run "kms_key_encrypts_and_is_granted" {
+ command = plan
+
+ variables {
+ kms_key_arn = "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"
+ create_beacon_reader = true
+ }
+
+ assert {
+ condition = (
+ one(one(aws_s3_bucket_server_side_encryption_configuration.this[0].rule).apply_server_side_encryption_by_default).sse_algorithm == "aws:kms"
+ && one(one(aws_s3_bucket_server_side_encryption_configuration.this[0].rule).apply_server_side_encryption_by_default).kms_master_key_id == var.kms_key_arn
+ && one(aws_s3_bucket_server_side_encryption_configuration.this[0].rule).bucket_key_enabled
+ )
+ error_message = "A KMS key becomes the bucket default, with an S3 Bucket Key."
+ }
+
+ assert {
+ condition = contains(jsondecode(aws_iam_user_policy.writer.policy).Statement, {
+ Sid = "EncryptBeaconObjects"
+ Effect = "Allow"
+ Action = "kms:GenerateDataKey"
+ Resource = "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"
+ })
+ error_message = "The writer needs kms:GenerateDataKey to upload to an SSE-KMS bucket."
+ }
+
+ assert {
+ condition = contains(jsondecode(aws_iam_user_policy.beacon_reader[0].policy).Statement, {
+ Sid = "DecryptBeaconObjects"
+ Effect = "Allow"
+ Action = "kms:Decrypt"
+ Resource = "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"
+ })
+ error_message = "The Beacon reader needs kms:Decrypt to read an SSE-KMS bucket."
+ }
+}
+
+run "healthcheck_permission_can_be_dropped" {
+ command = plan
+
+ variables {
+ allow_writer_healthcheck = false
+ }
+
+ assert {
+ condition = [for s in jsondecode(aws_iam_user_policy.writer.policy).Statement : s.Action] == ["s3:PutObject"]
+ error_message = "Without the health check the writer holds s3:PutObject alone."
+ }
+}
+
+run "beacon_reader_reads_only_the_prefix" {
+ command = plan
+
+ variables {
+ create_beacon_reader = true
+ }
+
+ assert {
+ condition = jsondecode(aws_iam_user_policy.beacon_reader[0].policy).Statement == [
+ {
+ Sid = "ListBeaconBucket"
+ Effect = "Allow"
+ Action = ["s3:ListBucket", "s3:GetBucketLocation"]
+ Resource = "arn:aws:s3:::acme-beacon-telemetry"
+ },
+ {
+ Sid = "ReadBeaconObjects"
+ Effect = "Allow"
+ Action = "s3:GetObject"
+ Resource = "arn:aws:s3:::acme-beacon-telemetry/beacon-prod/*"
+ },
+ ]
+ error_message = "The Beacon reader may list the bucket and read only the Beacon prefix."
+ }
+
+ assert {
+ condition = aws_iam_user.beacon_reader[0].name == "beacon-s3-reader" && length(aws_iam_access_key.beacon_reader) == 0
+ error_message = "The reader is created without a key unless create_access_keys is set."
+ }
+}
+
+run "access_keys_when_asked" {
+ command = plan
+
+ variables {
+ create_beacon_reader = true
+ create_access_keys = true
+ }
+
+ assert {
+ condition = length(aws_iam_access_key.writer) == 1 && length(aws_iam_access_key.beacon_reader) == 1
+ error_message = "create_access_keys creates one key per user."
+ }
+}
+
+run "existing_bucket_is_left_alone" {
+ command = apply
+
+ variables {
+ create_bucket = false
+ bucket_name = "acme-security-logs"
+ }
+
+ assert {
+ condition = (
+ length(aws_s3_bucket.this) == 0
+ && length(aws_s3_bucket_policy.this) == 0
+ && length(aws_s3_bucket_public_access_block.this) == 0
+ && length(aws_s3_bucket_server_side_encryption_configuration.this) == 0
+ && length(aws_s3_bucket_versioning.this) == 0
+ && length(aws_s3_bucket_lifecycle_configuration.this) == 0
+ && length(aws_s3_bucket_ownership_controls.this) == 0
+ )
+ error_message = "With create_bucket = false the module must not manage any bucket setting."
+ }
+
+ assert {
+ condition = output.forwarder_settings.AWS_REGION == "eu-west-1" && output.forwarder_settings.BEACON_S3_BUCKET == "acme-security-logs"
+ error_message = "An existing bucket's name and region come from the bucket itself."
+ }
+
+ assert {
+ condition = jsondecode(aws_iam_user_policy.writer.policy).Statement[0].Resource == "arn:aws:s3:::acme-security-logs/beacon-prod/*"
+ error_message = "The writer is scoped to the existing bucket's Beacon prefix."
+ }
+
+ assert {
+ condition = data.aws_s3_bucket.existing[0].region == "eu-west-1"
+ error_message = "Without existing_bucket_region the bucket is looked up in the provider's region."
+ }
+}
+
+run "existing_bucket_in_another_region" {
+ command = plan
+
+ variables {
+ create_bucket = false
+ bucket_name = "acme-security-logs"
+ existing_bucket_region = "ap-southeast-2"
+ }
+
+ assert {
+ condition = data.aws_s3_bucket.existing[0].region == "ap-southeast-2"
+ error_message = "existing_bucket_region is where the bucket is looked up, so the lookup works across regions."
+ }
+}
+
+run "rejects_existing_bucket_region_for_a_new_bucket" {
+ command = plan
+
+ variables {
+ existing_bucket_region = "ap-southeast-2"
+ }
+
+ expect_failures = [aws_s3_bucket.this]
+}
+
+run "expiration_when_asked" {
+ command = plan
+
+ variables {
+ expiration_days = 365
+ versioning_enabled = false
+ }
+
+ assert {
+ condition = one(aws_s3_bucket_lifecycle_configuration.this[0].rule[0].expiration).days == 365
+ error_message = "expiration_days expires current objects."
+ }
+
+ assert {
+ condition = length(aws_s3_bucket_versioning.this) == 0 && length(aws_s3_bucket_lifecycle_configuration.this[0].rule[0].noncurrent_version_expiration) == 0
+ error_message = "Without versioning there is no versioning resource and no noncurrent rule."
+ }
+}
+
+run "nested_prefix_is_allowed" {
+ command = plan
+
+ variables {
+ prefix = "security/beacon"
+ }
+
+ assert {
+ condition = jsondecode(aws_iam_user_policy.writer.policy).Statement[0].Resource == "arn:aws:s3:::acme-beacon-telemetry/security/beacon/*"
+ error_message = "A nested root prefix is scoped as written."
+ }
+}
+
+run "rejects_stream_suffix_prefix" {
+ command = plan
+
+ variables {
+ prefix = "beacon-prod/runtime"
+ }
+
+ expect_failures = [var.prefix]
+}
+
+run "rejects_slashes_around_prefix" {
+ command = plan
+
+ variables {
+ prefix = "/beacon-prod/"
+ }
+
+ expect_failures = [var.prefix]
+}
+
+run "rejects_wildcard_prefix" {
+ command = plan
+
+ variables {
+ prefix = "beacon*"
+ }
+
+ expect_failures = [var.prefix]
+}
+
+run "rejects_kms_alias" {
+ command = plan
+
+ variables {
+ kms_key_arn = "arn:aws:kms:us-west-2:111122223333:alias/beacon"
+ }
+
+ expect_failures = [var.kms_key_arn]
+}
+
+run "rejects_fractional_expiration" {
+ command = plan
+
+ variables {
+ expiration_days = 1.5
+ }
+
+ expect_failures = [var.expiration_days]
+}
diff --git a/terraform/aws-s3/variables.tf b/terraform/aws-s3/variables.tf
new file mode 100644
index 00000000..71a7b529
--- /dev/null
+++ b/terraform/aws-s3/variables.tf
@@ -0,0 +1,157 @@
+variable "bucket_name" {
+ description = "Name of the S3 bucket Beacon writes to. With create_bucket = true it must be globally unique."
+ type = string
+
+ validation {
+ condition = can(regex("^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$", var.bucket_name))
+ error_message = "bucket_name must be a valid S3 bucket name: 3 to 63 lowercase letters, digits, dots and hyphens."
+ }
+}
+
+variable "create_bucket" {
+ description = "Create and harden the bucket. Set to false to use a bucket you already manage: the module then only creates the IAM users and changes nothing on the bucket."
+ type = bool
+ default = true
+}
+
+variable "existing_bucket_region" {
+ description = "Region of an existing bucket (create_bucket = false) when it is not the provider's region. Terraform cannot find a bucket in another region without it. A bucket the module creates is always in the provider's region, so leave this null then."
+ type = string
+ default = null
+
+ validation {
+ condition = var.existing_bucket_region == null || can(regex("^[a-z]{2}(-[a-z]+)+-[0-9]+$", var.existing_bucket_region))
+ error_message = "existing_bucket_region must be an AWS region name such as us-west-2."
+ }
+}
+
+variable "prefix" {
+ description = "Root prefix for Beacon objects, such as beacon-prod. Beacon adds runtime/ and inventory/ below it."
+ type = string
+ default = "beacon"
+
+ validation {
+ condition = (
+ can(regex("^[A-Za-z0-9._-]+(/[A-Za-z0-9._-]+)*$", var.prefix))
+ && !can(regex("(^|/)(runtime|inventory)$", var.prefix))
+ )
+ error_message = "prefix must be a root prefix such as beacon-prod: letters, digits, dots, hyphens, underscores and inner slashes, without a leading or trailing slash, and not ending in runtime or inventory, which Beacon adds itself."
+ }
+}
+
+variable "storage_class" {
+ description = "S3 storage class the forwarder writes objects with (BEACON_S3_STORAGE_CLASS). It is passed to the forwarder through the forwarder_settings output; the bucket itself has no storage class."
+ type = string
+ default = "STANDARD"
+
+ validation {
+ condition = contains([
+ "STANDARD",
+ "INTELLIGENT_TIERING",
+ "STANDARD_IA",
+ "ONEZONE_IA",
+ "GLACIER_IR",
+ "GLACIER",
+ "DEEP_ARCHIVE",
+ ], var.storage_class)
+ error_message = "storage_class must be one of STANDARD, INTELLIGENT_TIERING, STANDARD_IA, ONEZONE_IA, GLACIER_IR, GLACIER or DEEP_ARCHIVE."
+ }
+}
+
+variable "kms_key_arn" {
+ description = "ARN of a customer managed KMS key. With create_bucket = true it becomes the bucket's default encryption (SSE-KMS with an S3 Bucket Key); with an existing bucket, set it to the key that bucket already uses. Either way the writer gets kms:GenerateDataKey and the Beacon reader gets kms:Decrypt on it. Leave null for SSE-S3."
+ type = string
+ default = null
+
+ validation {
+ condition = var.kms_key_arn == null || can(regex("^arn:aws[a-z-]*:kms:[a-z0-9-]+:[0-9]{12}:key/.+$", var.kms_key_arn))
+ error_message = "kms_key_arn must be a KMS key ARN (arn:aws:kms:<region>:<account>:key/<id>), not an alias."
+ }
+}
+
+variable "versioning_enabled" {
+ description = "Turn on bucket versioning, so objects deleted or overwritten by an administrator can be recovered. Applies only when the module creates the bucket."
+ type = bool
+ default = true
+}
+
+variable "expiration_days" {
+ description = "Delete Beacon objects this many days after upload. Leave null to keep them until you delete them. Applies only when the module creates the bucket."
+ type = number
+ default = null
+
+ validation {
+ condition = var.expiration_days == null || try(var.expiration_days >= 1 && floor(var.expiration_days) == var.expiration_days, false)
+ error_message = "expiration_days must be a whole number of days, at least 1."
+ }
+}
+
+variable "noncurrent_version_expiration_days" {
+ description = "With versioning on, delete replaced or deleted object versions this many days after they stop being current. Applies only when the module creates the bucket."
+ type = number
+ default = 30
+
+ validation {
+ condition = var.noncurrent_version_expiration_days >= 1 && floor(var.noncurrent_version_expiration_days) == var.noncurrent_version_expiration_days
+ error_message = "noncurrent_version_expiration_days must be a whole number of days, at least 1."
+ }
+}
+
+variable "force_destroy" {
+ description = "Let terraform destroy delete the bucket even when it still holds objects. Leave false in production."
+ type = bool
+ default = false
+}
+
+variable "writer_user_name" {
+ description = "Name of the IAM user every Mac's forwarder authenticates as."
+ type = string
+ default = "beacon-endpoint-writer"
+}
+
+variable "allow_writer_healthcheck" {
+ description = "Grant the writer s3:ListBucket on the bucket. The forwarder's startup health check calls HeadBucket, which needs it; without it uploads still work, but the forwarder logs a health-check error each time it starts. s3:ListBucket also lets the writer list object names in the bucket, though never read them."
+ type = bool
+ default = true
+}
+
+variable "create_beacon_reader" {
+ description = "Create a read-only IAM user for Beacon Cloud's S3 data connector, which reads your bucket with an access key. It can read only the Beacon prefix."
+ type = bool
+ default = false
+}
+
+variable "beacon_reader_user_name" {
+ description = "Name of the read-only IAM user created when create_beacon_reader = true."
+ type = string
+ default = "beacon-s3-reader"
+}
+
+variable "create_access_keys" {
+ description = "Also create an access key for the writer (and for the Beacon reader, when created). The secret keys are then stored in Terraform state, so leave this false unless your state is encrypted and access-controlled, and create the keys with the AWS CLI instead."
+ type = bool
+ default = false
+}
+
+variable "iam_path" {
+ description = "Path for the IAM users."
+ type = string
+ default = "/"
+
+ validation {
+ condition = can(regex("^/([A-Za-z0-9+=,.@_-]+/)*$", var.iam_path))
+ error_message = "iam_path must begin and end with a slash, such as / or /beacon/."
+ }
+}
+
+variable "permissions_boundary_arn" {
+ description = "ARN of a permissions boundary policy to attach to the IAM users, if your organization requires one."
+ type = string
+ default = null
+}
+
+variable "tags" {
+ description = "Tags to apply to every resource the module creates."
+ type = map(string)
+ default = {}
+}
diff --git a/terraform/aws-s3/versions.tf b/terraform/aws-s3/versions.tf
new file mode 100644
index 00000000..70998f0a
--- /dev/null
+++ b/terraform/aws-s3/versions.tf
@@ -0,0 +1,10 @@
+terraform {
+ required_version = ">= 1.5.0"
+
+ required_providers {
+ aws = {
+ source = "hashicorp/aws"
+ version = ">= 6.0"
+ }
+ }
+}
diff --git a/terraform/gcs/README.md b/terraform/gcs/README.md
new file mode 100644
index 00000000..8e2c7fa6
--- /dev/null
+++ b/terraform/gcs/README.md
@@ -0,0 +1,46 @@
+# Beacon Google Cloud Storage module
+
+Creates the Google Cloud side of Beacon's GCS forwarding:
+
+- a Cloud Storage bucket with uniform bucket-level access, public access prevention
+ enforced, versioning, optional CMEK (`kms_key_name`), and lifecycle rules scoped to
+ the Beacon prefix (skipped with `create_bucket = false`);
+- `beacon-endpoint-writer`, a service account with `roles/storage.objectCreator` on
+ the bucket, limited by an IAM condition to objects below the prefix;
+- optionally a read-only `beacon-endpoint-reader` (`create_reader = true`) and read
+ access for Beacon Cloud (`grant_beacon_read_access = true`).
+
+```hcl
+provider "google" {
+ project = "acme-security"
+}
+
+module "beacon_gcs" {
+ source = "github.com/asymptote-labs/agent-beacon//terraform/gcs?ref=<release tag>"
+
+ project = "acme-security"
+ location = "us-west1"
+ bucket_name = "acme-beacon-telemetry"
+ prefix = "beacon-prod"
+}
+
+output "forwarder_settings" {
+ value = module.beacon_gcs.forwarder_settings
+}
+```
+
+After `terraform apply`, create the writer's key outside Terraform, so the private key
+never enters state:
+
+```bash
+gcloud iam service-accounts keys create beacon-gcs-writer.json \
+ --iam-account [email protected]
+```
+
+`forwarder_settings` holds the non-secret values the packaged forwarder helper reads
+(`BEACON_GCS_BUCKET`, `BEACON_GCS_PREFIX`, `BEACON_GCS_STORAGE_CLASS`). The helper
+also needs `GOOGLE_APPLICATION_CREDENTIALS`, the path of the key file on the Mac.
+
+Every input is described in [`variables.tf`](variables.tf), and every output in
+[`outputs.tf`](outputs.tf). The full walkthrough is
+[Google Cloud Storage with Terraform](https://docs.beacon.sh/log-forwarding/gcs-terraform).
diff --git a/terraform/gcs/examples/basic/main.tf b/terraform/gcs/examples/basic/main.tf
new file mode 100644
index 00000000..340fad43
--- /dev/null
+++ b/terraform/gcs/examples/basic/main.tf
@@ -0,0 +1,65 @@
+# A new, dedicated bucket for Beacon telemetry and the create-only service account the forwarder uses.
+#
+# terraform init
+# terraform apply -var project=<project-id> -var location=us-west1 -var bucket_name=<globally-unique-name>
+# gcloud iam service-accounts keys create beacon-gcs-writer.json --iam-account "$(terraform output -raw writer_email)"
+#
+# Outside this repository, point source at a release:
+# source = "github.com/asymptote-labs/agent-beacon//terraform/gcs?ref=<release tag>"
+
+terraform {
+ required_version = ">= 1.5.0"
+
+ required_providers {
+ google = {
+ source = "hashicorp/google"
+ version = ">= 5.0"
+ }
+ }
+}
+
+variable "project" {
+ description = "Google Cloud project for the bucket and service account."
+ type = string
+}
+
+variable "location" {
+ description = "Bucket location, such as us-west1."
+ type = string
+}
+
+variable "bucket_name" {
+ description = "Globally unique name for the new bucket."
+ type = string
+}
+
+variable "prefix" {
+ description = "Root prefix for Beacon objects."
+ type = string
+ default = "beacon-prod"
+}
+
+provider "google" {
+ project = var.project
+}
+
+module "beacon_gcs" {
+ source = "../.."
+
+ project = var.project
+ location = var.location
+ bucket_name = var.bucket_name
+ prefix = var.prefix
+}
+
+output "bucket_name" {
+ value = module.beacon_gcs.bucket_name
+}
+
+output "prefix" {
+ value = module.beacon_gcs.prefix
+}
+
+output "writer_email" {
+ value = module.beacon_gcs.writer_email
+}
diff --git a/terraform/gcs/main.tf b/terraform/gcs/main.tf
new file mode 100644
index 00000000..d62767f6
--- /dev/null
+++ b/terraform/gcs/main.tf
@@ -0,0 +1,152 @@
+locals {
+ apis = var.enable_apis ? toset(["storage.googleapis.com", "iam.googleapis.com"]) : toset([])
+
+ bucket_name = var.create_bucket ? google_storage_bucket.this[0].name : var.bucket_name
+
+ # Beacon writes <prefix>/runtime/date=YYYY-MM-DD/... and <prefix>/inventory/date=YYYY-MM-DD/...
+ # The condition is built from the variable, not the bucket resource, so it is known at plan time.
+ writer_condition = "resource.name.startsWith(\"projects/_/buckets/${var.bucket_name}/objects/${var.prefix}/\")"
+}
+
+resource "google_project_service" "this" {
+ for_each = local.apis
+
+ project = var.project
+ service = each.value
+ disable_on_destroy = false
+}
+
+data "google_storage_project_service_account" "this" {
+ count = var.create_bucket && var.kms_key_name != null && var.grant_kms_to_storage_agent ? 1 : 0
+
+ project = var.project
+
+ depends_on = [google_project_service.this]
+}
+
+# Cloud Storage encrypts with a customer-managed key as its own service agent, not as the writer.
+resource "google_kms_crypto_key_iam_member" "storage_agent" {
+ count = length(data.google_storage_project_service_account.this)
+
+ crypto_key_id = var.kms_key_name
+ role = "roles/cloudkms.cryptoKeyEncrypterDecrypter"
+ member = "serviceAccount:${data.google_storage_project_service_account.this[0].email_address}"
+}
+
+resource "google_storage_bucket" "this" {
+ count = var.create_bucket ? 1 : 0
+
+ project = var.project
+ name = var.bucket_name
+ location = var.location
+ storage_class = var.storage_class
+ uniform_bucket_level_access = true
+ public_access_prevention = "enforced"
+ force_destroy = var.force_destroy
+ labels = var.labels
+
+ versioning {
+ enabled = var.versioning_enabled
+ }
+
+ dynamic "encryption" {
+ for_each = var.kms_key_name == null ? [] : [var.kms_key_name]
+ content {
+ default_kms_key_name = encryption.value
+ }
+ }
+
+ dynamic "lifecycle_rule" {
+ for_each = var.expiration_days == null ? [] : [var.expiration_days]
+ content {
+ action {
+ type = "Delete"
+ }
+ condition {
+ age = lifecycle_rule.value
+ matches_prefix = ["${var.prefix}/"]
+ }
+ }
+ }
+
+ dynamic "lifecycle_rule" {
+ for_each = var.versioning_enabled ? [var.noncurrent_version_expiration_days] : []
+ content {
+ action {
+ type = "Delete"
+ }
+ condition {
+ days_since_noncurrent_time = lifecycle_rule.value
+ matches_prefix = ["${var.prefix}/"]
+ }
+ }
+ }
+
+ lifecycle {
+ precondition {
+ condition = var.location != null
+ error_message = "location is required when create_bucket = true."
+ }
+ }
+
+ depends_on = [google_project_service.this, google_kms_crypto_key_iam_member.storage_agent]
+}
+
+# The identity every Mac's forwarder uses. roles/storage.objectCreator can create objects but not
+# list, read, replace or delete them.
+resource "google_service_account" "writer" {
+ project = var.project
+ account_id = var.writer_account_id
+ display_name = "Beacon endpoint GCS writer"
+ description = "Uploads Beacon endpoint telemetry to gs://${var.bucket_name}/${var.prefix}/"
+
+ depends_on = [google_project_service.this]
+}
+
+resource "google_storage_bucket_iam_member" "writer" {
+ bucket = local.bucket_name
+ role = "roles/storage.objectCreator"
+ member = "serviceAccount:${google_service_account.writer.email}"
+
+ dynamic "condition" {
+ for_each = var.scope_writer_to_prefix ? [local.writer_condition] : []
+ content {
+ title = "beacon-prefix-only"
+ description = "Create objects only below the Beacon prefix."
+ expression = condition.value
+ }
+ }
+}
+
+resource "google_service_account_key" "writer" {
+ count = var.create_writer_key ? 1 : 0
+
+ service_account_id = google_service_account.writer.name
+}
+
+resource "google_service_account" "reader" {
+ count = var.create_reader ? 1 : 0
+
+ project = var.project
+ account_id = var.reader_account_id
+ display_name = "Beacon endpoint GCS reader"
+ description = "Reads Beacon endpoint telemetry in gs://${var.bucket_name}"
+
+ depends_on = [google_project_service.this]
+}
+
+resource "google_storage_bucket_iam_member" "reader" {
+ count = var.create_reader ? 1 : 0
+
+ bucket = local.bucket_name
+ role = "roles/storage.objectViewer"
+ member = "serviceAccount:${google_service_account.reader[0].email}"
+}
+
+resource "google_storage_bucket_iam_member" "beacon_reader" {
+ count = var.grant_beacon_read_access ? 1 : 0
+
+ bucket = local.bucket_name
+ role = "roles/storage.objectViewer"
+ member = var.beacon_reader_member
+}
diff --git a/terraform/gcs/outputs.tf b/terraform/gcs/outputs.tf
new file mode 100644
index 00000000..ead15f6b
--- /dev/null
+++ b/terraform/gcs/outputs.tf
@@ -0,0 +1,44 @@
+output "bucket_name" {
+ description = "Bucket Beacon writes to."
+ value = local.bucket_name
+}
+
+output "bucket_url" {
+ description = "gs:// URL of the Beacon prefix."
+ value = "gs://${local.bucket_name}/${var.prefix}/"
+}
+
+output "prefix" {
+ description = "Root prefix Beacon writes below (BEACON_GCS_PREFIX)."
+ value = var.prefix
+}
+
+output "storage_class" {
+ description = "Storage class the forwarder writes objects with (BEACON_GCS_STORAGE_CLASS)."
+ value = var.storage_class
+}
+
+output "forwarder_settings" {
+ description = "The non-secret settings Beacon's GCS forwarder helper reads, keyed by environment variable name. The helper also needs GOOGLE_APPLICATION_CREDENTIALS, the path of the writer's key file on the Mac."
+ value = {
+ BEACON_GCS_BUCKET = local.bucket_name
+ BEACON_GCS_PREFIX = var.prefix
+ BEACON_GCS_STORAGE_CLASS = var.storage_class
+ }
+}
+
+output "writer_email" {
+ description = "Service account the forwarder authenticates as. Create its key with: gcloud iam service-accounts keys create beacon-gcs-writer.json --iam-account <this value>"
+ value = google_service_account.writer.email
+}
+
+output "writer_private_key" {
+ description = "Base64-encoded JSON key for the writer, when create_writer_key = true. Decode it with: terraform output -raw writer_private_key | base64 --decode"
+ value = try(google_service_account_key.writer[0].private_key, null)
+ sensitive = true
+}
+
+output "reader_email" {
+ description = "Read-only service account, when create_reader = true."
+ value = try(google_service_account.reader[0].email, null)
+}
diff --git a/terraform/gcs/tests/module.tftest.hcl b/terraform/gcs/tests/module.tftest.hcl
new file mode 100644
index 00000000..5e284049
--- /dev/null
+++ b/terraform/gcs/tests/module.tftest.hcl
@@ -0,0 +1,254 @@
+# Hermetic: the Google provider is mocked, so these runs need no project or credentials.
+
+mock_provider "google" {
+ mock_resource "google_service_account" {
+ defaults = {
+ email = "[email protected]"
+ name = "projects/acme-security/serviceAccounts/[email protected]"
+ }
+ }
+
+ mock_resource "google_storage_bucket" {
+ defaults = {
+ name = "acme-beacon-telemetry"
+ }
+ }
+
+ mock_data "google_storage_project_service_account" {
+ defaults = {
+ email_address = "[email protected]"
+ }
+ }
+}
+
+variables {
+ project = "acme-security"
+ bucket_name = "acme-beacon-telemetry"
+ location = "us-west1"
+ prefix = "beacon-prod"
+}
+
+run "writer_can_only_create_below_the_prefix" {
+ command = plan
+
+ assert {
+ condition = google_storage_bucket_iam_member.writer.role == "roles/storage.objectCreator"
+ error_message = "The writer may only create objects."
+ }
+
+ assert {
+ condition = one(google_storage_bucket_iam_member.writer.condition).expression == "resource.name.startsWith(\"projects/_/buckets/acme-beacon-telemetry/objects/beacon-prod/\")"
+ error_message = "The writer is limited to the Beacon prefix."
+ }
+
+ assert {
+ condition = google_service_account.writer.account_id == "beacon-endpoint-writer"
+ error_message = "The writer keeps the name the manual guides use."
+ }
+}
+
+run "no_key_reader_or_beacon_access_by_default" {
+ command = plan
+
+ assert {
+ condition = (
+ length(google_service_account_key.writer) == 0
+ && length(google_service_account.reader) == 0
+ && length(google_storage_bucket_iam_member.reader) == 0
+ && length(google_storage_bucket_iam_member.beacon_reader) == 0
+ )
+ error_message = "Keys, the reader and Beacon read access must all be opt-in."
+ }
+}
+
+run "new_bucket_is_hardened" {
+ command = plan
+
+ assert {
+ condition = (
+ google_storage_bucket.this[0].uniform_bucket_level_access
+ && google_storage_bucket.this[0].public_access_prevention == "enforced"
+ && google_storage_bucket.this[0].force_destroy == false
+ && one(google_storage_bucket.this[0].versioning).enabled
+ && google_storage_bucket.this[0].location == "us-west1"
+ && google_storage_bucket.this[0].storage_class == "STANDARD"
+ )
+ error_message = "A new bucket uses uniform access, enforced public access prevention and versioning."
+ }
+
+ assert {
+ condition = length(google_storage_bucket.this[0].encryption) == 0
+ error_message = "Without a KMS key the bucket uses Google-managed encryption."
+ }
+
+ assert {
+ condition = (
+ length(google_storage_bucket.this[0].lifecycle_rule) == 1
+ && one(google_storage_bucket.this[0].lifecycle_rule[0].condition).days_since_noncurrent_time == 30
+ && one(google_storage_bucket.this[0].lifecycle_rule[0].condition).matches_prefix == tolist(["beacon-prod/"])
+ )
+ error_message = "By default only noncurrent versions below the prefix expire, after 30 days."
+ }
+
+ assert {
+ condition = google_project_service.this["storage.googleapis.com"].disable_on_destroy == false
+ error_message = "The module enables the APIs it needs and never disables them."
+ }
+}
+
+run "forwarder_settings_match_the_helper" {
+ command = apply
+
+ assert {
+ condition = output.forwarder_settings == {
+ BEACON_GCS_BUCKET = "acme-beacon-telemetry"
+ BEACON_GCS_PREFIX = "beacon-prod"
+ BEACON_GCS_STORAGE_CLASS = "STANDARD"
+ }
+ error_message = "forwarder_settings must carry exactly the variables install-forwarder.sh reads."
+ }
+
+ assert {
+ condition = output.writer_email == "[email protected]"
+ error_message = "writer_email is the service account's email."
+ }
+}
+
+run "beacon_read_access_when_asked" {
+ command = plan
+
+ variables {
+ grant_beacon_read_access = true
+ create_reader = true
+ }
+
+ assert {
+ condition = (
+ google_storage_bucket_iam_member.beacon_reader[0].role == "roles/storage.objectViewer"
+ && google_storage_bucket_iam_member.beacon_reader[0].member == "serviceAccount:[email protected]"
+ && length(google_storage_bucket_iam_member.beacon_reader[0].condition) == 0
+ )
+ error_message = "Beacon's reader gets objectViewer on the bucket."
+ }
+
+ assert {
+ condition = google_storage_bucket_iam_member.reader[0].role == "roles/storage.objectViewer" && google_service_account.reader[0].account_id == "beacon-endpoint-reader"
+ error_message = "create_reader adds the read-only service account the manual guides use."
+ }
+}
+
+run "kms_key_encrypts_and_is_granted_to_the_storage_agent" {
+ command = plan
+
+ variables {
+ kms_key_name = "projects/acme-security/locations/us-west1/keyRings/beacon/cryptoKeys/telemetry"
+ }
+
+ assert {
+ condition = one(google_storage_bucket.this[0].encryption).default_kms_key_name == var.kms_key_name
+ error_message = "The key becomes the bucket's default encryption."
+ }
+
+ assert {
+ condition = (
+ google_kms_crypto_key_iam_member.storage_agent[0].crypto_key_id == var.kms_key_name
+ && google_kms_crypto_key_iam_member.storage_agent[0].role == "roles/cloudkms.cryptoKeyEncrypterDecrypter"
+ && google_kms_crypto_key_iam_member.storage_agent[0].member == "serviceAccount:[email protected]"
+ )
+ error_message = "Cloud Storage's service agent must be able to use the key."
+ }
+}
+
+run "existing_bucket_is_left_alone" {
+ command = apply
+
+ variables {
+ create_bucket = false
+ bucket_name = "acme-security-logs"
+ location = null
+ }
+
+ assert {
+ condition = length(google_storage_bucket.this) == 0 && length(google_kms_crypto_key_iam_member.storage_agent) == 0
+ error_message = "With create_bucket = false the module must not manage the bucket."
+ }
+
+ assert {
+ condition = google_storage_bucket_iam_member.writer.bucket == "acme-security-logs" && output.forwarder_settings.BEACON_GCS_BUCKET == "acme-security-logs"
+ error_message = "The writer is bound on the existing bucket."
+ }
+}
+
+run "unscoped_writer_when_asked" {
+ command = plan
+
+ variables {
+ scope_writer_to_prefix = false
+ }
+
+ assert {
+ condition = length(google_storage_bucket_iam_member.writer.condition) == 0
+ error_message = "scope_writer_to_prefix = false drops the IAM condition."
+ }
+}
+
+run "expiration_when_asked" {
+ command = plan
+
+ variables {
+ expiration_days = 365
+ versioning_enabled = false
+ }
+
+ assert {
+ condition = (
+ length(google_storage_bucket.this[0].lifecycle_rule) == 1
+ && one(google_storage_bucket.this[0].lifecycle_rule[0].condition).age == 365
+ && one(google_storage_bucket.this[0].lifecycle_rule[0].condition).matches_prefix == tolist(["beacon-prod/"])
+ )
+ error_message = "expiration_days deletes objects below the prefix, and no noncurrent rule exists without versioning."
+ }
+}
+
+run "key_when_asked" {
+ command = plan
+
+ variables {
+ create_writer_key = true
+ }
+
+ assert {
+ condition = length(google_service_account_key.writer) == 1
+ error_message = "create_writer_key creates one key."
+ }
+}
+
+run "location_required_for_a_new_bucket" {
+ command = plan
+
+ variables {
+ location = null
+ }
+
+ expect_failures = [google_storage_bucket.this]
+}
+
+run "rejects_stream_suffix_prefix" {
+ command = plan
+
+ variables {
+ prefix = "beacon-prod/inventory"
+ }
+
+ expect_failures = [var.prefix]
+}
+
+run "rejects_short_kms_name" {
+ command = plan
+
+ variables {
+ kms_key_name = "telemetry"
+ }
+
+ expect_failures = [var.kms_key_name]
+}
diff --git a/terraform/gcs/variables.tf b/terraform/gcs/variables.tf
new file mode 100644
index 00000000..235a80bb
--- /dev/null
+++ b/terraform/gcs/variables.tf
@@ -0,0 +1,156 @@
+variable "project" {
+ description = "Google Cloud project that holds the bucket and the service accounts."
+ type = string
+}
+
+variable "bucket_name" {
+ description = "Name of the Cloud Storage bucket Beacon writes to. With create_bucket = true it must be globally unique."
+ type = string
+
+ validation {
+ condition = can(regex("^[a-z0-9][a-z0-9._-]{1,61}[a-z0-9]$", var.bucket_name))
+ error_message = "bucket_name must be a valid bucket name: 3 to 63 lowercase letters, digits, dots, hyphens and underscores."
+ }
+}
+
+variable "create_bucket" {
+ description = "Create and harden the bucket. Set to false to use a bucket you already manage: the module then only creates the service account and its bucket IAM bindings."
+ type = bool
+ default = true
+}
+
+variable "location" {
+ description = "Bucket location, such as us-west1 or US. Required when create_bucket = true."
+ type = string
+ default = null
+}
+
+variable "prefix" {
+ description = "Root prefix for Beacon objects, such as beacon-prod. Beacon adds runtime/ and inventory/ below it."
+ type = string
+ default = "beacon"
+
+ validation {
+ condition = (
+ can(regex("^[A-Za-z0-9._-]+(/[A-Za-z0-9._-]+)*$", var.prefix))
+ && !can(regex("(^|/)(runtime|inventory)$", var.prefix))
+ )
+ error_message = "prefix must be a root prefix such as beacon-prod: letters, digits, dots, hyphens, underscores and inner slashes, without a leading or trailing slash, and not ending in runtime or inventory, which Beacon adds itself."
+ }
+}
+
+variable "storage_class" {
+ description = "Storage class the forwarder writes objects with (BEACON_GCS_STORAGE_CLASS), and the default class of a bucket the module creates."
+ type = string
+ default = "STANDARD"
+
+ validation {
+ condition = contains(["STANDARD", "NEARLINE", "COLDLINE", "ARCHIVE"], var.storage_class)
+ error_message = "storage_class must be one of STANDARD, NEARLINE, COLDLINE or ARCHIVE."
+ }
+}
+
+variable "kms_key_name" {
+ description = "Cloud KMS key (projects/<p>/locations/<l>/keyRings/<r>/cryptoKeys/<k>) to use as the default encryption of a bucket the module creates. Leave null for Google-managed encryption."
+ type = string
+ default = null
+
+ validation {
+ condition = var.kms_key_name == null || can(regex("^projects/[^/]+/locations/[^/]+/keyRings/[^/]+/cryptoKeys/[^/]+$", var.kms_key_name))
+ error_message = "kms_key_name must be a full key name: projects/<project>/locations/<location>/keyRings/<ring>/cryptoKeys/<key>."
+ }
+}
+
+variable "grant_kms_to_storage_agent" {
+ description = "With kms_key_name set, grant the project's Cloud Storage service agent permission to use the key, which Cloud Storage needs to encrypt objects with it. Set to false if you manage the key's IAM elsewhere."
+ type = bool
+ default = true
+}
+
+variable "versioning_enabled" {
+ description = "Turn on object versioning, so objects deleted or replaced by an administrator can be recovered. Applies only when the module creates the bucket."
+ type = bool
+ default = true
+}
+
+variable "expiration_days" {
+ description = "Delete Beacon objects this many days after upload. Leave null to keep them until you delete them. Applies only when the module creates the bucket."
+ type = number
+ default = null
+
+ validation {
+ condition = var.expiration_days == null || try(var.expiration_days >= 1 && floor(var.expiration_days) == var.expiration_days, false)
+ error_message = "expiration_days must be a whole number of days, at least 1."
+ }
+}
+
+variable "noncurrent_version_expiration_days" {
+ description = "With versioning on, delete replaced or deleted object versions this many days after they stop being current. Applies only when the module creates the bucket."
+ type = number
+ default = 30
+
+ validation {
+ condition = var.noncurrent_version_expiration_days >= 1 && floor(var.noncurrent_version_expiration_days) == var.noncurrent_version_expiration_days
+ error_message = "noncurrent_version_expiration_days must be a whole number of days, at least 1."
+ }
+}
+
+variable "force_destroy" {
+ description = "Let terraform destroy delete the bucket even when it still holds objects. Leave false in production."
+ type = bool
+ default = false
+}
+
+variable "enable_apis" {
+ description = "Enable the Cloud Storage and IAM APIs on the project. They are left enabled when the module is destroyed."
+ type = bool
+ default = true
+}
+
+variable "writer_account_id" {
+ description = "Account ID of the service account every Mac's forwarder authenticates as."
+ type = string
+ default = "beacon-endpoint-writer"
+}
+
+variable "scope_writer_to_prefix" {
+ description = "Limit the writer to creating objects below the Beacon prefix with an IAM condition. Conditions need uniform bucket-level access, which a bucket the module creates always has; set to false only for an existing bucket that still uses fine-grained ACLs."
+ type = bool
+ default = true
+}
+
+variable "create_writer_key" {
+ description = "Also create a JSON key for the writer. The private key is then stored in Terraform state, so leave this false unless your state is encrypted and access-controlled, and create the key with gcloud instead."
+ type = bool
+ default = false
+}
+
+variable "create_reader" {
+ description = "Create a read-only service account (roles/storage.objectViewer on the bucket) for checking uploads and for your own downstream consumers. The writer cannot list or read objects."
+ type = bool
+ default = false
+}
+
+variable "reader_account_id" {
+ description = "Account ID of the read-only service account created when create_reader = true."
+ type = string
+ default = "beacon-endpoint-reader"
+}
+
+variable "grant_beacon_read_access" {
+ description = "Grant Beacon Cloud read access to the bucket (roles/storage.objectViewer for beacon_reader_member), so Beacon can ingest the telemetry you store there. No key is involved."
+ type = bool
+ default = false
+}
+
+variable "beacon_reader_member" {
+ description = "Beacon Cloud's reader identity. Change it only if Beacon gives you a different one."
+ type = string
+ default = "serviceAccount:[email protected]"
+}
+
+variable "labels" {
+ description = "Labels to apply to a bucket the module creates."
+ type = map(string)
+ default = {}
+}
diff --git a/terraform/gcs/versions.tf b/terraform/gcs/versions.tf
new file mode 100644
index 00000000..55b5fcf4
--- /dev/null
+++ b/terraform/gcs/versions.tf
@@ -0,0 +1,10 @@
+terraform {
+ required_version = ">= 1.5.0"
+
+ required_providers {
+ google = {
+ source = "hashicorp/google"
+ version = ">= 5.0"
+ }
+ }
+}