Skip to content

Add an AWS deployment planning skill for Prebid Server Go - #1166

Open
ChristianPavilonis wants to merge 13 commits into
mainfrom
feature/terraform-skill
Open

ChristianPavilonis wants to merge 13 commits into
mainfrom
feature/terraform-skill

Conversation

@ChristianPavilonis

@ChristianPavilonis ChristianPavilonis commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add an explicitly invoked skill for planning Prebid Server Go deployments on AWS and generating approved Terraform/runtime files from an operator interview.
  • Add experimental Prebid Server inspection, validation, secret management, and EC2 status commands to the existing Trusted Server CLI.
  • Organize the CLI under ts prebid: browser bundle generation is ts prebid client, while self-hosted Prebid Server operations are under ts prebid server.
  • Add a production-shaped, locally checked EC2/Compose Terraform example under deploy/pbs-example/.
  • Keep planning and file generation separate from AWS execution. Deployment, rollback, and runtime secret injection remain deferred.

The earlier post-merge inspection compatibility blocker is resolved at the current head. The CLI tests now pass against the current configuration schema.

Changes

Files Change
.claude/skills/planning-prebid-aws/ Defines explicit invocation, requirements gathering, design approval, generation, and evidence gates. Adds an optional AWS RTB Fabric outbound bidder-connectivity interview and lifecycle guidance. Routes supported operations through ts prebid server.
crates/trusted-server-cli/src/commands/pbs/ Implements local inspection and validation, guarded Secrets Manager writes, and EC2 infrastructure status.
crates/trusted-server-cli/src/run.rs Exposes the client and server command groups under ts prebid.
crates/trusted-server-cli/tests/pbs_cli.rs and module tests Exercise the real CLI against a fake AWS executable, plus discovery, merging, validation, redaction, target refusal, retries, and partial status.
crates/trusted-server-cli/README.md and examples/pbs/ Document usage, schemas, authorization boundaries, recovery, and limitations with fictional fixtures.
deploy/pbs-example/ Adds a two-region, two-AZ-per-region example with regional ALBs, Route 53 latency aliases, private EC2 Compose hosts, per-AZ NAT, monitoring, Secrets Manager metadata, runtime examples, a plan, and a runbook.
Prebid guides, examples, and diagnostics Replace ts prebid bundle references with ts prebid client.
.tool-versions Adds AWS CLI tooling and aligns the existing entries.

CLI layout

Client

ts prebid client [--config <path>] [--out <dir>]

This generates the publisher-specific browser bundle. It replaces the former ts prebid bundle command.

Server

Command Current scope
ts prebid server inspect --config <file> Reads selected local configuration without changing it. Sensitive account, endpoint, and bid-parameter values are withheld.
ts prebid server check --deployment <file> Validates descriptor and binding structure plus deterministic regional YAML merges without AWS calls.
ts prebid server secrets set <bidder> --deployment <file> --region <region> Writes a complete JSON payload to an existing declared secret after identity, metadata, history, and confirmation checks.
ts prebid server status --deployment <file> Reads declared EC2 instances and reports infrastructure state, not PBS health or readiness.

Add --json anywhere under ts prebid server for machine-readable output.

Secret values stay out of process arguments and reports. AWS request payloads use owner-only temporary files on Unix and are removed on normal success and error paths. Raw AWS stderr is withheld. Abrupt termination can leave temporary files, so operators must use protected temporary storage. Windows ACL behavior has not been validated.

Example deployment

deploy/pbs-example/ is a committed, locally checked example. It models:

  • Route 53 latency routing to one ALB in each of us-east-1 and us-west-2.
  • Two AZs per region, with one private PBS EC2 host per AZ.
  • Docker Compose as the host runtime.
  • Per-AZ NAT gateways for outbound bidder access.
  • Secrets Manager metadata and EC2 read permissions without committing secret values.
  • PBS Go v4.7.0 pinned to a verified image digest.

The example uses fictional account, certificate, hosted-zone, AMI, instance, CIDR, and bidder values. It is not deployable as-is. It has no remote Terraform backend, WAF, runtime secret loader, deployment command, rollback command, or load-test evidence.

Boundaries

The deployment descriptor supports ec2-compose only. The planning skill may recommend ECS or another approved architecture, but that requires separate CLI support.

There are no deploy or rollback server subcommands. This PR does not provision infrastructure, install a runtime secret loader, replace containers, adopt sandbox state, activate bidders, or change caller traffic. The example files document those deferred operations rather than presenting them as implemented.

The planning skill now treats AWS RTB Fabric as an optional outbound path per bidder and region. It records partner participation and acceptance, PBS endpoint mapping, regional quotas and timeouts, cost, fallback, monitoring, and Terraform link lifecycle limitations. It does not provision gateways or links, automate partner acceptance, or replace the current EC2/Compose descriptor.

Live AWS operations still require explicit operator authorization. No real AWS calls or secret writes were made during implementation.

Open questions

  • ECS support: Should a future version add an ECS/Fargate example and descriptor support alongside ec2-compose, or should this skill stay focused on the currently supported Compose/EC2 path? ECS would improve managed task replacement and deployment behavior, but it adds a second runtime and CLI contract.
  • Instance replacement: Should the example move from fixed EC2 instances to launch templates and Auto Scaling Groups? That would improve host replacement, but the current ts prebid server status descriptor accepts explicit instance IDs, not ASG membership.
  • Terraform state: Should a later production profile use a separately bootstrapped S3 backend with native lock-file locking instead of the demo's local state?
  • Capacity evidence: What real peak QPS, bidder fan-out, caller timeout, regional failover target, and latency SLO should replace the fictional planning assumptions before anyone treats the topology as capacity-tested?

Test plan

  • ./scripts/test-cli.sh
  • cargo fmt --all -- --check
  • cargo clippy --package trusted-server-cli --all-targets --target x86_64-unknown-linux-gnu -- -D warnings
  • cd crates/trusted-server-js/lib && npm run format
  • cd crates/trusted-server-js/lib && npx vitest run with 901 tests passing
  • cd crates/trusted-server-js/lib && node build-all.mjs
  • Smoke-tested ts prebid, ts prebid client --help, and ts prebid server --help
  • terraform fmt -check -recursive deploy/pbs-example
  • terraform -chdir=deploy/pbs-example init -backend=false -input=false
  • terraform -chdir=deploy/pbs-example validate
  • cargo run_cli_linux prebid server check --deployment deploy/pbs-example/deployment.yaml --json
  • docker compose --env-file deploy/pbs-example/runtime/examples/compose.env -f deploy/pbs-example/runtime/compose.yaml config --quiet
  • Parsed deploy/pbs-example/runtime/secret-bindings.json with Python
  • Verified deploy/pbs-test/ remains untracked and untouched

Deferred evidence

  • Fresh-agent skill invocation and end-to-end file-generation exercise
  • Live AWS authentication and service integration
  • Real-terminal interaction, PBS startup, and runtime delivery
  • Real bidder authorization, credential injection, and optional AWS RTB Fabric connectivity
  • Representative load, failover, replacement, alert delivery, and latency measurements
  • macOS and Windows validation

Checklist

  • Skill requires explicit invocation with disable-model-invocation: true.
  • New code has unit and process-level tests; production code adds no unwrap() calls.
  • Credentials are absent from committed examples and reports; test payloads use dummy values.
  • Unsupported operations and unverified integration behavior are documented rather than reported as working.
  • The example deployment uses fictional AWS and domain values and does not authorize cloud execution.

Closes

Closes #1163

Gather deployment requirements before choosing AWS services and generating
Terraform or runtime files. Keep cloud execution behind separate approval
and document safe testing, state ownership, and credential handling.

Refs #1163
@ChristianPavilonis
ChristianPavilonis marked this pull request as ready for review September 15, 2026 23:06

@aram356 aram356 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a complete review, but I wanted to make sure we keep the CLI clean and consistent. We already have a prebid subcommand, so I would recommend building on top of that.

For the new command:
ts prebid server ...

And the existing command would become:
ts prebid client ...

@prk-Jr prk-Jr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Adds an agent planning skill for self-hosted Prebid Server Go on AWS, a new experimental ts prebid server CLI namespace (local inspection and validation, guarded Secrets Manager writes, EC2 status), and renames ts prebid bundle to ts prebid client. The CLI subsystem is carefully built — sanitized &'static str error payloads, an injected Interaction trait so tests can't touch a terminal, secrets kept out of argv, owner-only temp payloads cleaned up on both success and failure — and the negative-path test suite is genuinely strong. All 20 CI checks pass.

One blocking item: .tool-versions pins every tool except the AWS CLI this PR adds, which is exactly the binary the credential-write path shells out to.

3 of the inline comments below carry a one-click GitHub suggestion — use Commit suggestion (or Add suggestion to batch for several at once) to apply them as commits on the PR branch. Each was verified in an isolated worktree, individually and as a batch, against cargo fmt --all -- --check, both host-target trusted-server-cli clippy invocations with -D warnings, and cargo test --package trusted-server-cli. The remaining comments describe the fix in prose because the change touches multiple files, lands outside the diff hunks, or didn't survive cargo fmt in the reviewed form.

Blocking

🔧 wrench

  • AWS CLI pinned to latest while every other tool is exact — see inline at .tool-versions:6

Non-blocking

♻️ refactor

  • rpassword / serde_yaml_ng bypass workspace dependency inheritance — see inline at crates/trusted-server-cli/Cargo.toml:27
  • The determinism check compares a pure function against itself — see inline at crates/trusted-server-cli/src/commands/pbs/config.rs:378
  • Hand-rolled JSON escaping round-trip in bidder_list — see inline at crates/trusted-server-cli/src/commands/pbs/inspect.rs:91 (suggestion)

🤔 thinking

  • ts prebid bundlets prebid client is a breaking rename with no alias — see inline at crates/trusted-server-cli/src/run.rs:75 (suggestion)
  • Transport failure on put-secret-value doesn't flag the outcome as uncertain — see inline at crates/trusted-server-cli/src/commands/pbs/secrets.rs:173
  • A dated Status: Implemented spec is rewritten retroactively — see inline at docs/superpowers/specs/2026-06-17-prebid-bundle-cli-design.md:5
  • The ts prebid server namespace is undocumented in docs/ — see inline at docs/guide/cli.md:274
  • Missing python3 makes two tests pass for the wrong reason — see inline at crates/trusted-server-cli/tests/pbs_cli.rs:23
  • identifier() rejects AWS profile names containing . — see inline at crates/trusted-server-cli/src/commands/pbs/config.rs:104

⛏ nitpick

  • Unparenthesized &&/|| on the noninteractive-write gate — see inline at crates/trusted-server-cli/src/commands/pbs/secrets.rs:112 (suggestion)

🌱 seedling

  • Unbounded recursion over operator YAML — see inline at crates/trusted-server-cli/src/commands/pbs/config.rs:318

📝 note

  • Identity failure aborts the whole status report; resource-query failure degrades — see inline at crates/trusted-server-cli/src/commands/pbs/status.rs:26

👍 praise

  • Negative-path test discipline — see inline at crates/trusted-server-cli/tests/pbs_cli.rs:39

Cross-cutting / body-level findings

  • 📌 Three separable concerns in one PR — this bundles (a) agent-only markdown under .claude/skills/ with zero runtime impact, (b) a ~1800-LOC experimental CLI subsystem that writes AWS credentials, and (c) a breaking rename of an already-shipped command. They have different audiences, different risk profiles, and different revert stories: the rename is the one most likely to need a fast follow-up or a release note, and it's currently welded to a large feature branch. Not a change request on this PR — but if the rename landed separately it could be communicated and reverted on its own cadence. Flagging under AGENTS.md's "every change should impact as little code as possible".

CI Status

  • integration tests (Fastly EC lifecycle): PASS
  • integration tests: PASS
  • browser integration tests: PASS
  • CodeQL: PASS
  • cargo test (ts CLI, native): PASS
  • vitest: PASS
  • format-typescript: PASS (required)
  • Analyze (javascript-typescript): PASS
  • cargo fmt: PASS (required)
  • cargo test (axum native): PASS
  • Analyze (rust): PASS
  • cargo check (cloudflare native + wasm32-unknown-unknown): PASS
  • cargo test: PASS (required)
  • format-docs: PASS (required)
  • cargo check/build/test (spin native + wasm32-wasip1): PASS
  • cargo test (cross-adapter parity): PASS
  • CLAUDE.md symlink guard: PASS
  • prepare integration artifacts: PASS
  • Analyze (actions): PASS

No failed, cancelled, or pending checks.

Comment thread .tool-versions Outdated
Comment thread crates/trusted-server-cli/Cargo.toml Outdated
Comment thread crates/trusted-server-cli/src/commands/pbs/config.rs
Comment thread crates/trusted-server-cli/src/commands/pbs/inspect.rs Outdated
Comment thread crates/trusted-server-cli/src/run.rs
Comment thread crates/trusted-server-cli/src/commands/pbs/status.rs
Comment thread crates/trusted-server-cli/src/commands/pbs/secrets.rs Outdated
Comment thread crates/trusted-server-cli/src/commands/pbs/config.rs
Comment thread crates/trusted-server-cli/src/commands/pbs/config.rs Outdated
Comment thread crates/trusted-server-cli/tests/pbs_cli.rs
@aram356
aram356 requested a review from jevansnyc September 17, 2026 15:27

@jevansnyc jevansnyc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing major so posting in here as single comment:

Breaking rename with no alias — [run.rs:76] ts prebid bundle became ts prebid client. Any existing script gets error: unrecognized subcommand 'bundle'. Confirmed against the built binary. Either add a hidden alias or call the break out in the PR description.

.tool-versions aws plugin name is wrong — [.tool-versions:6] The entry is aws 2.36.45, but asdf/mise call that plugin awscli. asdf install fails on the exact onboarding path the docs point at. CI is unaffected since the workflows grep only rust/nodejs/viceroy.

Regional module has no provider pin — [modules/regional/terraform.tf:3] No AWS provider version constraint, and [.gitignore:3] excludes its lock file, yet RUNBOOK.md tells operators to init/test inside the module. So the module test runs against an unpinned provider that will drift away from the root's = 6.64.0.

Confirm prompt rejects long input instead of declining — [pbs/mod.rs:228] Terminal::confirm caps the answer at 16 bytes and returns "input exceeds size limit" rather than treating it as a no. A 17-character answer makes the operator re-enter the secret through the hidden prompt.

CPU alarm pages on stopped hosts — [modules/regional/monitoring.tf:13] The per-instance high-CPU alarm sets treat_missing_data = "breaching", so a stopped or replaced instance pages as saturated.

ONE QUESTION for Christian:

The test plan lists terraform fmt, init, and validate, but not terraform test, even though both .tftest.hcl files ship and the README/RUNBOOK instruct operators to run them. Worth confirming those two suites actually ran. validate leaves module inputs unknown and evaluates very little of the plan.

@prk-Jr prk-Jr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Reviewed commit 74bdc5b57e5a8d3cca8174d9ccc7684f87466cbe.

The secret-write boundary handles account checks, payload privacy, confirmation, and uncertain outcomes carefully. The discovery command, however, reads the retired server configuration layout and misses server bidders in current valid configurations.

Blocking

  • 🔧 Read server demand from the current auction schema — see inline at crates/trusted-server-cli/src/commands/pbs/inspect.rs:134–140.

Validation

The unmodified production PBS module was imported into an isolated harness. Inspecting a current-format provider/bidder fixture returned an empty server-candidate list, false endpoint presence, null test mode, and zero override rules. This was a module harness, not a build of the complete CLI.

