pg_command_fw
PostgreSQL 的 DDL 与 utility 命令防火墙
pg_command_fw · PostgreSQL 的 DDL 与 utility 命令防火墙
概览
| ID | 扩展 | 软件包 | 版本 | 类别 | 许可证 | 编程语言 |
|---|---|---|---|---|---|---|
| 7400 | pg_command_fw | pg_command_fw | 0.1.0 | SEC | BSD-3-Clause | Rust |
| 属性 | 可执行文件 | 动态库 | 需要预加载 | 需要建扩展 | 可迁移 | 可信 |
|---|---|---|---|---|---|---|
| --sLd-- | 否 | 是 | 是 | 是 | 否 | 否 |
| 关联 | |
|---|---|
| 相关扩展 | pgextwlist supautils block_copy_command pg_kpart noset sepgsql set_user pg_permissions pg_readonly pg_roast |
Requires shared_preload_libraries = pg_command_fw to activate hooks for all sessions.
软件包
| Linux / PG | PG19 | PG18 | PG17 | PG16 | PG15 |
|---|---|---|---|---|---|
| el8.x86_64 | N/A | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
| el8.aarch64 | N/A | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
| el9.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
| el9.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
| el10.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
| el10.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
| d12.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
| d12.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
| d13.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
| d13.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
| u22.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
| u22.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
| u24.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
| u24.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
| u26.x86_64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
| u26.aarch64 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 | PIGSTY 0.1.0 |
源码
安装
将扩展加入 shared_preload_libraries,详见配置说明。
在数据库中创建扩展。
用法
- 来源:README
pg_command_fw 是 PostgreSQL 命令防火墙。它通过 ProcessUtility 钩子拦截 DDL 和工具命令,并通过解析后分析钩子阻断部分内置文件读取函数。每个命令类别都有自己的 GUC 控制。
启用扩展
该扩展必须预加载:
然后在数据库中启用:
Pigsty 包元数据记录版本 0.1.0,覆盖 PostgreSQL 15-18,并说明需要预加载才能在所有会话中激活钩子。上游 README 也记录 PostgreSQL 15-18 支持。
命令类别
上游 README 记录了这些防火墙类别:
TRUNCATE:pg_command_fw.block_truncate,默认on,阻断非超级用户。DROP TABLE:pg_command_fw.block_drop_table,默认off,启用后阻断非超级用户。ALTER SYSTEM:pg_command_fw.block_alter_system,默认on,阻断所有人。LOAD:pg_command_fw.block_load,默认on,阻断所有人。COPY ... PROGRAM:pg_command_fw.block_copy_program,默认on,阻断所有人。- 普通
COPY:pg_command_fw.block_copy,默认off,启用后阻断非超级用户。 pg_read_file()、pg_read_binary_file()和pg_stat_file():pg_command_fw.block_read_file,默认on,阻断所有人。
部分类别只阻断非超级用户,另一些类别阻断包括超级用户在内的所有人。除非显式列入 pg_command_fw.blocked_roles,超级用户只会豁免非超级用户类别。
重要 GUC
pg_command_fw.enabled:启用或禁用所有检查pg_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
设置 production_schemas 时,DROP TABLE 检查仅限这些模式中显式带模式名的表名;README 说明未限定名称不会通过 search_path 解析。
审计日志
扩展会在 command_fw.audit_log 中记录被拦截的命令。README 记录的列包括:
- timestamp 时间戳
- session 和 current user 名称
- 原始查询文本
- 命令类型
- 目标模式或对象
- 客户端地址
- 命令是否被阻断
- 内部阻断原因
被阻断的审计插入只会尽力完成,因为该行会随被阻断事务回滚;请使用 PostgreSQL 服务器日志作为被阻断事件的权威记录。
示例
在生产模式中阻断 TRUNCATE 和 DROP TABLE:
阻断某个角色执行任何受管命令:
在维护会话中临时禁用防火墙: