Skip to content

chore(aws): codify iCaptcha enforce in the EC2 node Terraform#139

Merged
kevincodex1 merged 1 commit into
mainfrom
chore/aws-icaptcha-enforce
Jul 1, 2026
Merged

chore(aws): codify iCaptcha enforce in the EC2 node Terraform#139
kevincodex1 merged 1 commit into
mainfrom
chore/aws-icaptcha-enforce

Conversation

@kevincodex1

@kevincodex1 kevincodex1 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Codify iCaptcha enforce into the AWS EC2 node Terraform so the enforce config survives instance rebuilds / user-data re-runs.

Motivation & context

The AWS node (manila) was upgraded to v0.4.0 and switched to iCaptcha enforce by hand-editing its running /opt/gitlawb/compose.yaml. That manual edit would be lost if the EC2 is replaced or user-data re-runs, silently dropping enforcement. This bakes it into the Terraform.
Closes #

Kind of change

  • Bug fix
  • Feature
  • Security fix
  • Docs
  • Tests / CI
  • Refactor (no behavior change)
  • Breaking or protocol change (issue required first)
  • Chore / infra

What changed

  • infra/aws/variables.tf — new vars: icaptcha_mode (default enforce), icaptcha_pubkey (default the pinned live icaptcha.gitlawb.com Ed25519 key), icaptcha_required_level (default 3).
  • infra/aws/main.tf — pass the three vars into the compose.yaml.tftpl render.
  • infra/aws/compose.yaml.tftpl — set ICAPTCHA_MODE / ICAPTCHA_PUBKEY / ICAPTCHA_REQUIRED_LEVEL on the node service environment.

Operators can override any of these per-deployment via terraform.tfvars.

How a reviewer can verify

cd infra/aws
terraform fmt -check
terraform validate    # after `terraform init`
# confirm the three ICAPTCHA_ vars are declared, passed into the templatefile, and referenced:
grep -rn 'icaptcha_' variables.tf main.tf compose.yaml.tftpl

Before you request review

- [x] Scope is one logical change; no unrelated churn
- [ ] cargo test --workspace passes locally  (N/A — infra only, no Rust changed)
- [ ] New behavior is covered by tests  (N/A — Terraform config)
- [x] cargo fmt --all and cargo clippy ... are clean  (N/A — no code changed)
- [x] Commit titles use Conventional Commits
- [x] Docs / config updated if behavior changed (this IS the config)
- [x] Checked existing PRs so this isn't a duplicate

Notes for reviewers

- No terraform apply is required to fix the live node — manila already has the config from the manual SSM edit; this just guarantees future rebuilds match.
- The pinned pubkey is a public key (safe to commit); it removes a startup dependency on fetching it from the service.

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

* **New Features**
  * Added configurable anti-spam protection for account creation, forking, and registration flows.
  * Introduced a proof-of-intelligence challenge with adjustable enforcement mode and difficulty level.
  * Enabled deployment-time configuration so the protection can be tuned without code changes.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

The AWS EC2 node (manila) was upgraded to v0.4.0 and enabled iCaptcha
enforce by hand-editing its running /opt/gitlawb/compose.yaml — which would
be lost on instance replacement or a user-data re-run. Codify it so rebuilds
stay enforced:

- variables.tf: add icaptcha_mode (default "enforce"), icaptcha_pubkey
  (default the pinned live icaptcha.gitlawb.com Ed25519 key), and
  icaptcha_required_level (default 3).
- main.tf: pass the three vars into the compose templatefile render.
- compose.yaml.tftpl: set ICAPTCHA_MODE / ICAPTCHA_PUBKEY /
  ICAPTCHA_REQUIRED_LEVEL on the node service environment.

