Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement RFC: Harmonize profile location targets #118

Closed
chris-rock opened this issue Oct 24, 2016 · 3 comments · Fixed by #121
Closed

Implement RFC: Harmonize profile location targets #118

chris-rock opened this issue Oct 24, 2016 · 3 comments · Fixed by #121
Labels
Type: Enhancement Adds new functionality.
Milestone

Comments

@chris-rock
Copy link
Contributor

chris-rock commented Oct 24, 2016

Cookbook version

2.x

Scenario:

It should be easy for customer to copy profile locations from inspec.yml to chef attributes. In inspec/inspec#1227 we defined the target format for audit cookbook. We change from

"profiles" => {
    # org / profile name from Chef Compliance
    "base/linux" => true,
    # supermarket url
    "brewinc/ssh-hardening" => {
      # location where inspec will fetch the profile from
      "source" => "supermarket://hardening/ssh-hardening"
    },
    # local Windows path
    "brewinc/win2012_audit" => {
      # filesystem path
      "source" => "E:/profiles/win2012_audit"
    },
    # github url
    "brewinc/tmp_compliance_profile" => {
      "source" => "https://github.com/nathenharvey/tmp_compliance_profile"
    },
    # disable profile
    "brewinc/tmp_compliance_profile-master" => {
      "source" => "/tmp/tmp_compliance_profile-master",
      "disabled" => true
    }
  }

to

{
  "profiles": [
    {
      "name": "hardening/ssh-hardening"
    },
    {
      "name": "os-hardening",
      "url": "https://github.com/dev-sec/tests-os-hardening/archive/master.zip"
    },
    {
      "git": "https://github.com/dev-sec/tests-ssh-hardening.git"
    },
    {
      "git": "https://github.com/dev-sec/tests-os-hardening.git"
    }
  ]
}
@chris-rock chris-rock added the Type: Enhancement Adds new functionality. label Oct 24, 2016
@chris-rock chris-rock added this to the 2.0 milestone Oct 24, 2016
@vjeffrey
Copy link

vjeffrey commented Oct 24, 2016

profiles = {
  "profiles": [
    {
      "name": "hardening/ssh-hardening"
    },
    {
      "name": "os-hardening",
      "url": "https://github.com/dev-sec/tests-os-hardening/archive/master.zip"
    },
    {
      "git": "https://github.com/dev-sec/tests-ssh-hardening.git"
    },
    {
      "git": "https://github.com/dev-sec/tests-os-hardening.git"
    }
  ]
}

profiles_array = []

profiles[:profiles].each { |profile| profiles_array.push(profile[:url] || profile[:git]) }

profiles[:profiles].each { |profile|
  if profile.length == 1 && profile[:name]
    profiles_array.push("supermarket://" + profile[:name])
  end
}

profiles[:profiles].each { |profile|
  if profile.include?(:supermarket_url)
    profiles_array.push(profile[:supermarket_url] + "/" + profile[:name])
  end
}

profiles[:profiles].each { |profile|
  if profile.include?(:compliance_url)
    profiles_array.push(profile[:compliance_url] + "/" + profile[:name])
  end
}


final_profiles = profiles_array.reject { |profile| profile.nil? }

final_profiles = 
 ["https://github.com/dev-sec/tests-os-hardening/archive/master.zip",
 "https://github.com/dev-sec/tests-ssh-hardening.git",
 "https://github.com/dev-sec/tests-os-hardening.git",
 "supermarket://hardening/ssh-hardening"]

@vjeffrey
Copy link

i think i'm probably over-complicating this....but does this make sense?

@chris-rock
Copy link
Contributor Author

chris-rock commented Oct 24, 2016

Lets not nest profiles. This should be enough:

"profiles": [
    {
      "name": "hardening/ssh-hardening"
    },
    {
      "name": "os-hardening",
      "url": "https://github.com/dev-sec/tests-os-hardening/archive/master.zip"
    },
    {
      "git": "https://github.com/dev-sec/tests-ssh-hardening.git"
    },
    {
      "git": "https://github.com/dev-sec/tests-os-hardening.git"
    }
  ]

I apologize for the extra curly brackets in the original definition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Adds new functionality.
Development

Successfully merging a pull request may close this issue.

2 participants