5장. Managing authorizations by using the REST API


To automate the maintenance of Red Hat Developer Hub permission policies and roles, you can use Developer Hub role-based access control (RBAC) REST API.

You can perform the following actions with the REST API:

  • Retrieve information about:

    • All permission policies
    • Specific permission policies
    • Specific roles
    • Static plugins permission policies
  • Create, update, or delete:

    • Permission policy
    • Role

5.1. Sending requests to the RBAC REST API by using the curl utility

You can send RBAC REST API requests by using the curl utility.

Procedure

  1. Find your Bearer token to authenticate to the REST API.

    1. In your browser, open the web console Network tab.
    2. In the main screen, reload the Developer Hub Homepage.
    3. In the web console Network tab, search for the query?term= network call.
    4. Save the token in the response JSON for the next steps.
  2. In a terminal, run the curl command and review the response:

    GET or DELETE request

    curl -v \
      -H "Authorization: Bearer <token>" \
      -X <method> "https://<my_developer_hub_domain>/<endpoint>" \

    POST or PUT request requiring JSON body data

    curl -v -H "Content-Type: application/json" \
      -H "Authorization: Bearer <token>" \
      -X POST "https://<my_developer_hub_domain>/<endpoint>" \
      -d <body>

    <token>
    Enter your saved authorization token.
    <method>

    Enter the HTTP method for your API endpoint.

    • GET: To retrieve specified information from a specified resource endpoint.
    • POST: To create or update a resource.
    • PUT: To update a resource.
    • DELETE: To delete a resource.
    https://<my_developer_hub_domain>
    Enter your Developer Hub URL.
    <endpoint>
    Enter the API endpoint to which you want to send a request, such as /api/permission/policies.
    <body>
    Enter the JSON body with data that your API endpoint might need with the HTTP POST or PUT request.

    Example request to create a role

    curl -v -H "Content-Type: application/json" \
      -H "Authorization: Bearer <token>" \
      -X POST "https://<my_developer_hub_domain>/api/permission/roles" \
      -d '{
          "memberReferences": ["group:default/example"],
          "name": "role:default/test",
          "metadata": { "description": "This is a test role" }
        }'

    Example request to update a role

    curl -v -H "Content-Type: application/json" \
      -H "Authorization: Bearer <token>" \
      -X PUT "https://<my_developer_hub_domain>/api/permission/roles/role/default/test" \
      -d '{
              "oldRole": {
                "memberReferences":  [ "group:default/example" ],
                "name": "role:default/test"
              },
              "newRole": {
                "memberReferences": [ "group:default/example", "user:default/test" ],
                "name": "role:default/test"
              }
            }'

    Example request to create a permission policy

    curl -v -H "Content-Type: application/json" \
      -H "Authorization: Bearer $token" \
      -X POST "https://<my_developer_hub_domain>/api/permission/policies" \
      -d '[{
          "entityReference":"role:default/test",
          "permission": "catalog-entity",
          "policy": "read", "effect":"allow"
        }]'

    Example request to update a permission policy

    curl -v -H "Content-Type: application/json" \
      -H "Authorization: Bearer $token" \
      -X PUT "https://<my_developer_hub_domain>/api/permission/policies/role/default/test" \
      -d '{
             "oldPolicy": [
               {
                 "permission": "catalog-entity", "policy": "read", "effect": "allow"
               }
             ],
             "newPolicy":
               [
                 {
                   "permission": "policy-entity", "policy": "read", "effect": "allow"
                 }
               ]
           }'

    Example request to create a condition

    curl -v -H "Content-Type: application/json" \
      -H "Authorization: Bearer $token" \
      -X POST "https://<my_developer_hub_domain>/api/permission/roles/conditions" \
      -d '{
          "result": "CONDITIONAL",
          "roleEntityRef": "role:default/test",
          "pluginId": "catalog",
          "resourceType": "catalog-entity",
          "permissionMapping": ["read"],
          "conditions": {
            "rule": "IS_ENTITY_OWNER",
            "resourceType": "catalog-entity",
            "params": {"claims": ["group:default/janus-authors"]}
          }
        }'

    Example request to update a condition

    curl -v -H "Content-Type: application/json" \
      -H "Authorization: Bearer $token" \
      -X PUT "https://<my_developer_hub_domain>/api/permission/roles/conditions/1" \
      -d '{
              "result":"CONDITIONAL",
              "roleEntityRef":"role:default/test",
              "pluginId":"catalog",
              "resourceType":"catalog-entity",
              "permissionMapping": ["read",  "update", "delete"],
              "conditions": {
                "rule": "IS_ENTITY_OWNER",
                "resourceType": "catalog-entity",
                "params": {"claims": ["group:default/janus-authors"]}
              }
           }'

Verification

  • Review the returned HTTP status code:

    200 OK
    The request was successful.
    201 Created
    The request resulted in a new resource being successfully created.
    204 No Content
    The request was successful, and the response payload has no more content.
    400 Bad Request
    Input error with the request.
    401 Unauthorized
    Lacks valid authentication for the requested resource.
    403 Forbidden
    Refusal to authorize request.
    404 Not Found
    Could not find requested resource.
    409 Conflict
    Request conflict with the current state and the target resource.
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 문서 정보

Legal Notice

Theme

© 2026 Red Hat
맨 위로 이동