2018-08-09 13:19:49 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
# frozen_string_literal: true
|
|
|
|
# check for web applications in IIS
|
|
|
|
# Note: this is only supported in windows 2012 and later
|
|
|
|
|
|
|
|
class IisAppPool < Inspec.resource(1)
|
|
|
|
name 'iis_app_pool'
|
|
|
|
desc 'Tests IIS application pool configuration on windows.'
|
2018-09-20 14:09:17 +00:00
|
|
|
supports platform: 'windows'
|
2019-03-19 14:17:32 +00:00
|
|
|
example <<~EXAMPLE
|
2018-08-09 13:19:49 +00:00
|
|
|
describe iis_app_pool('DefaultAppPool') do
|
|
|
|
it { should exist }
|
|
|
|
its('enable32bit') { should cmp 'True' }
|
|
|
|
its('runtime_version') { should eq 'v4.0' }
|
|
|
|
its('pipeline_mode') { should eq 'Integrated' }
|
|
|
|
end
|
2019-03-19 14:17:32 +00:00
|
|
|
EXAMPLE
|
2018-08-09 13:19:49 +00:00
|
|
|
|
|
|
|
def initialize(pool_name)
|
|
|
|
@pool_name = pool_name
|
|
|
|
@pool_path = "IIS:\\AppPools\\#{@pool_name}"
|
|
|
|
@cache = nil
|
|
|
|
|
|
|
|
# verify that this resource is only supported on Windows
|
|
|
|
return skip_resource 'The `iis_app_pool` resource is not supported on your OS.' unless inspec.os.windows?
|
|
|
|
end
|
|
|
|
|
|
|
|
def pool_name
|
|
|
|
iis_app_pool[:pool_name]
|
|
|
|
end
|
|
|
|
|
|
|
|
def runtime_version
|
|
|
|
iis_app_pool[:version]
|
|
|
|
end
|
|
|
|
|
|
|
|
def enable32bit
|
|
|
|
iis_app_pool[:e32b]
|
|
|
|
end
|
|
|
|
|
|
|
|
def pipeline_mode
|
|
|
|
iis_app_pool[:mode]
|
|
|
|
end
|
|
|
|
|
|
|
|
def max_processes
|
|
|
|
iis_app_pool[:processes]
|
|
|
|
end
|
|
|
|
|
|
|
|
def timeout
|
|
|
|
iis_app_pool[:timeout]
|
|
|
|
end
|
|
|
|
|
|
|
|
def timeout_days
|
|
|
|
iis_app_pool[:timeout_days]
|
|
|
|
end
|
|
|
|
|
|
|
|
def timeout_hours
|
|
|
|
iis_app_pool[:timeout_hours]
|
|
|
|
end
|
|
|
|
|
|
|
|
def timeout_minutes
|
|
|
|
iis_app_pool[:timeout_minutes]
|
|
|
|
end
|
|
|
|
|
|
|
|
def timeout_seconds
|
|
|
|
iis_app_pool[:timeout_seconds]
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_identity_type
|
|
|
|
iis_app_pool[:user_identity_type]
|
|
|
|
end
|
|
|
|
|
|
|
|
def username
|
|
|
|
iis_app_pool[:username]
|
|
|
|
end
|
|
|
|
|
|
|
|
def exists?
|
|
|
|
!iis_app_pool[:pool_name].empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
2018-09-20 14:09:41 +00:00
|
|
|
"IIS App Pool '#{@pool_name}'"
|
2018-08-09 13:19:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def iis_app_pool
|
|
|
|
return @cache unless @cache.nil?
|
|
|
|
|
2019-02-28 20:04:11 +00:00
|
|
|
# We use `-Compress` here to avoid a bug in PowerShell
|
|
|
|
# It does not affect validity of the output, only the representation
|
|
|
|
# See: https://github.com/inspec/inspec/pull/3842
|
2018-11-08 05:42:44 +00:00
|
|
|
script = <<~EOH
|
2018-09-20 14:08:10 +00:00
|
|
|
Import-Module WebAdministration
|
|
|
|
If (Test-Path '#{@pool_path}') {
|
2019-02-28 05:42:20 +00:00
|
|
|
Get-Item '#{@pool_path}' | Select-Object * | ConvertTo-Json -Compress
|
2018-09-20 14:08:10 +00:00
|
|
|
} Else {
|
|
|
|
Write-Host '{}'
|
|
|
|
}
|
|
|
|
EOH
|
|
|
|
cmd = inspec.powershell(script)
|
2018-08-09 13:19:49 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
pool = JSON.parse(cmd.stdout)
|
|
|
|
rescue JSON::ParserError => _e
|
|
|
|
raise Inspec::Exceptions::ResourceFailed, 'Unable to parse app pool JSON'
|
|
|
|
end
|
|
|
|
|
2018-09-20 14:08:10 +00:00
|
|
|
process_model = pool.fetch('processModel', {})
|
|
|
|
idle_timeout = process_model.fetch('idleTimeout', {})
|
|
|
|
|
2018-08-09 13:19:49 +00:00
|
|
|
# map our values to a hash table
|
|
|
|
@cache = {
|
|
|
|
pool_name: pool['name'],
|
|
|
|
version: pool['managedRuntimeVersion'],
|
|
|
|
e32b: pool['enable32BitAppOnWin64'],
|
|
|
|
mode: pool['managedPipelineMode'],
|
2018-09-20 14:08:10 +00:00
|
|
|
processes: process_model['maxProcesses'],
|
|
|
|
timeout: "#{idle_timeout['Hours']}:#{idle_timeout['Minutes']}:#{idle_timeout['Seconds']}",
|
|
|
|
timeout_days: idle_timeout['Days'],
|
|
|
|
timeout_hours: idle_timeout['Hours'],
|
|
|
|
timeout_minutes: idle_timeout['Minutes'],
|
|
|
|
timeout_seconds: idle_timeout['Seconds'],
|
|
|
|
user_identity_type: process_model['identityType'],
|
|
|
|
username: process_model['userName'],
|
2018-08-09 13:19:49 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|