覆盖默认 ImageMagick policy.xml
override default ImageMagick policy.xml
我在 ubuntu-16.04 上使用 ImageMagick 将 pdf 文件转换为 png 图像。
最近,转换停止了,因为包 imagemagick-common
添加了 <policy domain="coder" rights="none" pattern="PDF" />
到 /etc/ImageMagick-6/policy.xml
中的 policy.xml 文件
我不想更改 /etc/ImageMagick-6/policy.xml
以启用 PDF,因为此文件属于软件包,另一个更新可能会再次重写此文件
$dpkg -S /etc/ImageMagick-6/policy.xml
imagemagick-common: /etc/ImageMagick-6/policy.xml
我在主目录中创建配置文件
$ cat ~/.config/ImageMagick/policy.xml
<policymap>
<policy domain="coder" rights="read|write" pattern="PDF" />
</policymap>
似乎找到并加载了这个文件:
$ identify -list policy
Path: /etc/ImageMagick-6/policy.xml
...
Policy: Coder
rights: None
pattern: PDF
...
Path: /home/vasiliy/.config/ImageMagick/policy.xml
Policy: Coder
rights: Read Write
pattern: PDF
但这并没有帮助。
not authorized
引发异常。
如何强制 ImageMagic 更喜欢 ~/.config/ImageMagick/policy.xml
设置而不是 /etc/ImageMagick-6/policy.xml
设置?或者我可以使用其他一些解决方案来允许 PDF 读|写吗?
我和你有同样的问题。通过安全更新,ImageMagick 现在默认不允许 PDF 处理。 ghostscript (https://www.kb.cert.org/vuls/id/332928) 中的潜在漏洞已经修复,但默认配置尚未改回。
我用 ~/.config/ImageMagick/policy.xml
做了一些实验,发现这个配置确实有效。但是你不能允许全局禁用的东西。您只能对用户进程添加更多限制。
所以我的建议是:
- 调整
/etc/ImageMagick-6/policy.xml
- 等到软件包维护者决定再次默认激活该功能
更新:
使用#1 时,您应确保不要中断自动更新。也许这会帮助您找到解决方案:https://unix.stackexchange.com/questions/138751/unattended-upgrades-and-modified-configuration-files
我花了几个小时解决这个问题,终于找到了一个相对简单的解决方案。
您必须告诉 ImageMagick 以高于默认配置文件的优先级加载您的配置文件,您可以通过将 MAGICK_CONFIGURE_PATH
环境变量设置为您的 policy.xml
所在的目录来实现。
https://github.com/ImageMagick/ImageMagick/issues/1342#issuecomment-429494152
If ImageMagick is installed, only the policy in the system path is enforced, otherwise it would not be much of a security policy if it could easily be overridden. In certain cases, the user can set certain resource limits but only @ a lesser value that what the administrator sets (e.g. administrator sets a memory limit of 2GB, the user can set a limit of 1GB but not 3GB).
ImageMagick has an uninstalled build option. With that build option, ImageMagick will allow the security policy to be overridden by any policy in the paths you mention in your post.
更新(Ubuntu 18.04、2019-10、ImageMagick 6.9.7-4 Q16 x86_64、8:6.9.7.4+dfsg-16ubuntu6.7):
预先设置 MAGICK_CONFIGURE_PATH
的路径有效。
/my/path/policy.xml
<policymap>
<policy domain="coder" rights="read | write" pattern="PDF" />
</policymap>
MAGICK_CONFIGURE_PATH='/my/path/:/etc/ImageMagick-6/' identify -list policy
MAGICK_CONFIGURE_PATH='/my/path/:/etc/ImageMagick-6/' identify -list resource
我在为 moodle 插件添加 php 扩展时遇到了这个问题。这是我的修复:
我在 /etc/ImageMagick-6/policy.xml
中更改了这个
<policy domain="coder" rights="none" pattern="PDF" />
至此
<policy domain="coder" rights="read | write" pattern="PDF" />
对于Windows OS:
Under Windows, ImageMagick searches for these configuration files in the
following order, and loads them if found:
$MAGICK_CONFIGURE_PATH
<windows registry>
$PREFIX/config
$USERPROFILE/.config/ImageMagick
<client path>
因此您可以运行cmd.exe
中的下一个命令来打开环境变量编辑器:
START "" "%SystemRoot%\System32\rundll32.exe" "%SystemRoot%\System32\sysdm.cpl",EditEnvironmentVariables
然后单击其中一个 'New buttons' 并输入:
Variable Name: MAGICK_CONFIGURE_PATH
Variable Value: PATH\TO\THE\INSTALL\DIR\ROOT ( It may be something like this C:\Program Files\ImageMagick)
然后重新启动任何打开的 cmd.exe windows 以更新变量并对其进行测试!
我在 ubuntu-16.04 上使用 ImageMagick 将 pdf 文件转换为 png 图像。
最近,转换停止了,因为包 imagemagick-common
添加了 <policy domain="coder" rights="none" pattern="PDF" />
到 /etc/ImageMagick-6/policy.xml
我不想更改 /etc/ImageMagick-6/policy.xml
以启用 PDF,因为此文件属于软件包,另一个更新可能会再次重写此文件
$dpkg -S /etc/ImageMagick-6/policy.xml
imagemagick-common: /etc/ImageMagick-6/policy.xml
我在主目录中创建配置文件
$ cat ~/.config/ImageMagick/policy.xml
<policymap>
<policy domain="coder" rights="read|write" pattern="PDF" />
</policymap>
似乎找到并加载了这个文件:
$ identify -list policy
Path: /etc/ImageMagick-6/policy.xml
...
Policy: Coder
rights: None
pattern: PDF
...
Path: /home/vasiliy/.config/ImageMagick/policy.xml
Policy: Coder
rights: Read Write
pattern: PDF
但这并没有帮助。
not authorized
引发异常。
如何强制 ImageMagic 更喜欢 ~/.config/ImageMagick/policy.xml
设置而不是 /etc/ImageMagick-6/policy.xml
设置?或者我可以使用其他一些解决方案来允许 PDF 读|写吗?
我和你有同样的问题。通过安全更新,ImageMagick 现在默认不允许 PDF 处理。 ghostscript (https://www.kb.cert.org/vuls/id/332928) 中的潜在漏洞已经修复,但默认配置尚未改回。
我用 ~/.config/ImageMagick/policy.xml
做了一些实验,发现这个配置确实有效。但是你不能允许全局禁用的东西。您只能对用户进程添加更多限制。
所以我的建议是:
- 调整
/etc/ImageMagick-6/policy.xml
- 等到软件包维护者决定再次默认激活该功能
更新:
使用#1 时,您应确保不要中断自动更新。也许这会帮助您找到解决方案:https://unix.stackexchange.com/questions/138751/unattended-upgrades-and-modified-configuration-files
我花了几个小时解决这个问题,终于找到了一个相对简单的解决方案。
您必须告诉 ImageMagick 以高于默认配置文件的优先级加载您的配置文件,您可以通过将 MAGICK_CONFIGURE_PATH
环境变量设置为您的 policy.xml
所在的目录来实现。
https://github.com/ImageMagick/ImageMagick/issues/1342#issuecomment-429494152
If ImageMagick is installed, only the policy in the system path is enforced, otherwise it would not be much of a security policy if it could easily be overridden. In certain cases, the user can set certain resource limits but only @ a lesser value that what the administrator sets (e.g. administrator sets a memory limit of 2GB, the user can set a limit of 1GB but not 3GB).
ImageMagick has an uninstalled build option. With that build option, ImageMagick will allow the security policy to be overridden by any policy in the paths you mention in your post.
更新(Ubuntu 18.04、2019-10、ImageMagick 6.9.7-4 Q16 x86_64、8:6.9.7.4+dfsg-16ubuntu6.7):
预先设置 MAGICK_CONFIGURE_PATH
的路径有效。
/my/path/policy.xml
<policymap>
<policy domain="coder" rights="read | write" pattern="PDF" />
</policymap>
MAGICK_CONFIGURE_PATH='/my/path/:/etc/ImageMagick-6/' identify -list policy
MAGICK_CONFIGURE_PATH='/my/path/:/etc/ImageMagick-6/' identify -list resource
我在为 moodle 插件添加 php 扩展时遇到了这个问题。这是我的修复: 我在 /etc/ImageMagick-6/policy.xml
中更改了这个<policy domain="coder" rights="none" pattern="PDF" />
至此
<policy domain="coder" rights="read | write" pattern="PDF" />
对于Windows OS:
Under Windows, ImageMagick searches for these configuration files in the
following order, and loads them if found:
$MAGICK_CONFIGURE_PATH
<windows registry>
$PREFIX/config
$USERPROFILE/.config/ImageMagick
<client path>
因此您可以运行cmd.exe
中的下一个命令来打开环境变量编辑器:
START "" "%SystemRoot%\System32\rundll32.exe" "%SystemRoot%\System32\sysdm.cpl",EditEnvironmentVariables
然后单击其中一个 'New buttons' 并输入:
Variable Name: MAGICK_CONFIGURE_PATH
Variable Value: PATH\TO\THE\INSTALL\DIR\ROOT ( It may be something like this C:\Program Files\ImageMagick)
然后重新启动任何打开的 cmd.exe windows 以更新变量并对其进行测试!