#include "dbus-service.h"
#include "dbus-util.h"
#include "execute.h"
+#include "exec-credential.h"
#include "exit-status.h"
#include "fd-util.h"
#include "fileio.h"
if (!exec_needs_mount_namespace(c, NULL, unit_get_exec_runtime(u)))
return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Unit not running in private mount namespace, cannot activate bind mount");
+ if (mount_point_is_credentials(u->manager->prefix[EXEC_DIRECTORY_RUNTIME], dest))
+ return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Refusing to bind mount over credential mounts");
+
/* If it would be dropped at startup time, return an error. */
if (path_startswith_strv(dest, c->inaccessible_paths))
return sd_bus_error_setf(error, SD_BUS_ERROR_ACCESS_DENIED, "%s is not accessible to this unit", dest);
return false;
}
+bool mount_point_is_credentials(const char *runtime_prefix, const char *path) {
+ const char *e;
+
+ assert(runtime_prefix);
+ assert(path);
+
+ e = path_startswith(path, runtime_prefix);
+ if (!e)
+ return false;
+
+ return path_startswith(e, "credentials");
+}
+
static int get_credential_directory(
const char *runtime_prefix,
const char *unit,
#include "dbus-mount.h"
#include "dbus-unit.h"
#include "device.h"
+#include "exec-credential.h"
#include "exit-status.h"
#include "format-util.h"
#include "fs-util.h"
return false;
}
-static bool mount_point_is_credentials(Manager *manager, const char *path) {
- const char *e;
-
- assert(manager);
- assert(path);
-
- /* Returns true if this is a credentials mount. We don't want to generate mount units for them,
- * since their lifetime is strictly bound to services. */
-
- e = path_startswith(path, manager->prefix[EXEC_DIRECTORY_RUNTIME]);
- if (!e)
- return false;
-
- return !isempty(path_startswith(e, "credentials"));
-}
-
static int mount_add_default_ordering_dependencies(Mount *m, MountParameters *p, UnitDependencyMask mask) {
const char *after, *before, *e;
int r;
return log_unit_error_errno(UNIT(m), SYNTHETIC_ERRNO(ENOEXEC),
"Cannot create mount unit for API file system '%s'. Refusing.", m->where);
- if (mount_point_is_credentials(UNIT(m)->manager, m->where))
+ if (mount_point_is_credentials(UNIT(m)->manager->prefix[EXEC_DIRECTORY_RUNTIME], m->where))
return log_unit_error_errno(UNIT(m), SYNTHETIC_ERRNO(ENOEXEC),
"Cannot create mount unit for credential mount '%s'. Refusing.", m->where);
assert(fstype);
/* Ignore API and credential mount points. They should never be referenced in dependencies ever.
- * Also check the comment for mount_point_is_credentials(). */
- if (mount_point_is_api(where) || mount_point_ignore(where) || mount_point_is_credentials(m, where))
+ * Furthermore, the lifetime of credential mounts is strictly bound to the owning services,
+ * so mount units make little sense for them. */
+ if (mount_point_is_api(where) || mount_point_ignore(where) ||
+ mount_point_is_credentials(m->prefix[EXEC_DIRECTORY_RUNTIME], where))
return 0;
if (streq(fstype, "autofs"))