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 temp directory write permission before downloading binary #501

Open
1 of 2 tasks
yankeexe opened this issue Aug 14, 2021 · 9 comments
Open
1 of 2 tasks
Labels

Comments

@yankeexe
Copy link
Contributor

yankeexe commented Aug 14, 2021

Check if the user has permission to write to $TMPDIR before downloading binary. Else the following issue occurs:

$~ arkade get inletsctl
Downloading inletsctl
https://github.com/inlets/inletsctl/releases/download/0.8.2/inletsctl.tgz
Error: check with the vendor whether this tool is available for your system: open /tmp/inletsctl.tgz: permission denied 

Expected Behaviour

If the user running arkade does not have permission to write to $TMPDIR, show error messaging stating such.

Current Behaviour

Shows Binary Download prompt and fails on accessing $TMPDIR to store binary.

Are you a GitHub Sponsor (Yes/No?)

Check at https://github.com/sponsors/alexellis

  • Yes
  • No

Possible Solution

Check for writable permission to $TMPDIR before downloading the binary

tmp := os.TMPDIR()

info, err := os.Stat(tmp)
if err != nil {
panic(err)
}
     
permission := info.Mode().Perm()

Steps to Reproduce (for bugs)

  1. Create any random directory: mkdir test-temp
  2. Change directory mod to 100: chmod 100 test-temp
  3. Make it the default temp directory: export TMPDIR=<absolute-path-to-'test-temp'-directory>
  4. Run arkade get <any-binary>

Your Environment

  • Operating System and version (e.g. Linux, Windows, MacOS):
Linux  5.10.56-1  x86_64 GNU/Linux
  • What arkade version is this?
0.7.25
@yankeexe
Copy link
Contributor Author

/add label: proposal

@derek derek bot added the proposal label Aug 14, 2021
@yankeexe
Copy link
Contributor Author

@alexellis Can you please take a look at this? 🙂

@alexellis
Copy link
Owner

Sounds good to me, do you want to try it out in a PR?

@yankeexe
Copy link
Contributor Author

@alexellis I will create a draft PR

@alexellis
Copy link
Owner

Thanks @yankeexe, no need to make it a draft however.

@mrichar1
Copy link
Contributor

I can open this as a new bug if needed, but seeing as it's closely related to this issue...

arkade should use a temporary 'tempdir' when downloading, rather than writing to the root $TMPDIR. Otherwise there may be issues if there are equivalent files already present - either being unable to write that file, or accidentally overwriting an existing file.

E.g (when running arkade as non-root user):

sudo touch /tmp/kubectl
arkade get kubectl
Error: open /tmp/kubectl: permission denied

Or in reverse:

$ echo "Some text" >/tmp/kubectl
$ file /tmp/kubectl
/tmp/kubectl: ASCII text

$ sudo arkade get kubectl
$ file /tmp/kubectl
/tmp/kubectl: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped

@alexellis
Copy link
Owner

Hi @mrichar1

I've seen this a few times when I've put my own files into /tmp that conflict on name.

A unique tempdir name would get around that, I don't have a problem with you sending a PR.

What brought you here? Did you run into this issue yourself?

Alex

@mrichar1
Copy link
Contributor

Yes - I hit this when switching from running as root to running non-root, and was looking through existing issues to see if it had already been reported. Happy to have a go at drafting a separate PR for this.

@alexellis
Copy link
Owner

Thanks a PR would be great @mrichar1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants