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

Check for sudo before using it with package managers #300

Merged
merged 4 commits into from
Jun 5, 2017

Conversation

ararslan
Copy link
Member

This addresses an issue noticed in JuliaLang/julia#21956, where Yum is available so BinDeps tries to use it, but the installation uses sudo, which is not installed on the buildbots. With this PR, binary package managers are only usable if sudo is available.

@staticfloat
Copy link
Member

Personally, I don't think we should use this to gate can_use; I think we should use this to selectively add in sudo to the commands.

@ararslan
Copy link
Member Author

@staticfloat Something like this? (See second commit)

@staticfloat
Copy link
Member

Yeah, something like that should probably work. We'll need to initialize the :sudo option within BinDeps through a success(\sudo -V`)` or similar too.

@ararslan
Copy link
Member Author

Okay, I've now made it so that if the user does not explicitly pass a sudo= option, it uses sudo if it's found on the system. Does that seem reasonable, @staticfloat?

@staticfloat
Copy link
Member

Yeah that looks good. Have you tested this on any platforms?

@ararslan
Copy link
Member Author

I don't have Linux handy, and so far no packages are set up to use the BSDPkg provider, so I'm not really sure how to test it.

@staticfloat
Copy link
Member

I don't have Linux handy

tenor

@staticfloat
Copy link
Member

Aha! It took me a while to realize what was going on here. You need to initialize has_sudo within an __init__() function, otherwise it remembers whether sudo is or is not available from compile-time.

Other than that, this works!

@tkelman
Copy link
Contributor

tkelman commented May 26, 2017

What environments have package managers but not sudo? I'm confused by how that could ever happen

@staticfloat
Copy link
Member

staticfloat commented May 26, 2017

This is the case with all (default) docker images, for example. Environments in which you are expected to be root.

@tkelman
Copy link
Contributor

tkelman commented May 26, 2017

docker suggests that you should run things as an unpriviliged user within the container, and for security reasons we should do so on the buildbots. but guess this should be mostly harmless

@staticfloat
Copy link
Member

staticfloat commented May 26, 2017 via email

@tkelman
Copy link
Contributor

tkelman commented May 26, 2017

so this would only help if you happen to be running Pkg.build as root, which is probably a bad idea most of the time

@ararslan
Copy link
Member Author

I don't think I understand why this wouldn't address the issue in the linked invocation of jlbuild

@staticfloat
Copy link
Member

so this would only help if you happen to be running Pkg.build as root, which is probably a bad idea most of the time

This is what happens if you docker run -ti julia and try to install a package, for instance. Agreed it's not a good idea, but I'll be darned if I haven't done it many times before.

I don't think I understand why this wouldn't address the issue in the linked invocation of jlbuild

Because on the buildworkers you currently can't install new packages. There is no sudo and you're running as a non-root user. I may change this eventually (add passwordless sudo) but at the moment, it is what it is. ;)

@ararslan
Copy link
Member Author

Is this even useful then?

@staticfloat
Copy link
Member

Yes, I still think this is a good idea.

@codecov-io
Copy link

codecov-io commented May 26, 2017

Codecov Report

Merging #300 into master will decrease coverage by 0.19%.
The diff coverage is 5.88%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #300     +/-   ##
=========================================
- Coverage   36.89%   36.69%   -0.2%     
=========================================
  Files           4        4             
  Lines         805      812      +7     
=========================================
+ Hits          297      298      +1     
- Misses        508      514      +6
Impacted Files Coverage Δ
src/dependencies.jl 34.3% <0%> (-0.41%) ⬇️
src/BinDeps.jl 31.85% <100%> (+0.27%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 75f8460...2e81d61. Read the comment docs.

@tkelman
Copy link
Contributor

tkelman commented May 26, 2017

add passwordless sudo

would be better to only allow package installation privileges for the buildbot non-root user, if that's doable

@ararslan
Copy link
Member Author

ararslan commented Jun 1, 2017

Bump

@ararslan ararslan merged commit 55b8d4c into master Jun 5, 2017
@ararslan ararslan deleted the aa/ensure-sudo branch June 5, 2017 21:46

# Definitions that should be evaluated upon initialization, not stored in the cache
function __init__()
global const has_sudo = try success(`sudo -V`) catch err false end
Copy link
Contributor

@musm musm Jun 6, 2017

Choose a reason for hiding this comment

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

This shouldn't be a global const which can cause issues when used in __init__ for precompilation

Copy link
Member Author

Choose a reason for hiding this comment

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

Shouldn't matter in this case.

Copy link
Contributor

Choose a reason for hiding this comment

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

global const is incompatible with precompilation

Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -356,6 +356,7 @@ function provides{T}(::Type{T},providers::Dict; opts...)
end
end

sudoname(c::Cmd) = c == `` ? "" : "sudo "
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why include the space after sudo ?

Copy link
Member Author

Choose a reason for hiding this comment

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

So it looks nicer when it's interpolated below.

Copy link
Contributor

Choose a reason for hiding this comment

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

how so ? looks like it could be confusing, I wouldn't expect the sudo name to include a space after

Copy link
Contributor

Choose a reason for hiding this comment

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

look at the usages

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.

5 participants