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

[FEATURE] possibility to attach user to role (not backend role) #191

Closed
rapcore2 opened this issue May 22, 2024 · 7 comments
Closed

[FEATURE] possibility to attach user to role (not backend role) #191

rapcore2 opened this issue May 22, 2024 · 7 comments
Labels
enhancement New feature or request

Comments

@rapcore2
Copy link

rapcore2 commented May 22, 2024

Is your feature request related to a problem?

I tried to map custom role to user, but there is no possibility with opensearch terraform provider.

What solution would you like?

Possibility to attach (custom) role to user. For example (as it possible):

resource "opensearch_user" "simple_user" {
  username    = "simple.user"
  password    = "SuperPassword!"
  description = "Simple User"
  backend_roles = [
    "my_custom_backend_role"
  ]
  roles = [
    "my_custom_role
  ]
}

What alternatives have you considered?

In Dev Tools

PUT _plugins/_security/api/rolesmapping/custom_role
{
  "users" : [ "custom_user" ]
}
@rapcore2 rapcore2 added enhancement New feature or request untriaged labels May 22, 2024
@rblcoder
Copy link
Collaborator

PUT _plugins/_security/api/rolesmapping/custom_role
{
  "users" : [ "custom_user" ]
}

The above can be called using opensearch_roles_mapping resource

func resourceOpensearchPutOpenDistroRolesMapping(d *schema.ResourceData, m interface{}) (*RoleMappingResponse, error) {
var err error
response := new(RoleMappingResponse)
rolesMappingDefinition := RolesMapping{
BackendRoles: expandStringList(d.Get("backend_roles").(*schema.Set).List()),
Hosts: expandStringList(d.Get("hosts").(*schema.Set).List()),
Users: expandStringList(d.Get("users").(*schema.Set).List()),
Description: d.Get("description").(string),
AndBackendRoles: expandStringList(d.Get("and_backend_roles").(*schema.Set).List()),
}
roleJSON, err := json.Marshal(rolesMappingDefinition)
if err != nil {
return response, fmt.Errorf("Body Error : %s", roleJSON)
}
path, err := uritemplates.Expand("/_plugins/_security/api/rolesmapping/{name}", map[string]string{
"name": d.Get("role_name").(string),
})

"users": {
Description: "A list of users.",
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},

@rapcore2
Copy link
Author

@rblcoder thank You for reply. Could You provide example in terraform how to attach role (not backend role) in opensearch_roles_mapping ? In my opinion it is impossible.

@rblcoder
Copy link
Collaborator

@rapcore2
Copy link
Author

rapcore2 commented May 29, 2024

@rblcoder thank You for reply. But its backend_role not a role... I asked about possibility to attach role not backend role.

Role - Security roles define the scope of a permission or action group: cluster, index, document, or field. For example, a role named delivery_analyst might have no cluster permissions, the READ action group for all indexes that match the delivery-data-* pattern, access to all document types within those indexes, and access to all fields except delivery_driver_name.

Backend role - (Optional) Arbitrary strings that you specify or that come from an external authentication system (for example, LDAP/Active Directory). Backend roles can help simplify the role mapping process. Rather than mapping a role to 100 individual users, you can map the role to a single backend role that all 100 users share.

@rblcoder
Copy link
Collaborator

PUT _plugins/_security/api/rolesmapping/custom_role
{
"users" : [ "custom_user" ]
}
the above is mapping a user to a role.

@rblcoder
Copy link
Collaborator

You can see a test added here that the same works using the provider as well

https://github.com/opensearch-project/terraform-provider-opensearch/pull/193/files

@rapcore2
Copy link
Author

works as expected in version 2.3.0 .
@rblcoder thank You :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants