在非根上下文中发布 运行 linux AWS CodeDeploy 代理
Issue running linux AWS CodeDeploy agent in non root context
我正在使用 AWS CodeDeploy 将代码部署到我们的 AWS Amazon Linux 实例。我按照这篇知识库文章 https://aws.amazon.com/premiumsupport/knowledge-center/codedeploy-agent-non-root-profile/ 让代理在 ec2-user 上下文而不是 root
中执行
在进行更改之前,yml 文件中的脚本按预期执行(但我们需要脚本在非根上下文中执行)并将 运行 设置为:appspec.yml 的一部分文件似乎没有按预期在 ec2-user 上下文中执行脚本
appspec.yml:
version: 0.0
os: linux
files:
- source: /
destination: /home/ec2-user/veddor/api
owner: ec2-user
hooks:
AfterInstall:
- location: deploy/script/deploy-veddor-api.sh
timeout: 300
runas: ec2-user
进行更改后,现在显示此错误,而不是执行 appspec 文件中指定的脚本
LifecycleEvent - AfterInstall
Script - deploy/script/deploy-veddor-api.sh
[stderr]Password: su: Authentication failure
deploy-veddor 的内容-api.sh
cp /home/ec2-user/veddor/api/deploy/config/Config-roddev.php /home/ec2-user/veddor/api/app/config/Config.php
cd /home/ec2-user/veddor/api
chmod +x ./composer.phar
php ./composer.phar install
我正在寻求帮助,以弄清楚我需要做什么才能使脚本 deploy-veddor-api.sh 在 ec2-user 上下文中实际 运行。
您可能运行以非根用户身份使用 AWS CodeDeploy 代理。只有 root 能够在您的 AfterInstall
挂钩中拥有 runas
用户,因为没有其他用户帐户可以 运行 没有密码身份验证的替代用户 "su" 命令。
在 AWS 的 appspec 用户指南中查看 "runas" 的详细信息:
https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html
runas Optional. The user to impersonate when running the script. By
default, this is the AWS CodeDeploy agent running on the instance. AWS
CodeDeploy does not store passwords, so the user cannot be
impersonated if the runas user needs a password. This element applies
to Amazon Linux and Ubuntu Server instances only.
如果您已经 运行将 CodeDeploy 代理设置为 ec2-user
,则无需在 AfterInstall
挂钩中提供 runas
元素。
如果您使用SDK触发CodeDeploy,这里有一个参数:ignoreApplicationStopFailures: true
参见:https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CodeDeploy.html#createDeployment-property
如果您已将 codedeploy 配置为非 root,则 从 appspec.yml 中删除 runas
命令.保存并重试!
我正在使用 AWS CodeDeploy 将代码部署到我们的 AWS Amazon Linux 实例。我按照这篇知识库文章 https://aws.amazon.com/premiumsupport/knowledge-center/codedeploy-agent-non-root-profile/ 让代理在 ec2-user 上下文而不是 root
中执行在进行更改之前,yml 文件中的脚本按预期执行(但我们需要脚本在非根上下文中执行)并将 运行 设置为:appspec.yml 的一部分文件似乎没有按预期在 ec2-user 上下文中执行脚本
appspec.yml:
version: 0.0
os: linux
files:
- source: /
destination: /home/ec2-user/veddor/api
owner: ec2-user
hooks:
AfterInstall:
- location: deploy/script/deploy-veddor-api.sh
timeout: 300
runas: ec2-user
进行更改后,现在显示此错误,而不是执行 appspec 文件中指定的脚本
LifecycleEvent - AfterInstall
Script - deploy/script/deploy-veddor-api.sh
[stderr]Password: su: Authentication failure
deploy-veddor 的内容-api.sh
cp /home/ec2-user/veddor/api/deploy/config/Config-roddev.php /home/ec2-user/veddor/api/app/config/Config.php
cd /home/ec2-user/veddor/api
chmod +x ./composer.phar
php ./composer.phar install
我正在寻求帮助,以弄清楚我需要做什么才能使脚本 deploy-veddor-api.sh 在 ec2-user 上下文中实际 运行。
您可能运行以非根用户身份使用 AWS CodeDeploy 代理。只有 root 能够在您的 AfterInstall
挂钩中拥有 runas
用户,因为没有其他用户帐户可以 运行 没有密码身份验证的替代用户 "su" 命令。
在 AWS 的 appspec 用户指南中查看 "runas" 的详细信息:
https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html
runas Optional. The user to impersonate when running the script. By default, this is the AWS CodeDeploy agent running on the instance. AWS CodeDeploy does not store passwords, so the user cannot be impersonated if the runas user needs a password. This element applies to Amazon Linux and Ubuntu Server instances only.
如果您已经 运行将 CodeDeploy 代理设置为 ec2-user
,则无需在 AfterInstall
挂钩中提供 runas
元素。
如果您使用SDK触发CodeDeploy,这里有一个参数:ignoreApplicationStopFailures: true
参见:https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CodeDeploy.html#createDeployment-property
如果您已将 codedeploy 配置为非 root,则 从 appspec.yml 中删除 runas
命令.保存并重试!