amazeeio / algm_drutiny_plugin
ALGM 核心插件库,包含我们用于运行 Drutiny 审计的策略和配置文件
Requires
- drutiny/plugin-drupal-7: ^2.3
- drutiny/plugin-drupal-8: ^2.3
- spatie/ssl-certificate: ^1.20
Requires (Dev)
- dantleech/fink: ^0.10.1
- drutiny/drutiny: ^2.4
- phpunit/phpunit: ^9.2
- squizlabs/php_codesniffer: ^3.5
- dev-master
- v1.1.7
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.23
- v1.0.22
- v1.0.21
- v1.0.20
- v1.0.19
- v1.0.18
- v1.0.17
- v1.0.16
- v1.0.15
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.1
- v1.0.0
- v0.0.2
- v0.0.1
- dev-package-only
- dev-storage_space
- dev-d7profile
- dev-d8-security-mod-updates
- dev-replace-need-for-packagist-algm-drutiny
- dev-drutiny-3.x
This package is not auto-updated.
Last update: 2024-08-17 04:11:38 UTC
README
此插件提供了一组标准策略集合,可以被 Drutiny 使用。
设置
-
git clone git@github.com:AmazeeLabs/algm_drutiny.git
-
composer install -o
-
需要 Drush - https://docs.drush.org/en/9.x/install/
We also need Drush locally (preferably Drush 9+). There are also a couple of things you need to ensure your drush alias files have in order to get this working with Drutiny which we will cover below.
If you have drush but need to update to Drush 9 way of things, then this is your friend:
https://stackoverflow.com/questions/55587919/where-drush-9-aliases-file-should-be-located-in-drupal-8
- 测试 Drutiny 是否运行 -
./vendor/bin/drutiny
这是什么?
此存储库是 Drutiny 的插件,意味着它作为扩展添加到核心 Drutiny 上。然后我们构建、发布并作为单个 phar 文件运行。因此,此插件为我们提供了一种添加自己的策略、配置文件、格式化程序以及任何我们喜欢的东西以扩展现有 Drutiny 功能的方法。
文档解释得很好 - https://drutiny.readthedocs.io/en/2.x/README/
- 策略 - https://drutiny.readthedocs.io/en/2.x/policy/
- 配置文件 - https://drutiny.readthedocs.io/en/2.x/profiles/
工作流程
要添加策略/配置文件或以任何方式扩展我们的 Drutiny 插件,我们需要做几件事
- 确保本地有最新版本(获取并拉取以确保)
- 添加所需内容,提交并推送至 PR 或 master(取决于是否需要测试)
- 测试可以通过此存储库中的
drupal-web
docker 实例进行,或者通过使用远程 drush 别名并直接运行它们对这些站点进行。当然,如果您不确定预期的结果,请谨慎在生产站点上运行东西。 - 一旦推送到 master,并且对测试/工作情况满意后,我们需要创建一个新的标签。
- 从远程获取所有标签,并检查列表,使用
git tag v1.0.x
等. 添加一个带有-a
标志的注释。然后使用git push origin --tags
推送到我们的 origin。 - 这将触发我们拥有的 phar 构建器 github action。您可以在以下位置看到此构建 - https://github.com/AmazeeLabs/algm_drutiny/actions
- 将构建新版本 - 检查构建输出以查看您的策略是否存在。您还可以在本地下载 phar 并在本地站点上运行它以检查其是否按预期工作。
- 然后我们将使用最新的发布版在我们的 ansible/awx playbooks 中!
使用 Drutiny
Drutiny 有两个核心命令,我们运行:policy:audit 和 profile:run。
policy:audit
此命令对目标运行策略(通常是 drush 目标),将执行我们想要运行的检查。
基本上,我们需要提供一个策略(例如 algm:ModuleUpdates
)和一个目标(例如 drush 别名 @site-prod.site-name
)。我们还可以传递选项,如 --format
,它定义了输出格式。参数/默认值也可以通过 -p
标志传递到策略中,例如 -p module=8.6.8
。
policy:audit [options] [--] <policy> <target>
最终命令可能如下所示:./vendor/bin/drutiny policy:audit algm:ModuleUpdates @site-prod.site-name --format=markdown
profile:run
此操作将对目标进行配置运行,将遍历并检查整个策略套件。
对于配置文件,我们需要提供配置文件名称(例如 algm_sla_site
)和目标(例如 drush 别名 @site-prod.site-name
)。我们还可以传递一些选项,例如 '--format',它定义了输出格式。
profile:run [选项] [--] <配置文件> <目标>
最终的命令可能看起来像这样:./vendor/bin/drutiny profile:run algm_sla_site @site-prod.site-name --format==markdown
添加新策略
要添加新策略,我们需要两个文件:一个新策略 yaml 文件添加在这里(https://github.com/AmazeeLabs/algm_drutiny/tree/master/Policies)以及一个新审计类文件添加在这里(https://github.com/AmazeeLabs/algm_drutiny/tree/master/src/Audit)
策略详细信息
最重要的是,我们有 $sandbox
对象,它是执行我们的策略的运行时对象。
exec
exec
是一个方法,可以访问远程 shell 并执行给定的命令 - 例如 $output = $sandbox->exec('ls -la');
drush
可以使用 drush
方法运行 Drush。Drutiny 在这里支持驼峰命名 - 例如 $list = $sandbox->drush(['format' => 'json'])->pmList();
如果提供 json 格式,Drutiny 将解析响应并以 PHP 的形式返回输出。
Drush 别名
一个 Drush 9 别名文件示例
prod:
host: ssh.lagoon.amazeeio.cloud
root: /app/web
user: site-prod
remote-host: ssh.lagoon.amazeeio.cloud
remote-user: site-prod
ssh-options: '-o LogLevel=ERROR -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 32222'
请注意,这只是一个示例,您应该仅使用这些值更新您的 drush 别名以使其与 Drutiny 一起工作,而不是完全替换它。
此存储库中还有一个 example.drush.alias.yml
。
更改或添加新站点别名时,不要忘记清除 Drush 缓存 - drush cc
有关更多配置选项 - 这很有用 https://github.com/drush-ops/drush/blob/master/examples/example.site.yml
有用的事情
检查我们可用的策略列表:./vendor/bin/drutiny policy:list
检查配置文件列表:./vendor/bin/drutiny profile:list
可能需要清除 Drutiny 缓存:./vendor/bin/drutiny cache:clear
开发和测试
在包内部有一个 Drupal 安装,您可以在这里测试您的策略。请遵循 drupal-web/README.md 文件