Skip to content

Commit 06d0bd0

Browse files
gsoltisGreg Soltisvikrum
authored
Document permissions required, include terraform module (#9)
* Add terraform module for role to run rpCheckup * Add shell script to run built rpCheckup with an assumed role * Add permissions documentation to the readme * Added README in terraform/ to include instructions on how to use it. * Add check for aws cli to run_with_role.sh Co-authored-by: Greg Soltis <greg@goldfiglabs.ciom> Co-authored-by: Vikrum Nijjar <vsnijjar@gmail.com>
1 parent b0093cd commit 06d0bd0

File tree

7 files changed

+147
-0
lines changed

7 files changed

+147
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,24 @@ Run `./rpCheckup` and view the generated report found in `output/`.
7474

7575
<img width="800" alt="Screen Shot 2021-03-01 at 12 22 36 PM" src="https://user-images.githubusercontent.com/291215/109732631-61122780-7b72-11eb-8f6d-1b51758d2f19.png">
7676

77+
## Permissions
78+
79+
rpCheckup needs read-only access to portions of your AWS account.
80+
A principal (user/role/group) needs the following to make full use
81+
of rpCheckup:
82+
83+
```
84+
AWS Managed Policy: arn:aws:iam::aws:policy/SecurityAudit
85+
AWS Managed Policy: arn:aws:iam::aws:policy/job-function/ViewOnlyAccess
86+
Additional Permissions:
87+
"apigateway:GetRestApis",
88+
"efs:Describe*",
89+
"acm-pca:List*",
90+
"acm-pca:GetPolicy"
91+
```
92+
93+
Additionally, there is a [Terraform Module](./terraform) for creating a role with the appropriate credentials, as well as a [shell script](./run_with_role.sh) for running with an assumed role (requires running [./build.sh](./build.sh) first).
94+
7795
## Overview
7896
rpCheckup uses [goldfiglabs/introspector](https://github.com/goldfiglabs/introspector) to snapshot the configuration of your AWS account. rpCheckup runs SQL queries to generate findings based on this snapshot. Introspector does the heavy lifting of importing and normalizing the configurations while rpCheckup is responsible for querying and report generation.
7997

run_with_role.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
if [[ -z $(which jq) ]]; then
6+
echo "script requires jq"
7+
exit 1
8+
fi
9+
10+
if [[ -z $(which aws) ]]; then
11+
echo "script requires aws cli"
12+
exit 1
13+
fi
14+
15+
if [[ -z $1 ]]; then
16+
echo "usage: ./run_with_role.sh <ROLE_ARN> [<SESSION_NAME>]"
17+
exit 2
18+
fi
19+
20+
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
21+
bin="rpCheckup_linux"
22+
elif [[ "$OSTYPE" == "darwin"* ]]; then
23+
arch=$(uname -m)
24+
if [[ $arch == "arm64" ]]; then
25+
bin="rpCheckup_darwin_arm64"
26+
else
27+
bin="rpCheckup_darwin_amd64"
28+
fi
29+
else
30+
echo "Unsupported OS ${OSTYPE}"
31+
exit 3
32+
fi
33+
34+
ROLE_ARN=$1
35+
SESSION_NAME=${2:-rpCheckupSession}
36+
37+
cmd="aws sts assume-role --role-arn ${ROLE_ARN} --role-session-name ${SESSION_NAME}"
38+
creds=$($cmd)
39+
accessKeyId=$(echo $creds | jq -r '.Credentials.AccessKeyId')
40+
secretKey=$(echo $creds | jq -r '.Credentials.SecretAccessKey')
41+
sessionToken=$(echo $creds | jq -r '.Credentials.SessionToken')
42+
43+
AWS_ACCESS_KEY_ID=$accessKeyId \
44+
AWS_SECRET_ACCESS_KEY=$secretKey \
45+
AWS_SESSION_TOKEN=$sessionToken \
46+
dist/${bin}

terraform/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.terraform*
2+
*.tfstate

terraform/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# rpCheckup Terraform permissions role
2+
3+
This Terraform module creates a role in the AWS account you are currently signed in to. Review the permissions in `main.tf`.
4+
5+
Use Terraform to create the role in your account:
6+
7+
1. terraform init
8+
2. terraform plan
9+
3. terraform apply
10+
11+
Upon success, the Terraform run will output an ARN. This can be used by `run_with_role.sh` to invoke rpCheckup with the newly created role.

terraform/main.tf

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
provider "aws" {
2+
region = var.region
3+
}
4+
5+
data "aws_caller_identity" "current" {}
6+
7+
resource "aws_iam_role" "rpcheckup" {
8+
name = var.role_name
9+
assume_role_policy = <<EOF
10+
{
11+
"Version": "2012-10-17",
12+
"Statement": [
13+
{
14+
"Action": "sts:AssumeRole",
15+
"Principal": {
16+
"AWS": "${data.aws_caller_identity.current.account_id}"
17+
},
18+
"Effect": "Allow",
19+
"Sid": ""
20+
}
21+
]
22+
}
23+
EOF
24+
}
25+
26+
resource "aws_iam_policy" "rpcheckup" {
27+
name = "rpCheckupExtraPermissions"
28+
policy = jsonencode(
29+
{
30+
"Statement" = [
31+
{
32+
Action = [
33+
"apigateway:GetRestApis",
34+
"efs:Describe*",
35+
"acm-pca:List*",
36+
"acm-pca:GetPolicy"
37+
],
38+
Effect = "Allow",
39+
Resource = "*"
40+
}
41+
],
42+
Version = "2012-10-17"
43+
}
44+
)
45+
}
46+
47+
resource "aws_iam_role_policy_attachment" "extra_permissions" {
48+
role = aws_iam_role.rpcheckup.name
49+
policy_arn = aws_iam_policy.rpcheckup.arn
50+
}
51+
52+
resource "aws_iam_role_policy_attachment" "security_audit" {
53+
role = aws_iam_role.rpcheckup.name
54+
policy_arn = "arn:aws:iam::aws:policy/SecurityAudit"
55+
}
56+
57+
resource "aws_iam_role_policy_attachment" "view_only" {
58+
role = aws_iam_role.rpcheckup.name
59+
policy_arn = "arn:aws:iam::aws:policy/job-function/ViewOnlyAccess"
60+
}

terraform/outputs.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
output "arn" {
2+
value = aws_iam_role.rpcheckup.arn
3+
}

terraform/variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
variable "role_name" {
2+
default = "rpCheckup"
3+
}
4+
5+
variable "region" {
6+
default = "us-east-1"
7+
}

0 commit comments

Comments
 (0)