Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle user option for user selection through docker transport #669

Conversation

Vasu1105
Copy link
Contributor

@Vasu1105 Vasu1105 commented Mar 9, 2021

Signed-off-by: Vasu1105 vasundhara.jagdale@chef.io

Description

For testing created the non root docker image and executed docker run after that executed following train commands.

Before adding user option in the run_command

$ irb -I lib/
2.7.0 :001 > require 'train'
 => true 
2.7.0 :002 > t = Train.create('docker', host: '5f2dbf21d6ee')
 => #<Train::Transports::Docker:0x0000000001526948 @options={:host=>"5f2dbf21d6ee", :shell=>false, :shell_options=>nil, :shell_command=>... 
2.7.0 :003 > c = t.connection
 => Train::Transports::Docker::Connection[unknown] 
2.7.0 :004 > c.run_command("whoami").stdout
 => "john\n" 
2.7.0 :005 > t = Train.create('docker', host: '5f2dbf21d6ee', user: 'root')
 => #<Train::Transports::Docker:0x0000000001cfe030 @options={:host=>"5f2dbf21d6ee", :user=>"root", :shell=>false, :shell_options=>nil, :... 
2.7.0 :006 > c = t.connection
 => Train::Transports::Docker::Connection[unknown] 
2.7.0 :007 > c.run_command("whoami").stdout
 => "john\n" 

Output after adding option in run_command

$ irb -I lib/
2.7.0 :001 > require 'train'
 => true 
2.7.0 :002 > t = Train.create('docker', host: '5f2dbf21d6ee')
 => #<Train::Transports::Docker:0x0000000002129d08 @options={:host=>"5f2dbf21d6ee", :shell=>false, :shell_options=>nil, :shell_command=>... 
2.7.0 :003 > c = t.connection
 => Train::Transports::Docker::Connection[unknown] 
2.7.0 :004 > c.run_command("whoami").stdout
 => "john\n" 
2.7.0 :005 > t = Train.create('docker', host: '5f2dbf21d6ee', user: 'root')
 => #<Train::Transports::Docker:0x000000000201a6b0 @options={:host=>"5f2dbf21d6ee", :user=>"root", :shell=>false, :shell_options=>nil, :... 
2.7.0 :006 > c = t.connection
 => Train::Transports::Docker::Connection[unknown] 
2.7.0 :007 > c.run_command("whoami").stdout
 => "root\n" 

Also tested with the base image where non root user is not configured and following is the output for the same

2.7.0 :001 > require 'train'
 => true 
2.7.0 :002 > t = Train.create('docker', host: '946f59562e28')
 => #<Train::Transports::Docker:0x0000000003066f78 @options={:host=>"946f59562e28", :shell=>false, :shell_options=>nil, :shell_command=>... 
2.7.0 :003 > t.connection
 => Train::Transports::Docker::Connection[unknown] 
2.7.0 :004 > c = t.connection
 => Train::Transports::Docker::Connection[unknown] 
2.7.0 :005 > c.run_command("whoami").stdout
 => "root\n" 

Related Issue

Fixes #574

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New content (non-breaking change)
  • Breaking change (a content change which would break existing functionality or processes)

Checklist:

  • I have read the CONTRIBUTING document.

Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>
@Vasu1105 Vasu1105 requested a review from a team as a code owner March 9, 2021 08:50
@chef-expeditor
Copy link
Contributor

chef-expeditor bot commented Mar 9, 2021

Hello Vasu1105! Thanks for the pull request!

Here is what will happen next:

  1. Your PR will be reviewed by the maintainers.
  2. Possible Outcomes
    a. If everything looks good, one of them will approve it, and your PR will be merged.
    b. The maintainer may request follow-on work (e.g. code fix, linting, etc). We would encourage you to address this work in 2-3 business days to keep the conversation going and to get your contribution in sooner.
    c. Cases exist where a PR is neither aligned to Chef InSpec's product roadmap, or something the team can own or maintain long-term. In these cases, the maintainer will provide justification and close out the PR.

Thank you for contributing!

@clintoncwolfe
Copy link
Contributor

This works great! Only this I would ask is that we also update the README to document the new option.

Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>
@Vasu1105
Copy link
Contributor Author

This works great! Only this I would ask is that we also update the README to document the new option.

@clintoncwolfe I have updated the docs could you please have a look and let me know any changes required.

Copy link
Contributor

@clintoncwolfe clintoncwolfe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@clintoncwolfe clintoncwolfe merged commit 3dbb4f8 into inspec:master Mar 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

User selection for docker transport
2 participants