Skip to content

Commit

Permalink
Merge pull request #1279 from kinvolk/rata/features-expose-idmap
Browse files Browse the repository at this point in the history
features: Support mountExtensions
  • Loading branch information
giuseppe authored Aug 24, 2023
2 parents 555f60a + 668f5d5 commit 6369207
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/libcrun/container.c
Original file line number Diff line number Diff line change
Expand Up @@ -3886,7 +3886,7 @@ libcrun_container_get_features (libcrun_context_t *context, struct features_info

// Hardcoded feature information
(*info)->oci_version_min = xstrdup ("1.0.0");
(*info)->oci_version_max = xstrdup ("1.1.0");
(*info)->oci_version_max = xstrdup ("1.1.0+dev");

// Populate hooks
populate_array_field (&((*info)->hooks), hooks, num_hooks);
Expand Down Expand Up @@ -3925,6 +3925,9 @@ libcrun_container_get_features (libcrun_context_t *context, struct features_info
(*info)->linux.apparmor.enabled = true;
(*info)->linux.selinux.enabled = true;

// Put the values for mount extensions
(*info)->linux.mount_ext.idmap.enabled = true;

// Populate the values for annotations
#ifdef HAVE_SECCOMP
{
Expand Down
11 changes: 11 additions & 0 deletions src/libcrun/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ struct selinux_info_s
bool enabled;
};

struct idmap_info_s
{
bool enabled;
};

struct mount_ext_info_s
{
struct idmap_info_s idmap;
};

struct linux_info_s
{
char **namespaces;
Expand All @@ -129,6 +139,7 @@ struct linux_info_s
struct seccomp_info_s seccomp;
struct apparmor_info_s apparmor;
struct selinux_info_s selinux;
struct mount_ext_info_s mount_ext;
};

struct annotations_info_s
Expand Down
15 changes: 15 additions & 0 deletions src/oci_features.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,20 @@ crun_features_add_selinux_info (yajl_gen json_gen, const struct linux_info_s *li
yajl_gen_map_close (json_gen);
}

void
crun_features_add_mount_ext_info (yajl_gen json_gen, const struct linux_info_s *linux)
{
yajl_gen_string (json_gen, (const unsigned char *) "mountExtensions", strlen ("mountExtensions"));
yajl_gen_map_open (json_gen);

yajl_gen_string (json_gen, (const unsigned char *) "idmap", strlen ("idmap"));
yajl_gen_map_open (json_gen);
add_bool_to_json (json_gen, "enabled", linux->mount_ext.idmap.enabled);
yajl_gen_map_close (json_gen);

yajl_gen_map_close (json_gen);
}

void
crun_features_add_linux_info (yajl_gen json_gen, const struct linux_info_s *linux)
{
Expand All @@ -182,6 +196,7 @@ crun_features_add_linux_info (yajl_gen json_gen, const struct linux_info_s *linu
crun_features_add_seccomp_info (json_gen, linux);
crun_features_add_apparmor_info (json_gen, linux);
crun_features_add_selinux_info (json_gen, linux);
crun_features_add_mount_ext_info (json_gen, linux);

yajl_gen_map_close (json_gen);
}
Expand Down
7 changes: 6 additions & 1 deletion tests/test_oci_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_crun_features():
features = json.loads(output)
expected_features = {
"ociVersionMin": "1.0.0",
"ociVersionMax": "1.1.0",
"ociVersionMax": "1.1.0+dev",
"hooks": [
"prestart",
"createRuntime",
Expand Down Expand Up @@ -155,6 +155,11 @@ def test_crun_features():
},
"selinux": {
"enabled": True
},
"mountExtensions": {
"idmap": {
"enabled": True,
},
}
},
"annotations": {
Expand Down

0 comments on commit 6369207

Please sign in to comment.