OAuth2 clients
Categories:
Many APIs only accept short-lived OAuth2 access tokens. A token pasted into a playbook stops working when it expires, often within the hour. SOARCA can request these tokens itself with the client credentials grant (RFC 6749, section 4.4) and keep them until shortly before they expire.
You register each API client with SOARCA once, under an identifier. A playbook refers to that identifier, so the playbook holds neither the client secret nor a token. This works for the HTTP API and OpenC2 HTTP capabilities, with any identity provider that supports the client credentials grant.
Register SOARCA with the identity provider
In the identity provider that protects the API, create a client for SOARCA:
- Create a confidential client, also called an application or service account, that may use the client credentials grant.
- Give it access to the API: the scopes, roles or permissions the API expects. Grant only what your playbooks need.
- Create a client secret and store it where SOARCA can read it: a file or an environment variable.
- Note the client ID and the token endpoint. Most providers publish the token endpoint as
token_endpointin their discovery document, at/.well-known/openid-configurationor/.well-known/oauth-authorization-server(RFC 8414).
Note when the secret expires, if your provider sets an expiry.
Configure the clients
List the clients in a JSON file and point OAUTH2_CLIENTS_FILE to it:
[
{
"id": "ticketing",
"token_url": "https://auth.example.com/oauth2/token",
"client_id": "soarca",
"client_secret_file": "/run/secrets/ticketing",
"scopes": ["tickets:read", "tickets:write"]
}
]
| Field | Description |
|---|---|
id | The identifier playbooks use in kms_key_identifier. Must be unique. |
token_url | The token endpoint of the identity provider. Must use https, except for localhost while testing. |
client_id | The client ID registered with the identity provider. |
client_secret_file | A file that holds the client secret. Use this or client_secret_env. |
client_secret_env | An environment variable that holds the client secret. Use this or client_secret_file. |
scopes | The scopes to request, as the API’s documentation specifies them. Optional. |
OAUTH2_CLIENTS_FILE: "/etc/soarca/oauth2-clients.json"SOARCA reads the file at startup and refuses to start if an entry is incomplete or its secret can’t be read. Restart SOARCA after adding or changing a client. A changed secret, in its file or environment variable, is used the next time SOARCA requests a token, without a restart.
Use a client in a playbook
Refer to the client from oauth2 authentication information with kms set to true and the client’s id in kms_key_identifier:
"authentication_info_definitions": {
"oauth2--1b0e7c2d-3f4a-4b5c-8d6e-9f0a1b2c3d4e": {
"type": "oauth2",
"name": "Ticketing API",
"oauth_header": "Bearer",
"token": "",
"kms": true,
"kms_key_identifier": "ticketing"
}
},
"target_definitions": {
"http-api--5a3c9b1e-7d2f-4e8a-9b6c-1d0e2f3a4b5c": {
"type": "http-api",
"name": "Ticketing API",
"address": { "url": ["https://api.example.com"] },
"authentication_info": "oauth2--1b0e7c2d-3f4a-4b5c-8d6e-9f0a1b2c3d4e"
}
}
The CACAO schema requires oauth_header and token on oauth2 authentication information, and says the token must not be filled in when kms is used. Keep both, with token empty.
When a step runs, SOARCA sends Authorization: Bearer <access token>. The token is never stored in playbook variables or execution reports.
Tokens
- SOARCA requests a token the first time a playbook needs it and reuses it for every execution until shortly before it expires.
- If the API answers
401 Unauthorized, SOARCA requests a new token and repeats the call once. That covers tokens revoked before they expire. Other errors, including403 Forbidden, are returned as they are. - If the token request fails, the step fails with the identity provider’s error code and description, for example
invalid_client.
Limitations
- Only client secrets are supported. Other ways to authenticate the client, such as certificates (
private_key_jwt) or workload identities, are not, yet. - The clients come from a file. Integration with a key management service such as OpenBao is planned. Playbooks won’t need to change for it.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.