You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On the windows platform programs like xcopy set the archive bit on folders
as well as files.
The Inspec directory and file resources use the train backend for file when making assertions,
Train can either use remote or local implimentation for the windows platform.
Using trains local file class for windows, a directory with the archive bit set is correctly identified as directory. (it uses rubys ::File.stat(path) to get attributes about the path)
When Inspec is used remotely and Trains remote file class for windows is used, directories with the archive bit set are identified as files. (it uses powershell's 'Get-ItemProperty -Path' to get attribute information)
Expected behaviour:
Train should report that directories with the archive bit set are directories and not files
def type
if attributes.include?('Archive')
return :file
elsif attributes.include?('ReparsePoint')
return :symlink
elsif attributes.include?('Directory')
return :directory
end
:unknown
end
windows remote file gets the attributes via
def attributes
return @attributes if defined?(@attributes)
@attributes = @backend.run_command(
"(Get-ItemProperty -Path \"#{@spath}\").attributes.ToString()").stdout.chomp.split(/\s*,\s*/)
end
when Get-ItemProperty is called on a directory with the Archive bit set the logic fails and it is
reported as a file.
This causes controls to fail that are expecting a directory
control 'test folder' do
title 'Checking c:\test_folder directory'
describe directory ('c:\test_folder') do
it { should be_directory }
its('type') { should eq :directory }
end
end
Train and Platform Version
Train 0.29.1
Windows 2012 R2
Replication Case
Windows 2012
another server to run Inspec from (the remote server)
on the remote server
install inspec
and create a control
control 'test folder' do
title 'Checking c:\test_folder directory'
describe directory ('c:\test_folder') do
it { should be_directory }
its('type') { should eq :directory }
end
end
run the control against the windows server
Possible Solutions
def type
if attributes.include?('Archive') && attributes.include?('Directory')
return :directory
elsif attributes.include?('Archive')
return :file
elsif attributes.include?('ReparsePoint')
return :symlink
elsif attributes.include?('Directory')
return :directory
end
:unknown
end
or possibly
def type
if attributes.include?('Archive') && !attributes.include?('Directory')
return :file
elsif attributes.include?('ReparsePoint')
return :symlink
elsif attributes.include?('Directory')
return :directory
end
:unknown
end
Description
On the windows platform programs like xcopy set the archive bit on folders
as well as files.
The Inspec directory and file resources use the train backend for file when making assertions,
Train can either use remote or local implimentation for the windows platform.
Using trains local file class for windows, a directory with the archive bit set is correctly identified as directory. (it uses rubys ::File.stat(path) to get attributes about the path)
When Inspec is used remotely and Trains remote file class for windows is used, directories with the archive bit set are identified as files. (it uses powershell's 'Get-ItemProperty -Path' to get attribute information)
Expected behaviour:
Train should report that directories with the archive bit set are directories and not files
relevant code in Train
https://github.com/chef/train/blob/master/lib/train/file/remote/windows.rb#L41-L50
windows remote file gets the attributes via
you can test this on the command line:
when Get-ItemProperty is called on a directory with the Archive bit set the logic fails and it is
reported as a file.
This causes controls to fail that are expecting a directory
Train and Platform Version
Train 0.29.1
Windows 2012 R2
Replication Case
Windows 2012
another server to run Inspec from (the remote server)
create a folder with the archive bit set
on the remote server
install inspec
and create a control
run the control against the windows server
Possible Solutions
or possibly
PR #275
Stacktrace
The text was updated successfully, but these errors were encountered: