-
Notifications
You must be signed in to change notification settings - Fork 4
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
Safe copying of files from local to remote #35
Comments
This reminds me an old idea that cdist should have lib for reusable functions. For example |
Yup, "the library" would also be very useful here. (I resurrected the issue → skonfig/skonfig#17) |
See my idea: https://code.ungleich.ch/ungleich-public/cdist/issues/332#issuecomment-14780 Would that help? IMHO it's better than using |
Am I overlooking something? This is exactly what That doesn't resolve the attack vector nico mentioned, though.
|
Providing our own mktemp(1) implementation should be doable. |
What does the "safely" imply here? Imho it's not securely. AFAIK mktemp only purpose is to avoid collision and not protect temp files from attacker. Tho it uses perms 600, which is nice to have. If attacker can write somewhere they should not, then the game is already lost, no matter what tricks we pull. IMHO most reasonable thing is to use what Nico proposed in https://code.ungleich.ch/ungleich-public/cdist/issues/332#issuecomment-14777 |
Before we go into the mktemp topic too deeply, we first need to define which strategy we want to follow. As far as security of mktemp goes. Since cdist runs commands as root on the target and files are created with a What is important is that non-privileged users cannot in any way modify the temp file. Nico's proposal using |
Does it need to be checked? Something like Tho, some leftovers explorer would be nice, e.g. remove all files with |
A proper solution does check for the existence of a temp file. Of course one can always argue with percentages and say that it'll be fine in almost all cases, but you could do the same for mktemp(1), too. IMO this case is frequent enough to invest the time into a proper solution.
We need a solution for leftovers (cf. 4. in "Requirements to a solution"), but please not an explorer! I was thinking about whether we could |
Yes, explorers discover first and... :)
|
I keep my opinion to remove all cdist temp files before the But btw. I don't even know if I commited too much into the discussion, only disturbed them or was simply ignored. But after some flawed proposals, this where the parts I've finally came up with. Shouldn't start to get off-topic here :P Edit: After looking into cdist-ungleich's master, it looks like he took my last comment at heart - maybe. The fixes from Steven except the newest one (abbc7dfc37, 1 day ago) are already commited. Still uses |
In cdist-ungleich an interesting discussion has come up in #331:
how can we safely and atomically transfer file from the local machine to the remote machine?
The scope of this problem is not limited to the
__file
type. It also applies to other types in cdist-conf, e.g.__config_file
,__dot_file
,__staged_file
(via__file
),__download
and possibly others.I think the discussion is worth pursuing as a properly designed solution will benefit all cdist users (who doesn't use
__file
?).Requirements to a solution:
$destination
(think of applications usinginclude *
configuration),$destination
must be atomic (in the sense of made in one SSH connection).(Please extend if I forgot something.)
Proposals:
Common to all proposals is the division between
code-local
andcode-remote
:code-local
copies the file to a remote temp location,code-remote
moves the remote temp file to$destination
and ensures the attributes are set correctly.Copy to
$TMPDIR
usingmktemp(1)
, then move to$destination
.This is how
__file
has worked in the past, albeit usingmktemp -u
.pros: uses non-predictable file names (if
mktemp
is used on the target), no temp files in$destination
.cons: fails if the file is large and
$TMPDIR
is size constrained (e.g.tmpfs
), may leave the system in a broken state if insufficient space in$destination
.Copy to remote
${__object}/files/tempfile
, then move to$destination
.This solution uses completely predictable file names, but I don't think this is a problem because cdist's run directory is
root
-owned and 0700.Also the remote
$__object
directory is used for a single cdist run only, so there shouldn't be any collisions possible.pros: no temp files in
$destination
.cons: may fail if cdist's run directory is space-constained, may leave the system in a broken state if insufficient space in
$destination
.Copy to
$destination.tmp.XXXXXX
, then move to$destination
.Idea:
In
code-local
:$destination
on the target safely, usingmktemp
,$__object
.Then in
code-remote
:$destination.tmp.XXXXXX
(as stored in$__object
) to$destination
.pros: non-predictable temp names, does not use
$TMPDIR
, does not fail if$destination
has insufficient space (can't copy file in the first place)cons: may leave temp files in
$destination
ifcode-*
fails for some reason.Decisions
Can we rely on
mktemp(1)?
cdist is supposed to only rely on POSIX features and
mktemp(1)
isn't defined by POSIX.Furthermore
mktemp(1)
has no standardized interface. An invocation that works fine on Linux may fail or produce an unecpected result on e.g. OpenBSD.Or could we hack our own
mktemp
using/dev/random
,tr
andset -C
?The text was updated successfully, but these errors were encountered: