Skip to content

Commit 80b244f

Browse files
authored
feat: Updated the KMS auth policies created by the module and DA to now scope them to the exact KMS Key ID. Previously auth policies were scoped to the whole KMS instance. This change has been implemented in a way where it will create the new auth policy first before destroying the old one to ensure there is no disruption to every day operations.<br>- updated the configuration in the DA that is used to stored failed events in a COS bucket to now use the direct COS endpoint by default (previously it was using the public endpoint). This change is done as an update in place. (#313)
1 parent 85b939d commit 80b244f

File tree

11 files changed

+385
-150
lines changed

11 files changed

+385
-150
lines changed

.secrets.baseline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"files": "go.sum|^.secrets.baseline$",
44
"lines": null
55
},
6-
"generated_at": "2023-12-12T05:17:42Z",
6+
"generated_at": "2023-12-13T05:17:42Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ To create service credentials, access the Event Notifications service, and acces
9191
| [time_sleep.wait_for_cos_authorization_policy](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
9292
| [time_sleep.wait_for_kms_authorization_policy](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
9393
| [ibm_en_integrations.en_integrations](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/data-sources/en_integrations) | data source |
94-
| [ibm_iam_account_settings.iam_account_settings](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/data-sources/iam_account_settings) | data source |
9594

9695
### Inputs
9796

@@ -112,14 +111,15 @@ To create service credentials, access the Event Notifications service, and acces
112111
| <a name="input_root_key_id"></a> [root\_key\_id](#input\_root\_key\_id) | The key ID of a root key, existing in the KMS instance passed in `var.existing_kms_instance_crn`, which will be used to encrypt the data encryption keys which are then used to encrypt the data. Required only if `var.kms_encryption_enabled` is set to `true`. | `string` | `null` | no |
113112
| <a name="input_service_credential_names"></a> [service\_credential\_names](#input\_service\_credential\_names) | The mapping of names and roles for service credentials that you want to create for the Event Notifications instance. | `map(string)` | `{}` | no |
114113
| <a name="input_service_endpoints"></a> [service\_endpoints](#input\_service\_endpoints) | Specify whether you want to enable public, or both public and private service endpoints. Possible values: `public`, `public-and-private` | `string` | `"public-and-private"` | no |
115-
| <a name="input_skip_en_cos_auth_policy"></a> [skip\_en\_cos\_auth\_policy](#input\_skip\_en\_cos\_auth\_policy) | Whether an IAM authorization policy is created for your Event Notifications instance to interact with your Object Storage bucket. Set to `true` to use an existing policy. Ignored if `cos_integration_enabled` is set to `false`. | `bool` | `false` | no |
116-
| <a name="input_skip_en_kms_auth_policy"></a> [skip\_en\_kms\_auth\_policy](#input\_skip\_en\_kms\_auth\_policy) | Set to `true` to skip the creation of an IAM authorization policy that permits all Event Notifications instances in the resource group to read the encryption key from the KMS instance. If set to `false`, specify a value for the KMS instance in the `existing_kms_instance_guid` variable. In addition, no policy is created if `kms_encryption_enabled` is set to `false`. | `bool` | `false` | no |
114+
| <a name="input_skip_en_cos_auth_policy"></a> [skip\_en\_cos\_auth\_policy](#input\_skip\_en\_cos\_auth\_policy) | Set to `true` to skip the creation of an IAM authorization policy that permits the Event Notifications instance `Object Writer` and `Reader` access to the given Object Storage bucket. Ignored if `cos_integration_enabled` is set to `false`. | `bool` | `false` | no |
115+
| <a name="input_skip_en_kms_auth_policy"></a> [skip\_en\_kms\_auth\_policy](#input\_skip\_en\_kms\_auth\_policy) | Set to `true` to skip the creation of an IAM authorization policy that permits the Event Notifications instance to read the encryption key from the KMS instance. If set to `false`, a value must be passed for the KMS instance and key using inputs `existing_kms_instance_crn` and `root_key_id`. In addition, no policy is created if `kms_encryption_enabled` is set to `false`. | `bool` | `false` | no |
117116
| <a name="input_tags"></a> [tags](#input\_tags) | The list of tags to add to the Event Notifications instance. | `list(string)` | `[]` | no |
118117

119118
### Outputs
120119

121120
| Name | Description |
122121
|------|-------------|
122+
| <a name="output_account_id"></a> [account\_id](#output\_account\_id) | The Event Notifications account ID. |
123123
| <a name="output_crn"></a> [crn](#output\_crn) | The Event Notifications instance CRN. |
124124
| <a name="output_event_notification_instance_name"></a> [event\_notification\_instance\_name](#output\_event\_notification\_instance\_name) | The name of the Event Notifications instance. |
125125
| <a name="output_guid"></a> [guid](#output\_guid) | The globally unique identifier of the Event Notifications instance. |

main.tf

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ locals {
1919
can(regex(".*hs-crypto.*", var.existing_kms_instance_crn)) ? "hs-crypto" : null
2020
)
2121
) : null
22+
23+
# Get account ID
24+
account_id = ibm_resource_instance.en_instance.account_id
2225
}
2326

2427
resource "ibm_resource_instance" "en_instance" {
@@ -79,13 +82,6 @@ resource "ibm_en_integration" "en_kms_integration" {
7982
}
8083
}
8184

82-
##############################################################################
83-
# Get Cloud Account ID
84-
##############################################################################
85-
86-
data "ibm_iam_account_settings" "iam_account_settings" {
87-
}
88-
8985
##############################################################################
9086
# IAM Authorization Policy
9187
##############################################################################
@@ -102,30 +98,26 @@ resource "ibm_iam_authorization_policy" "cos_policy" {
10298
source_resource_instance_id = ibm_resource_instance.en_instance.guid
10399
roles = ["Object Writer", "Reader"]
104100
description = "Allow EN instance with GUID ${ibm_resource_instance.en_instance.guid} `Object Writer` and `Reader` access to the COS instance with GUID ${local.existing_cos_instance_guid}."
105-
106101
resource_attributes {
107102
name = "serviceName"
108103
operator = "stringEquals"
109104
value = "cloud-object-storage"
110105
}
111-
112106
resource_attributes {
113107
name = "accountId"
114108
operator = "stringEquals"
115-
value = data.ibm_iam_account_settings.iam_account_settings.account_id
109+
value = local.account_id
116110
}
117111
resource_attributes {
118112
name = "serviceInstance"
119113
operator = "stringEquals"
120114
value = local.existing_cos_instance_guid
121115
}
122-
123116
resource_attributes {
124117
name = "resourceType"
125118
operator = "stringEquals"
126119
value = "bucket"
127120
}
128-
129121
resource_attributes {
130122
name = "resource"
131123
operator = "stringEquals"
@@ -145,10 +137,38 @@ resource "ibm_iam_authorization_policy" "kms_policy" {
145137
count = var.kms_encryption_enabled == false || var.skip_en_kms_auth_policy ? 0 : 1
146138
source_service_name = "event-notifications"
147139
source_resource_instance_id = ibm_resource_instance.en_instance.guid
148-
target_service_name = local.kms_service
149-
target_resource_instance_id = local.existing_kms_instance_guid
150140
roles = ["Reader"]
151-
description = "Allow Event Notification instance ${ibm_resource_instance.en_instance.guid} to read from the ${local.kms_service} instance ${local.existing_kms_instance_guid}"
141+
description = "Allow Event Notifications instance ${ibm_resource_instance.en_instance.guid} to read the ${local.kms_service} key ${var.root_key_id} from instance ${local.existing_kms_instance_guid}"
142+
resource_attributes {
143+
name = "serviceName"
144+
operator = "stringEquals"
145+
value = local.kms_service
146+
}
147+
resource_attributes {
148+
name = "accountId"
149+
operator = "stringEquals"
150+
value = local.account_id
151+
}
152+
resource_attributes {
153+
name = "serviceInstance"
154+
operator = "stringEquals"
155+
value = local.existing_kms_instance_guid
156+
}
157+
resource_attributes {
158+
name = "resourceType"
159+
operator = "stringEquals"
160+
value = "key"
161+
}
162+
resource_attributes {
163+
name = "resource"
164+
operator = "stringEquals"
165+
value = var.root_key_id
166+
}
167+
# Scope of policy now includes the key, so ensure to create new policy before
168+
# destroying old one to prevent any disruption to every day services.
169+
lifecycle {
170+
create_before_destroy = true
171+
}
152172
}
153173

154174
# workaround for https://github.com/IBM-Cloud/terraform-provider-ibm/issues/4478

outputs.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ output "event_notification_instance_name" {
66
description = "The name of the Event Notifications instance."
77
value = ibm_resource_instance.en_instance.name
88
}
9+
910
output "crn" {
1011
description = "The Event Notifications instance CRN."
1112
value = ibm_resource_instance.en_instance.crn
1213
}
1314

15+
output "account_id" {
16+
description = "The Event Notifications account ID."
17+
value = local.account_id
18+
}
19+
1420
output "guid" {
1521
description = "The globally unique identifier of the Event Notifications instance."
1622
value = ibm_resource_instance.en_instance.guid

0 commit comments

Comments
 (0)