AWS Organizations + SCP - Allow ONLY Infra as Code (i.e. no GUI!)

I’m creating a new organization for a company. Underneath that org I’ve created OUs for various environments like Prod, Staging, QA, UAT, Sandbox, POC, etc etc.

One thing I want to enforce is the creation of resources only via code, i.e. Infrastructure as Code. That way I can avoid having some developer create an AWS resource in the GUI and click around till it works, then forget how he/she got it to work when they are reproducing it for another process. Keeping everyone on IaC is my goal!

Can I enforce this via SCP (or what else?) to only allow creation (etc.) of AWS resources by code only? All OUs except the Sandbox and POC OUs, since those should be the place for experimenting and using the GUI to create/delete/modify AWS resources.

Yes, your IAC tools will need to use an IAM role to deploy resources. You can set your SCPs to Deny your protected services unless they are created by your “trusted” IAM roles (Admins, IAC tooling, etc)

The correct way to do this would be through a CI/CD pipeline that deploys IaC on behalf of developers rather than giving them direct AWS access for certain permissions/actions. Mind you this is an oversimplified explanation and won’t work for console-only actions, developers who are not familiar with AWS and Cloudformation, or an environment where this restriction did not exist and now suddenly will as if development workflows are an SCP you can turn on and off.

Don’t give anyone accounts that have UI access, only api keys

so how would i do that…

first, u/allisbright is right and people will be able to “click around” using the CLI. so you’ll want to prohibit that too.

one option is indeed remove their rights to create anything and make them use a delivery system instead.

another would be an IAM policy (session policy, user/role policy, SCP - depends on the auth model).

in both cases, especially if you’re planning on allowing web console for the read-only operations, you’ll have to maintain a ridiculously complicated list of allowed/prohibited operations. maintain as in, update it on weekly basis. and you’ll hit the character limit of SCP very soon. and the character limit of the IAM policy equally inevitably.

and your users will hate you.

on the other hand what you have is a cultural problem. and that can be solved by … culture and, let’s call it, traditions. introduce code reviews. introduce project readiness checks. introduce disaster-practice exercises or even chaos monkey.

you have a noble goal but prohibition will only lead to people hating IaC.

Use AWS config to require resources to have a specific tag, make your IAC create that tag on all resources like

terraform=true

That way you can have a report on anything missing the tag so you know what wasn’t created with IAC. This way if you create something manually you can then use the aws config report to identify those items and add them to your IAC where necessary. Somethings will need to be setup manually before IAC can take control such as creating the cicd iam user that will apply the changes from your build platform on git pushes. Also the S3 bucket that will store your state. In fact you can even make your IAC create the AWS config rules for the tag.

If you’re cool with Cloudformation you can do things like use the calledvia condition to deny certain actions unless it was calledvia Cloudformation.

Or you could force people to pass a role to Cloudformation to be able to make any changes.

But it ultimately boils down to the stuff other folks are saying - encouraging code reviews and cicd so people don’t get upset about any of the above things.

You can make user accounts as cli only. And you can make service catalogs so people who log in to console can only use the services you allow.

But if iac is what you want then you’ll probably want to allow only the ci tools to deploy to aws.

What about generating the IAM credentials for the environment that you only want to allow IaC with only programmatic access and restricting it to cloudformation?

Then any other environment you can have programmatic, console and possibly a power user policy so they can play around with aws.

May be attach the Org SCP with an explicit deny for all iam:CreateAccessKey actions with a condion that excludes StringNotEquals for aws:username with a value of the excepon list. Also, deploy AWS Config rules to all accounts in Org that match the IAM policies.

SCPs apply to all users and roles in account to which they belong. Since SCPs also operate with implicit denials, there is no way to attach one to an account that only allows certain users to do things while restricting others. I stand corrected!

I would still create a break glass account/role. Nothing worse than having shit go down and having to troubleshoot it all via the CLI while people are screaming.

I’m sorry, but this is not correct. You apply a condition to the deny statement to create an allow list to the protected service calls.

For example:

{
“action”: [
“s3:Create Bucket”
],
“Condition”: {
“ArnNotLike”: {
“aws:PrincipalARN”: [
“arn:aws:iam:::role/IAC-role",
"arn:aws:iam::
:role/admin-role”,
]
}
},
“Effect”: “Deny”,
“Resource”: [“*”]
}

Ah - good call out! Didn’t think about that pattern of using the ARN in the condition for evaluation.

If you’re using CloudFormation, you can create roles for the stacks to actually change things, and then give your devs iam:PassRole permissions on the roles so they can get handed off to CloudFormation but not assumed.