Skip to content

Commit 5ea508e

Browse files
committed
hostnamed: expose DMI board_asset_tag as BoardAssetTag
Exposes /sys/class/dmi/id/board_asset_tag via hostnamed's D-Bus, Varlink and hostnamectl interfaces, mirroring the ChassisAssetTag support added in PR systemd#36487. This is useful for attestation on AWS EC2, where the EC2 instance ID is exposed as board_asset_tag [1]. The instance ID can then be used to fetch the instance's Endorsement Key via the EC2 API [2]. I am planning to use this in SPIRE's TPM attestation plugin [3]. [1] https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/identify_ec2_instances.html [2] https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/retrieve-ekpub.html [3] spiffe/spire-tpm-plugin#35 Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 317714d commit 5ea508e

6 files changed

Lines changed: 60 additions & 1 deletion

File tree

hwdb.d/20-dmi-id.hwdb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ dmi:*:catToBeFilledByO.E.M.:*
6363
dmi:*:catTo Be Filled By O.E.M.:*
6464
ID_CHASSIS_ASSET_TAG_IS_RUBBISH=1
6565

66+
dmi:*:ratDefaultstring:*
67+
dmi:*:ratDefault string:*
68+
dmi:*:ratN/A:*
69+
dmi:*:ratO.E.M.:*
70+
dmi:*:ratOEM:*
71+
dmi:*:ratTobefilledbyO.E.M.:*
72+
dmi:*:ratToBeFilledByO.E.M.:*
73+
dmi:*:ratTo Be Filled By O.E.M.:*
74+
ID_BOARD_ASSET_TAG_IS_RUBBISH=1
75+
6676
# Fix "Lenovo" capitalization in /sys/class/dmi/id/sys_vendor
6777
dmi:bvnLENOVO*
6878
ID_SYSFS_ATTRIBUTE_MODEL=product_version

man/org.freedesktop.hostname1.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ node /org/freedesktop/hostname1 {
115115
readonly u VSockCID = ...;
116116
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
117117
readonly s ChassisAssetTag = '...';
118+
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
119+
readonly s BoardAssetTag = '...';
118120
};
119121
interface org.freedesktop.DBus.Peer { ... };
120122
interface org.freedesktop.DBus.Introspectable { ... };
@@ -210,6 +212,8 @@ node /org/freedesktop/hostname1 {
210212

211213
<variablelist class="dbus-property" generated="True" extra-ref="ChassisAssetTag"/>
212214

215+
<variablelist class="dbus-property" generated="True" extra-ref="BoardAssetTag"/>
216+
213217
<!--End of Autogenerated section-->
214218

215219
<para>Whenever the hostname or other metadata is changed via the daemon,
@@ -342,6 +346,9 @@ node /org/freedesktop/hostname1 {
342346
<para><varname>ChassisAssetTag</varname> exposes an unique identifier of the system chassis. If this
343347
information is not known this property is set to an empty string.</para>
344348

349+
<para><varname>BoardAssetTag</varname> exposes an unique identifier of the system board. If this
350+
information is not known this property is set to an empty string.</para>
351+
345352
<refsect2>
346353
<title>Methods</title>
347354

@@ -505,6 +512,7 @@ node /org/freedesktop/hostname1 {
505512
<varname>OperatingSystemImageVersion</varname>, <varname>HardwareSKU</varname>, and
506513
<varname>HardwareVersion</varname> were added in version 258.</para>
507514
<para><varname>OperatingSystemFancyName</varname> was added in version 260.</para>
515+
<para><varname>BoardAssetTag</varname> was added in version 261.</para>
508516
<para><function>GetMachineInfo()</function> was added in version 261.</para>
509517
</refsect2>
510518
</refsect1>

rules.d/60-dmi-id.rules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ ENV{ID_HARDWARE_VERSION}=="", ENV{ID_BOARD_VERSION_IS_RUBBISH}!="1", ENV{ID_HARD
2323
ENV{MODALIAS}!="", ATTR{chassis_asset_tag}!="", IMPORT{builtin}="hwdb '$attr{modalias}cat$attr{chassis_asset_tag}:'"
2424
ENV{ID_CHASSIS_ASSET_TAG_IS_RUBBISH}!="1", ENV{ID_CHASSIS_ASSET_TAG}="$attr{chassis_asset_tag}"
2525

26+
# Board asset tag
27+
ENV{MODALIAS}!="", ATTR{board_asset_tag}!="", IMPORT{builtin}="hwdb '$attr{modalias}rat$attr{board_asset_tag}:'"
28+
ENV{ID_BOARD_ASSET_TAG_IS_RUBBISH}!="1", ENV{ID_BOARD_ASSET_TAG}="$attr{board_asset_tag}"
29+
2630
# Allow units to be ordered after the DMI device
2731
TAG+="systemd"
2832

src/hostname/hostnamectl.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ typedef struct StatusInfo {
4747
const char *icon_name;
4848
const char *chassis;
4949
const char *chassis_asset_tag;
50+
const char *board_asset_tag;
5051
const char *deployment;
5152
const char *location;
5253
const char *kernel_name;
@@ -180,6 +181,14 @@ static int print_status_info(StatusInfo *i) {
180181
return table_log_add_error(r);
181182
}
182183

184+
if (!isempty(i->board_asset_tag)) {
185+
r = table_add_many(table,
186+
TABLE_FIELD, "Board Asset Tag",
187+
TABLE_STRING, i->board_asset_tag);
188+
if (r < 0)
189+
return table_log_add_error(r);
190+
}
191+
183192
if (!isempty(i->deployment)) {
184193
r = table_add_many(table,
185194
TABLE_FIELD, "Deployment",
@@ -425,6 +434,7 @@ static int show_all_names(sd_bus *bus) {
425434
{ "IconName", "s", NULL, offsetof(StatusInfo, icon_name) },
426435
{ "Chassis", "s", NULL, offsetof(StatusInfo, chassis) },
427436
{ "ChassisAssetTag", "s", NULL, offsetof(StatusInfo, chassis_asset_tag)},
437+
{ "BoardAssetTag", "s", NULL, offsetof(StatusInfo, board_asset_tag) },
428438
{ "Deployment", "s", NULL, offsetof(StatusInfo, deployment) },
429439
{ "Location", "s", NULL, offsetof(StatusInfo, location) },
430440
{ "KernelName", "s", NULL, offsetof(StatusInfo, kernel_name) },

src/hostname/hostnamed.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,10 @@ static int get_chassis_asset_tag(Context *c, char **ret) {
386386
return get_dmi_property(c, "ID_CHASSIS_ASSET_TAG", ret);
387387
}
388388

389+
static int get_board_asset_tag(Context *c, char **ret) {
390+
return get_dmi_property(c, "ID_BOARD_ASSET_TAG", ret);
391+
}
392+
389393
static int get_hardware_vendor(Context *c, char **ret) {
390394
return get_dmi_properties(c, STRV_MAKE_CONST("ID_VENDOR_FROM_DATABASE", "ID_VENDOR"), ret);
391395
}
@@ -1049,6 +1053,23 @@ static int property_get_chassis_asset_tag(
10491053
return sd_bus_message_append(reply, "s", chassis_asset_tag);
10501054
}
10511055

1056+
static int property_get_board_asset_tag(
1057+
sd_bus *bus,
1058+
const char *path,
1059+
const char *interface,
1060+
const char *property,
1061+
sd_bus_message *reply,
1062+
void *userdata,
1063+
sd_bus_error *error) {
1064+
1065+
_cleanup_free_ char *board_asset_tag = NULL;
1066+
Context *c = ASSERT_PTR(userdata);
1067+
1068+
(void) get_board_asset_tag(c, &board_asset_tag);
1069+
1070+
return sd_bus_message_append(reply, "s", board_asset_tag);
1071+
}
1072+
10521073
static int property_get_hostname(
10531074
sd_bus *bus,
10541075
const char *path,
@@ -1720,7 +1741,8 @@ static int method_get_machine_info(sd_bus_message *m, void *userdata, sd_bus_err
17201741
static int build_describe_response(Context *c, bool privileged, sd_json_variant **ret) {
17211742
_cleanup_free_ char *hn = NULL, *dhn = NULL, *in = NULL,
17221743
*chassis = NULL, *vendor = NULL, *model = NULL, *serial = NULL, *firmware_version = NULL,
1723-
*firmware_vendor = NULL, *chassis_asset_tag = NULL, *sku = NULL, *hardware_version = NULL;
1744+
*firmware_vendor = NULL, *chassis_asset_tag = NULL, *board_asset_tag = NULL,
1745+
*sku = NULL, *hardware_version = NULL;
17241746
_cleanup_strv_free_ char **os_release_pairs = NULL, **machine_info_pairs = NULL;
17251747
usec_t firmware_date = USEC_INFINITY, eol = USEC_INFINITY;
17261748
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
@@ -1770,6 +1792,7 @@ static int build_describe_response(Context *c, bool privileged, sd_json_variant
17701792
(void) get_firmware_vendor(c, &firmware_vendor);
17711793
(void) get_firmware_date(c, &firmware_date);
17721794
(void) get_chassis_asset_tag(c, &chassis_asset_tag);
1795+
(void) get_board_asset_tag(c, &board_asset_tag);
17731796

17741797
if (c->data[PROP_OS_SUPPORT_END])
17751798
(void) os_release_support_ended(c->data[PROP_OS_SUPPORT_END], /* quiet= */ false, &eol);
@@ -1797,6 +1820,7 @@ static int build_describe_response(Context *c, bool privileged, sd_json_variant
17971820
SD_JSON_BUILD_PAIR_STRING("IconName", in ?: c->data[PROP_ICON_NAME]),
17981821
SD_JSON_BUILD_PAIR_STRING("Chassis", chassis),
17991822
SD_JSON_BUILD_PAIR_STRING("ChassisAssetTag", chassis_asset_tag),
1823+
SD_JSON_BUILD_PAIR_STRING("BoardAssetTag", board_asset_tag),
18001824
SD_JSON_BUILD_PAIR_STRING("Deployment", c->data[PROP_DEPLOYMENT]),
18011825
SD_JSON_BUILD_PAIR_STRING("Location", c->data[PROP_LOCATION]),
18021826
SD_JSON_BUILD_PAIR_STRING("KernelName", u.sysname),
@@ -1897,6 +1921,7 @@ static const sd_bus_vtable hostname_vtable[] = {
18971921
SD_BUS_PROPERTY("BootID", "ay", property_get_boot_id, 0, SD_BUS_VTABLE_PROPERTY_CONST),
18981922
SD_BUS_PROPERTY("VSockCID", "u", property_get_vsock_cid, 0, SD_BUS_VTABLE_PROPERTY_CONST),
18991923
SD_BUS_PROPERTY("ChassisAssetTag", "s", property_get_chassis_asset_tag, 0, SD_BUS_VTABLE_PROPERTY_CONST),
1924+
SD_BUS_PROPERTY("BoardAssetTag", "s", property_get_board_asset_tag, 0, SD_BUS_VTABLE_PROPERTY_CONST),
19001925

19011926
SD_BUS_METHOD_WITH_ARGS("SetHostname",
19021927
SD_BUS_ARGS("s", hostname, "b", interactive),

src/shared/varlink-io.systemd.Hostname.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ static SD_VARLINK_DEFINE_METHOD(
1515
SD_VARLINK_DEFINE_OUTPUT(Chassis, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
1616
SD_VARLINK_FIELD_COMMENT("An unique identifier of the system chassis."),
1717
SD_VARLINK_DEFINE_OUTPUT(ChassisAssetTag, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
18+
SD_VARLINK_FIELD_COMMENT("An unique identifier of the system board."),
19+
SD_VARLINK_DEFINE_OUTPUT(BoardAssetTag, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
1820
SD_VARLINK_DEFINE_OUTPUT(Deployment, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
1921
SD_VARLINK_DEFINE_OUTPUT(Location, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
2022
SD_VARLINK_DEFINE_OUTPUT(KernelName, SD_VARLINK_STRING, 0),

0 commit comments

Comments
 (0)