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

sudo crictl: not found if installed to a directory outside of sudoers secure_path #5547

Closed
afbjorklund opened this issue Oct 6, 2019 · 11 comments · Fixed by #6220
Closed
Assignees
Labels
co/runtime/crio CRIO related issues help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/feature Categorizes issue or PR as related to a new feature. os/linux priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete.

Comments

@afbjorklund
Copy link
Collaborator

We have some things breaking on CentOS, which does not have /usr/local/bin in the PATH.
That is: users do have it in their PATH, but root does not. And sudo runs with the root PATH.

So if you are trying to run something that is not from a package, you will get a "command not found"
This goes both for "crio version" (when run as root) and for "sudo crictl", only work with /usr/bin.

One workaround is to move everything to /usr/bin, which is violating the FHS but whatever.

It would be nice if minikube was able to find crio and crictl - also in their default location ?

This would have worked better if crio and cri-tools would be available in the default distribution.

But it doesn't (at the moment), and when you try to install it locally you run into these issues...

@afbjorklund afbjorklund added os/linux kind/feature Categorizes issue or PR as related to a new feature. labels Oct 6, 2019
@afbjorklund
Copy link
Collaborator Author

Actually the same thing happens with minikube itself:

$ sudo install minikube-linux-amd64 /usr/local/bin/minikube
$ sudo minikube version
sudo: minikube: command not found
$ sudo rpm -ivh minikube-1.4.0.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:minikube-1.4.0-0                 ################################# [100%]
$ sudo minikube version
minikube version: v1.4.0
commit: 7969c25a98a018b94ea87d949350f3271e9d64b6

That is, anything installed in /usr/local is not found.

@afbjorklund
Copy link
Collaborator Author

afbjorklund commented Oct 6, 2019

Here is how things work in CentOS:

[admin@7d58aaaae462 ~]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/admin/.local/bin:/home/admin/bin
[admin@7d58aaaae462 ~]$ sudo -i
[root@7d58aaaae462 ~]# echo $PATH
/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@7d58aaaae462 ~]# logout
[admin@7d58aaaae462 ~]$ sudo su -
[root@7d58aaaae462 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@7d58aaaae462 ~]# logout

i.e. when using sudo, /usr/local/bin is missing from the PATH.

(Normally "sudo" itself wasn't installed either, but seems to be now...)

Tested with:

  • CentOS Linux release 7.6.1810 (Core)
  • CentOS Linux release 8.0.1905 (Core)

RH Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1166185
Fixed in: sudo-1.8.22-0.1.b1.fc28 and up (but not in "c8" branch)

Fedora: https://src.fedoraproject.org/rpms/sudo/blob/f28/f/sudoers
Defaults secure_path = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
CentOS: https://git.centos.org/rpms/sudo/blob/c8/f/SOURCES/sudoers
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin

Note that /usr/local/sbin is still in the PATH, added by /etc/profile.
(probably by accident, since it is using a different "pathmunge" function)

@tstromberg
Copy link
Contributor

tstromberg commented Oct 9, 2019

I wouldn't want to make it the default everywhere, but alternatively, we could use sudo -E for calls to crictl and other necessary places?

This is definitely not a CentOS only issue, but it's admittedly less common elsewhere.

@tstromberg tstromberg changed the title Path issues running on RHEL/CentOS sudo crio/crictl fails if installed to a directory outside of sudoers secure_path Oct 9, 2019
@tstromberg tstromberg changed the title sudo crio/crictl fails if installed to a directory outside of sudoers secure_path sudo crio/crictl: not found if installed to a directory outside of sudoers secure_path Oct 9, 2019
@tstromberg tstromberg added help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. labels Oct 9, 2019
@RA489
Copy link

RA489 commented Oct 10, 2019

/assign

@afbjorklund afbjorklund added the co/runtime/crio CRIO related issues label Oct 21, 2019
@afbjorklund afbjorklund added this to the v1.7.0-candidate milestone Nov 9, 2019
@RA489
Copy link

RA489 commented Nov 21, 2019

@afbjorklund I tried replicating this on CentOS and following two approaches works for me.

  1. Changing the secure_path to /usr/local/bin
[rohit@localhost root]$ sudo visudo
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
  1. copying to usr/bin solves this issue.

Let me know which approach can be good for this issue.

@RA489
Copy link

RA489 commented Nov 21, 2019

IIUC The secure_path value, if set, will be used as PATH environment variable for the commands you run using sudo

@afbjorklund
Copy link
Collaborator Author

afbjorklund commented Nov 21, 2019

I think the plan was to change the sudo invocation in minikube, rather than have the user change...

i.e. either do sudo -E crictl or perhaps sudo /usr/local/bin/crictl (using which)

@tstromberg tstromberg removed this from the v1.7.0-candidate milestone Dec 9, 2019
@sharifelgamal
Copy link
Collaborator

We should probably fix this at some point, having a centos machine to test on would help.

@afbjorklund
Copy link
Collaborator Author

Arguably, the default config is stupid (and indeed, they did fix it for later versions)

Most likely we will go with the /usr/local/bin/crictl workaround, when needed.
Installing /usr/bin/crictl with the cri-tools package would be the preferred approach.

Problem is that upstream sometimes suggests to use the tarball and /usr/local instead:

https://github.com/kubernetes-sigs/cri-tools#install-crictl

sudo tar zxvf crictl-$VERSION-linux-amd64.tar.gz -C /usr/local/bin

The correct way would be to install the rpm package from the kubernetes repositories:

https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#installing-kubeadm-kubelet-and-kubectl

yum install cri-tools

But this gets confusing with minikube, since we use our own binaries for the other three...
And since docker doesn't use crictl ("yet"), we don't install it but leave it to the poor user.

@afbjorklund
Copy link
Collaborator Author

We currently use it from 4 different places (before refactoring, one was hiding in "logs"):

pkg/minikube/cruntime/cri.go:		c := exec.Command("sudo", "crictl", "ps", "-a", fmt.Sprintf("--name=%s", filter), fmt.Sprintf("--state=%s", state), "--quiet")
pkg/minikube/cruntime/cri.go:		rr, err = cr.RunCmd(exec.Command("sudo", "crictl", "ps", "-a", fmt.Sprintf("--state=%s", state), "--quiet"))
pkg/minikube/cruntime/cri.go:	cmd.WriteString("sudo crictl logs ")
pkg/minikube/logs/logs.go:	cmds["container status"] = "sudo crictl ps -a || sudo docker ps -a"

So maybe do a which call, before those sudo calls.

Only difference would be running /usr/bin/crictl.

@afbjorklund afbjorklund changed the title sudo crio/crictl: not found if installed to a directory outside of sudoers secure_path sudo crictl: not found if installed to a directory outside of sudoers secure_path Jan 6, 2020
@tunt102
Copy link

tunt102 commented Jul 28, 2022

@afbjorklund I tried replicating this on CentOS and following two approaches works for me.

  1. Changing the secure_path to /usr/local/bin
[rohit@localhost root]$ sudo visudo
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
  1. copying to usr/bin solves this issue.

Let me know which approach can be good for this issue.

it worked for me too, thanks pro!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
co/runtime/crio CRIO related issues help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/feature Categorizes issue or PR as related to a new feature. os/linux priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants