Bootstrap FreeKB - Kong Enterprise Edition (KongEE) - List Admins using REST API
Kong Enterprise Edition (KongEE) - List Admins using REST API


This assumes Kong has been secured with Role Based Access Control (RBAC) and you have created your Kong-Admin-Token. The following curl command can be used to list the endpoints that can be used with the API.

curl --header "Kong-Admin-Token: abc123" --request GET "https://kong.example.com/endpoints"

 

Something like this should be returned. Notice that the /admins endpoint can be used.

{       
    "data": [
        "/",
        "/acls",
        "/acls/{acls}",
        "/acls/{acls}/consumer",
        "/acme",
        "/acme/certificates",
        "/acme/certificates/{ceritificates}",
        "/acme_storage",
        "/acme_storage/{acme_storage}",
        "/admins",
        "/admins/password_resets",
        "/admins/register",
        "/admins/self/password",
        "/admins/self/token",
        "/admins/{admins}",
        "/admins/{admins}/consumer",
        "/admins/{admins}/rbac_user",
        "/admins/{admin}/roles",
        "/admins/{admin}/workspaces"
    ]
}

 

The following curl command can be used to list every admin.

curl --header "Kong-Admin-Token: abc123" --request GET "https://kong.example.com/admins"

 

Something like this should be returned.

{
    "data": [
        {
            "created_at": 1603213998,
            "email": "john.doe@example.com",
            "id": "025f899e-46de-45a8-aedd-9a6e60eb0cd9",
            "rbac_token_enabled": true,
            "status": 0,
            "updated_at": 1603215092,
            "username": "john.doe",
            "workspaces": [
                {
                    "name": "*"
                },
                {
                    "config": {
                        "portal": false,
                        "portal_developer_meta_fields": "[{\"label\":\"Full Name\",\"title\":\"full_name\",\"validator\":{\"required\":true,\"type\":\"string\"}}]"
                    },
                    "created_at": 1556808555,
                    "id": "23dcd187-1f7a-463c-8565-8f6e5bfbb430",
                    "is_admin_workspace": true,
                    "name": "default"
                }
            ]
        }
    ],
    "next": null
}

 

Or, a specific admin can be listed.

curl --header "Kong-Admin-Token: abc123" --request GET "https://kong.example.com/admin/john.doe"

 


100+ results

If you have more than 100 admins, the REST API will only return the first 100 admins and the output will include offset, like this.

"offset":"WyI2MTQ4ZDU5MC0zNzdhLTQ5MWItYjMxYS1lMTYwYzYwNDgwYTYiXQ"

 

You would then use the offset to return the next 100 admins.

curl --header "Kong-Admin-Token: abc123" --request GET "https://kong.example.com/admins?offset=WyI2MTQ4ZDU5MC0zNzdhLTQ5MWItYjMxYS1lMTYwYzYwNDgwYTYiXQ"

 


Postgres

Undeneath the hood, the admins are stored in the admins table in the Kong Postgres database.

~]# psql --username postgres --dbname kong --command "select * from admins" --expanded
-[ RECORD 1 ]-
id                 | 831a23ea-8b18-445b-8a8c-234392567861
created_at         | 2020-02-14 18:54:06
updated_at         | 2022-09-15 11:45:59
consumer_id        | 5339f1aa-8f78-492d-b2af-dc1e674340fa
rbac_user_id       | f3e21828-e790-41ee-ab6a-ca76cfa1abe4
email              | john.doe@example.com
status             | 0
username           | john.doe
custom_id          | 
rbac_token_enabled | t
username_lower     | john.doe

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 3897d2 in the box below so that we can be sure you are a human.