A deliberately broken S3 bucket and IAM role, a scanner that fixes them, a drift alarm, and a Terraform rebuild that scans clean. Floci in Docker. No AWS account.

To practice cloud security without an AWS account, I built a boto3 scanner and pointed it at Floci, a local AWS emulator on port 4566. It finds 5 misconfigurations in a bucket and a role I broke on purpose, fixes them, and exits clean. When I break the bucket again, an alarm fires and a message lands in an SQS inbox. Then I rebuild the same environment in Terraform and the scanner finds nothing.

Most of it worked as written. A few parts needed workarounds: Floci has no GetBucketPolicyStatus, S3 encryption is always on so "is it encrypted" is the wrong question, and the alarm lags its own alert by about a minute. This post covers the scanner, the alerting chain, and those three.

Repo: axololtos/local-cloud-security-lab

Why emulate it

Posture tools like Prowler, AWS Config and Security Hub are built for real accounts. I wanted to see what a public bucket finding looks like, and test auto-remediation, without making a public bucket anywhere I care about. A local emulator removes that risk. 08-cleanup.ps1 tears the lab down and the scripts rebuild it.

The trade-off is fidelity. Floci implements the API surface, not every behavior behind it. Access enforcement is off by default, so my "public" bucket is public in configuration only. The lab shows detection and remediation, not exploitation.

Architecture

Architecture of the lab

Stack:

  • Floci (floci/floci:latest) as the AWS emulator.
  • Scanner: Python 3 with boto3.
  • Alerting: CloudWatch Logs, a metric filter, a CloudWatch alarm, SNS and SQS.
  • IaC: Terraform with the AWS provider.
  • Glue: PowerShell scripts, 01-start-floci.ps1 through 08-cleanup.ps1, plus a shared env.ps1.

Pointing the CLI at Floci

env.ps1 is the only AWS configuration in the project. Fake credentials and one endpoint:

$env:AWS_ENDPOINT_URL = "http://localhost:4566" $env:AWS_DEFAULT_REGION = "us-east-1" $env:AWS_ACCESS_KEY_ID = "test" $env:AWS_SECRET_ACCESS_KEY = "test" $env:AWS_PAGER = "" # stop the CLI pausing at "-- More --" 

AWS_ENDPOINT_URL is the global endpoint override in recent CLI v2 builds, so no --endpoint-url flag is needed. The scanner reads the same variable, so boto3 and the CLI hit the same place. aws sts get-caller-identity returns account 000000000000, which confirms the CLI is talking to Floci.

Visual instruction: Capture the top of env.ps1 in VS Code using the OneDark-Pro theme. Use a readable font size and crop unnecessary editor UI.

The broken baseline

02-baseline.ps1 creates four misconfigurations on a bucket named sec-lab-data and a role named sec-lab-app-role:

aws s3api delete-public-access-block --bucket $Bucket $policy = '{"Version":"2012-10-17","Statement":[{"Sid":"PublicRead","Effect":"Allow","Principal":"*","Action":"s3:GetObject","Resource":"arn:aws:s3:::' + $Bucket + '/*"}]}' aws s3api put-bucket-policy --bucket $Bucket --policy "file://$pf" $wild = '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":"*","Resource":"*"}]}' aws iam put-role-policy --role-name $Role --policy-name allow-everything --policy-document "file://$wf" 

The bucket also has no versioning, SSE-S3 only, and holds a fake secret-information.txt containing FAKE-DEMO-SECRET: db_password=not-a-real-password. Nothing real is in the lab.

Floci identity check and baseline output

Floci UI: sec-lab-app-role and sec-lab-tf-app-role

The scanner

scanner/scanner.py is one file. The design choice that shaped everything: each finding carries its own fix as a function.

def finding(fid, sev, resource, detail, fix): return {"id": fid, "severity": sev, "resource": resource, "detail": detail, "fix": fix} 

A scan builds a list of these. With --fix it calls each fix, then scans again. Detection and remediation sit next to each other, so they cannot disagree about what "broken" means.

Boto3 raises ClientError for things that are simply not configured, such as NoSuchBucketPolicy. A small helper turns the expected codes into None and re-raises the rest:

