IaC (Infrastructure as Code) IAM is a set of AWS CloudFormation templates for quickly setting up cross-account access.
IaC AWS IAM is a set of example AWS CloudFormation templates for quickly setting up infrastructure pipelines for Cross-Account Access using AWS CodePipeline and GitHub repo as the pipeline trigger/source. Using this setup, IAM users(human users intended) only have to be created once in the jump account(manager account) and then can assume roles to other AWS accounts owned by the same owner(think AWS Organizations).
This repository contains cloudformation templates for setting up: IAM Users, IAM Groups and IAM Roles for those who:
User Login: Login to manager account -> Assume role to a managed account based upon group membership
iac-aws-iam
│
├── README.md
├── managed-accounts
│ └── project1-production
│ ├── pipeline.yaml
│ └── roles.yaml
└── manager-account
├── groups-admin.yaml
├── pipeline.yaml
└── users.yaml
Following two types of pipelines will be setup using only the already defined resources in templates:
AssumeRole
of the relevant role will not point to a non-existent resource. Each AWS account should have its own pipeline for setting up roles.project1-production
as desired and add all the aws accounts as directories under: managed-accounts
TemplatePath
values accordingly in pipeline.yaml.012345678901
in project1-production
and subsequently for all managed accounts you want to use.managed-accounts/project1-production/pipeline.yaml
which will setup the roles stack itself. See this for how to do that.groups-admin.yaml
. Create more group templates if desired using this file and name appropriately e.g. groups-developer.yaml
or groups-readonly.yaml
. Also change project names as desired and adjust GroupName
and Output Export values accordingly.Action
under Group-Stage
in the pipeline with correct TemplatePath
for each new template added(assuming more group templates were created in above step).users.yaml
as desired and adjust passwords and group memberships. GroupName
attribute is being imported from the IAM groups stack so the names must match. manager-account/pipeline.yaml
and provide GuitHub access token again.Once the pipelines finish, the users should be able to login using their one-time passwords and can then assume roles into various AWS accounts as defined by the IAM groups they are members of.
Here are some documentation links which can be used as references:
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-codepipeline-pipeline.html
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/best-practices.html
https://docs.aws.amazon.com/codepipeline/latest/userguidereference-pipeline-structure.html#pipeline-requirements