Class: SeccompTools::CLI::Audit

Inherits:
Base
  • Object
show all
Includes:
FilterInput
Defined in:
lib/seccomp-tools/cli/audit.rb

Overview

Handle 'audit' command.

Constant Summary collapse

SUMMARY =

Summary of this command.

'Assess a seccomp filter for weaknesses and escape routes.'
USAGE =

Usage of this command.

"audit - #{SUMMARY}\n\nUsage: seccomp-tools audit [options] [BPF_FILE|EXEC]".freeze

Instance Attribute Summary

Attributes inherited from Base

#argv, #option

Instance Method Summary collapse

Methods included from Dumpable

#dump_seccomp, #dumping_supported?

Constructor Details

#initializeAudit

Instantiate an SeccompTools::CLI::Audit object.

Takes the same arguments as Base#initialize.



25
26
27
28
# File 'lib/seccomp-tools/cli/audit.rb', line 25

def initialize(*)
  super
  option[:format] = :human
end

Instance Method Details

#handlevoid

This method returns an undefined value.

Reads the filter(s) from a BPF file, an executable, or an existing process, then reports the weaknesses of each.



49
50
51
52
53
54
55
56
# File 'lib/seccomp-tools/cli/audit.rb', line 49

def handle
  return unless super

  filters = collect_filters
  return if filters.empty?

  option[:format] == :json ? emit_json(filters) : emit_human(filters)
end

#parserOptionParser

Define option parser.

Returns:

  • (OptionParser)

    The parser of this command's options.



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/seccomp-tools/cli/audit.rb', line 33

def parser
  @parser ||= OptionParser.new do |opt|
    opt.banner = usage
    option_filter_source(opt, 'audit')
    option_arch(opt, 'With an executable or --pid the architecture is auto-detected instead.')

    opt.on('-f', '--format FORMAT', %i[human json], 'Output format, one of <human|json>.',
           'Default: human') do |f|
      option[:format] = f
    end
  end
end