|
| 1 | +--- |
| 2 | +subcategory: "" |
| 3 | +page_title: "Managing Vault Radar Resource IAM Policies" |
| 4 | +description: |- |
| 5 | + A guide to setting up and managing access to select Radar resources. |
| 6 | +--- |
| 7 | + |
| 8 | +# Managing Vault Radar Resource IAM Policies |
| 9 | + |
| 10 | +-> **Note:** This feature is currently in private beta. |
| 11 | + |
| 12 | +Administrators can limit users' access to specific Vault Radar resources by using either `hcp_vault_radar_resource_iam_binding` or `hcp_vault_radar_resource_iam_policy`. |
| 13 | + |
| 14 | +Only users with no role at the organization or project level can be restricted to specific Radar resources. |
| 15 | + |
| 16 | +## Pre-requisites and Constraints |
| 17 | +* An IAM group should be created with the role `roles/vault-radar.developer` at the project level. This will allow the group's members to access Radar. |
| 18 | +* It's recommended to create a group for each team that will be require access to a select set of Radar resources. |
| 19 | +* Add users without any roles to the group created above. |
| 20 | +* Use the group created above to set the policy or binding for a select set of Radar resources. |
| 21 | +* Only the roles `roles/vault-radar.resource-viewer` or `roles/vault-radar.resource-contributor` can be applied to the policy or binding for Radar resources. |
| 22 | + |
| 23 | +## Sample Usage |
| 24 | +The following is an example of create a group with the role `roles/vault-radar.developer` at the project level and set the policy for a set of Radar resource that match a resource URI prefix with the role `roles/vault-radar.resource-viewer` for that group. |
| 25 | + |
| 26 | +```terraform |
| 27 | +variable "project_id" { |
| 28 | + type = string |
| 29 | +} |
| 30 | +
|
| 31 | +
|
| 32 | +# Create a group for members with no roles. |
| 33 | +resource "hcp_group" "group" { |
| 34 | + display_name = "my-developer-group" |
| 35 | + description = "my developer group managed by TF" |
| 36 | +} |
| 37 | +
|
| 38 | +# Assign 'roles/vault-radar.developer' role on the group. |
| 39 | +# This allows the groups members access to Vault Radar. |
| 40 | +resource "hcp_project_iam_binding" "binding" { |
| 41 | + project_id = var.project_id |
| 42 | + principal_id = hcp_group.group.resource_id |
| 43 | + role = "roles/vault-radar.developer" |
| 44 | +} |
| 45 | +
|
| 46 | +# Create a policy that will grant Radar Resource Viewer access to the group. |
| 47 | +data "hcp_iam_policy" "policy" { |
| 48 | + bindings = [ |
| 49 | + { |
| 50 | + role = "roles/vault-radar.resource-viewer" |
| 51 | + principals = [hcp_group.group.resource_id] |
| 52 | + } |
| 53 | + ] |
| 54 | +} |
| 55 | +
|
| 56 | +# Get the list of Radar resources intended to be accessed by the group. |
| 57 | +# This example uses a URI 'LIKE' filter to only include resources that start with "git://github.com/ibm/" or "git://github.com/hashicorp/". |
| 58 | +data "hcp_vault_radar_resources" "radar_resources" { |
| 59 | + uri_like_filter = { |
| 60 | + values = [ |
| 61 | + "git://github.com/ibm/%", |
| 62 | + "git://github.com/hashicorp/%", |
| 63 | + ] |
| 64 | + case_insensitive = false |
| 65 | + } |
| 66 | +} |
| 67 | +
|
| 68 | +# Map the list of Radar resources to a map of Radar URIs to HCP resource names, and filter out any resources that are not registered. |
| 69 | +locals { |
| 70 | + resources_uri_to_resource_name = { |
| 71 | + for radar_resource in data.hcp_vault_radar_resources.radar_resources.resources : radar_resource.uri => radar_resource.hcp_resource_name |
| 72 | + # This is done as a precaution to ensure that only valid resources are processed. |
| 73 | + if radar_resource.hcp_resource_status == "registered" |
| 74 | + } |
| 75 | +
|
| 76 | +} |
| 77 | +
|
| 78 | +# Create IAM policies for each Radar resource's HCP resource name that the group should have access to. |
| 79 | +# Note this will replace any existing policies for the resources. If that is not desired, consider using `hcp_vault_radar_resource_iam_binding` instead. |
| 80 | +resource "hcp_vault_radar_resource_iam_policy" "policy" { |
| 81 | + for_each = local.resources_uri_to_resource_name |
| 82 | + resource_name = each.value |
| 83 | + policy_data = data.hcp_iam_policy.policy.policy_data |
| 84 | +} |
| 85 | +``` |
0 commit comments