Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ GUARDRAILS_HUB_API_KEY="<ADD-KEY>"
HF_TOKEN="<ADD-HF-KEY>"
# SHA-256 hex digest of your bearer token (64 lowercase hex chars)
AUTH_TOKEN="<ADD-HASH-TOKEN>"
KAAPI_AUTH_URL="<ADD-KAAPI-AUTH-URL>"
KAAPI_AUTH_TIMEOUT=5
# Comma-separated source IPs allowed to call this service (kaapi-backend).
# Empty disables the check; required when ENVIRONMENT=production.
ALLOWED_IPS="127.0.0.1"

# URL for the guardrails API — required for the multiple_validators evaluation script
GUARDRAILS_API_URL="http://localhost:8001/api/v1/guardrails/"
Expand Down
5 changes: 3 additions & 2 deletions .env.test.example
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ OPENAI_API_KEY="<ADD-KEY>"
GUARDRAILS_HUB_API_KEY="<ADD-KEY>"
# SHA-256 hex digest of your bearer token (64 lowercase hex chars)
AUTH_TOKEN="<ADD-HASH-TOKEN>"
KAAPI_AUTH_URL="<ADD-KAAPI-AUTH-URL>"
KAAPI_AUTH_TIMEOUT=5
# Comma-separated source IPs allowed to call this service (kaapi-backend).
# Empty disables the check; required when ENVIRONMENT=production.
ALLOWED_IPS="127.0.0.1"
10 changes: 5 additions & 5 deletions backend/.guardrails/hub_registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,39 @@
"exports": [
"BanList"
],
"installed_at": "2026-05-12T05:28:55.036165+00:00",
"installed_at": "2026-08-18T06:55:12.094065+00:00",
"package_name": "guardrails-grhub-ban-list"
},
"guardrails/llm_critic": {
"import_path": "guardrails_grhub_llm_critic",
"exports": [
"LLMCritic"
],
"installed_at": "2026-05-12T05:29:05.596003+00:00",
"installed_at": "2026-08-18T06:57:19.392503+00:00",
"package_name": "guardrails-grhub-llm-critic"
},
"guardrails/llamaguard_7b": {
"import_path": "guardrails_grhub_llamaguard_7b",
"exports": [
"LlamaGuard7B"
],
"installed_at": "2026-05-12T05:29:16.995441+00:00",
"installed_at": "2026-08-18T06:56:38.901794+00:00",
"package_name": "guardrails-grhub-llamaguard-7b"
},
"guardrails/profanity_free": {
"import_path": "guardrails_grhub_profanity_free",
"exports": [
"ProfanityFree"
],
"installed_at": "2026-05-12T05:29:28.079410+00:00",
"installed_at": "2026-08-18T06:58:01.196192+00:00",
"package_name": "guardrails-grhub-profanity-free"
},
"guardrails/nsfw_text": {
"import_path": "guardrails_grhub_nsfw_text",
"exports": [
"NSFWText"
],
"installed_at": "2026-05-12T05:29:50.654888+00:00",
"installed_at": "2026-08-18T07:03:49.839668+00:00",
"package_name": "guardrails-grhub-nsfw-text"
}
}
Expand Down
33 changes: 24 additions & 9 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,19 +191,32 @@ echo -n "your-plain-text-token" | shasum -a 256

Set the resulting digest as `AUTH_TOKEN` in your `.env` / `.env.test`.

## Multi-tenant API Key Configuration
## Caller Authentication

Ban List and LLM Prompt Config APIs use `X-API-KEY` auth instead of bearer token auth.
kaapi-guardrails is an internal service. Its only caller is kaapi-backend, which authenticates the
end user and resolves the tenant before calling.

Required environment variables:
- `KAAPI_AUTH_URL`: Base URL of the Kaapi auth service used to verify API keys.
- `KAAPI_AUTH_TIMEOUT`: Timeout in seconds for auth verification calls.
Every request (except the health check) must carry:

At runtime, the backend calls:
- `GET {KAAPI_AUTH_URL}/apikeys/verify`
- Header: `X-API-KEY: <token>`
- `Authorization: Bearer <plain-text-token>`
- `X-ORGANIZATION-ID: <int>` and `X-PROJECT-ID: <int>` — the tenant, resolved by kaapi-backend
- and originate from an IP listed in `ALLOWED_IPS`

If verification succeeds, tenant's scope (`organization_id`, `project_id`) is resolved from the auth response and applied to tenant-scoped CRUD operations (for example Ban Lists and LLM Prompt Configs).
`ALLOWED_IPS` is a comma-separated list of source IPs allowed to reach this service:

```bash
ALLOWED_IPS="10.0.3.14"
```

Leave it empty to disable the check for local development. It is required when
`ENVIRONMENT=production` — the service will not start without it.

Rejections:
- Source IP not whitelisted → `403` (checked before the token)
- Missing or invalid token → `401`
- Missing or non-integer tenant headers → `422`

Tenant scope is never read from the query string or request body.

## Guardrails AI Setup

Expand Down Expand Up @@ -339,3 +352,5 @@ class GenderAssumptionBiasSafetyValidatorConfig(BaseValidatorConfig):
```

3. In `backend/app/schemas/guardrail_config.py`, add the newly created config class to `ValidatorConfigItem`.

# test

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this

Loading
Loading