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

feat: Allow usage of sudo [while not accessing root] in x.py #95671

Merged
merged 1 commit into from
Apr 12, 2022
Merged

feat: Allow usage of sudo [while not accessing root] in x.py #95671

merged 1 commit into from
Apr 12, 2022

Conversation

gimbling-away
Copy link
Contributor

@gimbling-away gimbling-away commented Apr 5, 2022

Fixes

This PR should fix #93344

Info

Allows usage of sudo (while not accessing root) in x.py

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Mark-Simulacrum (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 5, 2022
@rust-log-analyzer

This comment has been minimized.

@jyn514
Copy link
Member

jyn514 commented Apr 5, 2022

bootstrap.py should skip the check if SUDO_USER is not root, or an option to bypass this check should be provided

@gimbles could you change this to check SUDO_USER instead of adding more configuration options?

The place to add flags is in the argparse section near the bottom of bootstrap.py, but I don't think a new flag is the best approach.

@jyn514
Copy link
Member

jyn514 commented Apr 5, 2022

@rustbot label A-rustbuild

@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Apr 5, 2022
@gimbling-away
Copy link
Contributor Author

bootstrap.py should skip the check if SUDO_USER is not root, or an option to bypass this check should be provided

@gimbles could you change this to check SUDO_USER instead of adding more configuration options?

The place to add flags is in the argparse section near the bottom of bootstrap.py, but I don't think a new flag is the best approach.

Sure!
image
But I don't think it will exactly fix OPs problem? The logs say that SUDO_USER is root

@jyn514
Copy link
Member

jyn514 commented Apr 5, 2022

The logs say that SUDO_USER is root

Ah, so they do. @chbaker0 can you confirm whether making the SUDO_CHECK smarter would help you or not? I do see that you're calling build.py and not x.py, so maybe you're changing the user there?

@chbaker0
Copy link
Contributor

chbaker0 commented Apr 5, 2022

The logs say that SUDO_USER is root

Ah, so they do. @chbaker0 can you confirm whether making the SUDO_CHECK smarter would help you or not? I do see that you're calling build.py and not x.py, so maybe you're changing the user there?

My bad. Looks like SUDO_USER is the user who invoked sudo rather than who is being impersonated.

The sudo check can still be made smarter, by checking the regular UID. If sudo is not being used to run as root, instead just as a different user, then the user probably intended it.

build.py is just a helper script to check out, configure, and build Rust (using x.py) for use in Chromium

@jyn514
Copy link
Member

jyn514 commented Apr 5, 2022

The sudo check can still be made smarter, by checking the regular UID. If sudo is not being used to run as root, instead just as a different user, then the user probably intended it.

Sounds good :) I found that python -c 'import os; print(os.getuid())' works consistently to get the user ID; since bootstrap.py is already in python I think you can check this just with os.getuid() == 0 rather than looking at SUDO_USER at all.

@gimbling-away
Copy link
Contributor Author

The sudo check can still be made smarter, by checking the regular UID. If sudo is not being used to run as root, instead just as a different user, then the user probably intended it.

Sounds good :) I found that python -c 'import os; print(os.getuid())' works consistently to get the user ID; since bootstrap.py is already in python I think you can check this just with os.getuid() == 0 rather than looking at SUDO_USER at all.

So should I remove the environment variable check and change this line to check if os.getuid() == 0 instead?

@gimbling-away
Copy link
Contributor Author

image
Update: @chbaker0 you should be able to use sudo for accessing other users while running x.py now. Pushing soon 🎉

@gimbling-away gimbling-away changed the title feat: BYPASS_SUDO_CHECK environment variable feat: Allow usage of sudo [while not accessing root] in x.py Apr 8, 2022
@chbaker0
Copy link
Contributor

chbaker0 commented Apr 9, 2022

Thank you! I appreciate this a lot!

@Mark-Simulacrum
Copy link
Member

Mark-Simulacrum commented Apr 10, 2022

Can you adjust the PR description to reflect the new state of this PR, and squash commits? r=me with that done.

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 10, 2022
@gimbling-away
Copy link
Contributor Author

gimbling-away commented Apr 10, 2022

Updated the description and squashed the commits.

@gimbling-away
Copy link
Contributor Author

@bors r=Mark-Simulacrum

@bors
Copy link
Contributor

bors commented Apr 10, 2022

@gimbles: 🔑 Insufficient privileges: Not in reviewers

@gimbling-away
Copy link
Contributor Author

Welp I think I'm..doing something wrong here.

@Mark-Simulacrum So just manually pinging you 😅

@Mark-Simulacrum
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Apr 10, 2022

📌 Commit 386ca6a has been approved by Mark-Simulacrum

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 10, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Apr 10, 2022
feat: Allow usage of sudo [while not accessing root] in x.py

# Fixes
This PR should fix rust-lang#93344
# Info
Allows usage of sudo (while not accessing root) in x.py
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Apr 11, 2022
feat: Allow usage of sudo [while not accessing root] in x.py

# Fixes
This PR should fix rust-lang#93344
# Info
Allows usage of sudo (while not accessing root) in x.py
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Apr 11, 2022
feat: Allow usage of sudo [while not accessing root] in x.py

# Fixes
This PR should fix rust-lang#93344
# Info
Allows usage of sudo (while not accessing root) in x.py
@bors
Copy link
Contributor

bors commented Apr 11, 2022

⌛ Testing commit 386ca6a with merge 51d0df67856c2fe572c864cdef875437d90ef94b...

@bors
Copy link
Contributor

bors commented Apr 11, 2022

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 11, 2022
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-msvc-cargo failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
test workspaces::ws_warn_unused ... ok

failures:

---- registry::update_multiple_packages_http stdout ----
running `D:\a\rust\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\cargo.exe fetch -Zhttp-registry`
running `D:\a\rust\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\cargo.exe update -pa -pb -Zhttp-registry`
running `D:\a\rust\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\cargo.exe update -pb -pc -Zhttp-registry`
thread 'registry::update_multiple_packages_http' panicked at '
test failed running `D:\a\rust\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\cargo.exe update -pb -pc -Zhttp-registry`
error: process exited with code 101 (expected 0)

--- stderr
--- stderr
    Updating `dummy-registry` index
error: failed to get `b` as a dependency of package `foo v0.5.0 (D:\a\rust\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\tmp\cit\t1866\foo)`
Caused by:
Caused by:
  failed to query replaced source registry `crates-io`
Caused by:
Caused by:
  download of 1/b failed
Caused by:
Caused by:
  [1] Unsupported protocol (Received HTTP/0.9 when not allowed)
', src\tools\cargo\tests\testsuite\registry.rs:1634:10

failures:
    registry::update_multiple_packages_http

@fee1-dead
Copy link
Member

@bors retry spurious

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 12, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 12, 2022
Rollup of 5 pull requests

Successful merges:

 - rust-lang#95671 (feat: Allow usage of sudo [while not accessing root] in x.py)
 - rust-lang#95716 (sess: warn w/out fluent bundle w/ user sysroot)
 - rust-lang#95820 (simplify const params diagnostic on stable)
 - rust-lang#95900 (Fix documentation for wasm32-unknown-unknown)
 - rust-lang#95947 (`impl const Default for Box<[T]>` and `Box<str>`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit ae068e7 into rust-lang:master Apr 12, 2022
@rustbot rustbot added this to the 1.62.0 milestone Apr 12, 2022
Samyak2 added a commit to Samyak2/rust that referenced this pull request Aug 22, 2022
This makes it consistent with `x.py` as changed in rust-lang#95671

Fixes rust-lang#100459
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Aug 23, 2022
…lacrum

Use `getuid` to check instead of `USER` env var in rustbuild

This makes it consistent with `x.py` as changed in rust-lang#95671

Fixes rust-lang#100459
Samyak2 added a commit to Samyak2/rust that referenced this pull request Aug 26, 2022
This makes it consistent with `x.py` as changed in rust-lang#95671

Fixes rust-lang#100459
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 1, 2022
…lacrum

Use `getuid` to check instead of `USER` env var in rustbuild

This makes it consistent with `x.py` as changed in rust-lang#95671

Fixes rust-lang#100459
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 1, 2022
…lacrum

Use `getuid` to check instead of `USER` env var in rustbuild

This makes it consistent with `x.py` as changed in rust-lang#95671

Fixes rust-lang#100459
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 1, 2022
…lacrum

Use `getuid` to check instead of `USER` env var in rustbuild

This makes it consistent with `x.py` as changed in rust-lang#95671

Fixes rust-lang#100459
bors pushed a commit to rust-lang-ci/rust that referenced this pull request Sep 19, 2022
This makes it consistent with `x.py` as changed in rust-lang#95671

Fixes rust-lang#100459
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot run x.py under sudo as non-root user
9 participants