Skip to content

Commit 5300df0

Browse files
JohannesRudolphhenryde
authored andcommitted
feat: add permissions to close accounts in explicitly defined OUs
this change will support the upcoming automated tenant deletion feature of meshStack
1 parent 429ab18 commit 5300df0

File tree

7 files changed

+53
-20
lines changed

7 files changed

+53
-20
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ Before opening a Pull Request, we recommend following the below steps to get a f
167167
168168
| Name | Version |
169169
|------|---------|
170-
| <a name="provider_aws.automation"></a> [aws.automation](#provider\_aws.automation) | 5.41.0 |
171-
| <a name="provider_aws.management"></a> [aws.management](#provider\_aws.management) | 5.41.0 |
172-
| <a name="provider_aws.meshcloud"></a> [aws.meshcloud](#provider\_aws.meshcloud) | 5.41.0 |
170+
| <a name="provider_aws.automation"></a> [aws.automation](#provider\_aws.automation) | >= 2.7.0 |
171+
| <a name="provider_aws.management"></a> [aws.management](#provider\_aws.management) | >= 2.7.0 |
172+
| <a name="provider_aws.meshcloud"></a> [aws.meshcloud](#provider\_aws.meshcloud) | >= 2.7.0 |
173173
174174
## Modules
175175
@@ -196,6 +196,7 @@ Before opening a Pull Request, we recommend following the below steps to get a f
196196
|------|-------------|------|---------|:--------:|
197197
| <a name="input_automation_account_service_role_name"></a> [automation\_account\_service\_role\_name](#input\_automation\_account\_service\_role\_name) | Name of the custom role in the automation account. See https://docs.meshcloud.io/docs/meshstack.how-to.integrate-meshplatform-aws-manually.html#set-up-aws-account-3-automation | `string` | `"MeshfedAutomationRole"` | no |
198198
| <a name="input_aws_sso_instance_arn"></a> [aws\_sso\_instance\_arn](#input\_aws\_sso\_instance\_arn) | AWS SSO Instance ARN. Needs to be of the form arn:aws:sso:::instance/ssoins-xxxxxxxxxxxxxxx. Setup instructions https://docs.meshcloud.io/docs/meshstack.aws.sso-setup.html. | `string` | n/a | yes |
199+
| <a name="input_can_close_accounts_in_resource_org_paths"></a> [can\_close\_accounts\_in\_resource\_org\_paths](#input\_can\_close\_accounts\_in\_resource\_org\_paths) | AWS ResourceOrgPaths that are used in Landing Zones and where meshStack is allowed to close accounts. | `list(string)` | `[]` | no |
199200
| <a name="input_control_tower_enrollment_enabled"></a> [control\_tower\_enrollment\_enabled](#input\_control\_tower\_enrollment\_enabled) | Set to true, to allow meshStack to enroll Accounts via AWS Control Tower for the meshPlatform. | `bool` | `false` | no |
200201
| <a name="input_control_tower_portfolio_id"></a> [control\_tower\_portfolio\_id](#input\_control\_tower\_portfolio\_id) | Must be set for AWS Control Tower | `string` | `""` | no |
201202
| <a name="input_cost_explorer_management_account_service_role_name"></a> [cost\_explorer\_management\_account\_service\_role\_name](#input\_cost\_explorer\_management\_account\_service\_role\_name) | Name of the custom role in the management account used by the cost explorer user. | `string` | `"MeshCostExplorerServiceRole"` | no |
@@ -214,6 +215,7 @@ Before opening a Pull Request, we recommend following the below steps to get a f
214215
| Name | Description |
215216
|------|-------------|
216217
| <a name="output_automation_account_id"></a> [automation\_account\_id](#output\_automation\_account\_id) | Automation Account ID |
218+
| <a name="output_cost_explorer_identity_federation_role"></a> [cost\_explorer\_identity\_federation\_role](#output\_cost\_explorer\_identity\_federation\_role) | n/a |
217219
| <a name="output_cost_explorer_management_account_role_arn"></a> [cost\_explorer\_management\_account\_role\_arn](#output\_cost\_explorer\_management\_account\_role\_arn) | Amazon Resource Name (ARN) of Management Account Role for replicator |
218220
| <a name="output_cost_explorer_privileged_external_id"></a> [cost\_explorer\_privileged\_external\_id](#output\_cost\_explorer\_privileged\_external\_id) | Cost explorer privileged\_external\_id |
219221
| <a name="output_management_account_id"></a> [management\_account\_id](#output\_management\_account\_id) | Management Account ID |

main.tf

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,16 @@ module "management_account_replicator_access" {
6868
providers = {
6969
aws = aws.management
7070
}
71-
meshcloud_account_id = data.aws_caller_identity.meshcloud.account_id
72-
privileged_external_id = var.replicator_privileged_external_id
73-
support_root_account_via_aws_sso = var.support_root_account_via_aws_sso
74-
aws_sso_instance_arn = var.aws_sso_instance_arn
75-
control_tower_enrollment_enabled = var.control_tower_enrollment_enabled
76-
control_tower_portfolio_id = var.control_tower_portfolio_id
77-
meshcloud_account_service_user_name = var.meshcloud_account_service_user_name
78-
management_account_service_role_name = var.management_account_service_role_name
79-
landing_zone_ou_arns = var.landing_zone_ou_arns
71+
meshcloud_account_id = data.aws_caller_identity.meshcloud.account_id
72+
privileged_external_id = var.replicator_privileged_external_id
73+
support_root_account_via_aws_sso = var.support_root_account_via_aws_sso
74+
aws_sso_instance_arn = var.aws_sso_instance_arn
75+
control_tower_enrollment_enabled = var.control_tower_enrollment_enabled
76+
control_tower_portfolio_id = var.control_tower_portfolio_id
77+
meshcloud_account_service_user_name = var.meshcloud_account_service_user_name
78+
management_account_service_role_name = var.management_account_service_role_name
79+
landing_zone_ou_arns = var.landing_zone_ou_arns
80+
can_close_accounts_in_resource_org_paths = var.can_close_accounts_in_resource_org_paths
8081

8182
allow_federated_role = var.workload_identity_federation != null
8283

modules/meshcloud-cost-explorer/ce-management-account-access/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
| Name | Version |
1111
|------|---------|
12-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 2.7.0 |
12+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.21.0 |
1313

1414
## Modules
1515

modules/meshcloud-replicator/replicator-management-account-access/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
| Name | Version |
1111
|------|---------|
12-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 2.7.0 |
12+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.21.0 |
1313

1414
## Modules
1515

@@ -39,9 +39,10 @@ No modules.
3939
|------|-------------|------|---------|:--------:|
4040
| <a name="input_allow_federated_role"></a> [allow\_federated\_role](#input\_allow\_federated\_role) | n/a | `bool` | `false` | no |
4141
| <a name="input_aws_sso_instance_arn"></a> [aws\_sso\_instance\_arn](#input\_aws\_sso\_instance\_arn) | ARN of the AWS SSO instance to use | `string` | n/a | yes |
42+
| <a name="input_can_close_accounts_in_resource_org_paths"></a> [can\_close\_accounts\_in\_resource\_org\_paths](#input\_can\_close\_accounts\_in\_resource\_org\_paths) | AWS ResourceOrgPaths that are used in Landing Zones and where meshStack is allowed to close accounts. | `list(string)` | `[]` | no |
4243
| <a name="input_control_tower_enrollment_enabled"></a> [control\_tower\_enrollment\_enabled](#input\_control\_tower\_enrollment\_enabled) | Set to true, to allow meshStack to enroll Accounts via AWS Control Tower for the meshPlatform | `bool` | `false` | no |
4344
| <a name="input_control_tower_portfolio_id"></a> [control\_tower\_portfolio\_id](#input\_control\_tower\_portfolio\_id) | Must be set for AWS Control Tower | `string` | `""` | no |
44-
| <a name="input_landing_zone_ou_arns"></a> [landing\_zone\_ou\_arns](#input\_landing\_zone\_ou\_arns) | Organizational Unit ARNs that are used in Landing Zones. We recommend to explicitly list the OU ARNs that meshStack should manage. | `list(string)` | <pre>[<br> "arn:aws:organizations::*:ou/o-*/ou-*"<br>]</pre> | no |
45+
| <a name="input_landing_zone_ou_arns"></a> [landing\_zone\_ou\_arns](#input\_landing\_zone\_ou\_arns) | Organizational Unit ARNs that are used in Landing Zones. We recommend to explicitly list the OU ARNs that meshStack should manage. | `list(string)` | `[]` | no |
4546
| <a name="input_management_account_service_role_name"></a> [management\_account\_service\_role\_name](#input\_management\_account\_service\_role\_name) | Name of the custom role in the management account. See https://docs.meshcloud.io/docs/meshstack.how-to.integrate-meshplatform-aws-manually.html#set-up-aws-account-2-management | `string` | `"MeshfedServiceRole"` | no |
4647
| <a name="input_meshcloud_account_id"></a> [meshcloud\_account\_id](#input\_meshcloud\_account\_id) | The ID of the meshcloud AWS Account | `string` | n/a | yes |
4748
| <a name="input_meshcloud_account_service_user_name"></a> [meshcloud\_account\_service\_user\_name](#input\_meshcloud\_account\_service\_user\_name) | Name of the meshfed-service user. This user is responsible for replication. | `string` | `"meshfed-service-user"` | no |
@@ -55,4 +56,4 @@ No modules.
5556
|------|-------------|
5657
| <a name="output_management_account_role_arn"></a> [management\_account\_role\_arn](#output\_management\_account\_role\_arn) | Amazon Resource Name (ARN) of Management Account Role |
5758
| <a name="output_meshstack_access_role_name"></a> [meshstack\_access\_role\_name](#output\_meshstack\_access\_role\_name) | The name for the Account Access Role that will be rolled out to all managed accounts. |
58-
<!-- END_TF_DOCS -->
59+
<!-- END_TF_DOCS -->

modules/meshcloud-replicator/replicator-management-account-access/data.tf

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,31 @@ data "aws_iam_policy_document" "meshfed_service" {
5050
[
5151
# The actions organizations:TagResource and organizations:UntagResource act on accounts.
5252
# The actions can not be restricted to a subtree of the OU hierarchy. This is a limitation in the permission model of AWS Organization Service.
53-
# To supprt tagging for this meshPlatform we need to allow both actions on all accounts.
53+
# To support tagging for this meshPlatform we need to allow both actions on all accounts.
5454
"arn:${data.aws_partition.current.partition}:organizations::*:account/o-*/*",
5555
# New accounts need to be moved from root to the target OU.
5656
"arn:${data.aws_partition.current.partition}:organizations::${local.account_id}:root/o-*/r-*"
5757
],
5858
var.landing_zone_ou_arns)
5959
}
6060

61+
statement {
62+
sid = "OrgManagementAccessCloseAccount"
63+
effect = "Allow"
64+
actions = [
65+
"organizations:CloseAccount"
66+
]
67+
resources = [
68+
// allow acting on any account owned by this org
69+
"arn:${data.aws_partition.current.partition}:organizations::*:account/o-*/*",
70+
]
71+
condition {
72+
test = "ForAnyValue:StringLike"
73+
variable = "aws:ResourceOrgPaths"
74+
values = var.can_close_accounts_in_resource_org_paths
75+
}
76+
}
77+
6178
statement {
6279
sid = "OrgManagementAccessNoResourceLevelRestrictions"
6380
effect = "Allow"

modules/meshcloud-replicator/replicator-management-account-access/variables.tf

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,14 @@ variable "support_root_account_via_aws_sso" {
5252
variable "landing_zone_ou_arns" {
5353
type = list(string)
5454
description = "Organizational Unit ARNs that are used in Landing Zones. We recommend to explicitly list the OU ARNs that meshStack should manage."
55-
default = [
56-
"arn:aws:organizations::*:ou/o-*/ou-*"
57-
]
55+
default = []
56+
}
57+
58+
variable "can_close_accounts_in_resource_org_paths" {
59+
type = list(string)
60+
// see https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-resourceorgpaths
61+
description = "AWS ResourceOrgPaths that are used in Landing Zones and where meshStack is allowed to close accounts."
62+
default = [] // example: o-a1b2c3d4e5/r-f6g7h8i9j0example/ou-ghi0-awsccccc/ou-jkl0-awsddddd/
5863
}
5964

6065
variable "allow_federated_role" {

variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ variable "landing_zone_ou_arns" {
3939
default = ["arn:aws:organizations::*:ou/o-*/ou-*"]
4040
}
4141

42+
variable "can_close_accounts_in_resource_org_paths" {
43+
type = list(string)
44+
// see https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-resourceorgpaths
45+
description = "AWS ResourceOrgPaths that are used in Landing Zones and where meshStack is allowed to close accounts."
46+
default = [] // example: o-a1b2c3d4e5/r-f6g7h8i9j0example/ou-ghi0-awsccccc/ou-jkl0-awsddddd/
47+
}
48+
4249
# ---------------------------------------------------------------------------------------------------------------------
4350
# OPTIONAL PARAMETERS
4451
# These parameters have reasonable defaults.

0 commit comments

Comments
 (0)