Improving mktemp

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I am wondering how to best improve on mktemp for use with encrypted containers or file systems.
The issue that I am dealing with is that I would like my shell scripts to store temporary files inside the file system that contains the working directory, if possible.
The normal behaviour of mktemp seems to be to use a root path specified in an environment variables or /tmp. This will, however, routinely leak temporary data to unencrypted locations if I am working with files inside encrypted containers.
The idea is to first check the presence of a tmp directory in the mount point of the current file system and to use /tmponly as a last resort. How can I reliably (and efficiently) realize that.
Edit
A possible way to identify the mount directory of a given path is the following
dir=`realpath [path]`;
res=1;
while [ $res -ne 0 ]; do
dir="$dir%/*";
mountpoint -q "$dir/";
res=$?;
done;
echo "$dir";
I am not sure, however, if that is the most efficient one.
bash mktemp
add a comment |Â
up vote
1
down vote
favorite
I am wondering how to best improve on mktemp for use with encrypted containers or file systems.
The issue that I am dealing with is that I would like my shell scripts to store temporary files inside the file system that contains the working directory, if possible.
The normal behaviour of mktemp seems to be to use a root path specified in an environment variables or /tmp. This will, however, routinely leak temporary data to unencrypted locations if I am working with files inside encrypted containers.
The idea is to first check the presence of a tmp directory in the mount point of the current file system and to use /tmponly as a last resort. How can I reliably (and efficiently) realize that.
Edit
A possible way to identify the mount directory of a given path is the following
dir=`realpath [path]`;
res=1;
while [ $res -ne 0 ]; do
dir="$dir%/*";
mountpoint -q "$dir/";
res=$?;
done;
echo "$dir";
I am not sure, however, if that is the most efficient one.
bash mktemp
Why not just encrypt /tmp, or use tmpfs so it stays in ram?
â psusi
Jan 5 at 23:59
My tmp is already encrypted, but with a security policy different from the differing policies of the various containers, so it won't help. For the same reason, I would need a different tmpfs for each container.
â highsciguy
Jan 6 at 14:13
When you say "container" are you talking about LXC containers? If so, then yes, they absolutely should each have their own /tmp.
â psusi
Jan 6 at 17:17
You may think of truecrypt containers or volumes mounted somewhere in a users home directory.
â highsciguy
Jan 6 at 17:34
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am wondering how to best improve on mktemp for use with encrypted containers or file systems.
The issue that I am dealing with is that I would like my shell scripts to store temporary files inside the file system that contains the working directory, if possible.
The normal behaviour of mktemp seems to be to use a root path specified in an environment variables or /tmp. This will, however, routinely leak temporary data to unencrypted locations if I am working with files inside encrypted containers.
The idea is to first check the presence of a tmp directory in the mount point of the current file system and to use /tmponly as a last resort. How can I reliably (and efficiently) realize that.
Edit
A possible way to identify the mount directory of a given path is the following
dir=`realpath [path]`;
res=1;
while [ $res -ne 0 ]; do
dir="$dir%/*";
mountpoint -q "$dir/";
res=$?;
done;
echo "$dir";
I am not sure, however, if that is the most efficient one.
bash mktemp
I am wondering how to best improve on mktemp for use with encrypted containers or file systems.
The issue that I am dealing with is that I would like my shell scripts to store temporary files inside the file system that contains the working directory, if possible.
The normal behaviour of mktemp seems to be to use a root path specified in an environment variables or /tmp. This will, however, routinely leak temporary data to unencrypted locations if I am working with files inside encrypted containers.
The idea is to first check the presence of a tmp directory in the mount point of the current file system and to use /tmponly as a last resort. How can I reliably (and efficiently) realize that.
Edit
A possible way to identify the mount directory of a given path is the following
dir=`realpath [path]`;
res=1;
while [ $res -ne 0 ]; do
dir="$dir%/*";
mountpoint -q "$dir/";
res=$?;
done;
echo "$dir";
I am not sure, however, if that is the most efficient one.
bash mktemp
edited Mar 23 at 12:42
asked Jan 5 at 21:48
highsciguy
88931121
88931121
Why not just encrypt /tmp, or use tmpfs so it stays in ram?
â psusi
Jan 5 at 23:59
My tmp is already encrypted, but with a security policy different from the differing policies of the various containers, so it won't help. For the same reason, I would need a different tmpfs for each container.
â highsciguy
Jan 6 at 14:13
When you say "container" are you talking about LXC containers? If so, then yes, they absolutely should each have their own /tmp.
â psusi
Jan 6 at 17:17
You may think of truecrypt containers or volumes mounted somewhere in a users home directory.
â highsciguy
Jan 6 at 17:34
add a comment |Â
Why not just encrypt /tmp, or use tmpfs so it stays in ram?
â psusi
Jan 5 at 23:59
My tmp is already encrypted, but with a security policy different from the differing policies of the various containers, so it won't help. For the same reason, I would need a different tmpfs for each container.
â highsciguy
Jan 6 at 14:13
When you say "container" are you talking about LXC containers? If so, then yes, they absolutely should each have their own /tmp.
â psusi
Jan 6 at 17:17
You may think of truecrypt containers or volumes mounted somewhere in a users home directory.
â highsciguy
Jan 6 at 17:34
Why not just encrypt /tmp, or use tmpfs so it stays in ram?
â psusi
Jan 5 at 23:59
Why not just encrypt /tmp, or use tmpfs so it stays in ram?
â psusi
Jan 5 at 23:59
My tmp is already encrypted, but with a security policy different from the differing policies of the various containers, so it won't help. For the same reason, I would need a different tmpfs for each container.
â highsciguy
Jan 6 at 14:13
My tmp is already encrypted, but with a security policy different from the differing policies of the various containers, so it won't help. For the same reason, I would need a different tmpfs for each container.
â highsciguy
Jan 6 at 14:13
When you say "container" are you talking about LXC containers? If so, then yes, they absolutely should each have their own /tmp.
â psusi
Jan 6 at 17:17
When you say "container" are you talking about LXC containers? If so, then yes, they absolutely should each have their own /tmp.
â psusi
Jan 6 at 17:17
You may think of truecrypt containers or volumes mounted somewhere in a users home directory.
â highsciguy
Jan 6 at 17:34
You may think of truecrypt containers or volumes mounted somewhere in a users home directory.
â highsciguy
Jan 6 at 17:34
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
You can specify any directory to mktemp; either using the -p option or setting a different TMPDIR.
-p temp-dir, --tmpdir=temp-dir
temp directory for the file. This option is a member of the
tmpdir class of options.
If this option is not provided, mktemp will use the environment
variable TMPDIR to find a suitable directory. If these are not
available, it will fall back to ~/tmp or /tmp. A <file-pat>
command line argument containing a directory component will con-
flict with this option.
For instance:
#!/bin/bash
TMPDIR=`pwd`
mktemp
OK, need to try that. My man page reads a little bit differently. Will it find a tmp directory in a super directory of pwd if there is none in pwd itself?
â highsciguy
Jan 6 at 14:10
Try it and see how it behaves.
â Rui F Ribeiro
Jan 6 at 14:27
Tried it. On my system,TMPDIR=pwd; export TMPDIR; mktempwill create a temporary file inpwd. This is not the behaviour that I want, since it will create temporary files everywhere. Perhaps that is better than leaking confidential information to directories that are not encrypted. However, I would still prefer to have my temporary files in a central location for each container.
â highsciguy
Jan 6 at 17:57
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You can specify any directory to mktemp; either using the -p option or setting a different TMPDIR.
-p temp-dir, --tmpdir=temp-dir
temp directory for the file. This option is a member of the
tmpdir class of options.
If this option is not provided, mktemp will use the environment
variable TMPDIR to find a suitable directory. If these are not
available, it will fall back to ~/tmp or /tmp. A <file-pat>
command line argument containing a directory component will con-
flict with this option.
For instance:
#!/bin/bash
TMPDIR=`pwd`
mktemp
OK, need to try that. My man page reads a little bit differently. Will it find a tmp directory in a super directory of pwd if there is none in pwd itself?
â highsciguy
Jan 6 at 14:10
Try it and see how it behaves.
â Rui F Ribeiro
Jan 6 at 14:27
Tried it. On my system,TMPDIR=pwd; export TMPDIR; mktempwill create a temporary file inpwd. This is not the behaviour that I want, since it will create temporary files everywhere. Perhaps that is better than leaking confidential information to directories that are not encrypted. However, I would still prefer to have my temporary files in a central location for each container.
â highsciguy
Jan 6 at 17:57
add a comment |Â
up vote
0
down vote
You can specify any directory to mktemp; either using the -p option or setting a different TMPDIR.
-p temp-dir, --tmpdir=temp-dir
temp directory for the file. This option is a member of the
tmpdir class of options.
If this option is not provided, mktemp will use the environment
variable TMPDIR to find a suitable directory. If these are not
available, it will fall back to ~/tmp or /tmp. A <file-pat>
command line argument containing a directory component will con-
flict with this option.
For instance:
#!/bin/bash
TMPDIR=`pwd`
mktemp
OK, need to try that. My man page reads a little bit differently. Will it find a tmp directory in a super directory of pwd if there is none in pwd itself?
â highsciguy
Jan 6 at 14:10
Try it and see how it behaves.
â Rui F Ribeiro
Jan 6 at 14:27
Tried it. On my system,TMPDIR=pwd; export TMPDIR; mktempwill create a temporary file inpwd. This is not the behaviour that I want, since it will create temporary files everywhere. Perhaps that is better than leaking confidential information to directories that are not encrypted. However, I would still prefer to have my temporary files in a central location for each container.
â highsciguy
Jan 6 at 17:57
add a comment |Â
up vote
0
down vote
up vote
0
down vote
You can specify any directory to mktemp; either using the -p option or setting a different TMPDIR.
-p temp-dir, --tmpdir=temp-dir
temp directory for the file. This option is a member of the
tmpdir class of options.
If this option is not provided, mktemp will use the environment
variable TMPDIR to find a suitable directory. If these are not
available, it will fall back to ~/tmp or /tmp. A <file-pat>
command line argument containing a directory component will con-
flict with this option.
For instance:
#!/bin/bash
TMPDIR=`pwd`
mktemp
You can specify any directory to mktemp; either using the -p option or setting a different TMPDIR.
-p temp-dir, --tmpdir=temp-dir
temp directory for the file. This option is a member of the
tmpdir class of options.
If this option is not provided, mktemp will use the environment
variable TMPDIR to find a suitable directory. If these are not
available, it will fall back to ~/tmp or /tmp. A <file-pat>
command line argument containing a directory component will con-
flict with this option.
For instance:
#!/bin/bash
TMPDIR=`pwd`
mktemp
answered Jan 5 at 21:53
Rui F Ribeiro
35.3k1270114
35.3k1270114
OK, need to try that. My man page reads a little bit differently. Will it find a tmp directory in a super directory of pwd if there is none in pwd itself?
â highsciguy
Jan 6 at 14:10
Try it and see how it behaves.
â Rui F Ribeiro
Jan 6 at 14:27
Tried it. On my system,TMPDIR=pwd; export TMPDIR; mktempwill create a temporary file inpwd. This is not the behaviour that I want, since it will create temporary files everywhere. Perhaps that is better than leaking confidential information to directories that are not encrypted. However, I would still prefer to have my temporary files in a central location for each container.
â highsciguy
Jan 6 at 17:57
add a comment |Â
OK, need to try that. My man page reads a little bit differently. Will it find a tmp directory in a super directory of pwd if there is none in pwd itself?
â highsciguy
Jan 6 at 14:10
Try it and see how it behaves.
â Rui F Ribeiro
Jan 6 at 14:27
Tried it. On my system,TMPDIR=pwd; export TMPDIR; mktempwill create a temporary file inpwd. This is not the behaviour that I want, since it will create temporary files everywhere. Perhaps that is better than leaking confidential information to directories that are not encrypted. However, I would still prefer to have my temporary files in a central location for each container.
â highsciguy
Jan 6 at 17:57
OK, need to try that. My man page reads a little bit differently. Will it find a tmp directory in a super directory of pwd if there is none in pwd itself?
â highsciguy
Jan 6 at 14:10
OK, need to try that. My man page reads a little bit differently. Will it find a tmp directory in a super directory of pwd if there is none in pwd itself?
â highsciguy
Jan 6 at 14:10
Try it and see how it behaves.
â Rui F Ribeiro
Jan 6 at 14:27
Try it and see how it behaves.
â Rui F Ribeiro
Jan 6 at 14:27
Tried it. On my system,
TMPDIR=pwd; export TMPDIR; mktemp will create a temporary file in pwd. This is not the behaviour that I want, since it will create temporary files everywhere. Perhaps that is better than leaking confidential information to directories that are not encrypted. However, I would still prefer to have my temporary files in a central location for each container.â highsciguy
Jan 6 at 17:57
Tried it. On my system,
TMPDIR=pwd; export TMPDIR; mktemp will create a temporary file in pwd. This is not the behaviour that I want, since it will create temporary files everywhere. Perhaps that is better than leaking confidential information to directories that are not encrypted. However, I would still prefer to have my temporary files in a central location for each container.â highsciguy
Jan 6 at 17:57
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f415098%2fimproving-mktemp%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Why not just encrypt /tmp, or use tmpfs so it stays in ram?
â psusi
Jan 5 at 23:59
My tmp is already encrypted, but with a security policy different from the differing policies of the various containers, so it won't help. For the same reason, I would need a different tmpfs for each container.
â highsciguy
Jan 6 at 14:13
When you say "container" are you talking about LXC containers? If so, then yes, they absolutely should each have their own /tmp.
â psusi
Jan 6 at 17:17
You may think of truecrypt containers or volumes mounted somewhere in a users home directory.
â highsciguy
Jan 6 at 17:34