Skip to content

Commit

Permalink
[feature] Adds support for SAML trust relationship to existing roles (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Lopez authored Nov 27, 2019
1 parent 8bc7c98 commit c59aa0e
Show file tree
Hide file tree
Showing 27 changed files with 345 additions and 88 deletions.
3 changes: 2 additions & 1 deletion aws-iam-role-cloudfront-poweruser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ This module will create a role which is granted poweruser control over AWS Cloud
| iam\_path | | string | `"/"` | no |
| role\_name | Name of the role to create | string | n/a | yes |
| s3\_bucket\_prefixes | Limits role permissions to buckets with specific prefixes. Empty for all buckets. | list | `<list>` | no |
| source\_account\_id | AWS Account that can assume this role. | string | n/a | yes |
| source\_account\_id | The source AWS account to establish a trust relationship. Ignored if empty or not provided. | string | '' | no |
| saml\_idp\_arn | The AWS SAML IDP arn to establish a trust relationship. Ignored if empty or not provided. | string | '' | no |

## Outputs

Expand Down
30 changes: 25 additions & 5 deletions aws-iam-role-cloudfront-poweruser/main.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
data "aws_iam_policy_document" "assume-role" {
statement {
principals {
type = "AWS"
identifiers = ["arn:aws:iam::${var.source_account_id}:root"]
dynamic "statement" {
for_each = compact([var.source_account_id])
content {
principals {
type = "AWS"
identifiers = ["arn:aws:iam::${var.source_account_id}:root"]
}
actions = ["sts:AssumeRole"]
}
}

dynamic "statement" {
for_each = compact([var.saml_idp_arn])
content {
principals {
type = "Federated"
identifiers = ["${var.saml_idp_arn}"]
}

actions = ["sts:AssumeRole"]
actions = ["sts:AssumeRoleWithSAML"]

condition {
test = "StringEquals"
variable = "SAML:aud"
values = ["https://signin.aws.amazon.com/saml"]
}
}
}
}

Expand Down
17 changes: 12 additions & 5 deletions aws-iam-role-cloudfront-poweruser/variables.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
variable "source_account_id" {
type = "string"
description = "AWS Account that can assume this role."
}

variable "role_name" {
type = "string"
description = "Name of the role to create"
Expand All @@ -21,3 +16,15 @@ variable "iam_path" {
type = "string"
default = "/"
}

variable "source_account_id" {
type = "string"
default = ""
description = "The source AWS account to establish a trust relationship. Ignored if empty or not provided."
}

variable "saml_idp_arn" {
type = "string"
default = ""
description = "The AWS SAML IDP arn to establish a trust relationship. Ignored if empty or not provided."
}
3 changes: 2 additions & 1 deletion aws-iam-role-crossacct/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ module "group" {
|------|-------------|:----:|:-----:|:-----:|
| iam\_path | The IAM path to put this role in. | string | `"/"` | no |
| role\_name | The name of the role. | string | n/a | yes |
| source\_account\_id | The AWS account id that should be able to assume this role. | string | n/a | yes |
| source\_account\_id | The source AWS account to establish a trust relationship. Ignored if empty or not provided. | string | '' | no |
| saml\_idp\_arn | The AWS SAML IDP arn to establish a trust relationship. Ignored if empty or not provided. | string | '' | no |

## Outputs

Expand Down
30 changes: 25 additions & 5 deletions aws-iam-role-crossacct/main.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
data "aws_iam_policy_document" "assume-role" {
statement {
principals {
type = "AWS"
identifiers = ["arn:aws:iam::${var.source_account_id}:root"]
dynamic "statement" {
for_each = compact([var.source_account_id])
content {
principals {
type = "AWS"
identifiers = ["arn:aws:iam::${var.source_account_id}:root"]
}
actions = ["sts:AssumeRole"]
}
}

dynamic "statement" {
for_each = compact([var.saml_idp_arn])
content {
principals {
type = "Federated"
identifiers = ["${var.saml_idp_arn}"]
}

actions = ["sts:AssumeRole"]
actions = ["sts:AssumeRoleWithSAML"]

condition {
test = "StringEquals"
variable = "SAML:aud"
values = ["https://signin.aws.amazon.com/saml"]
}
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion aws-iam-role-crossacct/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ variable "iam_path" {
}

variable "source_account_id" {
description = "The AWS account id that should be able to assume this role."
type = "string"
default = ""
description = "The source AWS account to establish a trust relationship. Ignored if empty or not provided."
}

variable "saml_idp_arn" {
type = "string"
default = ""
description = "The AWS SAML IDP arn to establish a trust relationship. Ignored if empty or not provided."
}
3 changes: 2 additions & 1 deletion aws-iam-role-ec2-poweruser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ module "ec2-poweruser" {
|------|-------------|:----:|:-----:|:-----:|
| iam\_path | | string | `"/"` | no |
| role\_name | | string | n/a | yes |
| source\_account\_id | | string | n/a | yes |
| source\_account\_id | The source AWS account to establish a trust relationship. Ignored if empty or not provided. | string | '' | no |
| saml\_idp\_arn | The AWS SAML IDP arn to establish a trust relationship. Ignored if empty or not provided. | string | '' | no |

## Outputs

Expand Down
30 changes: 25 additions & 5 deletions aws-iam-role-ec2-poweruser/main.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
data "aws_iam_policy_document" "assume-role" {
statement {
principals {
type = "AWS"
identifiers = ["arn:aws:iam::${var.source_account_id}:root"]
dynamic "statement" {
for_each = compact([var.source_account_id])
content {
principals {
type = "AWS"
identifiers = ["arn:aws:iam::${var.source_account_id}:root"]
}
actions = ["sts:AssumeRole"]
}
}

dynamic "statement" {
for_each = compact([var.saml_idp_arn])
content {
principals {
type = "Federated"
identifiers = ["${var.saml_idp_arn}"]
}

actions = ["sts:AssumeRole"]
actions = ["sts:AssumeRoleWithSAML"]

condition {
test = "StringEquals"
variable = "SAML:aud"
values = ["https://signin.aws.amazon.com/saml"]
}
}
}
}

Expand Down
16 changes: 12 additions & 4 deletions aws-iam-role-ec2-poweruser/variables.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
variable "source_account_id" {
type = "string"
}

variable "role_name" {
type = "string"
}
Expand All @@ -10,3 +6,15 @@ variable "iam_path" {
type = "string"
default = "/"
}

variable "source_account_id" {
type = "string"
default = ""
description = "The source AWS account to establish a trust relationship. Ignored if empty or not provided."
}

variable "saml_idp_arn" {
type = "string"
default = ""
description = "The AWS SAML IDP arn to establish a trust relationship. Ignored if empty or not provided."
}
3 changes: 2 additions & 1 deletion aws-iam-role-ecs-poweruser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ module "ec2-poweruser" {
|------|-------------|:----:|:-----:|:-----:|
| iam\_path | | string | `"/"` | no |
| role\_name | | string | n/a | yes |
| source\_account\_id | | string | n/a | yes |
| source\_account\_id | The source AWS account to establish a trust relationship. Ignored if empty or not provided. | string | '' | no |
| saml\_idp\_arn | The AWS SAML IDP arn to establish a trust relationship. Ignored if empty or not provided. | string | '' | no |

## Outputs

Expand Down
30 changes: 25 additions & 5 deletions aws-iam-role-ecs-poweruser/main.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
data "aws_iam_policy_document" "assume-role" {
statement {
principals {
type = "AWS"
identifiers = ["arn:aws:iam::${var.source_account_id}:root"]
dynamic "statement" {
for_each = compact([var.source_account_id])
content {
principals {
type = "AWS"
identifiers = ["arn:aws:iam::${var.source_account_id}:root"]
}
actions = ["sts:AssumeRole"]
}
}

dynamic "statement" {
for_each = compact([var.saml_idp_arn])
content {
principals {
type = "Federated"
identifiers = ["${var.saml_idp_arn}"]
}

actions = ["sts:AssumeRole"]
actions = ["sts:AssumeRoleWithSAML"]

condition {
test = "StringEquals"
variable = "SAML:aud"
values = ["https://signin.aws.amazon.com/saml"]
}
}
}
}

Expand Down
16 changes: 12 additions & 4 deletions aws-iam-role-ecs-poweruser/variables.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
variable "source_account_id" {
type = "string"
}

variable "role_name" {
type = "string"
}
Expand All @@ -10,3 +6,15 @@ variable "iam_path" {
type = "string"
default = "/"
}

variable "source_account_id" {
type = "string"
default = ""
description = "The source AWS account to establish a trust relationship. Ignored if empty or not provided."
}

variable "saml_idp_arn" {
type = "string"
default = ""
description = "The AWS SAML IDP arn to establish a trust relationship. Ignored if empty or not provided."
}
3 changes: 2 additions & 1 deletion aws-iam-role-infraci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ Creates a role useful for running `terraform plan` in CI jobs.
|------|-------------|:----:|:-----:|:-----:|
| iam\_path | | string | `"/"` | no |
| role\_name | | string | `"infraci"` | no |
| source\_account\_id | | string | n/a | yes |
| terraform\_state\_lock\_dynamodb\_arns | "A list of unique identifiers (ARNs) of state file DynamoDB tables" | string | `[]` | yes |
| source\_account\_id | The source AWS account to establish a trust relationship. Ignored if empty or not provided. | string | '' | no |
| saml\_idp\_arn | The AWS SAML IDP arn to establish a trust relationship. Ignored if empty or not provided. | string | '' | no |

## Outputs

Expand Down
30 changes: 25 additions & 5 deletions aws-iam-role-infraci/main.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
data "aws_iam_policy_document" "assume-role" {
statement {
principals {
type = "AWS"
identifiers = ["arn:aws:iam::${var.source_account_id}:root"]
dynamic "statement" {
for_each = compact([var.source_account_id])
content {
principals {
type = "AWS"
identifiers = ["arn:aws:iam::${var.source_account_id}:root"]
}
actions = ["sts:AssumeRole"]
}
}

actions = ["sts:AssumeRole"]
dynamic "statement" {
for_each = compact([var.saml_idp_arn])
content {
principals {
type = "Federated"
identifiers = ["${var.saml_idp_arn}"]
}

actions = ["sts:AssumeRoleWithSAML"]

condition {
test = "StringEquals"
variable = "SAML:aud"
values = ["https://signin.aws.amazon.com/saml"]
}
}
}
}

Expand Down
16 changes: 12 additions & 4 deletions aws-iam-role-infraci/variables.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
variable "source_account_id" {
type = "string"
}

variable "role_name" {
default = "infraci"
}
Expand All @@ -15,3 +11,15 @@ variable "terraform_state_lock_dynamodb_arns" {
default = []
description = "ARNs of the state file DynamoDB tables"
}

variable "source_account_id" {
type = "string"
default = ""
description = "The source AWS account to establish a trust relationship. Ignored if empty or not provided."
}

variable "saml_idp_arn" {
type = "string"
default = ""
description = "The AWS SAML IDP arn to establish a trust relationship. Ignored if empty or not provided."
}
5 changes: 3 additions & 2 deletions aws-iam-role-poweruser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module "group" {
# defaults to "poweruser"
role_name = "..."
# The id of the other AWS account that can assume this role.
# The id of the other AWS account that can assume this role.
source_account_id = "..."
}
```
Expand All @@ -23,7 +23,8 @@ module "group" {
|------|-------------|:----:|:-----:|:-----:|
| iam\_path | | string | `"/"` | no |
| role\_name | | string | `"poweruser"` | no |
| source\_account\_id | | string | n/a | yes |
| source\_account\_id | The source AWS account to establish a trust relationship. Ignored if empty or not provided. | string | '' | no |
| saml\_idp\_arn | The AWS SAML IDP arn to establish a trust relationship. Ignored if empty or not provided. | string | '' | no |

## Outputs

Expand Down
Loading

0 comments on commit c59aa0e

Please sign in to comment.