Watch your servers
Watch a database
A database that fills its disk or plan stops your app. Kiyesi reads each one, read-only, and warns you while there is still time.
Print the steps for your server
Section titled “Print the steps for your server”On the server, as root:
sudo kiyesi databases setupIt lists the databases it finds: on this server, in its Docker containers, and hosted ones its apps use (the host and engine only, never a password). With exactly one hosted database, it prints its steps straight away. Otherwise, ask for one:
sudo kiyesi databases setup postgres ordersIt prints numbered steps for this server, which you review and run yourself: Kiyesi changes nothing. The engines are postgres, mysql, mariadb, mongodb and redis. Add --container <name> for a database in a Docker container, or --host <host> for one elsewhere.
It picks the safest way to sign in: no password wherever the database allows it. --login picks another: password, aws-iam, gcp-iam, azure-identity, certificate, aws-secret or vault.
Run the steps
Section titled “Run the steps”They make a user for Kiyesi with only what it needs, set how it signs in, and give the lines for /etc/kiyesi/config.yaml. Each database’s steps are below.
Check it
Section titled “Check it”sudo kiyesi databases checkIt signs in as the agent will, and prints what Kiyesi sees and any right its user should not have, with the fix. The database appears in Databases within 5 minutes.
What Kiyesi’s user may do
Section titled “What Kiyesi’s user may do”Only read sizes and counts. Every session is read-only too, so even a user given too much cannot write through Kiyesi.
| Database | Its user may | It may not |
|---|---|---|
| PostgreSQL | Connect to the one database, read its size and the connection count. No admin power of any kind (NOSUPERUSER NOCREATEDB NOCREATEROLE NOREPLICATION NOBYPASSRLS), at most 3 connections, every session read-only. |
Read a row, or the text of anyone’s query (so no pg_monitor), or write. |
| MySQL, MariaDB | SHOW VIEW on the one database: its tables’ sizes. Signs in from one address, at most 3 connections. |
Read a row, see anyone’s queries (so no PROCESS), or write. |
| MongoDB | A role of its own, kiyesiStats: dbStats on the database and serverStatus. |
Read a document, or see running operations. |
| Redis, Valkey | INFO and PING. |
Read a key or value, or a setting (the main password is one). |
How it signs in
Section titled “How it signs in”| Where | How | Password kept |
|---|---|---|
| PostgreSQL on the same server | Through its socket (peer): only this server’s root user, which runs the agent, may sign in as kiyesi_ro |
None |
| MySQL on the same server | Through its socket (auth_socket), only for root |
None |
| AWS RDS and Aurora, PostgreSQL and MySQL | A 15-minute token made from the server’s own AWS role, which may connect as kiyesi_ro on that one database and nothing else |
None |
| Azure Database for PostgreSQL and MySQL | A token from the VM’s managed identity, which is the database user | None |
| Google Cloud SQL for PostgreSQL | A token from the VM’s service account, which is the database user | None |
| MongoDB Atlas | An X.509 certificate Atlas makes, kept on the server, readable by root only; or the server’s AWS role | None |
| Your company’s HashiCorp Vault | A short-lived user Vault makes for each lease: the agent renews it, and takes a new one when it ends. The server signs in to Vault with its cloud identity, or an AppRole | None |
| AWS Secrets Manager | The password, read with the server’s AWS role, which may read that one secret | In Secrets Manager |
| MariaDB, MongoDB, Redis, and any database that only takes a password | A random password nobody sees: made, set on the database and encrypted in one go, never typed, shown or kept in your shell’s history | Encrypted on the server |
Every login is used only over TLS that checks the database’s certificate.
Where the password is encrypted:
- systemd 254 and later (Ubuntu 24.04 and later, Debian 13): with
systemd-creds, using the server’s TPM chip when it has one, in/etc/credstore.encrypted. systemd decrypts it only for the agent’s service, into memory. - Older systemd (Ubuntu 22.04, Debian 12): with Kiyesi’s own key, AES-256-GCM. The password is in
/etc/kiyesi/credentialsand the key in/var/lib/kiyesi, both readable by root only, so a copy of either folder alone opens nothing.
systemd-creds may say “Credential secret file … is not located on encrypted media, using anyway.” That is normal without a TPM chip or an encrypted disk: its key is readable by root only, and the password is still never in plain text.
The password is read only into the agent’s memory: never logged, never sent. A password written in an address in config.yaml is refused.
Someone already root on the server can decrypt a password kept there, as with any tool. The strongest logins keep nothing to steal: a socket login, a 15-minute cloud token, or Vault’s short-lived user.
Step by step
Section titled “Step by step”PostgreSQL on the same server: no password
Section titled “PostgreSQL on the same server: no password”sudo kiyesi databases setup postgres orders-
Make Kiyesi’s user. It may connect and read sizes and counts, never a row, and every session it opens is read-only:
Terminal window sudo -u postgres psql -v ON_ERROR_STOP=1 -c 'CREATE ROLE kiyesi_ro LOGIN NOSUPERUSER NOCREATEDB NOCREATEROLE NOREPLICATION NOBYPASSRLS CONNECTION LIMIT 3' -c 'ALTER ROLE kiyesi_ro SET default_transaction_read_only = on;' -c 'GRANT CONNECT ON DATABASE "orders" TO kiyesi_ro;' -
Let this server’s root user sign in as
kiyesi_rothrough the socket only. The line goes first inpg_hba.conf, which is read top to bottom:Terminal window hba="$(sudo -u postgres psql -tAc 'SHOW hba_file')"; ident="$(sudo -u postgres psql -tAc 'SHOW ident_file')"echo 'kiyesi root kiyesi_ro' | sudo tee -a "$ident" >/dev/nullsudo sed -i '1i local orders kiyesi_ro peer map=kiyesi' "$hba"sudo -u postgres psql -c 'SELECT pg_reload_conf()' -
In
/etc/kiyesi/config.yaml:databases:- name: ordersurl: postgres://kiyesi_ro@/orders?host=/var/run/postgresql
MySQL on the same server: no password
Section titled “MySQL on the same server: no password”sudo kiyesi databases setup mysql shop-
Make Kiyesi’s user. Only root may sign in as it, and only through the socket:
Terminal window sudo mysql -e "CREATE USER 'kiyesi_ro'@'localhost' IDENTIFIED WITH auth_socket AS 'root' WITH MAX_USER_CONNECTIONS 3; GRANT SHOW VIEW ON \`shop\`.* TO 'kiyesi_ro'@'localhost';"If it says the
auth_socketplugin is not loaded:sudo mysql -e "INSTALL PLUGIN auth_socket SONAME 'auth_socket.so'". -
In
/etc/kiyesi/config.yaml:databases:- name: shopurl: mysql://kiyesi_ro@localhost/shop?socket=/var/run/mysqld/mysqld.sock
MariaDB: an encrypted password
Section titled “MariaDB: an encrypted password”MariaDB’s socket login lets a user in only under its own name, which would have to be root, so MariaDB gets a password nobody sees, kept encrypted.
sudo kiyesi databases setup mariadb shop-
Make Kiyesi’s user with a random password, allowed only from
127.0.0.1:Terminal window pw="$(openssl rand -base64 32 | tr -d '/+=')"printf "CREATE USER 'kiyesi_ro'@'127.0.0.1' IDENTIFIED BY '%s' WITH MAX_USER_CONNECTIONS 3;\nGRANT SHOW VIEW ON \`shop\`.* TO 'kiyesi_ro'@'127.0.0.1';\n" "$pw" | sudo mariadb -
Keep it encrypted. On systemd 254 and later:
Terminal window sudo install -d -m 700 /etc/credstore.encryptedprintf '%s' "$pw" | sudo systemd-creds encrypt - /etc/credstore.encrypted/kiyesi.db.shopunset pwOn older systemd, with Kiyesi’s own key:
Terminal window sudo install -d -m 700 /etc/kiyesi/credentialsprintf '%s' "$pw" | sudo kiyesi databases encrypt shop | sudo tee /etc/kiyesi/credentials/shop.enc >/dev/nullunset pw -
In
/etc/kiyesi/config.yaml:databases:- name: shopurl: mysql://kiyesi_ro@127.0.0.1:3306/shoppassword: credential
MongoDB
Section titled “MongoDB”sudo kiyesi databases setup mongodb catalogueIt makes a role, kiyesiStats, that may only read the database’s size and the server’s status, and a user with it and a random password, then the same encryption step as above:
pw="$(openssl rand -base64 32 | tr -d '/+=')"KIYESI_PW="$pw" mongosh --quiet admin -u <admin> --eval 'db.getSiblingDB("admin").createRole({ role: "kiyesiStats", privileges: [ { resource: { db: "catalogue", collection: "" }, actions: ["dbStats"] }, { resource: { cluster: true }, actions: ["serverStatus"] } ], roles: [] }); db.getSiblingDB("admin").createUser({ user: "kiyesi_ro", pwd: process.env.KIYESI_PW, roles: [{ role: "kiyesiStats", db: "admin" }] });'The address is mongodb://kiyesi_ro@127.0.0.1:27017/catalogue?authSource=admin, with password: credential.
MongoDB Atlas: a certificate, no password
Section titled “MongoDB Atlas: a certificate, no password”When the only database the server’s apps use is on Atlas, sudo kiyesi databases setup prints its steps straight away. Otherwise:
sudo kiyesi databases setup mongodb mydb --host cluster0.abcde.mongodb.netKiyesi signs in with an X.509 certificate Atlas makes, as MongoDB recommends; no password exists. Steps 1 and 2 are on Atlas’s website, on every plan, the free one too.
-
At cloud.mongodb.com, open the cluster’s project, then in the sidebar Security, Database & Network Access, and the Custom Roles tab. Add New Custom Role, named
kiyesiStats, with two actions:dbStatson your database, andserverStatus, a global action. Nothing else: it cannot read a document. (With the Atlas CLI instead:atlas customDbRoles create kiyesiStats --privilege DB_STATS@mydb,SERVER_STATUS.) -
On the Database Users tab, Add New Database User: Certificate, user
kiyesi_ro, expiration 12 months, Download certificate when user is added on; under Custom Roles, onlykiyesiStats; Restrict Access to Specific Clusters on, with only this cluster. Then Add User: Atlas downloads the certificate, a.pemfile, this once. (With the Atlas CLI:atlas dbusers create --username kiyesi_ro --x509Type MANAGED --role kiyesiStats@admin --scope cluster0, thenatlas dbusers certs create --username kiyesi_ro --monthsUntilExpiration 12 > kiyesi_ro.pem.) -
Send the certificate to the server from the computer it downloaded to. Atlas names it
X509-cert-<numbers>.pem, in Downloads. In a terminal on that computer, with your server’s address and the user you sign in with:Terminal window scp ~/Downloads/X509-cert-*.pem root@203.0.113.24:kiyesi-cert.pemWith more than one
X509-certfile, use the newest one’s full name, as you must on Windows:scp $HOME\Downloads\X509-cert-<numbers>.pem ….Then on the server, keep it readable by root only, and erase the copy you sent:
Terminal window sudo install -d -m 700 /etc/kiyesi/credentialssudo install -m 600 -o root -g root ~/kiyesi-cert.pem /etc/kiyesi/credentials/mydb.pemshred -u ~/kiyesi-cert.pemWithout scp: open the file, copy all of it, run
sudo install -m 600 /dev/null /etc/kiyesi/credentials/mydb.pemandsudo tee /etc/kiyesi/credentials/mydb.pem >/dev/null, paste it, and press Ctrl-D.Check it:
sudo grep -c BEGIN /etc/kiyesi/credentials/mydb.pemprints2(the certificate and its key). Then delete the downloaded file from your computer. -
On the IP Access List tab, this server’s public address must be listed (
setupprints it). If an app on the server already uses the cluster, it is. -
Add it to Kiyesi’s settings, with the one command
setupprints for your settings file as it is:Terminal window printf '%s\n' 'databases:' ' - name: mydb' ' url: mongodb+srv://cluster0.abcde.mongodb.net/mydb?authSource=%24external&authMechanism=MONGODB-X509&tlsCertificateKeyFile=/etc/kiyesi/credentials/mydb.pem' | sudo tee -a /etc/kiyesi/config.yaml >/dev/null -
sudo kiyesi databases check.
Before the 12 months end, download a new certificate in Atlas and send it the same way (step 3).
Moving from a password? Run the same command and keep your kiyesiStats role. After steps 2 and 3, the settings step shows the entry’s new url (with authMechanism=MONGODB-X509, and no password line). Once sudo kiyesi databases check says “Signs in with its certificate on this server, no password”, the last step removes the old password user and its file.
On AWS, the server’s own role can sign in, with nothing kept on the server: --login aws-iam. With a password: --login password, kept encrypted on the server.
In a Docker container
Section titled “In a Docker container”sudo kiyesi databases setup postgres orders --container app-db-1The steps run inside the container with docker exec, with the container’s own admin settings, so no admin password is typed. Kiyesi’s user gets a random password, kept encrypted, and the agent uses the port the container publishes, which should be on 127.0.0.1 only:
ports: - "127.0.0.1:5432:5432"Redis or Valkey
Section titled “Redis or Valkey”sudo kiyesi databases setup redis cachepw="$(openssl rand -base64 32 | tr -d '/+=')"printf 'ACL SETUSER kiyesi_ro on >%s -@all +info +ping\n' "$pw" | redis-cli -a <the admin password> --no-auth-warningThen the same encryption step, and url: redis://kiyesi_ro@127.0.0.1:6379 with password: credential. Redis before 6 has no users: use Redis 6 or later.
A database on another host
Section titled “A database on another host”Add --host, such as --host db.internal. The user is made the same way, with a random password kept encrypted on this server, and the address checks the database’s certificate. For hosted databases that only take a password, setup says where to run the SQL:
| Provider | The admin | Its certificate |
|---|---|---|
| AWS RDS, Aurora | The master user. IAM sign-in is the default there (below) | AWS’s own authority: setup fetches it from truststore.pki.rds.amazonaws.com into /etc/kiyesi/ca/aws-rds.pem |
| Supabase | postgres, with the database password (Project Settings, Database) |
Supabase’s own: Project Settings, Database, SSL Configuration, Download certificate; you paste it into /etc/kiyesi/ca/supabase.pem. Its direct connection is IPv6 only: on a server without IPv6, the steps go through its Session pooler (users postgres.<ref> and kiyesi_ro.<ref>) |
| DigitalOcean | doadmin, from a server in the database’s trusted sources |
DigitalOcean’s own: Connection Details, Download CA certificate (or doctl databases get-ca), pasted into /etc/kiyesi/ca/digitalocean.pem |
| Neon | The role in its connection string | A public authority every server trusts |
| Azure Database | The server’s admin user. Managed identity is the default there (below) | A public authority every server trusts |
| PlanetScale | Passwords are made in its dashboard; its smallest role, Reader, can read rows, so that password could read data even though Kiyesi only reads sizes | A public authority |
AWS RDS and Aurora: IAM, no password
Section titled “AWS RDS and Aurora: IAM, no password”sudo kiyesi databases setup postgres orders --host orders.c9x.eu-west-1.rds.amazonaws.comKiyesi signs in with a 15-minute token made from the EC2 instance’s role, allowed only to connect as kiyesi_ro to this database. Steps marked admin run where the AWS CLI is signed in as an admin:
-
Admin: turn on IAM sign-in for the database:
aws rds modify-db-instance --db-instance-identifier orders --enable-iam-database-authentication --apply-immediately(modify-db-clusterfor Aurora). It applies without a restart. -
Admin: when the server has no role yet,
setupmakes one,kiyesi-agent, with no rights, and attaches it to the instance. When it has one,setupnames it. -
Admin: the policy, for this one database user and nothing else:
{"Version": "2012-10-17","Statement": [{"Effect": "Allow","Action": "rds-db:connect","Resource": "arn:aws:rds-db:eu-west-1:123456789012:dbuser:db-ABCDEFGHIJKL/kiyesi_ro"}]}setupprints the commands that find the account and the database’s resource ID and attach it. -
AWS’s certificate authority for RDS is fetched into
/etc/kiyesi/ca/aws-rds.pem. -
As the master user,
kiyesi_rois made with the same small rights as everywhere, andGRANT rds_iam(PostgreSQL) orIDENTIFIED WITH AWSAuthenticationPlugin AS 'RDS' REQUIRE SSL(MySQL): it can sign in with tokens only. -
The settings line has
password: aws-iam, and the address checks AWS’s certificate.
Azure Database: the VM’s managed identity
Section titled “Azure Database: the VM’s managed identity”sudo kiyesi databases setup postgres orders --host orders.postgres.database.azure.comThe VM’s own identity becomes the database user, and Kiyesi signs in with the token Azure gives that identity:
- Admin: turn on the VM’s system-assigned managed identity (
az vm identity assign), and note its principal ID (and, for MySQL, its application ID). - In the Azure portal, on the database server: Security, Authentication, turn on Microsoft Entra authentication and add yourself as Entra admin.
- Admin: signed in as the Entra admin, make
kiyesi_rofor that identity:pgaadauth_create_principal_with_oidfor PostgreSQL,CREATE AADUSERfor MySQL, with the same small rights. - The settings line has
password: azure-identity(azure-identity:<client ID>for a user-assigned identity).
Google Cloud SQL for PostgreSQL: IAM
Section titled “Google Cloud SQL for PostgreSQL: IAM”Cloud SQL has no host name of its own, so name the way to sign in:
sudo kiyesi databases setup postgres orders --host 10.20.0.3 --login gcp-iamThe VM’s service account becomes the database user, and Kiyesi signs in with its token:
- The VM’s access scopes must allow Cloud SQL sign-in (
cloud-platformorsqlservice.login);setupprints how to see them. - Admin: turn on
cloudsql.iam_authenticationfor the instance, keeping the flags it has. - Admin: give the service account
roles/cloudsql.instanceUser, limited to this one instance by a condition, and make its database user (--type=cloud_iam_service_account). - As the admin, give it the same small rights.
- The instance’s certificate authority is kept in
/etc/kiyesi/ca/, and checked withsslmode=verify-ca. - The settings line has
password: gcp-iam.
HashiCorp Vault: a short-lived user for each lease
Section titled “HashiCorp Vault: a short-lived user for each lease”sudo kiyesi databases setup postgres orders --host db.internal --login vault --vault https://vault.example.com:8200Vault makes a new user for each lease, with the same small rights, and removes it when the lease ends. The agent renews the lease, and takes a new user when it runs out. Nothing is kept on the server.
- Vault admin: the database engine, with Vault’s own admin user for this database.
- Vault admin: the role
kiyesi-ro: users that live an hour, renewable up to a day, made with the statementssetupprints for your engine. - Vault admin: a policy that may only read
database/creds/kiyesi-roand renew its lease. - Vault admin: how the server signs in: with its AWS role, Google Cloud service account or Azure managed identity (
--vault-auth aws,gcporazure; AWS is the default on EC2), or an AppRole usable only from the server’s address, whose secret ID is kept encrypted on the server. - The settings get a
vault:section (its address and how to sign in, no secret) andpassword: vault:database/creds/kiyesi-ro.
A key-value secret works too: password: vault:secret/data/db/orders reads its password field (#field names another), and is read again every 5 minutes, so a changed password is picked up.
AWS Secrets Manager
Section titled “AWS Secrets Manager”sudo kiyesi databases setup postgres orders --host db.internal --login aws-secretThe password is made where the AWS CLI is signed in as an admin, set on the database and kept in Secrets Manager, never on the server. The server’s role may read that one secret (secretsmanager:GetSecretValue on its ARN). The settings line has password: aws-secret:<its ARN>. A secret in RDS’s JSON form gives its password field.
In the settings
Section titled “In the settings”databases: - name: orders url: postgres://kiyesi_ro@/orders?host=/var/run/postgresql - name: shop url: mysql://kiyesi_ro@127.0.0.1:3306/shop password: credential backups: /var/backups/mysql - name: catalogue url: mongodb+srv://kiyesi_ro@cluster0.example.mongodb.net/catalogue password: credential limit: 512MB- name: how Kiyesi shows it: letters, digits, dots, dashes and underscores. It also names its encrypted password.
- url:
postgres://,mysql://,mongodb://ormongodb+srv://,redis://orrediss://, with no password in it. - password: where the password comes from, never the password:
credential(encrypted on this server),aws-iam,gcp-iam,azure-identity(a token from the server’s cloud identity),aws-secret:<ARN>orvault:<path>. Leave it out for a socket login and for MongoDB’s certificate or AWS sign-in, which the address names (authMechanism=). - limit: for a hosted database, your plan’s storage, such as
512MBor25GB. - backups: the folder its backups are written to, to know when the newest is more than 26 hours old.
For Vault, one section for every database:
vault: address: https://vault.example.com:8200 auth: aws # or gcp, azure, approle role: kiyesi # for approle, its role ID # ca: /etc/kiyesi/ca/vault.pem, when Vault's certificate is signed by your own authorityVault’s address must be https://. The settings file is readable by root and the agent only, and the address is never sent.
Reading the Databases screen
Section titled “Reading the Databases screen”Each database shows four figures, each with a sentence on what it means:
- Storage: what it uses, against its plan’s size or the disk it is on, and how fast it grows. For a hosted database, set its plan’s size with
limit:(such aslimit: 512MB) so Kiyesi can warn before it fills. - Connections: your apps’ open connections to it, against how many it allows. When they are all in use, new ones are refused.
- Slow queries, last hour: what the database itself counted as slow. For a hosted database whose logs Kiyesi cannot read from your server, it says so: the provider shows them in its own console.
- Backups: the age of the newest file in its backup folder, which Kiyesi checks would restore. For a hosted database, they are kept by the provider, by your plan: check they are on there (MongoDB Atlas’s free M0 clusters keep none). For one on your server with no folder set, add
backups:under it.
Under the name: the engine and version, where it is (your server, or a provider such as Atlas, RDS or Supabase), how Kiyesi signs in, and when it was last read.
What alerts you
Section titled “What alerts you”| Alert | When |
|---|---|
| Filling | At the rate it grew, storage is full within 14 days. The alert says when, such as “full in about 6 days”. |
| Nearly full | Storage is 90% of its limit. At 80% it shows as needing attention, without an alert. |
| Connections | 90% of the connections it allows are in use: new ones will soon be refused. |
| Cannot be read | The agent could not read it for 15 minutes. The alert says why, never the address. |
A backup older than 26 hours shows as needing attention on the screen.
How fast it grows comes from the last week (from 20 minutes of readings for a new database). The alert closes by itself when it stops growing. For a hosted plan, Kiyesi also says what the plan does when full.
Open Databases in the dashboard, or in a terminal:
kiyesi databasesSlow queries
Section titled “Slow queries”MySQL and MariaDB count their own slow queries. For PostgreSQL and MongoDB, Kiyesi counts the slow-query lines in the server’s logs: turn on log_min_duration_statement in PostgreSQL, or the profiler’s slow threshold in MongoDB. Redis’s slow log shows values, so Kiyesi’s user is not given it.
What is kept
Section titled “What is kept”The last 24 readings (two hours), and its size once an hour for 31 days. Never a row, a table name, a query’s text or an address. See What the agent reads and sends.
If something goes wrong
Section titled “If something goes wrong”- “It refused the connection.” The database is not listening at that address. On Docker, use the port it publishes on the server.
- “A password is written in its address.” Take it out of the
url, and runsudo kiyesi databases setupfor a safe way to sign in. - “It has no encrypted password.” Run the encryption step from
setupagain; the error names where it looked. - “The user name or password was not accepted.” Check the user and, for MongoDB, the
authSource. For a socket login, check the line is first inpg_hba.conf, or that the MySQL user was madeAS 'root'. - “The read-only user may not open this database.” On MySQL or MariaDB, give it
SHOW VIEWon that database, as above. - Connections shows a dash. The user may not read the server’s status. Storage is still watched.
- The database does not appear. Run
sudo kiyesi databases check, and check the agent is connected (kiyesi servers).