Operators can override per-deployment via terraform.tfvars.
@github-actions github-actions Bot added the needs-issue PR has no linked issue label Jul 1, 2026
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Thanks for the contribution. A couple of things will help us review this faster:

  • Link the issue this addresses (Closes #123). For protocol changes, open an issue first.

See CONTRIBUTING.md. Update the PR and these notes will clear automatically.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds iCaptcha proof-of-intelligence gate configuration for spam protection. Three new Terraform variables (mode, pubkey, required level) are declared, passed into the compose_yaml templatefile call in main.tf, and consumed as new environment variables in the compose.yaml.tftpl template's node container.

Changes

iCaptcha Infrastructure Configuration

Layer / File(s) Summary
Declare iCaptcha variables
infra/aws/variables.tf
Adds icaptcha_mode (default "enforce"), icaptcha_pubkey (default pinned Ed25519 key), and icaptcha_required_level (default 3) as new Terraform input variables.
Wire variables into compose template
infra/aws/main.tf, infra/aws/compose.yaml.tftpl
Passes the three new iCaptcha variables into the templatefile call for compose_yaml, and the compose template injects them as ICAPTCHA_MODE, ICAPTCHA_PUBKEY, and ICAPTCHA_REQUIRED_LEVEL environment variables into the node container.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

A carrot key, a level three,
Hopping through the Terraform tree 🐇
Mode set firm, pubkey pinned tight,
Spam-bots turned away tonight,
Compose file whispers to the node,
"Prove you're real before you're stowed!" 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: codifying iCaptcha enforcement in AWS EC2 Terraform.
Description check ✅ Passed The description follows the template well and includes summary, context, changes, and verification steps; only the issue reference is left blank.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/aws-icaptcha-enforce

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
infra/aws/variables.tf (1)

88-104: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider adding validation blocks for the enum/range constraints.

icaptcha_mode only accepts off | shadow | enforce and icaptcha_required_level presumably has a bounded valid range, but neither is enforced by Terraform. A typo in terraform.tfvars (e.g. "enforce " or "enforced") would silently reach the container as an invalid value.

♻️ Optional validation blocks
 variable "icaptcha_mode" {
   description = "iCaptcha gate mode: off | shadow | enforce. The live gitlawb network enforces."
   type        = string
   default     = "enforce"
+  validation {
+    condition     = contains(["off", "shadow", "enforce"], var.icaptcha_mode)
+    error_message = "icaptcha_mode must be one of: off, shadow, enforce."
+  }
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@infra/aws/variables.tf` around lines 88 - 104, Add Terraform validation
blocks to the icaptcha variables so invalid values fail fast instead of
propagating into the container. Update the variable definitions for
icaptcha_mode and icaptcha_required_level in variables.tf: enforce icaptcha_mode
to only allow off, shadow, or enforce, and add a numeric range check for
icaptcha_required_level using a validation condition. Keep the existing variable
names and defaults, and place the new validation logic directly alongside those
variable blocks.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@infra/aws/compose.yaml.tftpl`:
- Around line 61-64: The ICAPTCHA_MODE entry in the Compose template is still
unquoted, so YAML may coerce values like off instead of passing the literal
string. Update the environment block in compose.yaml.tftpl so ICAPTCHA_MODE is
quoted like the other string values, keeping the container config aligned with
the icaptcha_mode setting.

---

Nitpick comments:
In `@infra/aws/variables.tf`:
- Around line 88-104: Add Terraform validation blocks to the icaptcha variables
so invalid values fail fast instead of propagating into the container. Update
the variable definitions for icaptcha_mode and icaptcha_required_level in
variables.tf: enforce icaptcha_mode to only allow off, shadow, or enforce, and
add a numeric range check for icaptcha_required_level using a validation
condition. Keep the existing variable names and defaults, and place the new
validation logic directly alongside those variable blocks.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: eae38442-ba02-48b8-ae37-8ba25e7a7749

📥 Commits

Reviewing files that changed from the base of the PR and between 8d96cab and d20e117.

📒 Files selected for processing (3)
  • infra/aws/compose.yaml.tftpl
  • infra/aws/main.tf
  • infra/aws/variables.tf

Comment on lines +61 to +64
# iCaptcha proof-of-intelligence gate (spam protection on create/fork/register)
ICAPTCHA_MODE: ${icaptcha_mode}
ICAPTCHA_PUBKEY: ${icaptcha_pubkey}
ICAPTCHA_REQUIRED_LEVEL: "${icaptcha_required_level}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

sed -n '1,120p' infra/aws/compose.yaml.tftpl

Repository: Gitlawb/node

Length of output: 3370


🏁 Script executed:

rg -n "icaptcha_mode|docker compose|compose version|compose plugin|go-yaml|compose.yaml.tftpl" .

Repository: Gitlawb/node

Length of output: 2309


🏁 Script executed:

sed -n '80,120p' infra/aws/variables.tf && printf '\n----\n' && sed -n '1,160p' infra/aws/user-data.sh.tftpl

Repository: Gitlawb/node

Length of output: 5833


🌐 Web query:

Docker Compose v2.32.4 YAML boolean off on environment mapping compose-go yaml.v3 behavior

💡 Result:

In Docker Compose, including version 2.32.4, the use of unquoted boolean-like values—such as "off", "on", "yes", or "no"—within an environment mapping can cause unexpected behavior or configuration errors because the underlying YAML parser may interpret these as boolean types rather than strings [1][2]. This behavior is primarily a result of Docker Compose using the go-yaml/v3 library for parsing YAML files [3][4]. While YAML 1.2 specifications removed these values from the default boolean set, go-yaml/v3 maintains limited backward compatibility with YAML 1.1 [4]: 1. Boolean Interpretation: When a YAML scalar is decoded into a typed boolean field, values like "off", "on", "yes", and "no" are correctly treated as booleans [4]. However, for environment variable definitions, Docker Compose expects string values [2]. 2. Contextual Parsing: If the YAML parser encounters these values in a context where it expects a string, it may still parse them based on its internal rules, potentially leading to the variable being set as a boolean literal (true/false) instead of the intended string "off" or "on" [2]. 3. Impact on Environment Variables: Docker Compose mandates that any boolean-like value used in the environment section must be enclosed in quotes (e.g., VAR: 'off') [5][6]. Quoting ensures the value is treated strictly as a string, preventing the parser from attempting to convert it into a boolean type [6][2]. If you omit the quotes, you risk configuration errors or the application receiving a boolean type rather than the literal string "off" or "on," which often causes failures in application-level environment variable parsing [2][7]. To ensure consistency and avoid errors, always quote these values in your compose files [6][8].

Citations:


Quote ICAPTCHA_MODE

icaptcha_mode accepts off, and this Compose environment entry is still unquoted. Docker Compose can treat boolean-like scalars as YAML values here, so off may not reach the container as the literal string. Quoting this field avoids a startup/config mismatch.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@infra/aws/compose.yaml.tftpl` around lines 61 - 64, The ICAPTCHA_MODE entry
in the Compose template is still unquoted, so YAML may coerce values like off
instead of passing the literal string. Update the environment block in
compose.yaml.tftpl so ICAPTCHA_MODE is quoted like the other string values,
keeping the container config aligned with the icaptcha_mode setting.

@kevincodex1
kevincodex1 merged commit cd4680e into main Jul 1, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-issue PR has no linked issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant