Data Sources
A data source is a database connection that an administrator adds to a catalog. It names the database, the user, and the catalog secret that holds the password. The password is decrypted only on the Studio server, at the moment a query runs. It never appears in an API response, a log, an error message, a prompt, or a terminal.
Every query, whoever sends it, goes through the same checks:
- it must be one read-only statement;
- it may read only the allowed tables;
- it may not use the hidden columns;
- the source's row cap and timeout apply;
- it is written to the source's query log.
Why Not Environment Variables?
A common way to give a terminal or an agent database access is to start it with -e DB_HOST=… -e DB_PASS=…. Don't do this for Hrida Terminal or any other place a model runs commands. The model can read every environment variable and every file there: env, cat /proc/1/environ, cat .env. Whatever it reads lands in the chat history and the process logs.
With data sources, the terminal holds only a short-lived session token:
- it opens Studio's data-source gateway and nothing else;
- it works only for the data sources granted to that user;
- it is read-only;
- it expires an hour after its last use.
Studio refuses terminal environment variables that look like credentials (see below).
Add a Data Source
-
Store the password. In Admin › Agent Catalogs, open the catalog. On the Secrets tab, add the database password as a secret, such as
SALES_DB_PASSWORD, or put the whole connection URL in one, such asSALES_DB_URL. -
Add the data source. On the Data sources tab, click New data source and fill in:
Field Meaning Name What agents and users type, such as sales. Lower-case letters, digits,-and_. Unique on the platform.Type PostgreSQL, MySQL / MariaDB, or Oracle. Connection Host, port, database (the service name for Oracle) and user, plus Password from secret. Or choose Connection URL from a secret instead. Create secret… adds one without leaving the form. SSL mode PostgreSQL only. requireby default.Allowed tables One per line: table,schema.table,schema.*, or*. Leave it empty to allow every table the database user can read.Hidden columns One per line: column,table.columnorschema.table.column. A query that names one is refused, andSELECT *shows it as***.Default schema The schema that unqualified table names, and unqualified allowed-table patterns, refer to. With none set, PostgreSQL's publicand SQLite'smaincount as the default, sopublic.customersis the same table ascustomers.Row cap The most rows a single call returns. 1,000 by default, 10,000 at most. Callers page past it with an offset. Timeout Seconds per query. 30 by default, 300 at most. Keep result rows in the query log Off by default: the log keeps the SQL, the row count and the duration, but not the rows. Who may use it Users and groups (for chat, automations and Hrida Terminal), and spaces of this catalog (for Agent Builder agents). Nobody has access until you grant it. API Builder spaces API spaces, from any API catalog, whose APIs may serve this data source as REST operations. A ticked space is the grant for those APIs' calls. The developers who build them also need a read grant above. -
Test it. Test connection runs a probe query and shows the server version and the tables the source can read. An error is shown with the password, host, user and IP addresses removed.
If you were given DB_HOST=… DB_PORT=… DB_NAME=… DB_USER=… DB_PASS=… lines, a DATABASE_URL=… line, or a docker run -e … command, click Paste env block and paste it. The form is filled in, and the password (or URL) is saved as a catalog secret straight away. The pasted text is then cleared. The password never stays in the form.
Studio refuses anything but read-only queries, and runs each one in a read-only transaction. Still, give every data source a database user that can only SELECT from the tables it needs. The checks are the first layer, not the only one.
What the Checks Refuse
Studio parses each query before sending it. It refuses:
- more than one statement, and anything that isn't a query:
INSERT,UPDATE,DELETE,MERGE, DDL,SET, transactions; - a data-modifying CTE (
WITH x AS (DELETE …) SELECT …),SELECT … INTOandFOR UPDATE/FOR SHARE; - functions that wait, read files, reach the network or run SQL text:
pg_sleep,sleep,benchmark,pg_read_file,lo_import,dblink,query_to_xml,load_extension,dbms_*,utl_*, sequences (nextval,setval), and similar; - tables outside Allowed tables, including tables hidden behind a CTE of the same name, another database (
otherdb.schema.table), and table functions when the source has an allowed-tables list; - hidden columns: naming one anywhere (also in
WHERE), whole-row references such asrow_to_json(c), and*inside a function or a subquery. A*in the outerSELECTis allowed, and the hidden columns come back as***.
PostgreSQL, MySQL and Oracle then run the query in a read-only transaction. PostgreSQL also gets a server-side statement timeout.
Using a Data Source
Users see the data sources granted to them in Settings › Data Sources: each one's name, type and description, and how to use it. They never see hosts, users or secrets.
In chat
Turn on the Data Sources built-in tool category for a model: Workspace › Models › the model › Builtin Tools. It is off by default. The model then gets these tools, and answers with the data sources granted to the chatting user:
| Tool | What it does |
|---|---|
list_datasources | The data sources you may use. |
list_datasource_tables | The readable tables and views, with row counts. |
describe_datasource_table | Columns, types, keys, foreign keys and sample values. |
query_datasource | One read-only query, paged with an offset. |
An administrator can turn the tools off for a group with the Data Sources permission in Admin › Users › Groups. It is on by default.
In automations
In the automation editor, tick Data Sources under the tools the runs may use. A run uses the data sources granted to the automation's owner. The query log shows its calls as automation.
In Agent Builder
Give a skill or node the tools list_datasources, list_tables, describe_table and sql_query, and pass the data source's name as datasource. A run may use a data source when it runs in one of the source's spaces (in the source's catalog), or when the user it acts as is granted the source. See Built-in Tools.
A global, draft Agent Builder skill named Database Analyst comes with these tools and the database-analyst instructions attached. Review it and publish it to use it.
In API Builder
An API operation can be served from a data source instead of an upstream service: it runs one saved SELECT, and the request's values are bound as parameters. See Database-Backed Operations.
- Who may use it. Tick the API's space under API Builder spaces. A call to such an API involves no user: the ticked space is the grant. A developer building one also needs their own read grant.
- Same rules. Allowed tables, hidden columns, the row cap, the timeout and read-only queries apply to every call.
- Query log. The refusals and errors of API calls appear in the query log as
api. Their successful queries don't, because the gateway's call log records every call. Previews from the API editor and its AI assistant appear asapi_builder. - Take the grant away by unticking the space. Calls to the API's database operations then get
502 datasource_unavailable.
In Hrida Terminal
When a user with at least one data source uses a terminal from Studio, Studio writes a session token to that user's home on the terminal, as ~/.hrida/db_token. In multi-user mode, only that user can read it. The hrida-db client in the terminal image uses it:
hrida-db sources
hrida-db tables sales
hrida-db describe sales orders
hrida-db query sales "SELECT region, SUM(amount) AS total FROM orders GROUP BY region ORDER BY total DESC"
hrida-db query sales "SELECT * FROM orders WHERE order_date >= '2026-01-01'" --all --out orders.csvfrom hrida_db import connect
db = connect("sales")
df = db.query("SELECT region, SUM(amount) AS total FROM orders GROUP BY region") # a pandas DataFrameThe token is renewed ten minutes before it expires, and the old one is revoked. Each user gets their own token.
Terminal sessions. The Terminal sessions panel at the bottom of the Data sources tab lists every live token, for all catalogs: the user, the terminal, when it started, when it was last used and when it expires. The token itself is never shown. Revoke ends one session; Revoke all of this user ends all of theirs. The API equivalents are GET /api/v1/datasources/sessions, DELETE /api/v1/datasources/sessions/{id} and DELETE /api/v1/datasources/sessions?user_id=….
A revoked token is refused at once, including by a script already running in the terminal. But a user who is still granted a data source gets a new session on their next terminal request through Studio. To stop someone using a data source, remove them from its grants: the next request then finds nothing granted, and every query is refused.
| Setting (Studio) | Default | Purpose |
|---|---|---|
DATASOURCE_GATEWAY_URL | the address the request came in on | Studio's address as the terminal reaches it, such as http://hrida-ai-studio:8080 in Docker. It is written into the token file. |
DATASOURCE_TERMINAL_TOKENS | true | false: never write tokens to terminals. |
For the terminal side (multi-user mode, an egress allowlist with only the Studio host, no NOPASSWD sudo), see the Hrida Terminal production setup guide, section 14, Databases.
Reports in run results
When an automation or an Agent Builder run used a terminal, Studio copies the report folders the run wrote, reports/<name>/, into Studio files that belong to the run's user:
- What is copied. Only folders with a file changed since the run started, and only report files:
.md,.html,.csv,.tsv,.json,.txt,.png,.jpg,.svg,.pdfand.xlsx. Scripts and archives are left behind. There are limits of 5 folders per run, 20 files per folder, 10 MB per file and 30 MB in all. - Automations. The files are listed on the run (the run history shows Reports: …). They are linked at the end of the chat answer, and in the email when the automation emails its report. The email also attaches them, up to 10 MB in all.
- Agent Builder. A run on the catalog's Hrida Terminal lists them under Reports from the terminal in the run's details (the run's
artifactsin the API).
Collecting reports never changes a run's result. If the terminal can't be read, the run simply has no reports.
The database-analyst Skill
A Workspace Skill named database-analyst is installed for every user. It is the method for "analyze this database" requests:
- List the data sources; never ask for or look for credentials.
- Explore the schema first, and summarize it.
- Write efficient, read-only SQL: JOINs, LIMIT, aggregation in the database, ORDER BY.
- Analyze the results in Python: growth, shares, rankings, anomalies, data quality.
- Make charts with matplotlib, saved as PNG under
reports/<name>/. - Write the report,
reports/<name>/report.mdandreport.html. It covers the question, the sources and tables used, the findings with their numbers, every SQL query run, and the caveats (row caps, hidden columns, data quality, date range). Key tables are saved as CSV beside it.
The skill works with the chat tools, the Agent Builder tools, and hrida-db in Hrida Terminal. Edit it in Workspace › Skills; Studio won't overwrite your changes.
Terminal Environment Variables
A terminal connection's Environment Variables (Admin › Settings › Integrations › Terminal servers, orchestrator policy) are visible to the model running commands there. Studio refuses to save:
- a variable named like a credential:
*PASS*,*PASSWORD*,*SECRET*,*TOKEN*,*API_KEY*,*ACCESS_KEY*,*PRIVATE_KEY*,*CREDENTIAL*,*DSN*,DATABASE_URL,DB_URL; - a value that is a URL with a password in it (
scheme://user:password@host); - a value equal to any catalog secret.
The dialog warns about this and masks such values. TERMINAL_ALLOW_SECRET_ENV=true turns the check off. Only use it if the terminal never runs model commands.
How a Secret Used by a Data Source Is Protected
A secret that a data source uses (its password or URL secret):
- is not filled into prompts as
${NAME}; - can't be used as
api_caller'sauth_secret, or as a rawsql_queryURL. The model is told to use the data source's name instead; - can't be deleted while a data source uses it. The Secrets tab shows Data source: name on it.
Creating, replacing and deleting secrets, changing data sources and their grants, connection tests, and issuing and revoking terminal tokens are all written to the audit log. Audit rows hold names and settings, never a value.
API
| Method | Path | Who | Purpose |
|---|---|---|---|
GET | /api/v1/datasources?catalog_id= | admin | The definitions. Secrets appear by name only. |
POST | /api/v1/datasources | admin | Create (catalog_id required). |
GET / PUT / DELETE | /api/v1/datasources/{id} | admin | Read, replace, delete. |
POST | /api/v1/datasources/{id}/test | admin | Test connection. |
GET | /api/v1/datasources/{id}/log?limit= | admin | Recent queries, table listings, describes and tests. |
GET | /api/v1/datasources/sessions | admin | Live terminal session tokens. The token itself is never shown. |
DELETE | /api/v1/datasources/sessions/{id} · ?user_id= | admin | Revoke one token, or all of a user's. |
GET | /api/v1/datasources/mine | user | Name, type and description of the sources granted to you. |
GET / POST | /api/v1/datasources/gateway/sources[/{name}/tables|/describe|/query] | terminal token | The hrida-db gateway. Accepts a dsq_ session token only. |
Development and tests only: DATASOURCE_ALLOW_SQLITE=true allows SQLite data sources, which read a file on the Studio server.
Verifying a Deployment
Two checks ship with Studio's source:
- Real databases.
backend/hrida_ai_studio/test/util/test_datasources_live.pyruns the data-source rules against PostgreSQL and MySQL: test connection, schema, queries, hidden columns, the row cap, the server-side timeout, the read-only transaction, a wrong password and a connection-URL secret. SetDATASOURCE_LIVE_POSTGRES_URLand/orDATASOURCE_LIVE_MYSQL_URLto servers it may change; the file's docstring has thedocker runlines. - Hrida Terminal end to end.
scripts/e2e_datasources_terminal.shstarts PostgreSQL and a terminal container with the egress allowlist, then drives Studio as an admin and an analyst. It checks that:hrida-dbworks and its refusals hold;- no password is in the terminal's environment, processes or files;
- the token opens nothing but the gateway;
- the terminal can't reach the database directly;
- reports reach Studio;
- a revoked token is refused, and removing the grant ends access.