arkade
arkade copied to clipboard
Check for temp directory write permission before downloading binary
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
- [x] 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)
- Create any random directory:
mkdir test-temp
- Change directory mod to 100:
chmod 100 test-temp
- Make it the default temp directory:
export TMPDIR=<absolute-path-to-'test-temp'-directory>
- 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
/add label: proposal
@alexellis Can you please take a look at this? :slightly_smiling_face:
Sounds good to me, do you want to try it out in a PR?
@alexellis I will create a draft PR
Thanks @yankeexe, no need to make it a draft however.
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
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
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.
Thanks a PR would be great @mrichar1