是否可以从YAML文件中运行unix命令?

时间:2016-09-08 23:07:17

标签: unix amazon-web-services sed yaml app.yaml

我正在编写this结构后的YAML文件。

我的确切代码是:

# This is an appspec.yml template file for use with AWS CodeDeploy.
# The lines in this template starting with the hashtag symbol are 
#   instructional comments and can be safely left in the file or 
#   ignored.
# For help completing this file, see the "AppSpec File Reference" in the  
#   "AWS CodeDeploy User Guide" at
#   http://docs.aws.amazon.com/codedeploy/latest/userguide/app-spec-ref.html
version: 0.0
# Specify "os: linux" if this revision targets Amazon Linux, 
#   Red Hat Enterprise Linux (RHEL), or Ubuntu Server  
#   instances.
# Specify "os: windows" if this revision targets Windows Server instances.
# (You cannot specify both "os: linux" and "os: windows".)
os: linux 

hooks:
  AfterInstall:
   - location: StartUIServices.sh
     timeout: 180
     runas: root 

问题是我需要在运行位置脚本之前运行一个Unix命令,该命令是cd到另一个目录或sed -i 's/\r$//' file1*(将文件转换为Unix行结尾)。我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

是否无法从YAML文件中运行命令取决于。 YAML规范中没有规定这样做 当然,YAML解析器仍然可以实现此功能,或者更可能的是,程序可以解释来自YAML解析器的数据并基于其内容执行命令。如果程序不安全,它可能允许加载标记的YAML,在这种情况下,对创建对象实例的唯一限制将在解析器或程序的实现语言中。

如果AWS会进行这种不安全的加载,这是一个巨大的安全风险,我们会听说有人在利用它。

AWS实例安全加载YAML数据并解释加载的数据。它内置了在安装之前运行脚本的规定(使用BeforeInstall挂钩)。这些脚本中的第一个应该在所有其他脚本上执行DOS到UNIX行结束转换,但当然不能这样做。正如您可能注意到DOS行结尾的脚本运行不正常。您必须通过其他方式转换第一个脚本,而不是进一步更改它。它应该只是一个简单的脚本,可以转换后来由相同或其他挂钩运行的其他脚本,以便您可以从Windows主机提供其他更改的脚本。

相关问题