def call_or_none(fn, *ok_codes, **kw): try: return fn(**kw) except ClientError as e: if err_code(e) in ok_codes: return None raise 

The rules:

ID Severity Remediation
S3-PUBLIC-POLICY HIGH Delete the policy
S3-PUBLIC-ACL HIGH Set ACL to private
S3-NO-PUBLIC-ACCESS-BLOCK HIGH Enable all 4 flags
S3-NO-KMS-ENCRYPTION MEDIUM Set KMS default encryption
S3-NO-VERSIONING LOW Enable versioning
IAM-WILDCARD-ACTION HIGH Delete that inline policy
IAM-ADMIN-ATTACHED HIGH Detach it

The scanner only touches buckets and roles whose names start with --prefix (default sec-lab), and it refuses an empty one:

if not a.prefix: sys.exit("--prefix must not be empty (it protects other resources on the emulator)") 

A tool that can delete policies should not be one typo away from acting on everything on a shared emulator.

Problem 1: no GetBucketPolicyStatus

On real AWS you can ask whether a bucket policy is public. Floci does not implement GetBucketPolicyStatus, so the scanner parses the policy itself. The check is deliberately small:

def is_public_statement(st): if st.get("Effect") != "Allow" or st.get("Condition"): return False # conditioned statements may be narrowed; heuristic skips them (limitation) p = st.get("Principal") return p == "*" or (isinstance(p, dict) and "*" in as_list(p.get("AWS"))) 

An Allow to a wildcard principal with no Condition counts as public. It misses NotPrincipal, conditioned statements, access points and account-level Block Public Access. Those gaps are in the README.

Visual instruction: Capture this exact code section in VS Code using the OneDark-Pro theme. Use a readable font size and crop unnecessary editor UI.

Problem 2: encryption is always on

New S3 buckets are SSE-S3 encrypted by default, so a check for "is it encrypted" never fires. The useful question is whether the bucket uses a key you control, so the rule looks for aws:kms:

if "aws:kms" not in algos: ... out.append(finding("S3-NO-KMS-ENCRYPTION", "MEDIUM", res, "default encryption is not a customer-managed KMS key (SSE-S3 only)", fix_enc)) 

The fix needs a key, so fix_enc raises needs --kms-key-id if you forget one.

Scan, fix, re-scan

cd cmd\scripts Set-ExecutionPolicy -Scope Process Bypass .\01-start-floci.ps1 .\02-baseline.ps1 .\03-scan.ps1 # BEFORE: 5 finding(s) .\04-fix.ps1 # AFTER: 0 finding(s) 

Step 01 reuses whatever already serves port 4566, or starts Floci from compose.yaml. Step 03 is read-only and writes work\report-before.json. Step 04 creates a KMS key with alias alias/sec-lab if it does not exist, then runs:

& $Py "$Root\scanner\scanner.py" --prefix $Prefix --fix --kms-key-id alias/sec-lab --report "$Work\report-after.json" 

The scanner exits 1 when findings remain and 0 when clean, so the same command can gate a pipeline.

report-before.json with 5 findings next to report-after.json

The IAM fix is blunt on purpose. It deletes the offending inline policy and writes no replacement, which leaves the role deny-by-default. A good replacement needs real usage data, and a scanner should not guess it.

Alerting

A scanner you run by hand helps once. Step 05 builds the chain that tells you when something comes back:

