2

I am using inspec to verify some AMIs that I am building, and in the main I want the controls in the profile to run as a normal user so I can test as a standard user would see things.

However there area couple of controls that I want to run as root (sudo) to check things like services.

I know I can pass --sudo to the exec command but that runs the whole profile as sudo. Is it possible to elevate a single control? (you would use become in Ansible). Or do I need to write two profiles and execute them independantly?

apr_1985
  • 1,764
  • 2
  • 14
  • 27

2 Answers2

1

hmm, if its just a single control couldn't you just use su -l USERNAME -c COMMAND and capture the output? Might not be ideal to use the command resource, but this would give you access to the users' environment. i.e.:

root@machine:~# su -l ubuntu -c env
shaftdiesel
  • 416
  • 4
  • 7
0

You can use below method to run sudo commands remotely via chef inspec:

history_file = ssh -o StrictHostKeyChecking=no -tt #{input('host')} sudo find / -name '.mysql_history'.strip 

file_check = ssh -o StrictHostKeyChecking=no -tt #{input('host')} sudo ls -l #{history_file}.strip
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77