RAGIFY
/Docs
developer mode
Audience: developerRead Time: 6 minStatus: built

Access and Semantics

Access and Semantics

Last verified against: commit 6f2f20b (v1.0)
Estimated Read Time: 6 min
Status: built

Locus controls access to relational data and calculated metrics through a semantic catalog that distinguishes between anonymous visitors, authenticated website users, and internal staff.


1. Access Classes

Every table and metric in the semantic layer belongs to one of three access classes:

Access ClassPermitted RolesRow Scoping BehaviorExample Use Case
publicAnonymous, End Users, StaffUnscoped (all active rows returned)Public product catalog, documentation, FAQs
user_scopedEnd Users, StaffEnforced owner_key_column = :user_subInvoices, personal orders, account statements
privateStaff onlyFails closed (HTTP 403) for non-staffFraud scoring, internal cost sheets, audit logs

When new database tables are synchronized from an external connector, they default to access_class = 'private' to prevent unintended exposure until an operator explicitly publishes or configures row scoping on the table.


2. End-User Identity Tokens

When end users interact with chat assistants that query user_scoped tables, the host application passes a signed JWT in the X-Locus-User-Token HTTP header.

Validation Rules

  • Algorithms: Supported algorithms are ES256, EdDSA, RS256.
  • Subject Extraction: By default, the user identifier is extracted from the sub claim (customizable per assistant).
  • Fail-Closed Policy: If the header is absent, the caller resolves to Scope.anonymous(). If the token is invalid, expired, or has an untrusted signature, Locus raises 401 Unauthorized.

Defect Disclosure: The token verifier in backend/access/tokens.py conditionally permits HS256 when ALLOW_INSECURE_DEV_TOKENS=1 or in dev/test, and contains code that fetches remote JWKS keys over HTTP. In production, always supply static PEM public keys directly in the assistant configuration.

Token Minting Example (Python)

import jwt
from datetime import datetime, timezone, timedelta

# Load your private RSA key
with open("private_key.pem", "rb") as f:
    private_key = f.read()

payload = {
    "sub": "cust_987654",
    "name": "Jane Doe",
    "iss": "https://auth.example.com",
    "aud": "locus-chat",
    "exp": datetime.now(timezone.utc) + timedelta(minutes=30),
}

user_jwt = jwt.encode(payload, private_key, algorithm="RS256")
print("Signed end-user token:", user_jwt)

3. Row Scoping Enforcement

On user_scoped tables, row boundaries are enforced in parameterized SQL queries:

SELECT data FROM table_rows
WHERE table_id = :table_id
  AND trim(data ->> :owner_col) = :user_sub

Because row filtering is applied directly within parameterized database queries rather than in LLM context prompts, prompt injection attempts cannot bypass ownership boundaries.


4. Staff Simulation ("Simulate As")

Staff members can simulate the access view of anonymous visitors or specific customers without requesting customer credentials:

Header Format: X-Locus-Simulate-As

  • Simulate anonymous visitor: anonymous
  • Simulate customer: user:cust_987654

When this header is passed by authenticated staff, the execution scope drops staff privileges and applies the constraints of the simulated identity:

# Run in terminal
curl -X POST http://127.0.0.1:8000/access/semantic/query \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer locus_session_REPLACE_ME" \
  -H "X-Locus-Simulate-As: user:cust_987654" \
  -d '{
    "question": "What is my total spend?"
  }'
Checked against build git-rev-access-semantics
Truth Audit Specification Validated