|
| 1 | +resource "aws_iam_account_password_policy" "strict" { |
| 2 | + minimum_password_length = 32 |
| 3 | + require_lowercase_characters = true |
| 4 | + require_numbers = true |
| 5 | + require_uppercase_characters = true |
| 6 | + require_symbols = true |
| 7 | + allow_users_to_change_password = true |
| 8 | + |
| 9 | + password_reuse_prevention = 24 |
| 10 | + max_password_age = 90 |
| 11 | +} |
| 12 | + |
| 13 | +# Role to be used for any administrative tasks |
| 14 | +data "aws_iam_policy_document" "administrator_assume_role_policy" { |
| 15 | + statement { |
| 16 | + actions = ["sts:AssumeRole"] |
| 17 | + |
| 18 | + principals { |
| 19 | + type = "AWS" |
| 20 | + identifiers = [aws_iam_user.ckdake.arn] |
| 21 | + } |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +resource "aws_iam_role" "administrator" { |
| 26 | + name = "administrator" |
| 27 | + assume_role_policy = data.aws_iam_policy_document.administrator_assume_role_policy.json |
| 28 | +} |
| 29 | + |
| 30 | +resource "aws_iam_role_policy_attachment" "administrator_gets_administrator" { |
| 31 | + role = aws_iam_role.administrator.id |
| 32 | + policy_arn = "arn:aws:iam::aws:policy/AdministratorAccess" |
| 33 | +} |
| 34 | + |
| 35 | +# Group of users allowed to assume the administrator role |
| 36 | +# TODO(ckdake): figure out the right way to enforce MFA with auth pattern |
| 37 | +# tfsec:ignore:aws-iam-enforce-group-mfa |
| 38 | +resource "aws_iam_group" "administrators" { |
| 39 | + name = "administrators" |
| 40 | +} |
| 41 | + |
| 42 | +resource "aws_iam_group_membership" "administrators" { |
| 43 | + name = "administrators" |
| 44 | + group = aws_iam_group.administrators.name |
| 45 | + |
| 46 | + users = [ |
| 47 | + aws_iam_user.ckdake.name, |
| 48 | + ] |
| 49 | +} |
| 50 | + |
| 51 | +resource "aws_iam_policy" "admin_assumption" { |
| 52 | + name = "admin-assumption" |
| 53 | + description = "allow assuming the admin role" |
| 54 | + policy = jsonencode({ |
| 55 | + Version = "2012-10-17", |
| 56 | + Statement = [ |
| 57 | + { |
| 58 | + Effect = "Allow", |
| 59 | + Action = "sts:AssumeRole", |
| 60 | + Resource = aws_iam_role.administrator.arn |
| 61 | + }] |
| 62 | + }) |
| 63 | +} |
| 64 | + |
| 65 | +resource "aws_iam_group_policy_attachment" "admin_assumption" { |
| 66 | + group = aws_iam_group.administrators.name |
| 67 | + policy_arn = aws_iam_policy.admin_assumption.arn |
| 68 | +} |
| 69 | + |
| 70 | +# Single user that can only assume to the administrator role |
| 71 | +resource "aws_iam_user" "ckdake" { |
| 72 | + name = "ckdake" |
| 73 | + force_destroy = true |
| 74 | + depends_on = [aws_iam_group.administrators] |
| 75 | +} |
| 76 | + |
| 77 | +resource "aws_iam_user_login_profile" "ckdake" { |
| 78 | + user = aws_iam_user.ckdake.name |
| 79 | + password_length = 32 |
| 80 | + password_reset_required = true |
| 81 | + |
| 82 | + lifecycle { |
| 83 | + ignore_changes = [ |
| 84 | + password_length, |
| 85 | + password_reset_required, |
| 86 | + pgp_key, |
| 87 | + ] |
| 88 | + } |
| 89 | +} |
0 commit comments