← Back to the blog

NOTES FROM THE LAB

Building and Verifying an AWS S3 Security Baseline with Terraform

I built an S3 security baseline with Terraform, verified the deployed settings directly through AWS APIs, and removed the resources after publishing sanitized evidence. The most useful lesson came from a small mistake: Terraform accepted my code, but the deployed tags did not match the requirements.

This was Lab 2.3 of the GRCEngClub CGEP labs. The lab took me through the full workflow: setting up the repository, writing Terraform, troubleshooting deployment issues, collecting evidence, and cleaning up the resources. It gave me a practical way to explore cloud security controls in a learning environment.

Outcome: two buckets deployed and checked, tag mistakes corrected, no drift found, evidence published, and both buckets confirmed deleted.

View the code and evidence on GitHub · Independent AWS verification · Cleanup confirmation

The problem I wanted to solve

Writing a security requirement is one task. Showing that a deployed resource actually follows it is another. I wanted to connect a small set of control objectives to infrastructure code, verify the results independently, and keep evidence that a reviewer could inspect after the environment was gone.

The tools were Terraform, the AWS CLI, Git Bash, VS Code, GitHub, and a small Python evidence-processing script. I used a separate IAM lab user with MFA and temporary CLI credentials. That user had administrator permissions in the dedicated learning account; it was separate from root, but it was not a least-privilege deployment identity.

What I built

The configuration created a primary data bucket and a separate destination for server access logs in us-east-1:

Terraform configuration
        |
        +-- Primary data bucket
        |     AES256 encryption
        |     Versioning enabled
        |     Public access blocked
        |     Required tags
        |
        +-- Access-log destination
              AES256 encryption
              Public access blocked
              Required tags
              Log-delivery permissions

Primary bucket -- server access logs --> log bucket / access-logs/

Terraform managed 11 resources, including the local random suffix used in the bucket names. Several resources configure different aspects of the same bucket; this was not 11 separate buckets or services.

The guide maps the safeguards to selected NIST SP 800-53 controls:

Control What the lab implemented What I could establish
SC-28 SSE-S3/AES256 default encryption on both buckets AWS returned the expected encryption settings.
AC-3 All four S3 Block Public Access settings on both buckets All four flags were enabled; this does not replace broader IAM access review.
CM-6 Required tags and primary-bucket versioning Tags matched the intended names and values, and primary versioning was enabled.
AU-3 / AU-6 Server access logging to a separate bucket The destination, prefix, ownership setting, and delivery permissions were configured. This did not establish a complete audit-review process.

Deploy, then verify independently

I formatted and validated the configuration, checked the active AWS identity, and reviewed a saved plan showing 11 additions with no changes or deletions. I then applied that plan.

After deployment, I used AWS API queries to check encryption, versioning, public-access settings, and tags. I also checked the logging destination and prefix, the log bucket’s ownership controls, and the log-delivery group’s WRITE and READ_ACP permissions.

This separated two questions: Does Terraform accept the configuration? Does AWS report the settings I intended? Both matter, and they are not interchangeable.

Two issues that changed how I approached verification

Valid code can still contain incorrect tags

My original tag keys included project instead of Project and ComplianceScpe instead of ComplianceScope. The code validated and deployed, but the AWS tag query exposed the mismatch.

I corrected the Terraform source, reviewed a plan containing two in-place bucket updates, applied it, and queried AWS again. A final plan reported no changes. The fix stayed in code rather than becoming an undocumented console edit.

The spelling mattered because later checks can depend on exact tag keys. It did not mean the bucket encryption had failed; it meant the configuration did not fully match the lab’s naming requirements.

A successful CLI login did not mean Terraform could use it

The AWS CLI authenticated successfully through aws login, but the AWS provider version used by the guide could not directly consume that login session. Planning failed with a credential-source error.

I kept the browser-login profile and added a separate profile using credential_process. That let Terraform obtain temporary credentials through the AWS CLI without placing access keys in the repository. I verified the identity again before retrying the plan.

Evidence I could publish responsibly

Raw Terraform JSON can contain sensitive values. Exporting state to a file named state.json does not make it safe to publish.

I kept the raw plan and state exports in an ignored local directory. A Python script selected known configuration fields for public extracts, leaving out account and bucket identifiers, outputs, and ACL owner details. The published evidence includes those extracts, independent AWS verification results, a hash manifest, and the final cleanup confirmation.

There are important limits to those artifacts. The plan extract comes from a post-deployment, post-correction no-change plan, not the original pre-deployment plan. The extracts also use a custom structure, so future policies expecting native Terraform JSON will need the private originals or an adapted input. The hashes help detect changes relative to the manifest; they do not prove authenticity by themselves.

What this lab does not prove

The implementation follows the guide’s ACL-based log-delivery approach, with an explicit dependency so logging waits for the destination permissions. AWS recommends a bucket policy for new log-delivery configurations, which is a useful improvement for a future iteration.

The guide’s prose says both buckets have versioning, but its code enables it only on the primary bucket. My implementation follows the code, and the documentation records that distinction.

No log objects were present during the initial independent verification. One object appeared under access-logs/ before cleanup and was removed during teardown. Its record contents were not reviewed, so I do not claim complete request coverage or operational audit review. S3 server access logging is best-effort.

These safeguards support control objectives. They do not, on their own, establish full NIST compliance.

Finish the lifecycle

After the code and sanitized evidence were pushed to GitHub and the remote commit was verified, logging was disabled and the generated log object was removed. A reviewed destroy plan removed the remaining 10 resources. The final checks confirmed an empty Terraform state and both buckets absent from the account’s owned-bucket list.

The evidence remained available after the infrastructure was gone. That was the outcome I wanted: a small cloud deployment with a documented path from requirements to code, live verification, correction, and cleanup.

For future labs, I want to carry forward three habits: verify exact requirements through the service API, treat evidence exports as potentially sensitive, and make teardown part of completion rather than a reminder for later.

References

Share this article