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

Install bats as root #7674

Merged
merged 1 commit into from
Sep 19, 2020
Merged

Install bats as root #7674

merged 1 commit into from
Sep 19, 2020

Conversation

xordspar0
Copy link
Contributor

Installing bats to /usr/local requires root privileges. Without this, make install.tools fails. However, if I do sudo make install.tools, then all of the other dependencies and git clones in the current directory end up owned by root. This limits root privileges to the part that needs it.

I'm not sure this is a very good solution. I wanted to open discussion about this issue because currently it's difficult to get a working test environment without digging into the Makefile and install scripts to see what's going on. Otherwise make install.tools fails like this:

HEAD is now at c706d14 Bats 1.1.0
install: cannot create directory ‘/usr/local/libexec’: Permission denied
install: cannot change permissions of ‘/usr/local/share/man/man1’: No such file or directory
install: cannot change permissions of ‘/usr/local/share/man/man7’: No such file or directory
make: *** [Makefile:640: .install.bats] Error 1

Another possible solution is installing bats to _output like the Go dependencies and invoking bats as $GOBIN/bats. Any other ideas?

@TomSweeneyRedHat
Copy link
Member

@edsantiago thoughts?

@mheon
Copy link
Member

mheon commented Sep 17, 2020

I would actually be fine requiring make install.tools to be run with sudo - though maybe a warning that it requires that could be added?

@xordspar0
Copy link
Contributor Author

make localunit has a check like that already:

podman/Makefile

Lines 308 to 311 in dc23ef1

localunit: test/goecho/goecho varlink_generate
hack/check_root.sh make localunit
rm -rf ${COVERAGE_PATH} && mkdir -p ${COVERAGE_PATH}
$(GOBIN)/ginkgo \

However, it would be hard to add the same thing to install.tools because it's a prerequisite that needs root privileges. If I added a check in the same place as localunit, it would run too late:

podman/Makefile

Lines 615 to 616 in dc23ef1

install.tools: .install.gitvalidation .install.md2man .install.ginkgo .install.golangci-lint .install.bats ## Install needed tools

What about putting the check on .install.bats, like this?

 .PHONY: .install.bats
 .install.bats: .gopathok
+       hack/check_root.sh make .install.bats
        VERSION=v1.1.0 ./hack/install_bats.sh

Or we could just document that make install.tools requires root in test/README.md?

@xordspar0
Copy link
Contributor Author

Oh, or we could add a new prerequisite that checks for root:

install.tools: .root-privileges .install.gitvalidation .install.md2man .install.ginkgo .install.golangci-lint .install.bats ## Install needed tools

.root-privileges:
	hack/check_root.sh something

@edsantiago
Copy link
Member

I'm pretty strongly opposed to sudo in any Makefile steps, for long-held philosophical reasons.

Can you just make a small tweak to hack/install_bats like

if [[ "$(type -t bats)" != "" ]]; then
    exit 0
fi

@xordspar0
Copy link
Contributor Author

That's fair.

Can you just make a small tweak to hack/install_bats

So if bats is already installed, skip installation. What about when it isn't installed yet?

@edsantiago
Copy link
Member

Can sudo be invoked from within install_bats? Preferably with a warning beforehand explaining what will happen and why this is needed? (eg "sudo needed in order to install BATS into /usr/local") ?

@xordspar0
Copy link
Contributor Author

Sure. I added the "skip if already installed" check and the sudo warning.

@xordspar0
Copy link
Contributor Author

I'm starting to like this better because now you know that it's trying to install to /usr/local when it asks for you password, and you can install bats yourself if you want to – the script will accept it as long as it's on your PATH.

@jwhonce
Copy link
Member

jwhonce commented Sep 18, 2020

LGTM

Installing bats to /usr/local requires root privileges. Without this,
`make install.tools` fails. However, if I do `sudo make install.tools`,
then all of the other dependencies and git clones in the current
directory end up owned by root. This limits root privileges to the part
that needs it.

Signed-off-by: Jordan Christiansen <[email protected]>
@TomSweeneyRedHat
Copy link
Member

LGTM
THX @xordspar0 !

@rhatdan
Copy link
Member

rhatdan commented Sep 19, 2020

/approve
/lgtm
Thanks @xordspar0

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 19, 2020
@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rhatdan, xordspar0

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 19, 2020
@openshift-merge-robot openshift-merge-robot merged commit 8529435 into containers:master Sep 19, 2020
@xordspar0 xordspar0 deleted the bats-install-root branch September 19, 2020 14:16
@xordspar0
Copy link
Contributor Author

🎉

@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants