On This Page

Home / Cribl as Code/ Cribl SDKs (Preview)/ SDK Code Examples/Create API Credentials with the Cribl SDK

Create API Credentials with the Cribl SDK

Preview Feature

The Cribl SDKs are Preview features that are still being developed. We do not recommend using them in a production environment, because the features might not be fully tested or optimized for performance, and related documentation could be incomplete.

Please continue to submit feedback through normal Cribl support channels, but assistance might be limited while the features remain in Preview.

These code examples demonstrate how to use the Cribl Python SDK for the management plane to create two new API Credentials: one with the Admin Role at all levels and one with the Editor Role at the product level on a single Workspace.

To use these examples, you must first create an API Credential manually in the Cribl UI. This is necessary because you need the CLIENT_ID and CLIENT_SECRET for an existing API Credential to create an authenticated SDK client for subsequent requests, including requests to create new API Credentials. Read Authenticate in Cribl.Cloud and Hybrid Deployments to create an API Credential in the Cribl UI and retrieve a Bearer token.

About the Code Example

The code example uses Bearer token authentication. Read the authentication documentation for the SDKs to learn how to configure authentication. The Bearer token must be granted Organization Owner or Admin Permissions.

Replace the variables in the example with the corresponding information for your Cribl deployment.

The resource configurations in the example does not include all available body parameters. For a complete list of body parameters for each resource, refer to the endpoint documentation in the API Reference.

Create an API Credential with Admin Role at All Levels

The following example creates an API Credential with Admin at all levels (Organization, all Workspaces, and all Cribl products in all Workspaces). For this request, you only need to specify admin as the Organization Role. The API Credential automatically inherits the Admin Role at lower levels from the Organization-level Role.

The example also includes the optional ipAllowlist body parameter to demonstrate how to restrict API access for the API Credential to a specific IPv4 CIDR range. Replace the placeholder value with your range. Omitting ipAllowlist allows access for all IPs.

The comment block at the beginning of the example includes instructions for using the new API Credential for subsequent SDK requests.

Python SDK (Cribl.Cloud)

Create an API Credential with Product-Level Editor Role in One Workspace

The following example creates an API Credential with specific Roles at the Organization, Workspace, and product levels:

The example also includes the optional ipAllowlist body parameter to demonstrate how to restrict API access for the API Credential to a specific IPv4 CIDR range. Replace the placeholder value with your range. Omitting ipAllowlist allows access for all IPs.

The Cribl Python SDK for the management plane does not support configuring Roles for API Credentials at the resource level. For API Credentials that do not inherit resource-level Roles from higher levels, use the Cribl UI to share Cribl Search resources as needed. See inheritance details for Dataset Providers and Datasets, Dashboards, and Notebooks.

The comment block at the beginning of the example includes instructions for using the new API Credential for subsequent SDK requests.

Python SDK (Cribl.Cloud)

Store and Protect the Client Secret

When api_credentials.create succeeds, the returned object includes client_id and client_secret for the new API Credential. Pass them to SchemeClientOauth when you create a CriblMgmtPlane client for the new credential as described in Authenticate in Cribl.Cloud and Hybrid Deployments.

The api_credentials.list and api_credentials.get methods do not return client_secret. Only the api_credentials.create response includes it. Save client_secret to your secret storage when you create a new API Credential or use automation to write it to a secrets manager. You cannot retrieve the client_secret later.

The client_secret is sensitive information and should be kept private.

Rotate API Credentials

On a CriblMgmtPlane client, api_credentials exposes create, list, get, update, and delete. Those operations wrap the same routes documented in the management plane API Reference.

To rotate with the SDK:

  1. Call api_credentials.create and get the new clientId and clientSecret from the response.

  2. Replace the old clientId and clientSecret values with the new values wherever they are used.

  3. In Python, pass the new client_id and client_secret to SchemeClientOauth when you construct the next CriblMgmtPlane client.

  4. Confirm that the old clientId and clientSecret values are replaced and validate the new values.

  5. Call api_credentials.delete to delete the old credential.

Rotate API Credentials on a schedule and when access requirements change to limit how long a credential is usable. Use one API Credential per integration with only the Roles that each integration requires. That way, rotating one credential does not affect other workloads or integrations that authenticate with other API Credentials.