Terraform formatting and validation, five root mock tests, two regional mock tests, Compose configuration, shell syntax, and both example descriptor checks passed. No live AWS calls, deployments, or secret writes were performed. Full Rust/JS/adapter gates rely on remote CI.

CI Status

Comment thread crates/trusted-server-cli/src/commands/pbs/inspect.rs Outdated

@aram356 aram356 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Adds an explicitly-invoked AWS planning skill for Prebid Server Go, an experimental ts prebid server CLI namespace (inspect / check / secrets set / status), and a locally-checked two-region EC2/Compose Terraform example. Reviewed at 18d1b4877.

Verification performed in an isolated worktree rather than by reading alone: built and ran the CLI live, ran ./scripts/test-cli.sh (239 tests pass), cargo fmt --all -- --check and target-matched clippy (both clean), exercised aws configure get history semantics against a real AWS CLI v2, ran the shipped Terraform through fmt/validate/test, and reproduced each defect below end-to-end.

The secret-handling path holds up under scrutiny: payloads stay out of argv, temporary request files are owner-only and removed on every error path via Drop, AWS CLI history is checked on both cli_history and default.cli_history (I confirmed the two-key probe catches the [default]-inherited case), and account / replica / ARN verification all fail closed. The redaction tests genuinely hold.

Two blocking items below. Neither is a live production defect: one is a removed command with no compatibility path, the other is a regression guard that does not guard.

2 of the inline comments carry a one-click GitHub suggestion. Both were applied in a scratch worktree and verified in isolation (fmt, clippy, full 239-test CLI suite, byte-exact post-verify drift check). The remaining comments describe fixes in prose because they span multiple assertions or files.

Blocking

🔧 wrench

  • security_unit_test.tftest.hcl does not defend the invariants it is named for — see inline at deploy/pbs-example/modules/regional/tests/security_unit_test.tftest.hcl:36
  • ts prebid bundle removed with no alias — silent breaking change — see inline at crates/trusted-server-cli/src/run.rs:75

Non-blocking

♻️ refactor / 🤔 thinking / ⛏ nitpick

  • pinned_image() accepts uppercase digests that Docker rejects — see inline at crates/trusted-server-cli/src/commands/pbs/config.rs:275
  • Retry guidance is wrong when a request token is reused with different content — see inline at crates/trusted-server-cli/src/commands/pbs/aws.rs:79
  • I/O errors name no path, so a multi-file descriptor failure is unactionable — see inline at crates/trusted-server-cli/src/commands/pbs/mod.rs:150
  • ALB egress rule contradicts its own description — see inline at deploy/pbs-example/modules/regional/security.tf:18
  • --deployment is the only PBS flag with empty help text — see inline at crates/trusted-server-cli/src/commands/pbs/secrets.rs:23

