pg_command_fw
pg_command_fw : DDL and utility command firewall for PostgreSQL
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 7400 | pg_command_fw | pg_command_fw | 0.1.0 |
SEC | BSD-3-Clause | Rust |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --sLd-- | No | Yes | Yes | Yes | no | no |
| Relationships | |
|---|---|
| See Also | pgextwlist supautils block_copy_command pg_kpart noset sepgsql set_user pg_permissions pg_readonly pg_roast |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.1.0 |
18 17 16 15 14 | pg_command_fw |
- |
| RPM | PIGSTY | 0.1.0 |
18 17 16 15 14 | pg_command_fw_$v |
- |
| DEB | PIGSTY | 0.1.0 |
18 17 16 15 14 | postgresql-$v-pg-command-fw |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A |
| el8.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A |
| el9.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A |
| el9.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A |
| el10.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A |
| el10.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A |
| d12.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A |
| d12.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A |
| d13.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A |
| d13.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A |
| u22.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A |
| u22.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A |
| u24.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A |
| u24.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A |
| u26.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A |
| u26.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | N/A |
Source
github.com/rustwizard/pg_command_fw
pg_command_fw-0.1.0.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Config this extension to shared_preload_libraries:
Create this extension with:
Usage
- Source: README
pg_command_fw is a PostgreSQL command firewall. It intercepts DDL and utility commands through the ProcessUtility hook and blocks selected built-in file-reading functions through the post-parse analyze hook. Each command category is controlled by its own GUC.
Enable It
The extension must be preloaded:
Then enable it in the database:
Pigsty package metadata is version 0.1.0 for PostgreSQL 15-18 and notes that preloading is required to activate hooks for all sessions. The upstream README also documents PostgreSQL 15-18 support.
Command Categories
The upstream README documents these firewall categories:
TRUNCATE:pg_command_fw.block_truncate, defaulton, blocks non-superusers.DROP TABLE:pg_command_fw.block_drop_table, defaultoff, blocks non-superusers when enabled.ALTER SYSTEM:pg_command_fw.block_alter_system, defaulton, blocks everyone.LOAD:pg_command_fw.block_load, defaulton, blocks everyone.COPY ... PROGRAM:pg_command_fw.block_copy_program, defaulton, blocks everyone.- plain
COPY:pg_command_fw.block_copy, defaultoff, blocks non-superusers when enabled. pg_read_file(),pg_read_binary_file(), andpg_stat_file():pg_command_fw.block_read_file, defaulton, blocks everyone.
Some categories block only non-superusers, while others block everyone including superusers. Superusers are only exempt from non-superuser categories unless they are explicitly listed in pg_command_fw.blocked_roles.
Important GUCs
pg_command_fw.enabledto enable or disable all checkspg_command_fw.block_truncatepg_command_fw.block_drop_tablepg_command_fw.production_schemaspg_command_fw.block_alter_systempg_command_fw.block_loadpg_command_fw.block_copy_programpg_command_fw.block_copypg_command_fw.block_read_filepg_command_fw.blocked_rolespg_command_fw.hintpg_command_fw.audit_log_enabled
When production_schemas is set, DROP TABLE checks are limited to schema-qualified table names in those schemas; the README says unqualified names are not resolved through search_path.
Audit Log
The extension records intercepted commands in command_fw.audit_log. The README documents columns such as:
- timestamp
- session and current user names
- original query text
- command type
- target schema or object
- client address
- whether the command was blocked
- internal block reason
Blocked audit inserts are best-effort because the row is rolled back with the blocked transaction; use the PostgreSQL server log as the authoritative record for blocked events.
Examples
Block TRUNCATE and DROP TABLE in production schemas:
Block a specific role from any governed command:
Temporarily disable the firewall in a maintenance session: