{"id":22825359,"url":"https://github.com/crabdancing/elevate","last_synced_at":"2025-08-19T00:19:32.988Z","repository":{"id":170209694,"uuid":"646342733","full_name":"crabdancing/elevate","owner":"crabdancing","description":"A fork of sudo.rs with some adjustments to make it work on NixOS, as well as basic updates","archived":false,"fork":false,"pushed_at":"2024-04-28T20:45:28.000Z","size":24,"stargazers_count":4,"open_issues_count":1,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-04T19:06:55.539Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/crabdancing.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-28T04:40:39.000Z","updated_at":"2024-11-18T03:37:33.000Z","dependencies_parsed_at":"2024-12-12T17:20:32.775Z","dependency_job_id":null,"html_url":"https://github.com/crabdancing/elevate","commit_stats":null,"previous_names":["alxpettit/elevate","a7287/elevate"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/crabdancing/elevate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crabdancing%2Felevate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crabdancing%2Felevate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crabdancing%2Felevate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crabdancing%2Felevate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crabdancing","download_url":"https://codeload.github.com/crabdancing/elevate/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crabdancing%2Felevate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271079226,"owners_count":24695596,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-18T02:00:08.743Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-12T17:10:29.472Z","updated_at":"2025-08-19T00:19:32.948Z","avatar_url":"https://github.com/crabdancing.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sudo\n\n[![crates.io](https://img.shields.io/crates/v/sudo?logo=rust)](https://crates.io/crates/sudo/)\n[![docs.rs](https://docs.rs/sudo/badge.svg)](https://docs.rs/sudo)\n\nDetect if you are running as root, restart self with `sudo` if needed or setup uid zero when running with the SUID flag set.\n\n## Requirements\n\n* The `sudo` program is required to be installed and setup correctly on the target system.\n* Linux or Mac OS X tested\n    * It should work on *BSD. However, it is not tested.\n\n# Example:\n\nFirst, add sudo to your `Cargo.toml`:\n\n```yaml\n[dependencies]\nelevate = \"0.6.1\"\n```\n\nIn your `main.rs`:\n\n```rust\nfn main() -\u003e Result\u003c(), Box\u003cdyn Error\u003e\u003e {\n    elevate::escalate_if_needed()?;\n    println!(\"Hello, Root-World!\");\n    Ok( () )\n}\n```\n\nIf you are using logging based on the [log infrastructure](https://crates.io/crates/log) you will get timestamped and formatted output.\n\n## Passing RUST_BACKTRACE\n\nThe crate will automatically keep the setting of `RUST_BACKTRACE` intact if it is set to one of the following values:\n\n* `` \u003c- empty string means no pass-through\n* `1` or `true` \u003c- standard trace\n* `full` \u003c- full trace\n\n```bash\n$ RUST_BACKTRACE=full cargo run --example backtrace\n2020-07-05 18:10:31,544 TRACE [sudo] Running as User\n2020-07-05 18:10:31,544 DEBUG [sudo] Escalating privileges\n2020-07-05 18:10:31,544 TRACE [sudo] relaying RUST_BACKTRACE=full\n[sudo] Passwort für user:\n2020-07-05 18:10:39,238 TRACE [sudo] Running as Root\n2020-07-05 18:10:39,238 TRACE [sudo] already running as Root\n2020-07-05 18:10:39,238 INFO  [backtrace] entering failing_function\nthread 'main' panicked at 'now you see me fail', examples/backtrace.rs:16:5\n```\n\n## Keeping part of the environment\n\nYou can keep parts of your environment across the sudo barrier.\nThis enables more configuration options often used in daemons or cloud environments:\n\n```rust\n    // keeping all environment variables starting with \"EXAMPLE_\" or \"CARGO\"\n    elevate::with_env(\u0026[\"EXAMPLE_\", \"CARGO\"]).expect(\"sudo failed\");\n```\n\n**Warning:** This may introduce security problems to your application if untrusted users are able to set these variables.\n\n```bash\n$ EXAMPLE_EXEC='$(ls)' EXAMPLE_BTICKS='`ls`' cargo run --example environment\n2020-07-07 16:32:11,261 INFO  [environment] ① uid: 1000; euid: 1000;\n\n...\n\ndeclare -x EXAMPLE_BTICKS=\"\\`ls\\`\"\ndeclare -x EXAMPLE_EXEC=\"\\$(ls)\"\n...\n\n[sudo] password for user:\n\n2020-07-07 16:32:11,285 TRACE [sudo] Running as Root\n2020-07-07 16:32:11,285 TRACE [sudo] already running as Root\n2020-07-07 16:32:11,285 INFO  [environment] ② uid: 0; euid: 0;\n\n...\n\ndeclare -x EXAMPLE_BTICKS=\"\\`ls\\`\"\ndeclare -x EXAMPLE_EXEC=\"\\$(ls)\"\n```\n\n## Run a program with SUID\n\n```bash\n$ cargo run --example suid\n2020-04-17 15:13:49,450 INFO  [suid] ① uid: 1000; euid: 1000;\nuid=1000(user) gid=1000(user) groups=1000(user),4(adm),27(sudo)\n2020-04-17 15:13:49,453 TRACE [sudo] Running as User\n2020-04-17 15:13:49,453 DEBUG [sudo] Escalating privileges\n[sudo] password for user: \n2020-04-17 15:13:53,529 INFO  [suid] ① uid: 0; euid: 0;\nuid=0(root) gid=0(root) groups=0(root)\n2020-04-17 15:13:53,532 TRACE [sudo] Running as Root\n2020-04-17 15:13:53,532 TRACE [sudo] already running as Root\n2020-04-17 15:13:53,532 INFO  [suid] ② uid: 0; euid: 0;\nuid=0(root) gid=0(root) groups=0(root)\n\n```\n\nThen give the file to `root` and add the suid flag.\n\n```bash\n$ sudo chown root target/debug/examples/suid\n$ sudo chmod 4755 target/debug/examples/suid\n```\n\nNow run the program again:\n\n```bash\n$ target/debug/examples/suid\n2020-04-17 15:14:37,199 INFO  [suid] ① uid: 1000; euid: 0;\nuid=1000(user) gid=1000(user) euid=0(root) groups=1000(user),4(adm),27(sudo)\n2020-04-17 15:14:37,202 TRACE [sudo] Running as Suid\n2020-04-17 15:14:37,202 TRACE [sudo] setuid(0)\n2020-04-17 15:14:37,202 INFO  [suid] ② uid: 0; euid: 0;\nuid=0(root) gid=1000(user) groups=1000(user),4(adm),27(sudo)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrabdancing%2Felevate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrabdancing%2Felevate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrabdancing%2Felevate/lists"}