Skip to content

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.

On the server, as root:

Terminal window
sudo kiyesi databases setup

It 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:

Terminal window
sudo kiyesi databases setup postgres orders

It 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.

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.

Terminal window
sudo kiyesi databases check

It 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.

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).
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/credentials and 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.

PostgreSQL on the same server: no password

Section titled “PostgreSQL on the same server: no password”
Terminal window
sudo kiyesi databases setup postgres orders
  1. 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;'
  2. Let this server’s root user sign in as kiyesi_ro through the socket only. The line goes first in pg_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/null
    sudo sed -i '1i local orders kiyesi_ro peer map=kiyesi' "$hba"
    sudo -u postgres psql -c 'SELECT pg_reload_conf()'
  3. In /etc/kiyesi/config.yaml:

    databases:
    - name: orders
    url: postgres://kiyesi_ro@/orders?host=/var/run/postgresql
Terminal window
sudo kiyesi databases setup mysql shop
  1. 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_socket plugin is not loaded: sudo mysql -e "INSTALL PLUGIN auth_socket SONAME 'auth_socket.so'".

  2. In /etc/kiyesi/config.yaml:

    databases:
    - name: shop
    url: mysql://kiyesi_ro@localhost/shop?socket=/var/run/mysqld/mysqld.sock

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.

Terminal window
sudo kiyesi databases setup mariadb shop
  1. 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
  2. Keep it encrypted. On systemd 254 and later:

    Terminal window
    sudo install -d -m 700 /etc/credstore.encrypted
    printf '%s' "$pw" | sudo systemd-creds encrypt - /etc/credstore.encrypted/kiyesi.db.shop
    unset pw

    On older systemd, with Kiyesi’s own key:

    Terminal window
    sudo install -d -m 700 /etc/kiyesi/credentials
    printf '%s' "$pw" | sudo kiyesi databases encrypt shop | sudo tee /etc/kiyesi/credentials/shop.enc >/dev/null
    unset pw
  3. In /etc/kiyesi/config.yaml:

    databases:
    - name: shop
    url: mysql://kiyesi_ro@127.0.0.1:3306/shop
    password: credential
Terminal window
sudo kiyesi databases setup mongodb catalogue

It 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:

Terminal window
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.

When the only database the server’s apps use is on Atlas, sudo kiyesi databases setup prints its steps straight away. Otherwise:

Terminal window
sudo kiyesi databases setup mongodb mydb --host cluster0.abcde.mongodb.net

Kiyesi 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.

  1. 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: dbStats on your database, and serverStatus, 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.)

  2. 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, only kiyesiStats; Restrict Access to Specific Clusters on, with only this cluster. Then Add User: Atlas downloads the certificate, a .pem file, this once. (With the Atlas CLI: atlas dbusers create --username kiyesi_ro --x509Type MANAGED --role kiyesiStats@admin --scope cluster0, then atlas dbusers certs create --username kiyesi_ro --monthsUntilExpiration 12 > kiyesi_ro.pem.)

  3. 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.pem

    With more than one X509-cert file, 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/credentials
    sudo install -m 600 -o root -g root ~/kiyesi-cert.pem /etc/kiyesi/credentials/mydb.pem
    shred -u ~/kiyesi-cert.pem

    Without scp: open the file, copy all of it, run sudo install -m 600 /dev/null /etc/kiyesi/credentials/mydb.pem and sudo tee /etc/kiyesi/credentials/mydb.pem >/dev/null, paste it, and press Ctrl-D.

    Check it: sudo grep -c BEGIN /etc/kiyesi/credentials/mydb.pem prints 2 (the certificate and its key). Then delete the downloaded file from your computer.

  4. On the IP Access List tab, this server’s public address must be listed (setup prints it). If an app on the server already uses the cluster, it is.

  5. Add it to Kiyesi’s settings, with the one command setup prints 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
  6. 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.

Terminal window
sudo kiyesi databases setup postgres orders --container app-db-1

The 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"
Terminal window
sudo kiyesi databases setup redis cache
Terminal window
pw="$(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-warning

Then 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.

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
Terminal window
sudo kiyesi databases setup postgres orders --host orders.c9x.eu-west-1.rds.amazonaws.com

Kiyesi 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:

  1. 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-cluster for Aurora). It applies without a restart.

  2. Admin: when the server has no role yet, setup makes one, kiyesi-agent, with no rights, and attaches it to the instance. When it has one, setup names it.

  3. 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"
    }]
    }

    setup prints the commands that find the account and the database’s resource ID and attach it.

  4. AWS’s certificate authority for RDS is fetched into /etc/kiyesi/ca/aws-rds.pem.

  5. As the master user, kiyesi_ro is made with the same small rights as everywhere, and GRANT rds_iam (PostgreSQL) or IDENTIFIED WITH AWSAuthenticationPlugin AS 'RDS' REQUIRE SSL (MySQL): it can sign in with tokens only.

  6. 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”
Terminal window
sudo kiyesi databases setup postgres orders --host orders.postgres.database.azure.com

The VM’s own identity becomes the database user, and Kiyesi signs in with the token Azure gives that identity:

  1. 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).
  2. In the Azure portal, on the database server: Security, Authentication, turn on Microsoft Entra authentication and add yourself as Entra admin.
  3. Admin: signed in as the Entra admin, make kiyesi_ro for that identity: pgaadauth_create_principal_with_oid for PostgreSQL, CREATE AADUSER for MySQL, with the same small rights.
  4. The settings line has password: azure-identity (azure-identity:<client ID> for a user-assigned identity).

Cloud SQL has no host name of its own, so name the way to sign in:

Terminal window
sudo kiyesi databases setup postgres orders --host 10.20.0.3 --login gcp-iam

The VM’s service account becomes the database user, and Kiyesi signs in with its token:

  1. The VM’s access scopes must allow Cloud SQL sign-in (cloud-platform or sqlservice.login); setup prints how to see them.
  2. Admin: turn on cloudsql.iam_authentication for the instance, keeping the flags it has.
  3. 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).
  4. As the admin, give it the same small rights.
  5. The instance’s certificate authority is kept in /etc/kiyesi/ca/, and checked with sslmode=verify-ca.
  6. 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”
Terminal window
sudo kiyesi databases setup postgres orders --host db.internal --login vault --vault https://vault.example.com:8200

Vault 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.

  1. Vault admin: the database engine, with Vault’s own admin user for this database.
  2. Vault admin: the role kiyesi-ro: users that live an hour, renewable up to a day, made with the statements setup prints for your engine.
  3. Vault admin: a policy that may only read database/creds/kiyesi-ro and renew its lease.
  4. Vault admin: how the server signs in: with its AWS role, Google Cloud service account or Azure managed identity (--vault-auth aws, gcp or azure; 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.
  5. The settings get a vault: section (its address and how to sign in, no secret) and password: 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.

Terminal window
sudo kiyesi databases setup postgres orders --host db.internal --login aws-secret

The 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.

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:// or mongodb+srv://, redis:// or rediss://, 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> or vault:<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 512MB or 25GB.
  • 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 authority

Vault’s address must be https://. The settings file is readable by root and the agent only, and the address is never sent.

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 as limit: 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.

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:

Terminal window
kiyesi databases

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.

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.

  • “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 run sudo kiyesi databases setup for a safe way to sign in.
  • “It has no encrypted password.” Run the encryption step from setup again; 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 in pg_hba.conf, or that the MySQL user was made AS 'root'.
  • “The read-only user may not open this database.” On MySQL or MariaDB, give it SHOW VIEW on 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).