Skip to content

Commit 6eade3d

Browse files
committed
chore: add ability to rewrite uuids and set unique tokens for Talos
This PR does those things: - It allows API calls `MetaWrite` and `MetaRead` in maintenance mode. - SystemInformation resource now waits for available META - SystemInformation resource now overwrites UUID from META if there is an override - META now supports "UUID override" and "unique token" keys - ProvisionRequest now includes unique token and Talos version For #7694 Signed-off-by: Dmitriy Matrenichev <dmitry.matrenichev@siderolabs.com>
1 parent e9c7ac1 commit 6eade3d

File tree

26 files changed

+1019
-197
lines changed

26 files changed

+1019
-197
lines changed

api/api.descriptors

86 Bytes
Binary file not shown.

api/resource/definitions/runtime/runtime.proto

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ message MetaKeySpec {
6464
string value = 1;
6565
}
6666

67+
// MetaLoadedSpec is the spec for meta loaded. The Done field is always true when resource exists.
68+
message MetaLoadedSpec {
69+
bool done = 1;
70+
}
71+
6772
// MountStatusSpec describes status of the defined sysctls.
6873
message MountStatusSpec {
6974
string source = 1;
@@ -93,6 +98,11 @@ message SecurityStateSpec {
9398
string pcr_signing_key_fingerprint = 3;
9499
}
95100

101+
// UniqueMachineTokenSpec is the spec for the machine unique token. Token can be empty if machine wasn't assigned any.
102+
message UniqueMachineTokenSpec {
103+
string token = 1;
104+
}
105+
96106
// UnmetCondition is a failure which prevents machine from being ready at the stage.
97107
message UnmetCondition {
98108
string name = 1;

cmd/talosctl/cmd/talos/meta.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import (
1313
"github.com/siderolabs/talos/pkg/machinery/client"
1414
)
1515

16+
var metaCmdFlags struct {
17+
insecure bool
18+
}
19+
1620
var metaCmd = &cobra.Command{
1721
Use: "meta",
1822
Short: "Write and delete keys in the META partition",
@@ -26,14 +30,20 @@ var metaWriteCmd = &cobra.Command{
2630
Long: ``,
2731
Args: cobra.ExactArgs(2),
2832
RunE: func(cmd *cobra.Command, args []string) error {
29-
return WithClient(func(ctx context.Context, c *client.Client) error {
33+
fn := func(ctx context.Context, c *client.Client) error {
3034
key, err := strconv.ParseUint(args[0], 0, 8)
3135
if err != nil {
3236
return err
3337
}
3438

3539
return c.MetaWrite(ctx, uint8(key), []byte(args[1]))
36-
})
40+
}
41+
42+
if metaCmdFlags.insecure {
43+
return WithClientMaintenance(nil, fn)
44+
}
45+
46+
return WithClient(fn)
3747
},
3848
}
3949

@@ -43,18 +53,26 @@ var metaDeleteCmd = &cobra.Command{
4353
Long: ``,
4454
Args: cobra.ExactArgs(1),
4555
RunE: func(cmd *cobra.Command, args []string) error {
46-
return WithClient(func(ctx context.Context, c *client.Client) error {
56+
fn := func(ctx context.Context, c *client.Client) error {
4757
key, err := strconv.ParseUint(args[0], 0, 8)
4858
if err != nil {
4959
return err
5060
}
5161

5262
return c.MetaDelete(ctx, uint8(key))
53-
})
63+
}
64+
65+
if metaCmdFlags.insecure {
66+
return WithClientMaintenance(nil, fn)
67+
}
68+
69+
return WithClient(fn)
5470
},
5571
}
5672

5773
func init() {
74+
metaCmd.PersistentFlags().BoolVarP(&metaCmdFlags.insecure, "insecure", "i", false, "write|delete meta using the insecure (encrypted with no auth) maintenance service")
75+
5876
metaCmd.AddCommand(metaWriteCmd)
5977
metaCmd.AddCommand(metaDeleteCmd)
6078
addCommand(metaCmd)

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ require (
117117
github.com/siderolabs/grpc-proxy v0.4.0
118118
github.com/siderolabs/kms-client v0.1.0
119119
github.com/siderolabs/net v0.4.0
120-
github.com/siderolabs/siderolink v0.3.1
120+
github.com/siderolabs/siderolink v0.3.2-0.20231109194336-71dd3084984d
121121
github.com/siderolabs/talos/pkg/machinery v1.6.0-alpha.1
122122
github.com/spf13/cobra v1.8.0
123123
github.com/spf13/pflag v1.0.5
@@ -305,7 +305,7 @@ require (
305305
golang.org/x/oauth2 v0.12.0 // indirect
306306
golang.org/x/tools v0.12.0 // indirect
307307
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
308-
golang.zx2c4.com/wireguard v0.0.0-20230325221338-052af4a8072b // indirect
308+
golang.zx2c4.com/wireguard v0.0.0-20231022001213-2e0774f246fb // indirect
309309
google.golang.org/appengine v1.6.7 // indirect
310310
google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b // indirect
311311
google.golang.org/genproto/googleapis/api v0.0.0-20231012201019-e917dd12ba7a // indirect

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,8 @@ github.com/siderolabs/net v0.4.0 h1:1bOgVay/ijPkJz4qct98nHsiB/ysLQU0KLoBC4qLm7I=
669669
github.com/siderolabs/net v0.4.0/go.mod h1:/ibG+Hm9HU27agp5r9Q3eZicEfjquzNzQNux5uEk0kM=
670670
github.com/siderolabs/protoenc v0.2.0 h1:QFxWIAo//12+/bm27GNYoK/TpQGTYsRrrZCu9jSghvU=
671671
github.com/siderolabs/protoenc v0.2.0/go.mod h1:mu4gc6pJxhdJYpuloacKE4jsJojj87qDXwn8LUvs2bY=
672-
github.com/siderolabs/siderolink v0.3.1 h1:n0pkf7dEhiqX0nfcwWiEqGKoD5CuBRTrWdPBvmvQ8vs=
673-
github.com/siderolabs/siderolink v0.3.1/go.mod h1:LrkE9BoHzfi/m43EQx/Fk6kSal6Uvthu5AtRC3W5GcI=
672+
github.com/siderolabs/siderolink v0.3.2-0.20231109194336-71dd3084984d h1:05OjO5Ue/UGH6Onq9KLJN1VKl3G3EdKvbtLU2yNtl/E=
673+
github.com/siderolabs/siderolink v0.3.2-0.20231109194336-71dd3084984d/go.mod h1:3a+b/jpRwA+iyumrnyP2/VmkMUWr8AHZBo6LEHqx/rU=
674674
github.com/siderolabs/tcpproxy v0.1.0 h1:IbkS9vRhjMOscc1US3M5P1RnsGKFgB6U5IzUk+4WkKA=
675675
github.com/siderolabs/tcpproxy v0.1.0/go.mod h1:onn6CPPj/w1UNqQ0U97oRPF0CqbrgEApYCw4P9IiCW8=
676676
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
@@ -1014,8 +1014,8 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
10141014
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
10151015
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 h1:B82qJJgjvYKsXS9jeunTOisW56dUokqW/FOteYJJ/yg=
10161016
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2/go.mod h1:deeaetjYA+DHMHg+sMSMI58GrEteJUUzzw7en6TJQcI=
1017-
golang.zx2c4.com/wireguard v0.0.0-20230325221338-052af4a8072b h1:J1CaxgLerRR5lgx3wnr6L04cJFbWoceSK9JWBdglINo=
1018-
golang.zx2c4.com/wireguard v0.0.0-20230325221338-052af4a8072b/go.mod h1:tqur9LnfstdR9ep2LaJT4lFUl0EjlHtge+gAjmsHUG4=
1017+
golang.zx2c4.com/wireguard v0.0.0-20231022001213-2e0774f246fb h1:c5tyN8sSp8jSDxdCCDXVOpJwYXXhmTkNMt+g0zTSOic=
1018+
golang.zx2c4.com/wireguard v0.0.0-20231022001213-2e0774f246fb/go.mod h1:tkCQ4FQXmpAgYVh++1cq16/dH4QJtmvpRv19DWGAHSA=
10191019
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20230429144221-925a1e7659e6 h1:CawjfCvYQH2OU3/TnxLx97WDSUDRABfT18pCOYwc2GE=
10201020
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20230429144221-925a1e7659e6/go.mod h1:3rxYc4HtVcSG9gVaTs2GEBdehh+sYPOwKtyUWEOTb80=
10211021
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
@@ -1140,8 +1140,8 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
11401140
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
11411141
gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o=
11421142
gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g=
1143-
gvisor.dev/gvisor v0.0.0-20221203005347-703fd9b7fbc0 h1:Wobr37noukisGxpKo5jAsLREcpj61RxrWYzD8uwveOY=
1144-
gvisor.dev/gvisor v0.0.0-20221203005347-703fd9b7fbc0/go.mod h1:Dn5idtptoW1dIos9U6A2rpebLs/MtTwFacjKb8jLdQA=
1143+
gvisor.dev/gvisor v0.0.0-20230927004350-cbd86285d259 h1:TbRPT0HtzFP3Cno1zZo7yPzEEnfu8EjLfl6IU9VfqkQ=
1144+
gvisor.dev/gvisor v0.0.0-20230927004350-cbd86285d259/go.mod h1:AVgIgHMwK63XvmAzWG9vLQ41YnVHN0du0tEC46fI7yY=
11451145
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
11461146
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
11471147
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

internal/app/machined/pkg/adapters/hardware/system_information.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ type systemInformation struct {
2424
}
2525

2626
// Update current systemInformation info.
27-
func (p systemInformation) Update(systemInformation *smbios.SystemInformation) {
28-
translateSystemInformationInfo := func(in *smbios.SystemInformation) hardware.SystemInformationSpec {
29-
return hardware.SystemInformationSpec{
30-
Manufacturer: in.Manufacturer,
31-
ProductName: in.ProductName,
32-
Version: in.Version,
33-
SerialNumber: in.SerialNumber,
34-
UUID: in.UUID,
35-
WakeUpType: in.WakeUpType.String(),
36-
SKUNumber: in.SKUNumber,
37-
}
27+
func (p systemInformation) Update(systemInformation *smbios.SystemInformation, uuidRewrite string) {
28+
if uuidRewrite == "" {
29+
uuidRewrite = systemInformation.UUID
3830
}
3931

40-
*p.SystemInformation.TypedSpec() = translateSystemInformationInfo(systemInformation)
32+
*p.SystemInformation.TypedSpec() = hardware.SystemInformationSpec{
33+
Manufacturer: systemInformation.Manufacturer,
34+
ProductName: systemInformation.ProductName,
35+
Version: systemInformation.Version,
36+
SerialNumber: systemInformation.SerialNumber,
37+
UUID: uuidRewrite,
38+
WakeUpType: systemInformation.WakeUpType.String(),
39+
SKUNumber: systemInformation.SKUNumber,
40+
}
4141
}

internal/app/machined/pkg/controllers/hardware/hardware_test.go

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,6 @@ func (suite *HardwareSuite) SetupTest() {
4646
suite.Require().NoError(err)
4747
}
4848

49-
func (suite *HardwareSuite) assertResource(md resource.Metadata, check func(res resource.Resource) error) func() error {
50-
return func() error {
51-
r, err := suite.state.Get(suite.ctx, md)
52-
if err != nil {
53-
if state.IsNotFoundError(err) {
54-
return retry.ExpectedError(err)
55-
}
56-
57-
return err
58-
}
59-
60-
return check(r)
61-
}
62-
}
63-
6449
func (suite *HardwareSuite) assertNoResource(md resource.Metadata) func() error {
6550
return func() error {
6651
_, err := suite.state.Get(suite.ctx, md)
@@ -83,3 +68,11 @@ func (suite *HardwareSuite) TearDownTest() {
8368

8469
suite.wg.Wait()
8570
}
71+
72+
func (suite *HardwareSuite) State() state.State {
73+
return suite.state
74+
}
75+
76+
func (suite *HardwareSuite) Ctx() context.Context {
77+
return suite.ctx
78+
}

internal/app/machined/pkg/controllers/hardware/system.go

Lines changed: 76 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ import (
1010
"strings"
1111

1212
"github.com/cosi-project/runtime/pkg/controller"
13-
"github.com/cosi-project/runtime/pkg/resource"
13+
"github.com/cosi-project/runtime/pkg/safe"
14+
"github.com/cosi-project/runtime/pkg/state"
15+
"github.com/siderolabs/gen/optional"
1416
"github.com/siderolabs/go-smbios/smbios"
1517
"go.uber.org/zap"
1618

1719
hwadapter "github.com/siderolabs/talos/internal/app/machined/pkg/adapters/hardware"
1820
runtimetalos "github.com/siderolabs/talos/internal/app/machined/pkg/runtime"
21+
"github.com/siderolabs/talos/internal/pkg/meta"
1922
pkgSMBIOS "github.com/siderolabs/talos/internal/pkg/smbios"
2023
"github.com/siderolabs/talos/pkg/machinery/resources/hardware"
24+
"github.com/siderolabs/talos/pkg/machinery/resources/runtime"
2125
)
2226

2327
// SystemInfoController populates CPU information of the underlying hardware.
@@ -33,7 +37,19 @@ func (ctrl *SystemInfoController) Name() string {
3337

3438
// Inputs implements controller.Controller interface.
3539
func (ctrl *SystemInfoController) Inputs() []controller.Input {
36-
return nil
40+
return []controller.Input{
41+
{
42+
Namespace: runtime.NamespaceName,
43+
Type: runtime.MetaKeyType,
44+
Kind: controller.InputWeak,
45+
},
46+
{
47+
Namespace: runtime.NamespaceName,
48+
Type: runtime.MetaLoadedType,
49+
ID: optional.Some(runtime.MetaLoadedID),
50+
Kind: controller.InputWeak,
51+
},
52+
}
3753
}
3854

3955
// Outputs implements controller.Controller interface.
@@ -58,59 +74,83 @@ func (ctrl *SystemInfoController) Outputs() []controller.Output {
5874
//
5975
//nolint:gocyclo
6076
func (ctrl *SystemInfoController) Run(ctx context.Context, r controller.Runtime, logger *zap.Logger) error {
61-
select {
62-
case <-ctx.Done():
63-
return nil
64-
case <-r.EventCh():
65-
}
66-
6777
// smbios info is not available inside container, so skip the controller
6878
if ctrl.V1Alpha1Mode == runtimetalos.ModeContainer {
6979
return nil
7080
}
71-
// controller runs only once
72-
if ctrl.SMBIOS == nil {
73-
s, err := pkgSMBIOS.GetSMBIOSInfo()
81+
82+
for {
83+
select {
84+
case <-ctx.Done():
85+
return nil
86+
case <-r.EventCh():
87+
}
88+
89+
_, err := safe.ReaderGetByID[*runtime.MetaLoaded](ctx, r, runtime.MetaLoadedID)
7490
if err != nil {
75-
return err
91+
if state.IsNotFoundError(err) {
92+
continue
93+
}
94+
95+
return fmt.Errorf("error getting meta loaded resource: %w", err)
7696
}
7797

78-
ctrl.SMBIOS = s
79-
}
98+
if ctrl.SMBIOS == nil {
99+
var s *smbios.SMBIOS
80100

81-
if err := r.Modify(ctx, hardware.NewSystemInformation(hardware.SystemInformationID), func(res resource.Resource) error {
82-
hwadapter.SystemInformation(res.(*hardware.SystemInformation)).Update(&ctrl.SMBIOS.SystemInformation)
101+
s, err = pkgSMBIOS.GetSMBIOSInfo()
102+
if err != nil {
103+
return err
104+
}
83105

84-
return nil
85-
}); err != nil {
86-
return fmt.Errorf("error updating objects: %w", err)
87-
}
106+
ctrl.SMBIOS = s
107+
}
108+
109+
uuidRewriteRes, err := safe.ReaderGetByID[*runtime.MetaKey](ctx, r, runtime.MetaKeyTagToID(meta.UUIDOverride))
110+
if err != nil && !state.IsNotFoundError(err) {
111+
return fmt.Errorf("error getting meta key resource: %w", err)
112+
}
113+
114+
var uuidRewrite string
88115

89-
for _, p := range ctrl.SMBIOS.ProcessorInformation {
90-
// replaces `CPU 0` with `CPU-0`
91-
id := strings.ReplaceAll(p.SocketDesignation, " ", "-")
116+
if uuidRewriteRes != nil && uuidRewriteRes.TypedSpec().Value != "" {
117+
uuidRewrite = uuidRewriteRes.TypedSpec().Value
92118

93-
if err := r.Modify(ctx, hardware.NewProcessorInfo(id), func(res resource.Resource) error {
94-
hwadapter.Processor(res.(*hardware.Processor)).Update(&p)
119+
logger.Info("using UUID rewrite", zap.String("uuid", uuidRewrite))
120+
}
121+
122+
if err := safe.WriterModify(ctx, r, hardware.NewSystemInformation(hardware.SystemInformationID), func(res *hardware.SystemInformation) error {
123+
hwadapter.SystemInformation(res).Update(&ctrl.SMBIOS.SystemInformation, uuidRewrite)
95124

96125
return nil
97126
}); err != nil {
98127
return fmt.Errorf("error updating objects: %w", err)
99128
}
100-
}
101129

102-
for _, m := range ctrl.SMBIOS.MemoryDevices {
103-
// replaces `SIMM 0` with `SIMM-0`
104-
id := strings.ReplaceAll(m.DeviceLocator, " ", "-")
130+
for _, p := range ctrl.SMBIOS.ProcessorInformation {
131+
// replaces `CPU 0` with `CPU-0`
132+
id := strings.ReplaceAll(p.SocketDesignation, " ", "-")
105133

106-
if err := r.Modify(ctx, hardware.NewMemoryModuleInfo(id), func(res resource.Resource) error {
107-
hwadapter.MemoryModule(res.(*hardware.MemoryModule)).Update(&m)
134+
if err := safe.WriterModify(ctx, r, hardware.NewProcessorInfo(id), func(res *hardware.Processor) error {
135+
hwadapter.Processor(res).Update(&p)
108136

109-
return nil
110-
}); err != nil {
111-
return fmt.Errorf("error updating objects: %w", err)
137+
return nil
138+
}); err != nil {
139+
return fmt.Errorf("error updating objects: %w", err)
140+
}
112141
}
113-
}
114142

115-
return nil
143+
for _, m := range ctrl.SMBIOS.MemoryDevices {
144+
// replaces `SIMM 0` with `SIMM-0`
145+
id := strings.ReplaceAll(m.DeviceLocator, " ", "-")
146+
147+
if err := safe.WriterModify(ctx, r, hardware.NewMemoryModuleInfo(id), func(res *hardware.MemoryModule) error {
148+
hwadapter.MemoryModule(res).Update(&m)
149+
150+
return nil
151+
}); err != nil {
152+
return fmt.Errorf("error updating objects: %w", err)
153+
}
154+
}
155+
}
116156
}

0 commit comments

Comments
 (0)