- [x] [Capital One Data Breach](./assets/Capital%20One%20Data%20Breach%20—%202019.%20Introduction%20_%20by%20Tanner%20Jones%20_%20Nerd%20For%20Tech%20_%20Medium.pdf)
- [x] [Grant IAM User Access to Only One S3 Bucket](./assets/Grant%20IAM%20User%20Access%20to%20Only%20One%20S3%20Bucket%20_%20Medium.pdf)
* I think with terraform we can combine the two steps and use
`aws_ami_from_instance` to get the end result
(create an AMI from snapshot) for free. Otherwise I think
you would want to do [aws_ebs_snapshot](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ebs_snapshot) and then [aws_ami](https://registry.terraform.io/providers/hashicorp/aws/5.99.1/docs/resources/ami)
```sh
resource "aws_ami_from_instance" "ami_snapshot" {
name = "ami-snapshot-${formatdate("YYYY-MM-DD", timestamp())}"
- [x] How do you "version" a server with snapshots? Why is this useful?
* **Cattle, not pets**
This is useful for following the concept for treating your servers as
"cattle, not pets". Being able to keep versioned snapshots of your machines
means there's nothing special about your currently running server.
If it goes down (or you need to shoot it down), you can restore it on
another machine from an older snapshot.
Or, as another example, suppose you were tasked with installing a whole suite of tools
on an ec2 instance (ex: fail2ban, ClamAV, etc.). Then your boss tells
you the company needs the same setup for another 49 instances.
Having 1 AMI that contains all of those tools can save you from
re-running the same commands 50x times.
- [x] Launch a new instance from your AMI
Terraform is great. Terraform is life. This was really simple to do.
```sh
# Launch new instance from AMI
resource "aws_instance" "my_second_linux" {
instance_type = "t2.micro"
ami = aws_ami_from_instance.ami_snapshot.arn
security_groups = ["ssh-access-witch"]
tags = {
Name = "labs"
}
}
- [x] Convert to terraform
* Terraform files can be found [here](./terraform/main.tf)
## Reflection
* What I built
* A secured s3 bucket for secure content that can only be accessed via multi-factor authentication
Good for storing particularly sensitive information.
* A minimal HTML website served from an S3 bucket
* Challenges
* The stretch goal for setting up s3 + mfa was a bit of a pain:
* Groups cannot be used as the principal in a trust relationship so to get things
working I added the trust relationship to my user's ARN instead.
I prodded ChatGPT on a more practical way to do this (this wouldn't scale with 100s of users, onboarding/offboarding etc.) and had to go back and fix how the policies worked.
* Issues between setting up Cloudflare -> CloudFront -> s3 bucket
* I think adding an extra service (Cloudflare, where I host my domain) added a little bit of complexity, though
my main issue was figuring out how to set up the ACM cert -> CloudFront distribution -> S3.
Most of the instructions I was able to parse through with ChatGPT -- I have to say I had a much
better reading through those instructions than with the official AWS docs, which led me through
nested links (understandably, because there seem to be multiple ways of doing everything).
* Security concerns
Scale and security at scale
I started out this lab doing "click-ops", and I noticed while testing connections
that there was just a lot of trial and error in setting up permissions.
My process seemed to be: OK, this seems pretty straightforward, let's just add the policy.
But after adding the policy it looked like there was a cascade of errors where I
forgot to add additional permissions or trust relationships that weren't immediately
obvious until I actually went through the error logs one by one.
Once everything got set up via click-ops and imported to terraform though, repeating
the same steps via Terraform was *very easy*.
I think putting everything down into code really helps to self-document
the steps it takes to get a fully functioning setup.
## Terms
### Identity Access Management
```mermaid
graph LR
IAMPolicy -- attaches to --> IAMIdentity
ExplainIAMIdentity[users, groups of users, roles, AWS resources]:::aside