Configuring API Authentication

This topic describes the authentication required to make calls to the Stellar Cyber API. In general, you will need a user account with sufficient privileges, an API key, and a JSON Web Token created from the API key. See the following sections for details:

About Scoped API Keys in the 5.4.1 Release

This section describes a feature that is only available as part of an Early Access Program in the 5.4.1 release and may not appear in your version of the Stellar Cyber Platform. Contact your account manager to inquire about taking part in an Early Access Program.

Prior to the 5.4.1 release, public API access was only available to users with Root scope and Super Admin privileges. The 5.4.1 release introduces per-user API keys, scoped to a user's RBAC privileges and tenancy as an Early Access Program feature. If this feature is enabled in your deployment, you will see an API Keys tab in the Edit User and User Profile dialog boxes, as illustrated below:

If you do not see the API Keys tab, this Early Access Program feature is not enabled in your deployment. Super Admin users with Root scope can continue to configure API tokens using theAPI Access option in the Settings tab of the Edit Existing User dialog box.

Benefits of Scoped API Keys

The Early Access Program implementation of API keys has the following benefits:

  • Respects the industry-standard principle of least privilege, only granting an API key the tools that it needs to perform the job you want it to do.

  • Allows easy breach isolation, with API keys tied to specific users.

  • Enables immediate key revocation to contain exposures quickly and limit the dwell time of any unauthorized access.

Stellar Cyber recommends that you consider creating service accounts scoped with only the RBAC privileges necessary to perform specific tasks. This way you can grant personnel just the access they need to perform specific API tasks.

Managing Scoped API Keys

Both the Edit User and User Profile dialog boxes include an API Keys tab that lets you create and revoke an account's API keys. The keys listed in the API Keys tab are specific to the selected account and are limited by its user scope (tenancy) and RBAC privileges:

  • An account can only make calls to the public API endpoints available to its assigned RBAC privileges.

    Certain public API endpoints are restricted to Super Admin users with root scope even when Scoped API Keys are enabled. Refer to Restricted Public API Endpoints for a list.

  • An account can only access API data available to its user scope and tenancy. For example:

    • A partner user can access data for any of its associated tenants.

    • A tenant user can only access data for its own tenancy.

    • A root user can access data from the entire platform.

You use the API keys in the API Keys tab to generate a JSON Web Token for access to the API.

Administrative users can revoke keys for users with lower privileges than their own, subject to the normal limits on tenancy and scope. They cannot, however, create a key for another user.

API Authentication by Release and Early Access Program Status

The Stellar Cyber public API supports different authentication techniques depending on your deployment's version number and Early Access Program status. The table below summarizes the different techniques available.

Version Number Early Access Program Status Account Requirements Authentication Available
5.4.0 n/a Super Admin users with Root scope
  • Basic authentication using only the API key retrieved from System | Users to authenticate API calls.

  • JWT authentication using the API key retrieved from System | Users to generate a time-sensitive JWT.

5.4.0s n/a Super Admin users with Root scope
  • JWT authentication using the API key retrieved from System | Users to generate a time-sensitive JWT.

5.4.1/5.4.1s

Scoped API keys not enabled.

Same as 5.4.0/5.4.0s

Same as 5.4.0/5.4.0s

5.4.1/5.4.1s

Scoped API keys enabled.

None. Available public API endpoints are scoped according to account's RBAC privileges and tenancy. Super Admin users with Root scope continue to have access to all public API endpoints using the same techniques as in previous releases.

JWT authentication using the API key retrieved from API Keys tab in either Edit Existing User or Edit User Profile dialog box to generate a time-sensitive JWT.

Restricted Public API Endpoints

The table below lists the public API endpoints that remain accessible only to Super Admin users with root scope in 5.4.1 with Scoped API Keys enabled. These endpoints do not support user-scoped access:

Version 5.4.1

Version 5.4.1s

/storage-usages /storage-usages
/storage-usages/daily_and_monthly /storage-usages/daily_and_monthly

/incidents

/incidents

/entity_usages/entity_list/{scope}

/entity_usages/entity_list/{scope}

/reset_user

/reset_user

/ingestion-stats

 

/data

 

/update_ser

 

/security_events/{index}/[id|tags|status|comment]

 
/insert_ser  
/insert_ser_bulk  

Required Privileges to Make API Calls

The requirements to perform API calls are different depending on your release and Early Access Program status:

Version

Requirements

5.4.0/5.4.0s

Must have Root scope with Super Admin privileges (must be the default Super Admin template).

5.4.1/5.4.1s without Scoped API Keys enabled in Early Access Program
5.4.1/5.4.1s with Scoped API Keys enabled in Early Access Program No user account requirements. Public API endpoints are limited by account's RBAC privileges and tenancy.

We recommend creating a Stellar Cyber user dedicated to API calls. That way you can easily track changes made through API calls under System | Users | Activity Log. If you have Scoped API Keys enabled, you can create multiple service accounts, each dedicated to a particular level of API access.

Access to the API is only available using local user accounts. Single-sign on (SSO) users cannot access the API with their SSO credentials.

Necessary Information to Make API Calls

Calls to the Stellar Cyber API typically require a subset of the following information:

Data Description
Email Address Email address of the admin account making the call.
API Key

Generate an API key as follows:

  1. Navigate to System | Users.

  2. Locate the user account to perform the API call and select Edit () in its row.

  3. Use one of the following techniques, depending on your version and Early Access Program status:

    • 5.4.0/5.4.0s or 5.4.1/5.4.1s without Scoped API Keys enabled: Locate the API Access item in the dialog box that appears and select Generate New Token. You must be a Super Admin with root scope to use this technique.

    • 5.4.1/5.4.1s with Scoped API Keys enabled: Click on the API Keys tab and use the options there to generate a new key.

  4. Copy and paste the token into a text file to store it temporarily.

YourStellarCyberServer The URL or IP address of your Stellar Cyber server.

Generating a JSON Web Token (JWT) from the API Key

Requests to the Stellar Cyber public APIs are secured using JSON Web Token (JWT) authentication.

Generating a New JWT as Part of a Script

Because JWTs expire ten minutes after they are generated, you may want to include logic in your scripts similar to the previous code sample to generate and use a fresh JWT every time the script is run.

For example, the code sample below uses the same host, userid, and refresh_token as above but includes it as part of a script that pulls the ten most severe cases for a specific tenant. Note the following:

  • The script sets the host, userid, and refresh_token in the same places as the previous script (Step 1 in the sample).

  • The script runs the getAccessToken procedure to generate the new JWT (Step 2 in the sample).

  • The script uses the generated JWT to make a call to the cases API in the getCases procedure (Step 3 in the sample). This procedure also includes specific arguments that specify the tenant_id and how many cases to retrieve (10), as well as the order in which to return them (desc).

  • The script also prints the generated JWT to the screen. This, however, is not strictly necessary since the getAccessToken procedure already prints the status code for the call to the access_token API (200 for success; 401 for failure).

Copy

#!/usr/bin/python3

import requests
import base64
import json
from urllib.parse import urlunparse
requests.packages.urllib3.disable_warnings()

# Step 1
# Add DP IP/hostname, userid, and refresh token from GUI here
HOST = "myserver.stellarcyber.cloud"
userid = "myuser@stellarcyber.ai"
refresh_token = "2iRpBAyQYEfv77R2QtATlJN6Nvq6uzftBdzotSy2pjT-IvJTLw9aiHyh7Y2mo12IDSWc-FfHwUyPpmiHQnJrSH"

def getAccessToken(userid, refresh_token):
    auth = base64.b64encode(bytes(userid + ":" + refresh_token, "utf-8")).decode("utf-8")
    headers = {
        "Authorization": "Basic " + auth,
        "Content-Type": "application/x-www-form-urlencoded",
    }
    url = urlunparse(("https", HOST, "/connect/api/v1/access_token", "", "", ""))
    res = requests.post(url, headers=headers, verify=False)
    print(res.status_code)
    return res.json()["access_token"]


def getCases(token):
    headers = {"Authorization": "Bearer " + token}
    url = urlunparse(("https", HOST, "/connect/api/v1/cases?tenantid=817418af76d44358922636e34be9627c&limit=10&sort=score&order=desc", "", "", ""))
    res = requests.get(url, headers=headers, verify=False)
    print(res.status_code)
    return res.json()

if __name__ == "__main__":

    # Step 2: Use getAccessToken with supplied credentials to generate JWT
    jwt = getAccessToken(userid, refresh_token)
    print("------------ jwt -------------")
    print(jwt)
    print("------------ jwt  end -------------")

    # Step 3: use JWT token to call public API
    cases = getCases(jwt)
    print("------------ call result of /connect/api/v1/cases -------------")
    print(cases)
    print("------------ end api results -------------")

All API Calls Stored in User Activity Log

Any API request to the public APIs listed here is logged to the User Activity Log with the corresponding user. The request body is also visible by clicking the JSON Data button for the call in the User Activity Log page.