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

provisioner remote-exec > uploaded commands should be wiped out after exec #482

Closed
frntn opened this issue Oct 20, 2014 · 5 comments · Fixed by #5577
Closed

provisioner remote-exec > uploaded commands should be wiped out after exec #482

frntn opened this issue Oct 20, 2014 · 5 comments · Fixed by #5577

Comments

@frntn
Copy link
Contributor

frntn commented Oct 20, 2014

When provisioning a server using remote-exec provisioner there is a remaining /tmp/script.sh which contains either :

  • for inline argument : all the executed commands
  • for script argument : the full script
  • for scripts argument : the last script of the array

This can lead to security issue.
This file should be deleted by default.

@mitchellh mitchellh added bug and removed bug labels Oct 20, 2014
@mitchellh
Copy link
Contributor

The issue is that Terraform doesn't know how to delete the file. It uses SCP to upload it and SCP doesn't have a "delete" mode. We can reupload another file to take the place of it, but we can't delete without knowing the system that is there.

I think we can just reupload a blank file.

@mitchellh mitchellh added the bug label Oct 20, 2014
@frntn
Copy link
Contributor Author

frntn commented Oct 21, 2014

The blank file seems to meet the (minimal) requirements for me too.

@eppdot
Copy link

eppdot commented Apr 22, 2015

What about appending a script as last component that deletes itself?

@frntn
Copy link
Contributor Author

frntn commented Apr 22, 2015

LGTM

Considering the following user provided script

$ cat <<EOF >/tmp/script.sh
#!/bin/bash
echo "provisioner remote-exec script : I do something..."
EOF

$ chmod +x /tmp/script.sh

$ ls -l /tmp/script.sh
-rwxrwxr-x 1 frntn frntn 70 Apr 22 14:11 /tmp/script.sh

Terraform can append a autodelete command (try shred / fallback to rm)

$ cat <<EOF >>/tmp/script.sh
command -v shred >/dev/null && shred -uxz \$(readlink -f \$0) || rm -f \$(readlink -f \$0)
EOF

$ sh -c '/tmp/script.sh'
provisioner remote-exec script : I do something...

$ ls -l /tmp/script.sh
ls: cannot access /tmp/script.sh: No such file or directory

@ghost
Copy link

ghost commented Apr 27, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants