risky-file-permissions¶
此规则由各种模块触发,这些模块最终可能会在磁盘上创建权限过于开放或不可预测的新文件。请仔细阅读每个模块的文档,以了解使用不同参数值的影响,因为这些参数决定了安全地使用模块还是不安全地使用模块。修复方法取决于每个模块以及您的具体情况。
某些模块具有一个默认为true的create参数。对于这些模块,您需要设置create: false或提供一些权限,例如mode: 0600,以使行为可预测,并且不依赖于当前系统设置。
已检查的模块
ansible.builtin.assembleansible.builtin.copyansible.builtin.fileansible.builtin.get_urlansible.builtin.replaceansible.builtin.templatecommunity.general.archivecommunity.general.ini_file
警告
此规则不考虑module_defaults配置。目前没有计划实现此功能,因为更改任务位置也会更改任务行为。
问题代码¶
正确代码¶
---
- name: Safe example of using ini_file (1st solution)
community.general.ini_file:
path: foo
create: false # prevents creating a file with potentially insecure permissions
- name: Safe example of using ini_file (2nd solution)
community.general.ini_file:
path: foo
mode: "0600" # explicitly sets the desired permissions, to make the results predictable
- name: Safe example of using copy (3rd solution)
ansible.builtin.copy:
src: foo
dest: bar
mode: preserve # copy has a special mode that sets the same permissions as the source file