Skip to main content

Upstream Authentication & TLS

How the API Builder gateway authenticates to upstream APIs — bearer, API key, Basic, OAuth2 client credentials, WS-Security, custom CA and mutual TLS — and how to rotate secrets.

The API Gateway adds the upstream credential to each call itself, so agents and users never see it. Configure it in the Upstream card of the API's edit page.


Auth Types​

Auth typeSettingsSecret fieldSent to the upstream as
None——No credential
Bearer token—Bearer tokenAuthorization: Bearer <token>
API keyKey name, send in Header or Query parameterAPI keyX-API-Key: <key> (or your header name), or ?api_key=<key>
BasicUsernamePasswordAuthorization: Basic <base64(username:password)>
OAuth2 client credentialsToken URL, client ID, optional scope and audienceClient secretAuthorization: Bearer <access token>
WS-Security (ws_security)Username, password type, timestamp lifetimePasswordA <wsse:Security> UsernameToken header inside the SOAP envelope — see WS-Security

OAuth2 client credentials​

The gateway requests an access token from your Token URL with grant_type=client_credentials, your client ID and secret (plus scope and audience if set), and uses it as a bearer token.

  • Tokens are cached and reused until 60 seconds before they expire (using expires_in, or 5 minutes if the token endpoint doesn't say), so the token endpoint isn't called on every request.
  • The Token URL passes the same network protections and host allow-list as the upstream.
  • Changing the client ID, scope, audience or secret invalidates the cached token.
  • If the token endpoint fails, calls return 502 upstream_auth_failed.

WS-Security​

For SOAP services that require an OASIS WS-Security UsernameToken. The credential travels inside the SOAP envelope, not in an HTTP header, so every operation needs a SOAP request protocol mapper. A call to an operation without one is refused with 502 upstream_auth_unsupported.

Set it on the API with auth_type: "ws_security", the password as auth_key, and these auth_config settings:

auth_config keyDefaultNotes
wsse_username— (required)The UsernameToken username
wsse_password_typetexttext sends the password (#PasswordText). digest sends Base64(SHA-1(nonce + created + password)) with a fresh nonce instead of the password (#PasswordDigest)
wsse_timestamp_ttl300Seconds until the wsu:Timestamp expires, 0–86400. 0 sends no Timestamp
wsse_must_understandtrueMarks the header soap:mustUnderstand

A new header is built for every request, with the SOAP version of the operation's mapper, and it is never cached or logged. When you import a WSDL whose policy asks for a UsernameToken, the proposal's suggested_auth is ws_security. WS-Security is set through the API only for now; the Upstream card doesn't list it yet.

Secrets are never returned​

The secret field (token, API key, password or client secret) is encrypted at rest and always shown as •••••••• after saving. Leave it unchanged to keep the current secret, or type a new value to replace it.


Custom CA and Mutual TLS​

Tick Custom CA or mutual TLS on the Upstream card for upstreams that use a private certificate authority or require a client certificate:

FieldUse
CA certificate (PEM)Trust an upstream whose server certificate is signed by your own CA
Client certificate (PEM)The certificate the gateway presents for mutual TLS
Client private key (PEM)The matching private key — stored encrypted, shown as •••••••• after saving

Certificates are checked when you save, and an invalid PEM is rejected. The same TLS settings are used for the OAuth2 token request. TLS settings that can't be loaded at call time return 502 upstream_tls_config_invalid.


Secret Rotation​

The Security card lets you view and rotate secrets without pulling the API back to draft or re-approving it. These actions are available to lifecycle_manager, space_admin and admin, and each is recorded in the API's audit log.

ActionWhat it doesEffect
Show gateway secretDisplays the gateway URL, the gateway secret and a ready-to-run curl example, so the API can be called from outside Hrida.aiNothing changes. Each view is audited (REVEAL_GATEWAY_SECRET). If the API has never been published, a secret is generated
Rotate gateway secretReplaces the secret between callers and the gateway, and shows the new oneThe old secret stops working at once, on every server, when they share Redis; the Tool Server entry is updated, so agents pick up the new one automatically. Update any external caller with the new value
Rotate upstream credentialReplaces the upstream secret and/or the TLS client private keyThe next call uses the new credential; nothing else about the API changes

The same actions are available in the API:

POST /api/v1/api-definitions/{id}/gateway-secret/reveal
→ {"gateway_secret": "...", "gateway_url": "https://.../api/v1/api-definitions/{id}/proxy", "require_caller_identity": false}
POST /api/v1/api-definitions/{id}/rotate-gateway-secret (response includes "gateway_secret" once)
POST /api/v1/api-definitions/{id}/rotate-upstream-credential {"auth_key": "...", "tls_client_key": "...", "notes": "quarterly rotation"}

Rotating the encryption key​

Every stored secret (upstream credentials, gateway secrets, TLS client keys, stage credentials, catalog and trigger secrets) is encrypted with one key ring:

VariableWhat it is
HRIDAAI_ENCRYPTION_KEYThe current key. When unset, HRIDAAI_SECRET_KEY is used
HRIDAAI_ENCRYPTION_KEYS_PREVIOUSOlder keys, comma-separated, still accepted for reading

To change the key:

  1. Set the new key as HRIDAAI_ENCRYPTION_KEY, and the old one (if you never set one: your HRIDAAI_SECRET_KEY) in HRIDAAI_ENCRYPTION_KEYS_PREVIOUS, on Studio and the gateway service. Restart them.

  2. Re-encrypt every stored secret with the new key:

    bash
    docker exec <studio container> python -m hrida_ai_studio.models.catalog_secrets rotate

    It prints how many secrets it re-encrypted, and how many no key could read (those are left as they are).

  3. Remove the old key from HRIDAAI_ENCRYPTION_KEYS_PREVIOUS and restart.

With HRIDAAI_ENCRYPTION_KEY set, HRIDAAI_SECRET_KEY, which signs sessions, can also change without touching stored secrets.

If an API's upstream credential can't be decrypted with any key in the ring (for example after the key changed without step 1), its calls fail with 502 upstream_credentials_unreadable and the server log says so, rather than the upstream being called with an empty credential. Add the old key back, or enter the credential again with Rotate upstream credential.

Calling an API from outside Hrida.ai

Send Authorization: Bearer <gateway secret> to <gateway URL>/<operation path>, for example curl -H "Authorization: Bearer $SECRET" https://hrida.example.com/api/v1/api-definitions/<id>/proxy/posts/1. Only published APIs are served, and the call is refused if the API's policy has Require a signed caller identity turned on, since only Hrida.ai agents can sign one.


Hrida.ai is proprietary software of Zlabs Innovation. See the license for terms. © 2026 Zlabs Innovation.