GSA/BSP_Mode1_Reporting

Name: BSP_Mode1_Reporting

Owner: U.S. General Services Administration

Description: Lambda functions for creating and Emailing reports for BSP Mode1 AWS Accounts

Created: 2018-02-06 16:44:27.0

Updated: 2018-05-19 17:58:19.0

Pushed: 2018-05-04 16:04:36.0

Homepage: null

Size: 95

Language: HCL

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

BSP Mode1 Reporting CircleCI

AMI report using Lambda functions and Amazon SES

Diagram

There are two Lambda functions. One does a DescribeImages query for each tenant account, formats the data into CSV and saves the CSV to an S3 bucket. The second Lambda function creates a multi-part MIME Email, attaches the report from the S3 bucket and sends it via Amazon Simple Email Service (SES) to a list of recipients.

IAM Roles and Policies
Tenant Account Role

Cross-account permissions are required for the Lambda function in the “management” account to query the “tenant” accounts. This is done by creating an IAM role with delegation to the management account. See the Terraform configuration for details.

Tenant Account Policy

Attached to the tenant IAM role is a single policy with ec2:DescribeImages action allowed.

AMI Report Lambda Function IAM Policy

The Lambda function which creates the AMI Report is assinged an IAM role in the management account with a single policy attached that allows it to perform all of its necessary functions.

ec2:DescribeImages

Allows the Lambda function to query the Images in the management account.

s3:PutObject

Allows the Lambda function to write the CSV report to an S3 bucket

sts:AssumeRole

Allows the Lambda function to assume the delegated tenant IAM role and query DescribeImages in the tenant accounts.

kms:Encrypt

Allows the Lambda function to encrypt the CSV report it saves to the S3 bucket.

logs:CreateLogGroup, etc.

logs:CreateLogGroup, logs:CreateLogStream and logs:PutLogEvents actions are required by all Lambda functions to log their actions.

Report Emailing Lambda Function IAM Policy

The Lambda function which Emails the AMI Report is assinged an IAM role in the management account with a single policy attached that allows it to perform all of its necessary functions.

ses:SendRawEmail

Allows Lambda function to send Email via Amazon SES.

s3:GetObject

Allows Lambda function to read the report from an Amazon S3 bucket.

kms:Decrypt

Allows the Lambda function to decrypt the CSV report.

logs:CreateLogGroup, etc.

logs:CreateLogGroup, logs:CreateLogStream and logs:PutLogEvents actions are required by all Lambda functions to log their actions.

Terraform Variables
Tenants

In the tenants sub-directory, there is a terraform file to configure the cross-account IAM role and policy. To configure this:

For each tenant account, you will need to configure your AWS_PROFILE environment variable and perform a terraform apply for each account. You will need AWS credentials for each account with administrator privileges to apply the Terraform configuration.

TODO

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.