Configure Role Inheritance¶
Add or remove a parent role for a child role in a workspace and inspect the inheritance graph to verify permission propagation.
Task flow¶
Workspace IAM handle
│
▼
1. Read current lifecycle versions of the child and parent roles
│
▼
2. Submit request to add (or remove) the parent role
│
▼
3. Read role inheritance graph ──▶ Verify directed edges (child -> parent)
Prerequisites¶
Complete the endpoint, personal access token, and workspace setup in Use the SDK.
Ensure the current identity has role management permission in the target workspace.
Determine the child role ID and parent role ID; list the workspace role directory as shown in Manage Roles and Object Permissions.
Generate a unique request ID for each mutation and retain it to check status if a network timeout leaves the outcome uncertain.
Add role inheritance¶
Read the current permission views of both the child role and parent role to obtain their expected lifecycle versions, submit the inheritance addition request, and read back the inheritance graph. Directed edges point from child role to parent role, and the server validates lifecycle states and rejects cycles.
import os
import uuid
import moi_product_sdk as sdk
client = sdk.new_with_personal_access_token(
os.environ["PRODUCT_API_BASE_URL"],
os.environ["PRODUCT_API_KEY"],
)
iam = client.iam(os.environ["WORKSPACE_ID"])
child_id = os.environ["CHILD_ROLE_ID"]
parent_id = os.environ["PARENT_ROLE_ID"]
child = iam.role_permission_view(child_id)
parent = iam.role_permission_view(parent_id)
added = iam.add_role_inheritance(
child_id,
sdk.IAMRoleInheritanceMutationRequest(
parent_role_id=parent_id,
expected_child_lifecycle_version=child.expected_role_lifecycle_version,
expected_parent_lifecycle_version=parent.expected_role_lifecycle_version,
request_id=str(uuid.uuid4()),
),
)
print("Added edge:", added.child_role_id, "->", added.parent_role_id)
graph = iam.role_inheritance_graph(child_id)
for edge in graph.edges:
print(edge)
package main
import (
"context"
"fmt"
"os"
"time"
sdk "github.com/matrixorigin/matrixflow/sdk/go-sdk"
)
func main() {
ctx := context.Background()
client, err := sdk.NewWithPersonalAccessToken(
os.Getenv("PRODUCT_API_BASE_URL"),
os.Getenv("PRODUCT_API_KEY"),
)
if err != nil {
panic(err)
}
iam := client.IAM(os.Getenv("WORKSPACE_ID"))
childID := os.Getenv("CHILD_ROLE_ID")
parentID := os.Getenv("PARENT_ROLE_ID")
child, err := iam.RolePermissionView(ctx, childID)
if err != nil {
panic(err)
}
parent, err := iam.RolePermissionView(ctx, parentID)
if err != nil {
panic(err)
}
added, err := iam.AddRoleInheritance(ctx, childID, &sdk.IAMRoleInheritanceMutationRequest{
ParentRoleId: parentID,
ExpectedChildLifecycleVersion: child.GetExpectedRoleLifecycleVersion(),
ExpectedParentLifecycleVersion: parent.GetExpectedRoleLifecycleVersion(),
RequestId: fmt.Sprintf("role-inherit-add-%d", time.Now().UnixNano()),
})
if err != nil {
panic(err)
}
fmt.Println("Added edge:", added.GetChildRoleId(), "->", added.GetParentRoleId())
graph, err := iam.RoleInheritanceGraph(ctx, childID)
if err != nil {
panic(err)
}
for _, edge := range graph.GetEdges() {
fmt.Println(edge)
}
}
Remove role inheritance¶
To detach an existing parent role from a child role, re-read the latest lifecycle versions of both roles, submit the removal request, and inspect the inheritance graph to confirm the edge has been removed. On a version conflict, fetch updated role versions and review concurrent changes before retrying.
child = iam.role_permission_view(child_id)
parent = iam.role_permission_view(parent_id)
removed = iam.remove_role_inheritance(
child_id,
sdk.IAMRoleInheritanceMutationRequest(
parent_role_id=parent_id,
expected_child_lifecycle_version=child.expected_role_lifecycle_version,
expected_parent_lifecycle_version=parent.expected_role_lifecycle_version,
request_id=str(uuid.uuid4()),
),
)
print("Removed edge:", removed.child_role_id, "->", removed.parent_role_id)
child, err = iam.RolePermissionView(ctx, childID)
if err != nil {
panic(err)
}
parent, err = iam.RolePermissionView(ctx, parentID)
if err != nil {
panic(err)
}
removed, err := iam.RemoveRoleInheritance(ctx, childID, &sdk.IAMRoleInheritanceMutationRequest{
ParentRoleId: parentID,
ExpectedChildLifecycleVersion: child.GetExpectedRoleLifecycleVersion(),
ExpectedParentLifecycleVersion: parent.GetExpectedRoleLifecycleVersion(),
RequestId: fmt.Sprintf("role-inherit-rm-%d", time.Now().UnixNano()),
})
if err != nil {
panic(err)
}
fmt.Println("Removed edge:", removed.GetChildRoleId(), "->", removed.GetParentRoleId())