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

feat: s2s auth iam engine #237

Merged
merged 15 commits into from
Mar 5, 2025
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ You need the following permissions to run this module.
| Name | Type |
|------|------|
| [ibm_iam_authorization_policy.en_policy](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/iam_authorization_policy) | resource |
| [ibm_iam_authorization_policy.iam_groups_policy](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/iam_authorization_policy) | resource |
| [ibm_iam_authorization_policy.iam_identity_policy](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/iam_authorization_policy) | resource |
| [ibm_iam_authorization_policy.kms_policy](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/iam_authorization_policy) | resource |
| [ibm_resource_instance.secrets_manager_instance](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/resource_instance) | resource |
| [ibm_sm_en_registration.sm_en_registration](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/sm_en_registration) | resource |
Expand All @@ -95,6 +97,7 @@ You need the following permissions to run this module.
|------|-------------|------|---------|:--------:|
| <a name="input_allowed_network"></a> [allowed\_network](#input\_allowed\_network) | The types of service endpoints to set on the Secrets Manager instance. Possible values are `private-only` or `public-and-private`. | `string` | `"public-and-private"` | no |
| <a name="input_cbr_rules"></a> [cbr\_rules](#input\_cbr\_rules) | (Optional, list) List of CBR rules to create | <pre>list(object({<br/> description = string<br/> account_id = string<br/> rule_contexts = list(object({<br/> attributes = optional(list(object({<br/> name = string<br/> value = string<br/> }))) }))<br/> enforcement_mode = string<br/> }))</pre> | `[]` | no |
| <a name="input_create_iam_engine"></a> [create\_iam\_engine](#input\_create\_iam\_engine) | Whether to create an IAM credential engine using sserice to service (s2s) authentication. | `bool` | `true` | no |
| <a name="input_enable_event_notification"></a> [enable\_event\_notification](#input\_enable\_event\_notification) | Set this to true to enable lifecycle notifications for your Secrets Manager instance by connecting an Event Notifications service. When setting this to true, a value must be passed for `existing_en_instance_crn` and `existing_sm_instance_crn` must be null. | `bool` | `false` | no |
| <a name="input_endpoint_type"></a> [endpoint\_type](#input\_endpoint\_type) | The type of endpoint (public or private) to connect to the Secrets Manager API. The Terraform provider uses this endpoint type to interact with the Secrets Manager API and configure Event Notifications. | `string` | `"public"` | no |
| <a name="input_existing_en_instance_crn"></a> [existing\_en\_instance\_crn](#input\_existing\_en\_instance\_crn) | The CRN of the Event Notifications service to enable lifecycle notifications for your Secrets Manager instance. | `string` | `null` | no |
Expand Down
21 changes: 21 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,27 @@ resource "ibm_resource_instance" "secrets_manager_instance" {
}
}

# Create IAM credentials engine using s2s auth
resource "ibm_iam_authorization_policy" "iam_identity_policy" {
count = var.create_iam_engine ? 1 : 0
source_service_name = "secrets-manager"
source_resource_instance_id = local.secrets_manager_guid
target_service_name = "iam-identity"
roles = ["Operator"]
description = "Authorization Policy"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description needs more info as to the type of auth policy here. Check out other auth policy descrptions we have used in other modules for an idea

transaction_id = "terraformAuthorizationPolicy"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is transaction_id ?

}

resource "ibm_iam_authorization_policy" "iam_groups_policy" {
count = var.create_iam_engine ? 1 : 0
source_service_name = "secrets-manager"
source_resource_instance_id = local.secrets_manager_guid
target_service_name = "iam-groups"
roles = ["Groups Service Member Manage"]
description = "Authorization Policy"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, description needs to be updated

transaction_id = "terraformAuthorizationPolicy"
}

locals {
# determine which service name to use for the policy
kms_service_name = var.kms_encryption_enabled && var.kms_key_crn != null ? (
Expand Down
1 change: 1 addition & 0 deletions tests/existing-resources/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ module "secrets_manager" {
secrets_manager_name = "${var.prefix}-secrets-manager" #tfsec:ignore:general-secrets-no-plaintext-exposure
sm_service_plan = "trial"
sm_tags = var.resource_tags
create_iam_engine = false
}
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ variable "sm_service_plan" {
}
}

variable "create_iam_engine" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing getting "created" here is s2s auth policies between SM and IAM. So maybe we need to rename this to skip_iam_authorization_policy ?

The variable description needs to be more specific as to what exact type of auth policies are created (as its possible a consumer may already have them set in their account)

type = bool
description = "Whether to create an IAM credential engine using sserice to service (s2s) authentication."
default = true
}

variable "sm_tags" {
type = list(string)
description = "The list of resource tags that you want to associate with your Secrets Manager instance."
Expand Down