Class: AuditViaSsh

Inherits:
Ec2Script show all
Defined in:
lib/scripts/ec2/audit_via_ssh.rb

Overview

Audit an AMI or an instance via an SSH connection using a specific benchmark

Defined Under Namespace

Classes: AnalyseAuditViaSsh, AuditViaSshState, CleanUpAuditViaSsh, Done, InitialState, LaunchAuditViaSsh

Constant Summary

Constants inherited from Ec2Script

Ec2Script::CS_AWS_TIMEOUT, Ec2Script::CS_SEC_GRP_DESC, Ec2Script::CS_SEC_GRP_NAME

Instance Method Summary collapse

Methods inherited from Ec2Script

#get_execution_result, #post_message, #register_progress_message_listener, #register_state_change_listener, #start_script

Constructor Details

#initialize(input_params) ⇒ AuditViaSsh

Input parameters

  • ec2_api_handler => object that allows to access the EC2 API

  • ami_id => the ID of the AMI to be copied in another region

  • ssh_username => The username for ssh for source-instance (default = root)

  • key_name => Key name of the instance that manages the snaphot-volume in the source region

  • ssh_key_data => Key information for the security group that starts the AMI [if not set, use ssh_key_files]



19
20
21
# File 'lib/scripts/ec2/audit_via_ssh.rb', line 19

def initialize(input_params)
  super(input_params)
end

Instance Method Details

#check_input_parametersObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/scripts/ec2/audit_via_ssh.rb', line 23

def check_input_parameters()
  if @input_params[:ami_id] == nil && @input_params[:instance_id] == nil
    raise Exception.new("No Instance ID or AMI ID specified")
  end
  if @input_params[:ami_id] != nil && !(@input_params[:ami_id] =~ /^ami-.*$/)
    raise Exception.new("Invalid AMI ID specified")
  end
  if @input_params[:instance_id] != nil && !(@input_params[:instance_id] =~ /^i-.*$/)
    raise Exception.new("Invalid Instance ID specified")
  end

  if @input_params[:sec_grp_name] == nil
    @input_params[:sec_grp_name] = "default"
  end
  if @input_params[:audit_type] != nil && @input_params[:audit_type].downcase.eql?("ssh")
    @input_params[:benchmark_file] = "./lib/audit/benchmark_ssh.zip"
  elsif @input_params[:audit_type] != nil && @input_params[:audit_type].downcase.eql?("apache")
    @input_params[:benchmark_file] = "./lib/audit/benchmark_apache.zip"
  else
    raise Exception.new("Invalid Audit '#{@input_params[:audit_type]}' specified")
  end

  ec2_helper = Ec2Helper.new(@input_params[:ec2_api_handler])
  if !ec2_helper.check_open_port(@input_params[:sec_grp_name], 22)
    raise Exception.new("Port 22 must be opened for security group 'default' to connect via SSH")
  end
end

#load_initial_stateObject



51
52
53
# File 'lib/scripts/ec2/audit_via_ssh.rb', line 51

def load_initial_state()
  AuditViaSshState.load_state(@input_params)
end