diff --git a/Gemfile.lock b/Gemfile.lock index 69b3eada5..0d1b3cc12 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -16,6 +16,3 @@ DEPENDENCIES nokogiri rake xml-simple - -BUNDLED WITH - 1.10.4 diff --git a/config/scenario.xml b/config/scenario.xml index e44b1b2d6..d4e890ed9 100644 --- a/config/scenario.xml +++ b/config/scenario.xml @@ -1,16 +1,20 @@ - + - + - + --> + + + + diff --git a/lib/constants.rb b/lib/constants.rb index acf9e2cb8..46252a1bc 100644 --- a/lib/constants.rb +++ b/lib/constants.rb @@ -8,7 +8,7 @@ MOUNT_DIR = "#{ROOT_DIR}/mount/" BUILD_DIR = "#{ROOT_DIR}/modules/build/" MOUNT_PUPPET_DIR = "#{ROOT_DIR}/mount/puppet" PROJECTS_DIR = "#{ROOT_DIR}/projects" - +ENVIRONMENTS_PATH = "#{ROOT_DIR}/modules/environments" #PATH CONSTANTS MODULES_PATH = "#{ROOT_DIR}/modules/" VULNERABILITIES_PATH = "#{ROOT_DIR}/modules/vulnerabilities/" diff --git a/lib/filecreator.rb b/lib/filecreator.rb index 136756cd1..038a66cac 100644 --- a/lib/filecreator.rb +++ b/lib/filecreator.rb @@ -2,7 +2,7 @@ require 'erb' require_relative 'erb_controller' require_relative 'constants' require_relative 'configuration' - +require 'fileutils' class FileCreator # Creates project directory, uses .erb files to create a report and the vagrant file that will be used # to create the virtual machines @@ -20,9 +20,9 @@ class FileCreator puts "The system is now creating the Project#{build_number}" Dir::mkdir("#{PROJECTS_DIR}/Project#{build_number}") unless File.exists?("#{PROJECTS_DIR}/#{build_number}") - puts 'Creating the projects mount directory' - Dir::mkdir("#{PROJECTS_DIR}/Project#{build_number}/mount") unless File.exists?("#{PROJECTS_DIR}/Project#{build_number}/mount") - + puts 'Copying manifests to the projects manifest directory' + FileUtils.cp_r("#{ROOT_DIR}/mount/puppet/manifest/","#{PROJECTS_DIR}/Project#{build_number}/manifests") + # initialises box before creation command = "cd #{PROJECTS_DIR}/Project#{build_number}/; vagrant init" %x[#{command}] diff --git a/lib/objects/site.rb b/lib/objects/site.rb new file mode 100644 index 000000000..02d0b2949 --- /dev/null +++ b/lib/objects/site.rb @@ -0,0 +1,8 @@ +class Site + attr_accessor :name, :type + + def initialize(name='', type='') + @name = name + @type = type + end +end \ No newline at end of file diff --git a/lib/objects/system.rb b/lib/objects/system.rb index f3563a32c..26805a766 100644 --- a/lib/objects/system.rb +++ b/lib/objects/system.rb @@ -1,9 +1,9 @@ class System # can access from outside of class - attr_accessor :id, :os, :url,:basebox, :networks, :vulns, :services + attr_accessor :id, :os, :url,:basebox, :networks, :vulns, :services, :sites #initalizes system variables - def initialize(id, os, basebox, url, vulns=[], networks=[], services=[]) + def initialize(id, os, basebox, url, vulns=[], networks=[], services=[], sites=[]) @id = id @os = os @url = url @@ -11,6 +11,7 @@ class System @vulns = vulns @networks = networks @services = services + @sites = sites end def is_valid_base diff --git a/lib/systemreader.rb b/lib/systemreader.rb index 6f61fd9e5..0068612b7 100644 --- a/lib/systemreader.rb +++ b/lib/systemreader.rb @@ -6,6 +6,7 @@ require_relative 'helpers/vulnerability_processor' require_relative 'objects/base_box' require_relative 'objects/network' require_relative 'objects/service' +require_relative 'objects/site' require_relative 'objects/system' require_relative 'objects/vulnerability' require 'nokogiri' @@ -29,7 +30,14 @@ class SystemReader vulns = [] networks = [] services = [] + sites = [] + system.css('sites site').each do |site| + site_obj = Site.new + site_obj.name = site['name'] + site_obj.type = site['type'] + sites << site_obj + end system.css('vulnerabilities vulnerability').each do |v| vulnerability = Vulnerability.new # assign the value if the value is not nil (i.e. it's been specified in scenario.xml) @@ -43,6 +51,8 @@ class SystemReader vulns << vulnerability end + + system.css('services service').each do |v| service = Service.new service.name = v['name'] @@ -67,7 +77,7 @@ class SystemReader # pass in the already selected set of vulnerabilities, and additional secure services to find new_services = ServiceManager.process(services, Configuration.services, new_vulns) - s = System.new(id, os, basebox, url, new_vulns, new_networks, new_services) + s = System.new(id, os, basebox, url, new_vulns, new_networks, new_services, sites) if s.is_valid_base == false BaseManager.generate_base(s,Configuration.bases) end diff --git a/lib/templates/vagrantbase.erb b/lib/templates/vagrantbase.erb index 2b08771f9..3ceac4822 100644 --- a/lib/templates/vagrantbase.erb +++ b/lib/templates/vagrantbase.erb @@ -17,12 +17,6 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| <% end %> <%= systems.id %>.vm.synced_folder "<%= MOUNT_DIR %>", "/mount" end - config.vm.provision :shell, :inline => "apt-get --yes --force-yes install ruby " - config.vm.provision :shell, :inline => "gem uninstall puppet" - config.vm.provision :shell, :inline => "gem install puppet -v '3.5.1'" - config.vm.provision :shell, :inline => "apt-get update --fix-missing" - - # Add secure services <% systems.services.each do |service| %> @@ -30,14 +24,30 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| <% service_name = service.name%> config.vm.provision "puppet" do | <%=service_name%> | - <%=service_name%>.module_path = "<%="#{ROOT_DIR}/mount/puppet/module"%>" + <%=service_name%>.environment_path = "<%="#{ENVIRONMENTS_PATH}"%>" + <%=service_name%>.environment = "production" <%=service_name%>.manifests_path = "<%="#{ROOT_DIR}/mount/puppet/manifest"%>" + <%=service_name%>.manifest_file = "<%=service_name%>.pp" end <% end %> + #Add sites + <% systems.sites.each do |site| %> + config.vm.provision "puppet" do | wordpress | + wordpress.module_path = "<%="#{ROOT_DIR}/mount/puppet/module"%>" + wordpress.environment_path = "<%="#{ENVIRONMENTS_PATH}"%>" + wordpress.environment = "production" + wordpress.manifests_path = "<%="#{ROOT_DIR}/mount/puppet/manifest"%>" + wordpress.manifest_file = "wordpress.pp" + end + + <% end %> + + + # Add vulnerabilities #a vulnerability has 1 or many puppets @@ -45,8 +55,9 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| <% vulnerability_name = vulnerability.name %> config.vm.provision "puppet" do | <%=vulnerability_name%> | - <%=vulnerability_name%>.module_path = "<%="#{ROOT_DIR}/mount/puppet/module"%>" + <%=vulnerability_name%>.environment_path = "<%="#{ENVIRONMENTS_PATH}"%>" + <%=vulnerability_name%>.environment = "production" <%=vulnerability_name%>.manifests_path = "<%="#{ROOT_DIR}/mount/puppet/manifest"%>" <%=vulnerability_name%>.manifest_file = "<%=vulnerability_name%>.pp" end @@ -56,6 +67,8 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # clean up script which clears history from the VMs and clobs files together config.vm.provision "puppet" do |cleanup| cleanup.module_path = "<%="#{ROOT_DIR}/mount/puppet/module"%>" + cleanup.environment_path = "<%="#{ENVIRONMENTS_PATH}"%>" + cleanup.environment = "production" cleanup.manifests_path = "<%="#{ROOT_DIR}/mount/puppet/manifest"%>" cleanup.manifest_file = "cleanup.pp" end diff --git a/modules/environments/production/environment.conf b/modules/environments/production/environment.conf new file mode 100644 index 000000000..3263144d3 --- /dev/null +++ b/modules/environments/production/environment.conf @@ -0,0 +1 @@ +default_manifest = "../../mount/puppet/manifest" \ No newline at end of file diff --git a/xml/bases.xml b/xml/bases.xml index c0b5f17a7..b2ad87686 100644 --- a/xml/bases.xml +++ b/xml/bases.xml @@ -3,6 +3,7 @@ - + +