Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users manage own access keys #10

Merged
merged 11 commits into from
Dec 26, 2018
47 changes: 46 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ data "aws_iam_policy_document" "manage_mfa" {

data "aws_iam_policy_document" "allow_change_password" {
statement {
actions = ["iam:ChangePassword"]
actions = [
"iam:ChangePassword",
"iam:GetLoginProfile"
]
resources = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:user/&{aws:username}"]
}

Expand All @@ -100,6 +103,26 @@ data "aws_iam_policy_document" "allow_change_password" {
}
}

data "aws_iam_policy_document" "allow_manage_access_keys" {
osterman marked this conversation as resolved.
Show resolved Hide resolved
statement {
actions = [
"iam:DeleteAccessKey",
"iam:GetAccessKeyLastUsed",
"iam:UpdateAccessKey",
"iam:GetUser",
"iam:CreateAccessKey",
"iam:ListAccessKeys",
]

resources = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:user/&{aws:username}"]
}

statement {
actions = ["iam:ListUsers"]
resources = ["*"]
}
}

# Admin config

resource "aws_iam_policy" "manage_mfa_admin" {
Expand All @@ -114,6 +137,12 @@ resource "aws_iam_policy" "allow_change_password_admin" {
policy = "${data.aws_iam_policy_document.allow_change_password.json}"
}

resource "aws_iam_policy" "allow_manage_access_keys_admin" {
osterman marked this conversation as resolved.
Show resolved Hide resolved
name = "${module.admin_label.id}-permit-manage-keys"
osterman marked this conversation as resolved.
Show resolved Hide resolved
description = "Allow admin users to manage own access keys"
goruha marked this conversation as resolved.
Show resolved Hide resolved
policy = "${data.aws_iam_policy_document.allow_manage_access_keys.json}"
}

data "aws_iam_policy_document" "assume_role_admin" {
statement {
actions = ["sts:AssumeRole"]
Expand Down Expand Up @@ -151,6 +180,11 @@ resource "aws_iam_group_policy_attachment" "allow_chage_password_admin" {
policy_arn = "${aws_iam_policy.allow_change_password_admin.arn}"
}

resource "aws_iam_group_policy_attachment" "manage_access_key_admin" {
osterman marked this conversation as resolved.
Show resolved Hide resolved
group = "${aws_iam_group.admin.name}"
policy_arn = "${aws_iam_policy.allow_manage_access_keys_admin.arn}"
}

resource "aws_iam_role_policy_attachment" "admin" {
role = "${aws_iam_role.admin.name}"
policy_arn = "arn:aws:iam::aws:policy/AdministratorAccess"
Expand All @@ -177,6 +211,12 @@ resource "aws_iam_policy" "allow_change_password_readonly" {
policy = "${data.aws_iam_policy_document.allow_change_password.json}"
}

resource "aws_iam_policy" "allow_manage_access_keys_readonly" {
name = "${module.readonly_label.id}-permit-manage-keys"
description = "Allow readonly users to manage own access keys"
goruha marked this conversation as resolved.
Show resolved Hide resolved
policy = "${data.aws_iam_policy_document.allow_manage_access_keys.json}"
}

data "aws_iam_policy_document" "assume_role_readonly" {
statement {
actions = ["sts:AssumeRole"]
Expand Down Expand Up @@ -214,6 +254,11 @@ resource "aws_iam_group_policy_attachment" "allow_change_password_readonly" {
policy_arn = "${aws_iam_policy.allow_change_password_readonly.arn}"
}

resource "aws_iam_group_policy_attachment" "manage_access_key_readonly" {
group = "${aws_iam_group.readonly.name}"
policy_arn = "${aws_iam_policy.allow_manage_access_keys_readonly.arn}"
}

resource "aws_iam_role_policy_attachment" "readonly" {
role = "${aws_iam_role.readonly.name}"
policy_arn = "arn:aws:iam::aws:policy/ReadOnlyAccess"
Expand Down