Ville Mattila
02/25/2026, 1:57 PMresource "descope_management_key" "project_key" {
count = var.create_management_key ? 1 : 0
name = "${descope_project.descope_project.name} Management Key"
rebac = {
project_roles = [{
project_ids = [descope_project.descope_project.id]
roles = ["Full Access"]
}]
}
}
gives an error:
│
│ with module.descope_project.descope_management_key.project_key[0],
│ on ../../../base/terraform/descope_project/main.tf line 656, in resource "descope_management_key" "project_key":
│ 656: resource "descope_management_key" "project_key" {
│
│ [E111901] Failed managing management key [Status-Code:400]
I tried the script
#!/usr/bin/env python3
"""
Descope management key operations via the Descope SDK.
Usage:
python test_mgmt_key.py --project-id <id> --management-key <key> [--base-url <url>]
"""
import argparse
import json
import sys
from descope import (
DescopeClient,
MgmtKeyProjectRole,
MgmtKeyReBac,
MgmtKeyStatus,
MgmtKeyTagRole,
)
def _print_json(obj):
print(json.dumps(obj, indent=2, default=str))
def main():
parser = argparse.ArgumentParser(
description="Descope management key operations",
)
parser.add_argument("--project-id", required=True)
parser.add_argument("--management-key", required=True)
parser.add_argument("--base-url", default=None)
args = parser.parse_args()
client_kwargs = {
"project_id": args.project_id,
"management_key": args.management_key,
}
if args.base_url:
client_kwargs["base_url"] = args.base_url
descope_client = DescopeClient(**client_kwargs)
# Search all management keys
print("=== Search all management keys ===")
search_resp = descope_client.mgmt.management_key.search()
keys = search_resp["keys"]
for key in keys:
_print_json(key)
print()
# Create a new management key with RBAC configuration
print("=== Create a new management key ===")
rebac = MgmtKeyReBac(
company_roles=["company-full-access"],
project_roles=[
MgmtKeyProjectRole(
project_ids=["project-id-1", "project-id-2"],
roles=["project-admin"],
)
],
tag_roles=[
MgmtKeyTagRole(
tags=["production"],
roles=["read-only"],
)
],
)
create_resp = descope_client.mgmt.management_key.create(
name="My Management Key",
rebac=rebac,
description="Optional description for the management key",
expires_in=0,
permitted_ips=["10.0.0.1", "192.168.1.0/24"],
)
key = create_resp["key"]
cleartext = create_resp["cleartext"]
print("Created key:")
_print_json(key)
print(f"Cleartext (save securely, will not be shown again): {cleartext}")
key_id = key["id"]
# Load a specific management key by ID
print(f"\n=== Load management key {key_id} ===")
load_resp = descope_client.mgmt.management_key.load(key_id)
loaded_key = load_resp["key"]
_print_json(loaded_key)
# Update the management key
print(f"\n=== Update management key {key_id} ===")
update_resp = descope_client.mgmt.management_key.update(
id=key_id,
name="Updated Key Name",
description="Updated description",
permitted_ips=["10.0.0.2"],
status=MgmtKeyStatus.ACTIVE,
)
updated_key = update_resp["key"]
print("Updated key:")
_print_json(updated_key)
# Delete the management key
print(f"\n=== Delete management key {key_id} ===")
delete_resp = descope_client.mgmt.management_key.delete([key_id])
total_deleted = delete_resp["total"]
print(f"Deleted {total_deleted} key(s).")
if __name__ == "__main__":
main()
and this gives exact same error with given project_id.
Am holding this wrong?Akash Jivane
02/25/2026, 2:22 PM[E111901] Failed managing management key
is not coming from Terraform itself, it’s coming from the Descope API validation of the ReBAC roles payload.
In your Terraform config you’re passing:
roles = ["Full Access"]
But in Descope ReBAC roles must use the internal role identifiers, not the display name.
So "Full Access" is not a valid role identifier which is why the API returns 400.Akash Jivane
02/25/2026, 2:23 PMAkash Jivane
02/25/2026, 2:24 PMroles=["project-admin"]Akash Jivane
02/25/2026, 2:24 PMproject_ids don’t belong to the same region / project or the role mapping is invalid for that project, the API rejects it with the same error.Ville Mattila
02/25/2026, 5:31 PMAkash Jivane
02/25/2026, 5:37 PMBhagwanta Yeole
02/25/2026, 5:54 PMBhagwanta Yeole
02/25/2026, 6:13 PMVille Mattila
02/26/2026, 9:25 AM# Create a new management key with RBAC configuration
print("=== Create a new management key ===")
rebac = MgmtKeyReBac(
company_roles=[],
project_roles=[
MgmtKeyProjectRole(
project_ids=["Peuc13xxxxxx"],
roles=["ROL3A9wTrxxx"],
)
],
tag_roles=[],
)Akash Jivane
02/26/2026, 9:32 AMproject_roles at all, and instead use company roles.Akash Jivane
02/26/2026, 9:32 AMVille Mattila
02/26/2026, 10:00 AMprint(f"PRJ: {args.project_id}")
# Create a new management key with RBAC configuration
print("=== Create a new management key ===")
rebac = MgmtKeyReBac(
company_roles=["company-full-access"], # I also tried "Full Access" but error
project_roles=[],
tag_roles=[],
)
create_resp = descope_client.mgmt.management_key.create(
name="My Management Key",
rebac=rebac,
description="Optional description for the management key",
expires_in=0,
permitted_ips=[],
)Akash Jivane
02/26/2026, 10:45 AMAkash Jivane
02/26/2026, 10:57 AM[E111901] Failed managing management key:
- invalid mgmt key project role
- invalid mgmt key company role
- missing mgmt key roles
This seems the roles are not matching due to which you are getting this error.
Can you please list the available roles in your project and use one of those exact names?Akash Jivane
02/26/2026, 11:26 AMVille Mattila
02/26/2026, 12:31 PMrebac = MgmtKeyReBac(
company_roles=["Security Admin"],
project_roles=[],
tag_roles=[],
)
The "Security Admin" above is one of the RBAC roles in Authorization. I've have also tried the id ROL... None of this works
I've tried the "Full Access" and it is not working
I've tried Company Descoper role "admin" and custom role "testing" These do not work either.
It would be great to get step by step guide how to get python SDK mgmt key created for real. The example codes makes a lot of assumption about the environment. It would really help to see what needs to be there in managment console.
At the end of the day I'm looking for getting Full Access management key for the project.Akash Jivane
02/26/2026, 12:43 PMAkash Jivane
02/26/2026, 4:54 PMAkash Jivane
02/27/2026, 11:57 AM"Full Access", "Security Admin"
• custom RBAC role IDs (ROL...) is failing with invalid mgmt key role.
To create a “Full Access” management key via SDK, you need to use the built-in Descope management role:
company-full-access
Can you try this once and let me know if this works for you ?Ville Mattila
02/27/2026, 3:35 PMprint(f"PRJ: {args.project_id}")
# Create a new management key with RBAC configuration
print("=== Create a new management key ===")
rebac = MgmtKeyReBac(
company_roles=["company-full-access"],
project_roles=[],
tag_roles=[],
)
create_resp = descope_client.mgmt.management_key.create(
name="My Management Key",
rebac=rebac,
description="Optional description for the management key",
expires_in=0,
permitted_ips=[],
)
I'm getting this:
PRJ: Peuc13.....
=== Create a new management key ===
Traceback (most recent call last):
File "test_mgmt_key.py", line 111, in <module>
main()
~~~~^^
File "test_mgmt_key.py", line 69, in main
create_resp = descope_client.mgmt.management_key.create(
name="My Management Key",
...<3 lines>...
permitted_ips=[],
)
File "management_key.py", line 53, in create
response = self._http.put(
MgmtV1.mgmt_key_create_path,
body=body,
)
File "python3.13/site-packages/descope/http_client.py", line 239, in put
self._raise_from_response(response)
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
File "python3.13/site-packages/descope/http_client.py", line 356, in _raise_from_response
raise AuthException(
...<3 lines>...
)
descope.exceptions.AuthException: {'status_code': 400, 'error_type': 'server error', 'error_message': '{"errorCode":"E111901","errorDescription":"Failed managing management key"}'}Akash Jivane
02/27/2026, 4:07 PM[E111901] Failed managing management key this usually means the request is valid *b*ut the key you’re using to create the new management key does NOT have sufficient permissions to create company-level keys.
The parent management key you are using must itself already have company-level (Full Access) permissions.
Have you verified your current management key permissions ?Ville Mattila
02/27/2026, 4:24 PMAkash Jivane
02/27/2026, 4:28 PMBhagwanta Yeole
02/27/2026, 4:39 PMVille Mattila
02/27/2026, 4:57 PMBhagwanta Yeole
02/27/2026, 5:00 PMVille Mattila
02/27/2026, 5:59 PMBhagwanta Yeole
02/27/2026, 6:42 PMVille Mattila
03/02/2026, 5:11 PM{"errorCode":"E111901","errorDescription":"Failed managing management key"}'}
again if use US region and API then the script above works ok, but If try to use script with key that is for EU projects and with EU api endpoint then I have the problemAviad Lichtenstadt
03/02/2026, 7:19 PMVille Mattila
03/03/2026, 6:03 AMVille Mattila
03/03/2026, 6:04 AMMei
03/04/2026, 11:01 AMVille Mattila
03/04/2026, 11:04 AMMei
03/04/2026, 11:06 AMMei
03/09/2026, 11:42 AMMei
03/09/2026, 11:43 AMVille Mattila
03/09/2026, 11:58 AMMei
03/30/2026, 10:30 AMVille Mattila
03/30/2026, 11:08 AMMei
04/05/2026, 11:53 AMVille Mattila
04/09/2026, 9:22 AMMei
04/09/2026, 12:15 PMMei
04/13/2026, 12:46 PMVille Mattila
04/13/2026, 1:24 PM