Chef Inspec:未定义的局部变量或方法'aws_region'

问题描述 投票:0回答:1

我正在测试基本的Chef Inspec代码。我正在使用API​​调用从Mac运行它:

inspec exec sg-disallow-ftp.rb -t aws://

这是个人资料的厨师代码:

title 'Test AWS Security Groups Across All Regions For an Account Disallow FTP'

control 'aws-multi-region-security-group-ftp-1.0' do

  impact 1.0
  title 'Ensure AWS Security Groups disallow FTP ingress from 0.0.0.0/0.'

  aws_region.region_names.each do |region|
    aws_security_groups(aws_region: region).group_ids.each do |security_group_id|
      describe aws_security_group(aws_region: region, group_id: security_group_id) do
        it { should exist }
        it { should_not allow_in(ipv4_range: '0.0.0.0/0', port: 21) }
      end
    end
  end
end

我收到此错误:

×  aws-multi-region-security-group-ftp-1.0: Ensure AWS Security Groups disallow FTP ingress from 0.0.0.0/0.
     ×  Control Source Code Error sg-disallow-ftp.rb:3 
     undefined local variable or method `aws_region' for #<#<Class:0x00007fc35a095158>:0x00007fc356ebd568>
amazon-web-services chef inspec
1个回答
0
投票

似乎您缺少一些配置。

i将假定您已创建名为inspec profileaws。您可以利用inspec init

创建个人资料
inspec init

一旦创建了配置文件,就需要指定从$ inspec init profile aws inspec-aws的依存关系。您将在inspec-aws文件中执行此操作,该文件如下所示:

use the resources

并且您应该准备好出发。

您可以通过将aws/inspec.yml与资源包结合使用来验证它是否有效,例如:

name: aws
title: InSpec Profile
maintainer: The Authors
copyright: The Authors
copyright_email: [email protected]
license: Apache-2.0
summary: An InSpec Compliance Profile
version: 0.1.0
supports:
  platform: aws
inspec_version: '>= 4.6.9'
depends:
  - name: inspec-aws
    url: https://github.com/inspec/inspec-aws/archive/v1.3.2.tar.gz
© www.soinside.com 2019 - 2024. All rights reserved.