Cross-cutting / body-level findings

  • 📌 Committed Terraform lock file carries a single platform hashdeploy/pbs-example/.terraform.lock.hcl:7 records one h1: hash. On a non-matching platform terraform init silently rewrites the file, and a terraform test after restoring it fails with "does not match any of the checksums recorded in the dependency lock file". This contradicts RUNBOOK.md:8 ("use the committed AWS provider lock file") and RUNBOOK.md:70 ("review any lock-file change"): operators on other platforms get a spurious diff on every run, which trains them to rubber-stamp lock changes. Regenerate with terraform providers lock -platform=darwin_arm64 -platform=darwin_amd64 -platform=linux_amd64 -platform=linux_arm64.

  • 🌱 No ALB access loggingdeploy/pbs-example/modules/regional/load_balancing.tf:1-13 has no access_logs block anywhere in the tree. For an internet-facing ALB in a deliberately "production-shaped" reference there is no request-level forensic record. drop_invalid_header_fields = true and idle_timeout = 30 are both set, which makes the omission stand out. Either add an access_logs block or state in DEPLOYMENT_PLAN.md that it is deliberately out of scope — the current silence reads as an oversight.

  • 🌱 No VPC endpoints, so SSM and Secrets Manager traffic exits via NAT — there is no aws_vpc_endpoint in the tree. The instance role attaches AmazonSSMManagedInstanceCore and reads Secrets Manager (modules/regional/secrets.tf:42-62), but with no interface endpoints for ssm, ssmmessages, ec2messages, secretsmanager, or kms, that control-plane and credential traffic traverses the public internet and incurs per-GB NAT cost on every secret fetch. Notable for a design whose stated benefit is private hosts with regionally isolated credentials.

  • 📝 AmazonSSMManagedInstanceCore is the one broad IAM grant — the inline policy at modules/regional/secrets.tf:47-69 is tight (Resource enumerates the declared secret ARNs, KMS is conditionally scoped to one key, no wildcards). The AWS-managed SSM policy is the deliberate exception and carries "Resource": "*". Standard practice and hard to avoid, but worth a comment in an example that markets least-privilege.

  • Six new markdown files are not prettier-cleancrates/trusted-server-cli/README.md, four references/*.md, and deploy/pbs-example/DEPLOYMENT_PLAN.md fail prettier --check under docs/.prettierrc (mostly misaligned table pipes). No CI gate covers this: .github/workflows/format.yml:121-125 scopes format-docs to docs/, and nothing in CI touches .claude/, crates/**/README.md, or deploy/. Raised only because the other new markdown files in this PR are clean, so the inconsistency is internal. Do not extend the CI gate for this.

  • Terraform 1.16.2 is pinned in docs and HCL but not in .tool-versionsRUNBOOK.md:8 and deploy/pbs-example/terraform.tf (required_version = ">= 1.16.2, < 1.17.0") agree, but .tool-versions has no terraform entry while every other toolchain in the repo is asdf-pinned. references/terraform.md:29 advises selecting a reproducible Terraform version "in the repository's toolchain", so the skill's own guidance is not followed by the example it ships.

  • crates/trusted-server-cli/README.md:5 will be stale on merge — "The namespace is experimental and is being evaluated in PR review." Prefer a durable phrasing such as "experimental; the interface may change without a deprecation cycle".

  • deploy/pbs-example/runtime/compose.yaml:6 publishes on all interfaces"${PBS_HOST_PORT:-8000}:8000" renders without a host-IP restriction, so a smoke-test PBS instance is reachable from the local network. The smoke script itself only ever talks to 127.0.0.1. Consider "127.0.0.1:${PBS_HOST_PORT:-8000}:8000" for the example.

CI Status

  • cargo fmt: PASS (required)
  • cargo test: PASS (required)
  • format-docs: PASS (required)
  • format-typescript: PASS (required)
  • cargo test (ts CLI, native): PASS
  • cargo test (axum native): PASS
  • cargo test (cross-adapter parity): PASS
  • cargo check (cloudflare native + wasm32-unknown-unknown): PASS
  • cargo check/build/test (spin native + wasm32-wasip1): PASS
  • vitest: PASS
  • CodeQL: PASS
  • Analyze (rust): PASS
  • Analyze (javascript-typescript): PASS
  • Analyze (actions): PASS
  • CLAUDE.md symlink guard: PASS
  • prepare integration artifacts: PENDING

No failing checks. CI is not a factor in this verdict.

}

run "plans_private_hosts_and_scoped_ingress" {
command = plan

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧 wrench — This file is named security_unit_test and RUNBOOK.md:31 presents it as the gate on broad ingress and secret policy, but it is blind to the four highest-value invariants in the module.

All four are implemented correctly in the source — this is a regression hole, not a live defect:

Invariant Where it is implemented Asserted here?
IMDSv2 required compute.tf:15 http_tokens = "required" no
Root EBS encrypted compute.tf:21 encrypted = true no
Private subnet placement compute.tf:7 aws_subnet.private[...] no
TLS 1.3/1.2 listener policy load_balancing.tf:52 no

Each was mutated in a scratch copy and the suite still reported 2 passed, 0 failed on all four. Only the ingress-CIDR rule is genuinely locked in (breaking it does fail the suite).

The assertion at line 44 looks like it covers host exposure but is near-vacuous:

condition = alltrue([for instance in aws_instance.pbs : instance.associate_public_ip_address == false])

It re-reads the literal false written two lines away at compute.tf:9; it does not constrain subnet placement, which is what actually determines reachability.

Proposed fix (apply manually — adds four assertions to the existing run "plans_private_hosts_and_scoped_ingress" block; the exact set is a judgement call so it is not offered as a one-click suggestion):

  assert {
    condition     = alltrue([for i in aws_instance.pbs : i.metadata_options[0].http_tokens == "required"])
    error_message = "PBS hosts should require IMDSv2 session tokens."
  }

  assert {
    condition     = alltrue([for i in aws_instance.pbs : i.root_block_device[0].encrypted])
    error_message = "PBS host root volumes should be encrypted."
  }

  assert {
    condition     = alltrue([for az, i in aws_instance.pbs : i.subnet_id == aws_subnet.private[az].id])
    error_message = "PBS hosts should launch only in private subnets."
  }

  assert {
    condition     = aws_lb_listener.https.ssl_policy == "ELBSecurityPolicy-TLS13-1-2-2021-06"
    error_message = "The ALB listener should pin the TLS 1.3/1.2 policy."
  }

A security test that stays green through four broken invariants is worse than no test, because the next person to touch this module will trust it.

Comment thread crates/trusted-server-cli/src/run.rs
&& !image.contains('@')
&& !image.chars().any(char::is_whitespace)
&& digest.len() == 64
&& digest.bytes().all(|byte| byte.is_ascii_hexdigit())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ refactoris_ascii_hexdigit() accepts A-F, but OCI image digests are lowercase-only. A descriptor pinned with an uppercase digest passes ts prebid server check and then fails at container pull time with invalid checksum digest format.

Reproduced end-to-end against the shipped example with the digest uppercased:

$ ts prebid server check --deployment deployment.yaml --json
{ "local_checks": "passed", ... }
exit=0

Docker rejects the same reference:

$ docker pull alpine@sha256:AAAA...
invalid checksum digest format

Since the whole point of pinned_image() is that the operator has a pullable, immutable reference, this is worth catching locally rather than on the host.

Verified: with the change applied, the uppercase descriptor is rejected (exit=2), both shipped examples (crates/trusted-server-cli/examples/pbs/deployment.yaml and deploy/pbs-example/deployment.example.yaml) still pass, fmt and clippy clean, full CLI suite 239 tests pass, drift check clean.

Suggested change
&& digest.bytes().all(|byte| byte.is_ascii_hexdigit())
&& digest
.bytes()
.all(|byte| byte.is_ascii_digit() || matches!(byte, b'a'..=b'f'))

drop(payload);
if !output.status.success() {
let message = if operation == "put-secret-value" {
"write outcome uncertain; retain the request token and retry identical input"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 thinking — This message is wrong for one of the two ways put-secret-value commonly fails.

AWS treats ClientRequestToken as an idempotency key: reusing a token with the same SecretString is a no-op returning the existing version, while reusing it with different content returns ResourceExistsException. --request-token help (secrets.rs:37) documents this correctly: "Reuse with identical values only."

But when the operator does violate it, they get:

write outcome uncertain; retain the request token and retry identical input

Both halves mislead. The outcome is not uncertain — AWS definitively rejected the write and nothing changed. And "retry identical input" is the wrong remedy: their input is precisely what is not identical. The correct action is to issue a new token for genuinely new content.

I recognise the constraint here — withholding raw AWS stderr is a deliberate and correct secret-safety decision (PbsError::Aws), so the code cannot cheaply distinguish a timeout from a token collision. Two options, both compatible with that policy:

  1. Broaden the wording to cover both cases, e.g. "write not confirmed; if retrying identical input reuse this token, otherwise issue a new token for changed values".
  2. Inspect the AWS CLI exit status or a narrowly-matched error code without forwarding the message body, and emit a distinct PbsError variant for the collision.

Not blocking, but an operator hitting this at 3am will follow the instruction literally and retry unchanged, which cannot succeed.

/// # Errors
/// Returns an I/O error or rejects oversized/non-UTF-8 input.
pub(super) fn read_text(path: &Path, limit: usize) -> Result<String> {
let file = File::open(path).map_err(|_| Report::new(PbsError::Io("cannot open input file")))?;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 thinkingPbsError::Io("cannot open input file") is the same string for every file the descriptor pulls in, and it names none of them. A descriptor references the PBS config, a bindings file, and one overrides file per region, so a typo in any of four-plus paths produces an identical, unactionable message.

Reproduced against the shipped example — three distinct missing files, one indistinguishable error:

$ rm pbs.yaml      && ts prebid server check --deployment deployment.yaml
[ts] PBS I/O failed: cannot open input file
$ rm east.yaml     && ts prebid server check --deployment deployment.yaml
[ts] PBS I/O failed: cannot open input file
$ ts prebid server check --deployment nope.yaml
[ts] PBS I/O failed: cannot open input file

The sanitization rationale in the module docs is about file contents — parser snippets and AWS stderr can carry credential values. A path the operator typed into their own descriptor is not secret, and inspect already echoes "source": path into its JSON report (inspect.rs:177), so path disclosure is established behaviour in this module.

Proposed fix (apply manually — PbsError::Io holds &'static str, so attaching a runtime path means either adding a variant or using error-stack's attach, which touches the enum and several call sites):

// at the read_text call site
File::open(path)
    .map_err(|_| Report::new(PbsError::Io("cannot open input file")))
    .attach_printable_lazy(|| format!("path: {}", path.display()))?

attach keeps the sanitized Display string intact while giving the operator the failing path in the report.

Comment on lines +18 to +24
egress {
description = "Forward requests to private PBS hosts"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ refactor — The description says "Forward requests to private PBS hosts", but the rule permits all protocols to the entire internet. The ALB only ever needs to reach the PBS hosts on var.pbs_port.

Worth contrasting with the PBS host SG at security.tf:44-50, whose 0.0.0.0/0 egress is justified and correctly described ("Bidder and AWS API access through the per-AZ NAT gateway") — bidder endpoints are arbitrary public addresses. The ALB has no such requirement.

Proposed fix (apply manually — a referenced_security_group_id here creates a dependency cycle with the PBS SG's security_groups = [aws_security_group.alb.id] ingress at security.tf:41, so the rule has to move out of the inline block into a standalone resource, which is also the modern provider-6.x idiom):

resource "aws_vpc_security_group_egress_rule" "alb_to_pbs" {
  description                  = "Forward requests to private PBS hosts"
  security_group_id            = aws_security_group.alb.id
  referenced_security_group_id = aws_security_group.pbs.id
  from_port                    = var.pbs_port
  to_port                      = var.pbs_port
  ip_protocol                  = "tcp"
}

Then drop the inline egress block from aws_security_group.alb. Note that mixing inline blocks with standalone rules on the same SG is unsupported, so the ALB SG must use one style throughout.

Comment on lines +23 to +24
#[arg(long)]
pub deployment: PathBuf,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick--deployment is the only flag in the entire ts prebid server namespace without a doc comment, so it renders with empty help text:

Options:
      --deployment <DEPLOYMENT>
      --region <REGION>                Exactly one declared region; replicas cannot be written independently
      --file <FILE>                    Read a complete JSON string-valued object from this file; never changes the file

TargetArgs::deployment in mod.rs:51-52 already has the right wording, and the path-resolution semantics it describes matter here too, since every path inside the descriptor resolves relative to this file.

Suggested change
#[arg(long)]
pub deployment: PathBuf,
/// Deployment descriptor; paths inside it are relative to this file.
#[arg(long)]
pub deployment: PathBuf,

Separately: pub is wider than needed. mod.rs:134 is the only consumer, so pub(super) would match the module's otherwise-tight visibility and AGENTS.md's "avoid unnecessary pub". Left out of the suggestion above since it is a separate concern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create terraform deployment skill for prebid server dependency for TS

4 participants