discover-image: imply that hidden images are read-only
Marking a whole directory tree OS image as read-only is difficult privilege-wise, because so far we rely on the FS_IMMUTABLE_FL which is not accessible to unpriv clients. One fundamental place where we currently rely on marking images read-only is for keeping pristine copies of the originally downloaded image around, which we place in "hidden" image directories. This is probably the most relevant usecase for the read-only flag. And moreover, the only usecase for the hidden images are these read-only pristine copies. Hence, let's make this work reasonably in the unpriv case, and simply imply the read-only flag for hidden images. This is strictly speaking a change in behaviour, but effectively it shouldn't be, because for nspawn containers that are executed we insist on names that are hostname compatible, and hidden names aren't (because they start with a dot).
This commit is contained in:
@@ -24,6 +24,20 @@
|
||||
|
||||
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_type, image_type, ImageType);
|
||||
|
||||
static int property_get_read_only(
|
||||
sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
sd_bus_message *reply,
|
||||
void *userdata,
|
||||
sd_bus_error *error) {
|
||||
|
||||
Image *image = ASSERT_PTR(userdata);
|
||||
|
||||
return sd_bus_message_append(ASSERT_PTR(reply), "b", image_is_read_only(image));
|
||||
}
|
||||
|
||||
int bus_image_method_remove(
|
||||
sd_bus_message *message,
|
||||
void *userdata,
|
||||
@@ -448,7 +462,7 @@ const sd_bus_vtable image_vtable[] = {
|
||||
SD_BUS_PROPERTY("Name", "s", NULL, offsetof(Image, name), 0),
|
||||
SD_BUS_PROPERTY("Path", "s", NULL, offsetof(Image, path), 0),
|
||||
SD_BUS_PROPERTY("Type", "s", property_get_type, offsetof(Image, type), 0),
|
||||
SD_BUS_PROPERTY("ReadOnly", "b", bus_property_get_bool, offsetof(Image, read_only), 0),
|
||||
SD_BUS_PROPERTY("ReadOnly", "b", property_get_read_only, 0, 0),
|
||||
SD_BUS_PROPERTY("CreationTimestamp", "t", NULL, offsetof(Image, crtime), 0),
|
||||
SD_BUS_PROPERTY("ModificationTimestamp", "t", NULL, offsetof(Image, mtime), 0),
|
||||
SD_BUS_PROPERTY("Usage", "t", NULL, offsetof(Image, usage), 0),
|
||||
|
||||
@@ -823,7 +823,7 @@ static int method_list_images(sd_bus_message *message, void *userdata, sd_bus_er
|
||||
r = sd_bus_message_append(reply, "(ssbttto)",
|
||||
image->name,
|
||||
image_type_to_string(image->type),
|
||||
image->read_only,
|
||||
image_is_read_only(image),
|
||||
image->crtime,
|
||||
image->mtime,
|
||||
image->usage,
|
||||
|
||||
@@ -638,7 +638,7 @@ static int list_image_one_and_maybe_read_metadata(Manager *m, sd_varlink *link,
|
||||
JSON_BUILD_PAIR_STRING_NON_EMPTY("path", image->path),
|
||||
SD_JSON_BUILD_PAIR_STRING("type", image_type_to_string(image->type)),
|
||||
SD_JSON_BUILD_PAIR_STRING("class", image_class_to_string(image->class)),
|
||||
SD_JSON_BUILD_PAIR_BOOLEAN("readOnly", image->read_only),
|
||||
SD_JSON_BUILD_PAIR_BOOLEAN("readOnly", image_is_read_only(image)),
|
||||
JSON_BUILD_PAIR_UNSIGNED_NON_ZERO("creationTimestamp", image->crtime),
|
||||
JSON_BUILD_PAIR_UNSIGNED_NON_ZERO("modificationTimestamp", image->mtime),
|
||||
JSON_BUILD_PAIR_UNSIGNED_NOT_EQUAL("usage", image->usage, UINT64_MAX),
|
||||
|
||||
Reference in New Issue
Block a user