machined: add controlAddress field to Machine.Register and Machine.List
Follow the existing sshAddress pattern to add a controlAddress field that allows machine registrants (like vmspawn) to advertise a varlink socket address for direct VM control. machined stores and exposes the address but never connects to it itself. Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
This commit is contained in:
@@ -142,6 +142,7 @@ int vl_method_register(sd_varlink *link, sd_json_variant *parameters, sd_varlink
|
||||
{ "vSockCid", _SD_JSON_VARIANT_TYPE_INVALID, machine_cid, offsetof(Machine, vsock_cid), 0 },
|
||||
{ "sshAddress", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(Machine, ssh_address), SD_JSON_STRICT },
|
||||
{ "sshPrivateKeyPath", SD_JSON_VARIANT_STRING, json_dispatch_path, offsetof(Machine, ssh_private_key_path), 0 },
|
||||
{ "controlAddress", SD_JSON_VARIANT_STRING, json_dispatch_path, offsetof(Machine, control_address), SD_JSON_STRICT },
|
||||
{ "allocateUnit", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, offsetof(Machine, allocate_unit), 0 },
|
||||
VARLINK_DISPATCH_POLKIT_FIELD,
|
||||
{}
|
||||
|
||||
@@ -154,6 +154,7 @@ Machine* machine_free(Machine *m) {
|
||||
free(m->netif);
|
||||
free(m->ssh_address);
|
||||
free(m->ssh_private_key_path);
|
||||
free(m->control_address);
|
||||
|
||||
return mfree(m);
|
||||
}
|
||||
@@ -245,6 +246,7 @@ int machine_save(Machine *m) {
|
||||
|
||||
env_file_fputs_assignment(f, "SSH_ADDRESS=", m->ssh_address);
|
||||
env_file_fputs_assignment(f, "SSH_PRIVATE_KEY_PATH=", m->ssh_private_key_path);
|
||||
env_file_fputs_assignment(f, "CONTROL_ADDRESS=", m->control_address);
|
||||
|
||||
r = flink_tmpfile(f, temp_path, m->state_file, LINK_TMPFILE_REPLACE);
|
||||
if (r < 0)
|
||||
@@ -338,6 +340,7 @@ int machine_load(Machine *m) {
|
||||
"VSOCK_CID", &vsock_cid,
|
||||
"SSH_ADDRESS", &m->ssh_address,
|
||||
"SSH_PRIVATE_KEY_PATH", &m->ssh_private_key_path,
|
||||
"CONTROL_ADDRESS", &m->control_address,
|
||||
"UID", &uid);
|
||||
if (r == -ENOENT)
|
||||
return 0;
|
||||
|
||||
@@ -96,6 +96,7 @@ typedef struct Machine {
|
||||
unsigned vsock_cid;
|
||||
char *ssh_address;
|
||||
char *ssh_private_key_path;
|
||||
char *control_address;
|
||||
|
||||
LIST_HEAD(Operation, operations);
|
||||
|
||||
|
||||
@@ -489,6 +489,7 @@ static int list_machine_one_and_maybe_read_metadata(sd_varlink *link, Machine *m
|
||||
JSON_BUILD_PAIR_UNSIGNED_NOT_EQUAL("vSockCid", m->vsock_cid, VMADDR_CID_ANY),
|
||||
JSON_BUILD_PAIR_STRING_NON_EMPTY("sshAddress", m->ssh_address),
|
||||
JSON_BUILD_PAIR_STRING_NON_EMPTY("sshPrivateKeyPath", m->ssh_private_key_path),
|
||||
JSON_BUILD_PAIR_STRING_NON_EMPTY("controlAddress", m->control_address),
|
||||
JSON_BUILD_PAIR_VARIANT_NON_NULL("addresses", addr_array),
|
||||
JSON_BUILD_PAIR_STRV_ENV_PAIR_NON_EMPTY("OSRelease", os_release),
|
||||
JSON_BUILD_PAIR_UNSIGNED_NOT_EQUAL("UIDShift", shift, UID_INVALID),
|
||||
|
||||
@@ -57,6 +57,8 @@ static SD_VARLINK_DEFINE_METHOD(
|
||||
SD_VARLINK_DEFINE_INPUT(vSockCid, SD_VARLINK_INT, SD_VARLINK_NULLABLE),
|
||||
SD_VARLINK_DEFINE_INPUT(sshAddress, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
|
||||
SD_VARLINK_DEFINE_INPUT(sshPrivateKeyPath, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
|
||||
SD_VARLINK_FIELD_COMMENT("Varlink socket address for direct machine control. The server at this address is expected to implement io.systemd.MachineInstance and optionally io.systemd.VirtualMachineInstance and io.systemd.QemuMachineInstance."),
|
||||
SD_VARLINK_DEFINE_INPUT(controlAddress, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
|
||||
SD_VARLINK_FIELD_COMMENT("Controls whether to allocate a scope unit for the machine to register. If false, the client already took care of that and registered a service/scope specific to the machine."),
|
||||
SD_VARLINK_DEFINE_INPUT(allocateUnit, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE),
|
||||
VARLINK_DEFINE_POLKIT_INPUT);
|
||||
@@ -107,6 +109,8 @@ static SD_VARLINK_DEFINE_METHOD_FULL(
|
||||
SD_VARLINK_DEFINE_OUTPUT(sshAddress, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
|
||||
SD_VARLINK_FIELD_COMMENT("Path to private SSH key"),
|
||||
SD_VARLINK_DEFINE_OUTPUT(sshPrivateKeyPath, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
|
||||
SD_VARLINK_FIELD_COMMENT("Varlink socket address for direct machine control, implementing io.systemd.MachineInstance and optionally further interfaces"),
|
||||
SD_VARLINK_DEFINE_OUTPUT(controlAddress, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
|
||||
SD_VARLINK_FIELD_COMMENT("List of addresses of the machine"),
|
||||
SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(addresses, Address, SD_VARLINK_ARRAY | SD_VARLINK_NULLABLE),
|
||||
SD_VARLINK_FIELD_COMMENT("OS release information of the machine. It contains an array of key value pairs read from the os-release(5) file in the image."),
|
||||
|
||||
Reference in New Issue
Block a user