Skip to content
This repository was archived by the owner on Oct 30, 2018. It is now read-only.

Commit 7c3999a

Browse files
evgeniabadger
authored andcommitted
do not use a predictable filenames in the LXC plugin
* do not use a predictable filename for the LXC attach script * don't use predictable filenames for LXC attach script logging * don't set a predictable archive_path this should prevent symlink attacks which could result in * data corruption * data leakage * privilege escalation
1 parent f710908 commit 7c3999a

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

cloud/lxc/lxc_container.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
description:
145145
- Path the save the archived container. If the path does not exist
146146
the archive method will attempt to create it.
147-
default: /tmp
147+
default: null
148148
archive_compression:
149149
choices:
150150
- gzip
@@ -557,13 +557,8 @@ def create_script(command):
557557
import subprocess
558558
import tempfile
559559

560-
# Ensure that the directory /opt exists.
561-
if not path.isdir('/opt'):
562-
os.mkdir('/opt')
563-
564-
# Create the script.
565-
script_file = path.join('/opt', '.lxc-attach-script')
566-
f = open(script_file, 'wb')
560+
(fd, script_file) = tempfile.mkstemp(prefix='lxc-attach-script')
561+
f = os.fdopen(fd, 'wb')
567562
try:
568563
f.write(ATTACH_TEMPLATE % {'container_command': command})
569564
f.flush()
@@ -573,14 +568,11 @@ def create_script(command):
573568
# Ensure the script is executable.
574569
os.chmod(script_file, 0700)
575570

576-
# Get temporary directory.
577-
tempdir = tempfile.gettempdir()
578-
579571
# Output log file.
580-
stdout_file = open(path.join(tempdir, 'lxc-attach-script.log'), 'ab')
572+
stdout_file = os.fdopen(tempfile.mkstemp(prefix='lxc-attach-script-log')[0], 'ab')
581573

582574
# Error log file.
583-
stderr_file = open(path.join(tempdir, 'lxc-attach-script.err'), 'ab')
575+
stderr_file = os.fdopen(tempfile.mkstemp(prefix='lxc-attach-script-err')[0], 'ab')
584576

585577
# Execute the script command.
586578
try:
@@ -1747,14 +1739,16 @@ def main():
17471739
),
17481740
archive_path=dict(
17491741
type='str',
1750-
default='/tmp'
17511742
),
17521743
archive_compression=dict(
17531744
choices=LXC_COMPRESSION_MAP.keys(),
17541745
default='gzip'
17551746
)
17561747
),
17571748
supports_check_mode=False,
1749+
required_if = ([
1750+
('archive', True, ['archive_path'])
1751+
]),
17581752
)
17591753

17601754
if not HAS_LXC:

0 commit comments

Comments
 (0)