{"action":"created","issue":{"url":"https://api.github.com/repos/chef/chef/issues/2349","labels_url":"https://api.github.com/repos/chef/chef/issues/2349/labels{/name}","comments_url":"https://api.github.com/repos/chef/chef/issues/2349/comments","events_url":"https://api.github.com/repos/chef/chef/issues/2349/events","html_url":"https://github.com/chef/chef/pull/2349","id":47677929,"number":2349,"title":"Reset $HOME to user running chef-client when running via sudo","user":{"login":"drags","id":25615,"avatar_url":"https://avatars.githubusercontent.com/u/25615?v=3","gravatar_id":"","url":"https://api.github.com/users/drags","html_url":"https://github.com/drags","followers_url":"https://api.github.com/users/drags/followers","following_url":"https://api.github.com/users/drags/following{/other_user}","gists_url":"https://api.github.com/users/drags/gists{/gist_id}","starred_url":"https://api.github.com/users/drags/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drags/subscriptions","organizations_url":"https://api.github.com/users/drags/orgs","repos_url":"https://api.github.com/users/drags/repos","events_url":"https://api.github.com/users/drags/events{/privacy}","received_events_url":"https://api.github.com/users/drags/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/chef/chef/labels/Bug","name":"Bug","color":"e11d21"},{"url":"https://api.github.com/repos/chef/chef/labels/Chef%20Core","name":"Chef Core","color":"c7def8"},{"url":"https://api.github.com/repos/chef/chef/labels/Ready%20for%20Merge","name":"Ready for Merge","color":"5319e7"},{"url":"https://api.github.com/repos/chef/chef/labels/Signed%20CLA","name":"Signed CLA","color":"ededed"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2014-11-04T04:55:18Z","updated_at":"2015-03-27T12:58:29Z","closed_at":"2015-03-27T12:58:29Z","pull_request":{"url":"https://api.github.com/repos/chef/chef/pulls/2349","html_url":"https://github.com/chef/chef/pull/2349","diff_url":"https://github.com/chef/chef/pull/2349.diff","patch_url":"https://github.com/chef/chef/pull/2349.patch"},"body":"### Version: 11.16.4\r\n\r\n### Environment: Ubuntu 14.04 in EC2\r\n\r\n### Scenario:\r\n[What you are trying to achieve and you can't?]\r\nTrying to pull a docker image using the docker cookbook from the Chef Supermarket. Unfortunately, when running via `knife bootstrap` and logging in as a non-root user the `sudo` command does not use the `-H` argument in order to update the `$HOME` environment variable to become the home directory of the user that is being `sudo`'d to.\r\n\r\nIn this scenario `knife bootstrap -x ubuntu my-host.mydomain.tld --sudo -r 'role[base]'` kicks off the chef install as expected and begins running the converged cookbooks, however when it gets to the `docker pull` step it fails because `$HOME` is still set to `/home/ubuntu/`, and the `docker` command searches `$HOME` for a `.dockercfg`.\r\n\r\nThis is one example of how this issue will affect `execute`/`bash` resources which expect a well formed `env` for the running commands. \r\n\r\n### Steps to Reproduce:\r\nCreate an `execute` resource which runs a command that searches for its configuration within $HOME. Run the chef-client from a different user using `sudo -u <chef-user> chef-client`. Compare this with `sudo -H -u <chef-user> chef-client`.\r\n\r\nA terse reproduction example:\r\n\r\n<pre>\r\nsomeuser@host $ sudo -u root chef-apply -s -l debug\r\nexecute \"env\" do\r\n  command \"env\"\r\nend\r\n^D\r\n...snip...\r\nHOME=/home/someuser\r\n...snip...\r\n</pre>\r\n\r\n<pre>\r\nsomeuser@host $ sudo -u root -H chef-apply -s -l debug\r\nexecute \"env\" do\r\n  command \"env\"\r\nend\r\n...snip...\r\nHOME=/root\r\n...snip...\r\n</pre>\r\n\r\n\r\n### Expected Result:\r\nThe docker image to be pulled\r\n\r\n### Actual Result:\r\nThe docker pull command errors with a \"not found\" error (in this case, indicating a docker repository that the user does not have access to)"},"comment":{"url":"https://api.github.com/repos/chef/chef/issues/comments/86933248","html_url":"https://github.com/chef/chef/pull/2349#issuecomment-86933248","issue_url":"https://api.github.com/repos/chef/chef/issues/2349","id":86933248,"user":{"login":"btm","id":4381,"avatar_url":"https://avatars.githubusercontent.com/u/4381?v=3","gravatar_id":"","url":"https://api.github.com/users/btm","html_url":"https://github.com/btm","followers_url":"https://api.github.com/users/btm/followers","following_url":"https://api.github.com/users/btm/following{/other_user}","gists_url":"https://api.github.com/users/btm/gists{/gist_id}","starred_url":"https://api.github.com/users/btm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/btm/subscriptions","organizations_url":"https://api.github.com/users/btm/orgs","repos_url":"https://api.github.com/users/btm/repos","events_url":"https://api.github.com/users/btm/events{/privacy}","received_events_url":"https://api.github.com/users/btm/received_events","type":"User","site_admin":false},"created_at":"2015-03-27T12:58:29Z","updated_at":"2015-03-27T12:58:29Z","body":"Cherry-picked into master as 551ec22e7b8fe240a111f7124d820ff64299283f. Thanks @drags."}}