Skip to content

Commit

Permalink
prevent sudo on localhost targets
Browse files Browse the repository at this point in the history
See the original PR here: inspec/inspec#1741
  • Loading branch information
arlimus committed May 30, 2017
1 parent a876fd0 commit 592d14d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/train.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ def self.parse_uri(string)
def self.validate_backend(conf, default = :local)
return default if conf.nil?
res = conf[:backend]

if (res.nil? || res == 'localhost') && conf[:sudo]
fail Train::UserError, 'Sudo is only valid when running against a remote host. '\
'To run this locally with elevated privileges, run the command with `sudo ...`.'
end

return res if !res.nil?

if !conf[:target].nil?
Expand Down

0 comments on commit 592d14d

Please sign in to comment.