aws logs put-metric-filter --log-group-name $LogGroup --filter-name high-findings --filter-pattern SECFINDING_HIGH ` --metric-transformations "metricName=HighFindings,metricNamespace=SecLab,metricValue=1" aws cloudwatch put-metric-alarm --alarm-name $Alarm --namespace SecLab --metric-name HighFindings --statistic Sum ` --period 60 --evaluation-periods 1 --threshold 1 --comparison-operator GreaterThanOrEqualToThreshold ` --treat-missing-data notBreaching --alarm-actions $tArn 

The scanner writes one SECFINDING_<SEVERITY> id=... resource=... detail=... line per finding to CloudWatch Logs, and publishes a summary to the SNS topic. The metric filter counts SECFINDING_HIGH lines, the alarm fires at Sum >= 1 per 60 seconds, and the topic delivers to an SQS queue that stands in for email. A single greppable prefix drives the whole alarm, so the scanner needs no custom metric code.

Drift

Step 06 re-runs the baseline to re-open the bucket and bring back the wildcard role, then scans with alerting on. The scan reports 3 findings, not 5, because KMS encryption and versioning from the fix stay on.

Steps 05 and 06 output: alerting wired, drift detected with 3 findings

Alert message waiting in the SQS inbox

Alarm sec-lab-high-findings on SecLab/HighFindings

Problem 3: the alarm lags the alert

The alarm evaluates on a 60 second period, so right after step 06 its state can read OK or INSUFFICIENT_DATA even though the message is already in the inbox. Re-run describe-alarms after a minute and it catches up.

Rebuild it in Terraform

Fixing a broken bucket is the reactive half. terraform/main.tf is the proactive half: the same environment, secure from the first apply. All four Block Public Access flags, a KMS key with aws:kms default encryption, versioning, and a role limited to reading objects from one bucket:

resource "aws_iam_role_policy" "app_read" { name = "read-data-bucket" role = aws_iam_role.app.id policy = jsonencode({ Version = "2012-10-17" Statement = [{ Effect = "Allow" Action = ["s3:GetObject"] Resource = "${aws_s3_bucket.data.arn}/*" }] }) } 

The provider block follows Floci's own compatibility tests: skip the credential and metadata checks, use path-style S3, and override the endpoints for S3, IAM, STS and KMS.

provider "aws" { region = "us-east-1" access_key = "test" secret_key = "test" skip_credentials_validation = true skip_metadata_api_check = true skip_requesting_account_id = true s3_use_path_style = true ... } 

07-terraform.ps1 runs terraform init and apply, then scans only the Terraform resources with prefix sec-lab-tf:

& $Py "$Root\scanner\scanner.py" --prefix "sec-lab-tf" --report "$Work\report-terraform.json" 

report-terraform.json comes back with "before": [] and "after": []. That makes the scanner a test for the Terraform code.

Terraform plan for the secure rebuild

Reports and policy files: report-drift.json, report-terraform.json, wildcard-policy.json, public-policy.json

What it does not prove

This part matters more than the green output:

  • Floci is not AWS. I checked behavior against Floci's docs and my own runs, not against real AWS, and it can differ.
  • Nothing is enforced. IAM enforcement and S3 auth are off by default, so the wildcard role does not actually grant anything. A permissions bug would be invisible here.
  • GuardDuty is management-plane only. There are no real threat findings. Every alert in the lab comes from my scanner.
  • The IAM coverage is narrow. Role inline policies and AdministratorAccess only. No users, groups, customer-managed policies, trust policies or permission boundaries.
  • Existing objects are not re-encrypted by the KMS fix.
  • Floci is in-memory. Restarting it wipes every resource, so you rerun from step 02.

So this is a teaching tool and a rehearsal of the workflow, not a substitute for Prowler, AWS Config or Security Hub. Steps 01 to 08 passed end to end on Windows 11, PowerShell 5.1, AWS CLI 2.39, Terraform 1.13 and Python 3.12.

Run it

Needs Docker Desktop, AWS CLI v2, Python 3 and PowerShell 5.1+. Terraform is only needed for step 07.

cd cmd\scripts Set-ExecutionPolicy -Scope Process Bypass .\01-start-floci.ps1 .\02-baseline.ps1 .\03-scan.ps1 .\04-fix.ps1 .\05-alerting.ps1 .\06-drift-alert.ps1 .\07-terraform.ps1 .\08-cleanup.ps1 

08-cleanup.ps1 -StopFloci also stops the Floci container this folder started.

Next

  • Cover IAM users and groups, and Resource: "*" analysis.
  • Replace the IAM delete-only fix with a least-privilege policy derived from access logs.
  • Check customer-managed policies and trust policies.

Repo: github.com/axololtos/local-cloud-security-lab. A star helps if this saved you from practicing on a real account, and you can follow me here on DEV for more.