Security
Pigsty already provides a secure-by-default database authentication and access control model.
It is strong enough for most common scenarios, as long as you follow the security best-practices below.
Confidentiality
Files
pigsty.ymlhold very sensitive information like passwords- Limit access to admin/infra nodes to admin/DBA users only
- Limit access to repo, if you are managing pigsty config with GitOps
- Generated at
~/pigsty/files/pki/ca/ca.keyby default - Secure & backup it in a safe place, DON’T THROW IT AWAY!
- Also consider secure other private keys for various certs
Passwords
Always change these default passwords in serious deployment
grafana_admin_password:pigstypg_admin_password:DBUser.DBApg_monitor_password:DBUser.Monitorpg_replication_password:DBUser.Replicatorpatroni_password:Patroni.APIhaproxy_admin_password:pigstyminio_secret_key:minioadmin
If you are using MinIO as backup storage, also change these credentials:
- Change the password for
minio_users.[pgbackrest].secret_key - Change pgbackrest references:
pgbackrest_repo.minio.s3_key_secret
- add
$lib/passwordchecktopg_libsto enforce password policy. - stronger version:
passwordcheck_cracklib
- check
pgbackrest_repodefinitionrepo_cipher_type cipher_type: aes-256-cbcby default
- use
pg_pwd_encdefaultscram-sha-256instead of legacymd5 - default behavior is
scram-sha-256,md5is deprecated
You can set an expiry date for each user for compliance purposes.
Don’t forget to refresh these expiry dates periodically with pgsql-user.yml playbook
IP Addresses
- The default
pg_listenaddress is0.0.0.0, which is all IPv4 addresses. - Consider using
pg_listen: '${ip},${vip},${lo}'to bind to specific addresses for better security.
- Grafana/Prometheus are bind to all IP address by default for convenience.
- You can modify their bind configuration to listen on localhost/intranet IP and expose by Nginx.
- Redis server are bind to all IP address by default for convenience. You can change
redis_bind_addressto listen on intranet IP. - You can also implement it with the security group or firewall rules.
- There’s a security enhance config template:
safe.yml
- This is restricted by default with
restapi.allowlist
Network Traffic
- Nginx SSL is controlled by
nginx_sslmode, which isenableby default. - Nginx Domain names are specified by
infra_portal..domain.
patroni_ssl_enabledis disabled by default- Since it affects health checks and API invocation.
- Note this is a global option, and you have to decide before deployment.
pgbouncer_sslmodeisdisableby default- Since it has a significant performance impact.
Integrity
Consistency
- Use
crit.ymltemplates forpg_confwill trade some availability for the best consistency.
-
set
node_tunetocritto reduce dirty page ratio. -
Enable data checksum to detect silent data corruption.
-
pg_checksumis enabled by default in v3.7.0 -
This can be enabled later, which requires a full cluster scan/stop.
Audit
- Enable
log_connectionsandlog_disconnectionsafter the pg cluster bootstrap. - Audit incoming sessions; this is enabled in
crit.ymlby default.
Fat Finger
Running install.yml again will nuke (overwrite) the entire deployment!
It will OVERWRITE existing PostgreSQL by default before v3.5.
Use pg_safeguard to avoid fat fingers
Availability
Redundancy
- You need at least three nodes (tolerate one node failure) to achieve production-grade high availability.
- If you only have two nodes, you can tolerate the failure of the specific standby node.
- If you have one node, use an external S3/MinIO for cold backup & wal archive storage.
- Use multiple infra nodes in serious production deployment (e.g., 1~3)
- Usually, 2 ~ 3 is enough for a large production deployment.
- Use enough etcd members and use odd numbers (1,3,5,7).
- Check ETCD Configuration for details.
Fault Tolerance
Access
- Do not access the database directly via a fixed IP address; use VIP, DNS, HAProxy, or their combination.
- Haproxy will handle the traffic control for the clients in case of failover/switchover.