Using role scope
Overview
This topic explains how to work with role scope and role attributes. A role scope is a resource type by which a role may be parameterized. When you define a role, you can optionally specify a role scope and the parameter, which is called a role attribute.
If multiple members or teams should have similar permissions, but work with different resources, then defining role scope using an attribute key lets you reuse the same role for many members or teams. This means the total number of roles in your account is much smaller, and much easier to maintain.
This topic includes:
- Background information on resources, role scope, and role attributes
- How to define role scope using a role attribute
- How to set a role attribute value when you assign a role to a member or team
- Example: Consolidate existing roles using role attributes
Background: Resources, role scope, and role attributes
When you create a new role, you can specify resources that the role can or cannot access in the following ways:
Define role scope using attribute key
To define role scope using a role attribute when you create a new role policy:
- From the “New role” page, click Advanced to open the “Scope using attribute key” section:
- Click + Add resource type.
- Select a resource type from the menu, for example, “Project.”
- At the prompt, enter a key for the role attribute:
- The role attribute is now a parameter for this role.
- In the role’s policy statements, use the role attribute key any place that you would normally use a specific instance of that resource. For example, if you selected the “Project” resource type in step 3, then you can use the role attribute to allow access only to projects:
- Click Create role.
You set the value of the role attribute when you assign this role to a member or team. In this example, you would enter values for one or more project keys when you assign this role. To learn how, read Set role attribute values, below.
To learn more about creating roles, read Creating roles and policies.
Set role attribute values
You set a role attribute value, or specific resource, when you assign a role to an account member or team. In the “Assign access” dialog, enter the values for the role attribute in the Resources field:
You can enter one or more values when you set the role attribute. For example, you can set the value of the role attribute to projectA
(the project key of “Project A”) when you assign the role to one member, and then set the value of the role attribute to projectB
and projectC
(the project keys of “Project B” and “Project C”) when you assign the role to a different member.
You can also use the REST API: Custom roles.
In the REST API, use the syntax ${roleAttribute/<attributeKey>}
, for example ${roleAttribute/developerProjectKey}
, in your policy statements.
To learn more, read Assigning roles to members and Assigning roles to teams.
Example: Consolidate existing roles using role attributes
Without role scope, if you have two members who require a similar set of permissions, but require access to different flags, you need to define two roles, one for each member:
Given additional flags, or additional projects, the number of roles required increases rapidly, and quickly becomes unmanageable.
You can use role scope to define just one role. Then, you can assign the same role to both members.
Here’s the previous set of roles, rewritten to use the flagKey
role attribute:
When you assign this role to each member, you set the value of flagKey
to the specific flag that that member should have access to.
You can use multiple role attributes in a given role. For example, if you also wanted to parameterize the project, you could use a separate role attribute for that:
In this case, LaunchDarkly prompts you to set the value of both role attributes when you assign the role to a member.
For additional examples of roles defined using role attributes, read: