block_copy_command
通过可配置的 ProcessUtility hook 阻止 COPY 命令
block_copy_command · 通过可配置的 ProcessUtility hook 阻止 COPY 命令
概览
| ID | 扩展 | 软件包 | 版本 | 类别 | 许可证 | 编程语言 |
|---|---|---|---|---|---|---|
| 7440 | block_copy_command | block_copy_command | 0.1.5 | SEC | BSD-3-Clause | Rust |
| 属性 | 可执行文件 | 动态库 | 需要预加载 | 需要建扩展 | 可迁移 | 可信 |
|---|---|---|---|---|---|---|
| --sLd-- | 否 | 是 | 是 | 是 | 否 | 否 |
Requires shared_preload_libraries = block_copy_command.
软件包
| Linux / PG | PG19 | PG18 | PG17 | PG16 | PG15 |
|---|---|---|---|---|---|
| el8.x86_64 | N/A | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 |
| el8.aarch64 | N/A | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 |
| el9.x86_64 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 |
| el9.aarch64 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 |
| el10.x86_64 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 |
| el10.aarch64 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 |
| d12.x86_64 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 |
| d12.aarch64 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 |
| d13.x86_64 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 |
| d13.aarch64 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 |
| u22.x86_64 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 |
| u22.aarch64 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 |
| u24.x86_64 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 |
| u24.aarch64 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 |
| u26.x86_64 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 |
| u26.aarch64 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 | PIGSTY 0.1.5 |
源码
安装
将扩展加入 shared_preload_libraries,详见配置说明。
在数据库中创建扩展。
用法
- 来源:README
block_copy_command 安装一个会拦截 COPY 语句的 ProcessUtility hook。库加载后,该 hook 在集群范围内生效;CREATE EXTENSION 只是在某个数据库中登记元数据。
启用扩展
阻断规则
默认情况下,非超级用户不能执行 COPY TO 或 COPY FROM:
文档中的优先级如下:
block_copy_command.blocked_roles:始终阻断,即使是超级用户。block_copy_command.block_program = on:对所有用户阻断COPY ... PROGRAM。block_copy_command.enabled = off:允许不在blocked_roles中的角色执行COPY。- 其他情况下,超级用户会绕过方向阻断。
block_copy_command.block_to和block_copy_command.block_from控制对非超级用户的导出/导入阻断。
主要配置
block_copy_command.enabled:非超级用户阻断的总开关。block_copy_command.block_to:阻断COPY TO。block_copy_command.block_from:阻断COPY FROM。block_copy_command.block_program:对所有用户阻断COPY TO/FROM PROGRAM。block_copy_command.hint:给被阻断命令的错误追加自定义HINT。block_copy_command.blocked_roles:逗号分隔的始终阻断角色列表。block_copy_command.audit_log_enabled:将拦截事件写入审计表。
审计与注意事项
允许和被阻断的尝试都会被拦截;扩展定义了 block_copy_command.audit_log,并会把被阻断事件写入服务器日志。README 提到一个重要限制:被阻断的审计行是在抛出错误前插入的,因此会随事务一起回滚。实际使用中,PostgreSQL 服务器日志才是被阻断 COPY 尝试的权威记录。