{"action":"created","issue":{"url":"https://api.github.com/repos/habitat-sh/habitat/issues/1329","repository_url":"https://api.github.com/repos/habitat-sh/habitat","labels_url":"https://api.github.com/repos/habitat-sh/habitat/issues/1329/labels{/name}","comments_url":"https://api.github.com/repos/habitat-sh/habitat/issues/1329/comments","events_url":"https://api.github.com/repos/habitat-sh/habitat/issues/1329/events","html_url":"https://github.com/habitat-sh/habitat/pull/1329","id":181289756,"number":1329,"title":"[hab] Attempt to call `sudo` on `hab studio *` for non-root users.","user":{"login":"fnichol","id":261548,"avatar_url":"https://avatars.githubusercontent.com/u/261548?v=3","gravatar_id":"","url":"https://api.github.com/users/fnichol","html_url":"https://github.com/fnichol","followers_url":"https://api.github.com/users/fnichol/followers","following_url":"https://api.github.com/users/fnichol/following{/other_user}","gists_url":"https://api.github.com/users/fnichol/gists{/gist_id}","starred_url":"https://api.github.com/users/fnichol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fnichol/subscriptions","organizations_url":"https://api.github.com/users/fnichol/orgs","repos_url":"https://api.github.com/users/fnichol/repos","events_url":"https://api.github.com/users/fnichol/events{/privacy}","received_events_url":"https://api.github.com/users/fnichol/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/habitat-sh/habitat/labels/Feature","name":"Feature","color":"1d76db"},{"url":"https://api.github.com/repos/habitat-sh/habitat/labels/In%20Progress","name":"In Progress","color":"c2e0c6"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-10-05T23:20:36Z","updated_at":"2016-10-06T04:22:37Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/habitat-sh/habitat/pulls/1329","html_url":"https://github.com/habitat-sh/habitat/pull/1329","diff_url":"https://github.com/habitat-sh/habitat/pull/1329.diff","patch_url":"https://github.com/habitat-sh/habitat/pull/1329.patch"},"body":"This change set comprises 2 parts. The contents of each commit message is aggregated below:\r\n\r\n# [hab] Attempt to call `sudo` on `hab studio *` for non-root users.\r\n\r\nThis change only currently affects Linux non-root users who attempt to run the following subcommands:\r\n\r\n* `hab studio *`\r\n* `hab pkg build *`\r\n\r\nThe behavior introduced here will attempt to re-exec the command with prepended with a `sudo -p \"[sudo hab-studio] password for %u:\" -E` in front of the original `hab` subcommand. If the `sudo` command cannot be found on the `PATH` then an error message is displayed to the user and the program terminates with a non-zero exit code. The end result is that, for non-root users on systems using sudoers:\r\n\r\n    hab pkg build ...\r\n\r\nWill be the same as running:\r\n\r\n    sudo hab pkg build ...\r\n\r\nExamples\r\n--------\r\n\r\nRunning as a non-root user with appropriate permissions in sudoers:\r\n\r\n```\r\n> hab studio enter\r\n[sudo hab-studio] password for jdoe:\r\n   hab-studio: Creating Studio at /hab/studios/home--jdoe (default)\r\n   hab-studio: Importing jdoe secret origin key\r\n» Importing origin key from standard input\r\n★ Imported secret origin key jdoe-20161005175939.\r\n   hab-studio: Entering Studio at /hab/studios/home--jdoe (default)\r\n   hab-studio: Exported: HAB_ORIGIN=jdoe\r\n\r\n[1][default:/src:0]#\r\n```\r\n\r\nRunning as a non-root user when the `sudo` command cannot be found on `PATH`:\r\n\r\n```\r\n> sudo mv /usr/bin/sudo /usr/bin/ssudo\r\n\r\n> hab studio enter\r\n∅ Could not find the `sudo' command on the filesystem or in PATH.\r\n∅ Running Habitat Studio requires root or administrator privileges. Please retry this command as a super user or use a privilege-granting facility such as sudo.\r\n\r\n✗✗✗\r\n✗✗✗ Root or administrator permissions required to complete operation\r\n✗✗✗\r\n```\r\n\r\n# [core] Add core `become_command()` to abstract Unix/Windows exec diffs.\r\n\r\nThis change extracts the formerly named `exec_command()` function from\r\nhab's `exec` module into a common interface `become_command()` in core's\r\nnewly created `os::process` module. The intent of this function\r\nphilisophically is to turn the current process into some other process\r\nthat takes over for the duration of the new process. In other words, the\r\nexisting process ceases to do any work.\r\n\r\nThere are 2 implementations for this function, which depend on the\r\nunderlying target platform:\r\n\r\nUnix (i.e. Linux, Mac, BSD, etc)\r\n--------------------------------\r\n\r\nThis implementation uses [`execvp(3)`][] which is now provided by the\r\n[`exec()`][] function on Rust's stdlib [`CommandExt`][] trait. This\r\ninsures that there isn't a deeply nested process chain and that signals\r\nsuch as `Ctrl+C` correctly kill all related processes. If a developer\r\nneeds to create a child process and supervise it or act on the child's\r\nresults then this is **not** the appropriate API to invoke, hence the\r\nname `become_command()`.\r\n\r\n[`execvp(3)`]: https://linux.die.net/man/3/execvp\r\n[`exec()`]:\r\nhttps://doc.rust-lang.org/std/os/unix/process/trait.CommandExt.html#tymethod.exec\r\n[`CommandExt`]:\r\nhttps://doc.rust-lang.org/std/os/unix/process/trait.CommandExt.html\r\n\r\nWindows\r\n-------\r\n\r\nThis implementation uses Rust's stdlib [`Command`] to execute the\r\ncommand as a child process and then exits with the child's exit code.\r\nDue to the lack of `exec*()` behavior. Note that there is an older\r\n`_execv()` in a POSIX compatibility layer in MSVCRT, but the native\r\napproach is to use a child process here, and so that's what we do.\r\nAlso note that while the `hab` process is not replaced by the new\r\nprocess, we explicitly terminate the `hab` process after the child\r\nprocess completes. If a developer needs to create a child process and\r\nsupervise it or act on the child's results then this is **not** the\r\nappropriate API to invoke, hence the name `become_command()`.\r\n\r\n[`Command`]:\r\nhttps://doc.rust-lang.org/std/process/struct.Command.html#method.exec\r\n"},"comment":{"url":"https://api.github.com/repos/habitat-sh/habitat/issues/comments/251863791","html_url":"https://github.com/habitat-sh/habitat/pull/1329#issuecomment-251863791","issue_url":"https://api.github.com/repos/habitat-sh/habitat/issues/1329","id":251863791,"user":{"login":"thesentinels","id":18452204,"avatar_url":"https://avatars.githubusercontent.com/u/18452204?v=3","gravatar_id":"","url":"https://api.github.com/users/thesentinels","html_url":"https://github.com/thesentinels","followers_url":"https://api.github.com/users/thesentinels/followers","following_url":"https://api.github.com/users/thesentinels/following{/other_user}","gists_url":"https://api.github.com/users/thesentinels/gists{/gist_id}","starred_url":"https://api.github.com/users/thesentinels/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thesentinels/subscriptions","organizations_url":"https://api.github.com/users/thesentinels/orgs","repos_url":"https://api.github.com/users/thesentinels/repos","events_url":"https://api.github.com/users/thesentinels/events{/privacy}","received_events_url":"https://api.github.com/users/thesentinels/received_events","type":"User","site_admin":false},"created_at":"2016-10-06T04:22:37Z","updated_at":"2016-10-06T04:22:37Z","body":":neckbeard: Travis CI has [started testing this PR](https://travis-ci.org/habitat-sh/habitat/builds/165424666)."}}
{"actor":{"display_login":"thesentinels"}}