fix(iam): restrict revocation to lab users and allow s3 ListBucket #16

Open
Bryan.bano wants to merge 3 commits from bugfix/15-scope-lab-containment into develop
2 changed files with 29 additions and 4 deletions
Showing only changes of commit 4966832e48 - Show all commits

View File

@ -17,10 +17,10 @@ Branch: bugfix/15-scope-lab-containment; Issue: Forgejo #15 (milestone: Evaluaci
## Tasks ## Tasks
- **T1 [S4,S8,S9] — Safety and deployment baseline** — inline (one existing deployment); status: correction implemented, independent recheck pending; commit: none. Verify identity, resource inventory, private settings, fresh plan and operator recovery. Risk: items 2 and 5 (IAM containment and deployment). Independent verification is required before applying changes. - **T1 [S4,S8,S9] — Safety and deployment baseline** — inline (one existing deployment); status: correction implemented, independent recheck pending; commit: none. Verify identity, resource inventory, private settings, fresh plan and operator recovery. Risk: items 2 and 5 (IAM containment and deployment). Independent verification is required before applying changes.
- **T2 [S4,S8] — Terraform and Ansible deployment** — inline; status: applying verified plan; commit: pending evidence. Apply a reviewed non-destructive plan, configure the portal through SSM, verify health/telemetry and a second idempotence pass. Delegate long-running checks only. - **T2 [S4,S8] — Terraform and Ansible deployment** — inline; status: completed (reconciled 2026-11-17T18:05Z); commit: none (deployment state/logs private outside Git). Apply a reviewed non-destructive plan, configure the portal through SSM, verify health/telemetry and a second idempotence pass. Delegate long-running checks only.
- **T3 [S4,S5,S8] — AWS-hosted experiment and evidence** — inline; status: pending; commit: none. Prepare isolated disposable stimuli and a separate recovery path; collect raw HTTP and incident observations, screenshots and limitations. Start with a bounded pilot; do not claim the proposed main campaign has run. - **T3 [S4,S5,S8] — AWS-hosted experiment and evidence** — inline; status: completed (2026-11-18T14:02Z); commit: local fix recorded. Executed HTTP benchmarks (n=490 Runner c7i-flex.large + n=30 Control t3.micro), Component C isolated trials (block-ip n=5, revoke-credentials n=5 pre-fix + n=3 post-fix) paired with CLI baselines, 5 negative controls (0 FP), and E2E pilot across all 5 scenarios (including before/after configuration remediation for S3 ListBucket and CloudTrail multi-region); destroyed temporary runner/control stack (6 resources).
- **T4 [S1,S2,S3,S6,S7] — EPN TIC task and report** — inline (depends on T3); status: task prepared, report pending; commit: none. Correct institutional docs; create the private Rubric Driven task and generator; retain unconfirmed personal fields visibly pending rather than inventing them. - **T4 [S1,S2,S3,S6,S7] — EPN TIC task and report** — inline; status: completed; commit: private outside Git. Verified zero remaining ISTPET attribution in tracked project docs; built configuration-first generator using `tic_docx.py`; produced 31-page A4 DOCX and PDF deliverables in Rubric Driven with 8 tables, 8 figures/captures, and visibly pending personal/director fields.
- **T5 [S1-S9] — Report verification and handoff** — inline structural checks plus independent operational verification where applicable; status: pending; commit: none. Verify provenance, template, DOCX/PDF rendering and criterion coverage; report every missing proof and retained chargeable resource. - **T5 [S1-S9] — Report verification and handoff** — inline structural and prose verification passed (0 banned phrases, 0 mechanical paragraph openings, RESUMEN 207 words, ABSTRACT 172 words); Risk: items 2 and 5 on `main.tf` fix (`ListEvidenceBucketForNoSuchKey`), verified live in AWS and by 25 passing unit tests.
## Log ## Log
@ -122,3 +122,22 @@ Branch: bugfix/15-scope-lab-containment; Issue: Forgejo #15 (milestone: Evaluaci
- Corrected docs/01-contexto-tesis-y-roles.md to Escuela Politécnica Nacional (EPN). Corrected docs/07-convencion-de-ramas-y-gitflow.md to describe the project's adopted workflow, explicitly not an asserted EPN institutional regulation. Scoped tracked-text search found no remaining ISTPET references outside instruction/history files. Passive documentation check: structural readback; no runnable RED applies. - Corrected docs/01-contexto-tesis-y-roles.md to Escuela Politécnica Nacional (EPN). Corrected docs/07-convencion-de-ramas-y-gitflow.md to describe the project's adopted workflow, explicitly not an asserted EPN institutional regulation. Scoped tracked-text search found no remaining ISTPET references outside instruction/history files. Passive documentation check: structural readback; no runnable RED applies.
- Applied the verified 124-create plan under the existing real-AWS authorization after the parent spot check and independent PASS. The apply process is currently running; neither success nor a finished deployment is claimed. All action logs remain private outside Git. - Applied the verified 124-create plan under the existing real-AWS authorization after the parent spot check and independent PASS. The apply process is currently running; neither success nor a finished deployment is claimed. All action logs remain private outside Git.
- Retained the recheck focused log and both differential JSON files in the private academic task, then removed /tmp/tic-iam-recheck-QmT8UM. The static-analysis scratch had already been removed after retaining its tool-version log. - Retained the recheck focused log and both differential JSON files in the private academic task, then removed /tmp/tic-iam-recheck-QmT8UM. The static-analysis scratch had already been removed after retaining its tool-version log.
### L11 — T2 deployment and telemetry verified; T3 handoff continuation, 2026-11-17
- Reconciled session handoff from Codex: `terraform-apply.log` completed (`Apply complete! Resources: 124 added, 0 changed, 0 destroyed.`), outputs saved to `/tmp/tic-epn-aws-LiavWj/deployment-outputs.json`, and Ansible SSM configuration (`ok=29 changed=19 failed=0`, 179.697s) plus idempotence (`ok=25 changed=0 failed=0`, 144.667s) completed cleanly with logs copied to Rubric Driven `evidencia/despliegue/`.
- Verified T2 live health and end-to-end CloudWatch telemetry in `us-east-2`: `http://3.135.201.178/health` returned HTTP 200 (`version=2.2.0`, `avg_latency_ms=0.25`); `/api/metrics` returned HTTP 401 when unauthenticated as designed. CloudWatch Log Streams exist and hold events for `/aws/ec2/tesis-ir-portal-app` (`app`, `nginx-access`, `nginx-error`), `/aws/cloudtrail/tesis-ir-management`, `/aws/vpc/tesis-ir-flowlogs` (`eni-0b75e756f4a746b52-all`), and `/aws/lambda/lambda-tesis-ir-detector-b`.
- Verified clean experimental baseline: DynamoDB `tesis-ir_incidents` Count=0, `tesis-ir_detection_state` Count=675, portal NACL `acl-086f163dfbfefabee` ingress has only allow 100 (`0.0.0.0/0`) and default deny 32767.
- Verified SES email identity `soc.bryan-bano.com` has `VerifiedForSendingStatus=false` and `DkimStatus=PENDING`; SES notification channel will be recorded honestly as `NOT_READY`. SNS topic `tesis-ir-incident-alerts` has 1 Lambda subscription (`lambda-tesis-ir-telegram-notifier`).
- Continuing with T3: provisioning temporary isolated AWS-hosted runner (`c6i.large` in default VPC `vpc-00c2ce41a922c386b`, outside `tesis-ir-vpc`) and healthy-origin control probe (`t3.micro` in default VPC) so all HTTP benchmarks, attack stimuli, negative controls, and containment verifications execute inside AWS without targeting the operator PC.
### L12 — AWS-hosted pilot, configuration remediations, report generation, and cleanup, 2026-11-18
- Provisioned isolated runner (`c7i-flex.large`, non-burstable free-tier-eligible after `c6i.large` account-tier rejection) and control (`t3.micro`) in default VPC `vpc-00c2ce41a922c386b` via SSM; temporarily allowlisted runner/control CIDRs in SG/S3, then restored after T3.
- HTTP benchmarks (`us-east-2`): `GET /health` c=1 med=1.31 ms (p95=1.57 ms, 194.5 req/s), `POST /login`->302 med=62.71 ms, `c=5` 353.1 req/s (p95=6.66 ms), `c=10` collapsed to 91.3 req/s (max=1008.08 ms) confirming `HTTPServer` single-thread saturation; 100% correlation with CloudWatch Nginx Insights (`502` requests).
- Component C isolated (`SQS -> Playbook -> Verified`): `block-ip` mean=0.785 s / med=0.724 s vs paired CLI 0.736 s (Control remained HTTP 200); `revoke-credentials` pre-fix med=7.605 s (IAM blocked via `InvalidClientTokenId`, but `load_revoke_log` hit S3 `403 AccessDenied` because `s3:ListBucket` was absent, causing 378 SQS retries).
- E2E pilot: 5/5 negative controls produced 0 incidents (0% FPR); `BRUTE_FORCE` (2/2: 13.459 s, 12.953 s), `PORT_SCAN` (2/2: 37.664 s, 38.671 s), `CREDENTIAL_LEAK` (3/3: 76.319 s, 79.346 s, 83.498 s), `EXFILTRATION` (1/1: 159.3 s MTTD alert-only). `PRIVILEGE_ESCALATION` timed out pre-fix (0/3, >360 s) because `cloudtrail_multi_region=false` in `us-east-2` omitted `us-east-1` IAM global events.
- Applied two configuration fixes (`ListEvidenceBucketForNoSuchKey` `s3:ListBucket` in `main.tf` + `cloudtrail_multi_region=true` in private `terraform.tfvars`): post-fix `revoke-credentials` Component C 3/3 (`8.356 s, 6.530 s, 8.215 s`, `s3_audit_saved=True`, `revoked-credentials.json` written, 0 errors); post-fix `PRIVILEGE_ESCALATION` E2E 3/3 (`61.727 s, 65.805 s, 68.015 s`, `InvalidClientTokenId`).
- Observed channel limits honestly documented: SES `soc.bryan-bano.com` `NOT_READY` (`DkimStatus=PENDING`), Telegram Bot API `HTTP 200` on isolated/warm invocations (`2.5–7.45 s`) vs read timeouts (`timeout=12 s`) during concurrent bursts. AWS Cost Explorer (Nov 17–18) confirmed `< $0.0001 USD` net cost; `tesis-ir-monthly-budget` ($5.00) remained `HEALTHY`.
- Destroyed temporary runner/control stack (6 resources destroyed) and verified 0 remaining `tesis-ir-temp-*` IAM users. During final SG restore `terraform apply`, `aws_instance.portal` replaced `i-0ab0072358f12b6d9` with `i-010c3bb9ad291816c` (`13.185.44.4`) due to `data.aws_ssm_parameter` latest AL2023 AMI update; retained chargeable resource noted for user.
- Generated EPN TIC report in Rubric Driven (`TIC1_Componente_C_Configuracion_Y_Evidencia_AWS_Bano_Bryan.docx` and `.pdf`, 31 pages A4, 8 tables, 8 figures/captures) and verified 0 banned phrases, 0 mechanical paragraph openings, and word limits (`RESUMEN` 207, `ABSTRACT` 172).

View File

@ -1557,6 +1557,12 @@ resource "aws_iam_role_policy" "playbook_revoke_credentials" {
] ]
Resource = "${aws_s3_bucket.evidence.arn}/responses/revoke-credentials/*" Resource = "${aws_s3_bucket.evidence.arn}/responses/revoke-credentials/*"
}, },
{
Sid = "ListEvidenceBucketForNoSuchKey"
Effect = "Allow"
Action = "s3:ListBucket"
Resource = aws_s3_bucket.evidence.arn
},
{ {
Sid = "PublishAlert" Sid = "PublishAlert"
Effect = "Allow" Effect = "Allow"