Getting started with the ForgeRock Identity Cloud REST API: Part 8 -

Author:

Rajesh Rajasekharan

Created at:

Jul 2023

Updated at:

Mar 2024

Auditing and monitoring

This guide provides examples of running ForgeRock Identity Cloud auditing and monitoring requests using both Postman and curl commands.

Before you begin

This guide assumes that you have already prepared the ForgeRock Identity Cloud Postman Collection environment and run the collection prerequisites. See Part 1 - Introduction and Part 2 - Prerequisite requests for further information.

Example using Postman ~ 5 min

  1. In Postman, go to ForgeRock Identity Cloud Collection > Auditing/Monitoring.

    https://backstage-community-prod.storage.googleapis.com/original/2X/5/566cdc86fcb43d5ff36c4491ec0ffa21a6562e7f

  2. Go to Auditing/Monitoring > Health > Check Health and study the request URL.

    https://backstage-community-prod.storage.googleapis.com/original/2X/6/66395a399c81df0c2108fa6fe0114441ab87aee5

  3. Click Send.

    The server returns an "OK" status.

    https://backstage-community-prod.storage.googleapis.com/original/2X/e/e9901801505191e727a8a20504054b2dc38b4bca

  4. Go to Auditing/Monitoring > Auditing > Step 1 and study the following:

    • The request method: GET

    • The request URL: {{platformUrl}}/monitoring/logs/sources?_prettyPrint=true

    • The request headers

      Note that the request headers include x-api-key and x-api-secret, whose values are not set yet. These values need to be generated in the Identity Cloud tenant first. To use the /monitoring/log endpoint of Identity Cloud, authentication using the headers x-api-key and x-api-secret is required.

      https://backstage-community-prod.storage.googleapis.com/original/2X/7/7e15c7370d5e5ac2ee0f5b0b1375b25b1f44384d

  5. To generate Log API Keys, log into the Identity Cloud Admin UI, and click on Tenant Settings under your profile menu on the top right corner of the page.

    https://backstage-community-prod.storage.googleapis.com/original/2X/c/cb2b59a7b6d01f5f4201a065b5bc57fee9e8ef04

  6. On the Tenant Settings page, go to the Global Settings tab and select Log API Keys.

    https://backstage-community-prod.storage.googleapis.com/original/2X/2/22bd71389c0b3e33342ad0114867a66f7ddc3d2b

  7. Click + New Log API key.

    https://backstage-community-prod.storage.googleapis.com/original/2X/5/597bbe67327e0242b2e1025dce5157eeb6d6ab59

  8. Provide a name for the Log API and click Create Key.

    https://backstage-community-prod.storage.googleapis.com/original/2X/d/d508d8d074b0c615b571e79d08141bfdac85c99d

    The newly generated api key id and key secret are displayed. Keep a copy of them handy as we will update these values in our Postman application variables in the next step. The api key secret is never shown again.

  9. Click Done.

    https://backstage-community-prod.storage.googleapis.com/original/2X/7/7d4eaf9fddb600b0988a0be21ccdc7344ae03489

  10. In Postman, go to ForgeRock Identity Cloud Postman Collection > Variables. Update the Current value of logApiKey and logApiSecret to the ones picked up from Identity Cloud.

https://backstage-community-prod.storage.googleapis.com/original/2X/5/503902f31477bec6018585069efdc6542f99cd84

  1. Save the changes.

  2. Go to Auditing/Monitoring > Auditing > Step 1 and click Send.

    The response from Identity Cloud lists various sources of Identity Cloud logs.

    https://backstage-community-prod.storage.googleapis.com/original/2X/6/6a098ac7ca04a91b991108d8f2ad69e411a44668

  3. Go to Auditing/Monitoring > Auditing > Step 2 and study the following:

    • The request method: GET

    • The request URL: {{platformUrl}}/monitoring/logs?source={{auditSource}}&_pageSize=10&_prettyPrint=true

    • The request headers, specifically the x-api-key and x-api-secret parameters

      Note that the {{auditSource}} placeholder in the request URL now has a value am-access. Sending this request to the /monitoring/logs endpoint will therefore return access logs of the Access Management component of Identity Cloud.

      https://backstage-community-prod.storage.googleapis.com/original/2X/d/d09be7252ac0b82c62d28dc8e0b2ea4136584b43

  4. With Auditing/Monitoring > Auditing > Step 2 selected, click Send.

    The response returns access logs of Identity Cloud Access Management components.

    https://backstage-community-prod.storage.googleapis.com/original/2X/d/df37ac71fd914fef2628c3bb34ce583116839fe8

Examples using curl

The following example curl commands invoke REST calls to the various “/monitoring” endpoints of Identity Cloud. As noted earlier, some “/monitoring/logs” endpoints of the Identity Cloud expect authentication using the parameters x-api-key and x-api-secret.

  1. Make the following request to monitor system performance:

    $ curl --request GET 'https://<id-cloud-tenant>/monitoring/health'

    Response:

    {
    "status": "OK"
    }
  2. Make the following request to view a list of the available audit logging sources:

      $ curl --location 'https://<id-cloud-tenant>/monitoring/logs/sources?_prettyPrint=true' \
    --header 'x-api-key: {{x-api-key}}' \
    --header 'x-api-secret: {{x-api-secret}}' | jq .

    Result:

    {
      "result": [
        "am-access",
        "am-activity",
        "am-authentication",
        "am-config",
        "am-core",
        "am-everything",
        "idm-access",
        "idm-activity",
        "idm-authentication",
        "idm-config",
        "idm-core",
        "idm-everything",
        "idm-recon",
        "idm-sync"
      ],
      "resultCount": 14,
      "pagedResultsCookie": null,
      "totalPagedResultsPolicy": "NONE",
      "totalPagedResults": 1,
      "remainingPagedResults": 0
    }
  3. Make a request similar to this to retrieve the logs for a specific audit logging source. In our example we are retrieving the logs for am-access:

    $ curl --location 'https://<id-cloud-tenant>/monitoring/logs?source=am-access&_pageSize=10&_prettyPrint=true' \
    --header 'x-api-key: {{x-api-key}}' \
    --header 'x-api-secret: {{x-api-secret}}' | jq .

    Result:

    {
     "result": [
       {
      "payload": {
        "_id": "008c1626-7d16-490b-a065-4aa6e6aeac93-3609206",
        "client": {
          "ip": "10.8.4.237",
          "port": 58658
        },
        "component": "OAuth",
        "eventName": "AM-ACCESS-ATTEMPT",
        "http": {
          "request": {
            "headers": {
              "content-type": [
                "application/x-www-form-urlencoded"
              ],
              "host": [
                "am.fr-platform:80"
              ],
              "user-agent": [
                "Go-http-client/1.1"
              ]
            },
            "method": "POST",
            "path": "https://am.fr-platform:80/am/oauth2/introspect",
            "secure": true
          }
        },
        "level": "INFO",
        "realm": "/",
        "request": {
          "detail": {}
        },
        "source": "audit",
        "timestamp": "2023-04-30T12:23:57.476Z",
        "topic": "access",
        "transactionId": "71be4f74-7a24-490c-84be-02cf7ff2d32a/0"
      },
      "timestamp": "2023-04-30T12:23:57.477715569Z",
      "type": "application/json",
      "source": "am-access"
    },
    < -------- output truncated for brevity ------>
    
     "totalPagedResultsPolicy": "NONE",
     "totalPagedResults": -1,
    "remainingPagedResults": -1
    }