Security and best practices
In Arianet BaaS your client app (browser or mobile) talks to the Database directly. That is safe as long as you follow two rules: the Service Key never reaches the client and RLS is on for every Table.
Never ship the Service Key in client code
| Key | Where it may go |
|---|---|
| Anon Key / Publishable Key | Browser code, mobile apps, anywhere public. It is not a secret; RLS protects the data. |
| Service Key / Secret Key | Servers, server-side functions and CI secrets only. |
The Service Key bypasses RLS and has full access to every Row, file and User. If it lands in a JavaScript bundle, a mobile app or a public repository, anyone can read and wipe all your data.
- Keep it only in server environment variables, and put
.envfiles in.gitignore. - In front-end frameworks, variables with a public prefix (
NEXT_PUBLIC_,VITE_,NUXT_PUBLIC_,EXPO_PUBLIC_) are built into browser code; never define the Service Key with these prefixes. - If you think the Service Key leaked, rotate the keys at once.
Always keep RLS on
- The Table Editor creates every new Table with RLS on. A Table with RLS off has a red open-lock icon and a warning.
- A Table you create with SQL has no RLS until you turn it on. Always add straight away:
alter table public.my_table enable row level security;
- RLS on with no Policy means the API returns no Rows (the safest state). Then open exactly the access you need with Policies (Policy templates).
- For write commands, add
WITH CHECKas well asUSING, so a User cannot write a Row in someone else's name. - Do not trust
user_metadatain a Policy; the User can change it. For roles useapp_metadata(only a server changes it) or a separate Table. security definerFunctions bypass RLS; in themset search_path = ''and check the caller withauth.uid().- Files need Policies too: RLS on files. Never put personal data in a public Bucket.
Before releasing your app, send a GET to each Table with the Anon Key and no token, and make sure nothing comes back that should not.
How key rotation works
Key rotation replaces the Project's signing key and its Anon and Service Keys:
- The new keys are created and active at once.
- The previous keys stay "retiring" for 72 hours and are still accepted; replace them in every app, server and CI job in that time.
- After 72 hours the previous keys are revoked (
401 invalid_api_key) and tokens signed with the previous key are no longer accepted.
Your app's users are not signed out: their session is signed with the new key when it refreshes. The Publishable Key and Secret Key do not change with rotation. Rotating again during an overlap revokes the previous retiring keys at once.
Arianet API token permissions (baas:*)
For the CLI and the management API (https://api.ariaservice.net/baas/v1), create an Arianet API token with only the permissions it needs. This token is different from a Project's keys: the token manages Projects, the keys reach one Project's data.
| Scope | Allows |
|---|---|
baas:projects:read | Viewing Projects, Plans, Usage, Logs, Database structure, Users and files |
baas:projects:manage | Creating, renaming, pausing and resuming, changing the Plan, deleting Projects and changing Auth settings |
baas:keys:manage | Revealing and rotating keys and the Database password (and arianet baas env) |
baas:sql:execute | Running SQL, changing Table structure and Policies, writing Rows, db push |
baas:storage:manage | Creating and deleting Buckets, uploading and deleting files |
baas:auth-users:manage | Creating, changing and deleting Auth Users |
baas:functions:manage | Creating, deploying, testing and deleting Edge Functions and their secrets |
- For a CI job that only applies migrations,
baas:sql:execute(plusbaas:projects:readif needed) is enough. - For team members, set permissions per Project in the panel's team section.
- Every management action, key reveal and SQL run is recorded in your account's activity log (the SQL text and keys are never recorded).
More tips
- Sign-ups: if your app has no public sign-up, turn on "New sign-ups closed" in the Auth settings. Do not turn email confirmation off.
- Redirect URLs: list only your own domains as allowed redirects.
- The direct Database connection has owner access; guard its password like the Service Key.
- Traffic is always over HTTPS.