Skip to content

Commit

Permalink
Merge pull request #264 from NERSC/feature/allow_var_tmp
Browse files Browse the repository at this point in the history
Feature/allow var tmp
  • Loading branch information
dmjacobsen authored Oct 10, 2019
2 parents 5186aac + ff923b6 commit 24a9d9a
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 15 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.62])
AC_INIT([shifter], [18.03.0], [[email protected]])
AC_INIT([shifter], [18.03.3], [[email protected]])
AC_CONFIG_SRCDIR([src/shifter_core.h])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_AUX_DIR([auxdir])
Expand Down
3 changes: 3 additions & 0 deletions extra/CI/integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ shifterimg pull ubuntu:16.04
shifterimg lookup ubuntu:16.04
ls /images

echo "var/tmp exists"
ls -ld /var/tmp

echo "Ensure container gets basic setup"
python $CIDIR/integration/test_shifterConfig_format.py ubuntu:16.04

Expand Down
6 changes: 4 additions & 2 deletions shifter.spec
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
%{!?systemd_requires: %global _without_systemd --without-systemd}
%endif

%{!?shifter_release: %global shifter_release 1.nersc%{?dist}}

%{?_with_slurm: %global with_slurm %{_prefix}}

Summary: NERSC Shifter -- Containers for HPC
Name: shifter
Version: 18.03.2
Release: 1.nersc%{?dist}
Version: 18.03.3
Release: %{shifter_release}
License: BSD (LBNL-modified)
Group: System Environment/Base
URL: https://github.com/NERSC/shifter
Expand Down
36 changes: 24 additions & 12 deletions src/VolumeMap.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ int validateVolumeMap_userRequest(
const char *to,
VolumeMapFlag *flags)
{
const char *toExactAllowed[] = {"/var/tmp", NULL};
const char *toStartsWithDisallowed[] = {
"/etc", "/var", "etc", "var", "/opt/udiImage", "opt/udiImage", NULL
};
Expand All @@ -76,8 +77,9 @@ int validateVolumeMap_userRequest(
size_t allowedFlags = VOLMAP_FLAG_READONLY | VOLMAP_FLAG_PERNODECACHE;

return _validateVolumeMap(
from, to, flags, toStartsWithDisallowed, toExactDisallowed,
fromStartsWithDisallowed, fromExactDisallowed, allowedFlags
from, to, flags, toExactAllowed, toStartsWithDisallowed,
toExactDisallowed, fromStartsWithDisallowed, fromExactDisallowed,
allowedFlags
);
}

Expand All @@ -86,6 +88,7 @@ int validateVolumeMap_siteRequest(
const char *to,
VolumeMapFlag *flags)
{
const char *toExactAllowed[] = { NULL };
const char *toStartsWithDisallowed[] = { NULL };
const char *toExactDisallowed[] = {
"/opt", "opt",
Expand All @@ -105,8 +108,9 @@ int validateVolumeMap_siteRequest(
| VOLMAP_FLAG_PRIVATE;

return _validateVolumeMap(
from, to, flags, toStartsWithDisallowed, toExactDisallowed,
fromStartsWithDisallowed, fromExactDisallowed, allowedFlags
from, to, flags, toExactAllowed, toStartsWithDisallowed,
toExactDisallowed, fromStartsWithDisallowed, fromExactDisallowed,
allowedFlags
);
}

Expand Down Expand Up @@ -585,6 +589,7 @@ int _validateVolumeMap(
const char *from,
const char *to,
VolumeMapFlag *flags,
const char **toExactAllowed,
const char **toStartsWithDisallowed,
const char **toExactDisallowed,
const char **fromStartsWithDisallowed,
Expand Down Expand Up @@ -628,25 +633,32 @@ int _validateVolumeMap(
return 4;
}

for (ptr = toStartsWithDisallowed; *ptr != NULL; ptr++) {
/* checking "from" before "to" since the "to" checks can return early */
for (ptr = fromStartsWithDisallowed; *ptr != NULL; ptr++) {
size_t len = strlen(*ptr);
if (strncmp(to, *ptr, len) == 0) {
if (strncmp(from, *ptr, len) == 0) {
return 1;
}
}
for (ptr = toExactDisallowed; *ptr != NULL; ptr++) {
if (strcmp(to, *ptr) == 0) {
for (ptr = fromExactDisallowed; *ptr != NULL; ptr++) {
if (strcmp(from, *ptr) == 0) {
return 1;
}
}
for (ptr = fromStartsWithDisallowed; *ptr != NULL; ptr++) {

for (ptr = toExactAllowed; *ptr != NULL; ptr++) {
if (strcmp(to, *ptr) == 0) {
return 0;
}
}
for (ptr = toStartsWithDisallowed; *ptr != NULL; ptr++) {
size_t len = strlen(*ptr);
if (strncmp(from, *ptr, len) == 0) {
if (strncmp(to, *ptr, len) == 0) {
return 1;
}
}
for (ptr = fromExactDisallowed; *ptr != NULL; ptr++) {
if (strcmp(from, *ptr) == 0) {
for (ptr = toExactDisallowed; *ptr != NULL; ptr++) {
if (strcmp(to, *ptr) == 0) {
return 1;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/VolumeMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ int _validateVolumeMap(
const char *from,
const char *to,
VolumeMapFlag *flags,
const char **toExactAllowed,
const char **toStartsWithDisallowed,
const char **toExactDisallowed,
const char **fromStartsWithDisallowed,
Expand Down
7 changes: 7 additions & 0 deletions src/shifter_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ int prepareSiteModifications(const char *username,
_MKDIR("var", 0755);
_MKDIR("var/spool", 0755);
_MKDIR("var/run", 0755);
_MKDIR("var/tmp", 0755);
_MKDIR("var/empty", 0700);
_MKDIR("proc", 0755);
_MKDIR("sys", 0755);
Expand Down Expand Up @@ -948,6 +949,12 @@ int prepareSiteModifications(const char *username,
mntBuffer[PATH_MAX-1] = 0;
_BINDMOUNT(&mountCache, "/tmp", mntBuffer, 0, 1);

/* mount /var/tmp, checking if executable as an existance check */
if (access("/var/tmp", X_OK) == 0) {
snprintf(mntBuffer, PATH_MAX, "%s/var/tmp", udiRoot);
mntBuffer[PATH_MAX-1] = 0;
_BINDMOUNT(&mountCache, "/var/tmp", mntBuffer, 0, 1);
}

#undef _MKDIR
#undef _BINDMOUNT
Expand Down
3 changes: 3 additions & 0 deletions src/test/test_VolumeMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ TEST(VolumeMapTestGroup, ValidateVolumeMap_basic) {
ret = validateVolumeMap_userRequest("/test1Loc", "/var/log", NULL);
CHECK(ret != 0);

ret = validateVolumeMap_userRequest("/test1Loc", "/var/tmp", NULL);
CHECK(ret == 0);

ret = validateVolumeMap_userRequest("/test1Loc", "/opt", NULL);
CHECK(ret != 0);

Expand Down

0 comments on commit 24a9d9a

Please sign in to comment.