跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

cidata.go

649 行 · 19.9 KB历史下载
1// SPDX-FileCopyrightText: Copyright The Lima Authors
2// SPDX-License-Identifier: Apache-2.0
3
4package cidata
5
6import (
7 "compress/gzip"
8 "context"
9 "errors"
10 "fmt"
11 "io"
12 "maps"
13 "net"
14 "net/url"
15 "os"
16 "path"
17 "path/filepath"
18 "slices"
19 "strconv"
20 "strings"
21 "time"
22
23 "github.com/docker/go-units"
24 "github.com/sirupsen/logrus"
25
26 "github.com/lima-vm/lima/v2/pkg/debugutil"
27 "github.com/lima-vm/lima/v2/pkg/driver"
28 "github.com/lima-vm/lima/v2/pkg/instance/hostname"
29 "github.com/lima-vm/lima/v2/pkg/iso9660util"
30 "github.com/lima-vm/lima/v2/pkg/limatype"
31 "github.com/lima-vm/lima/v2/pkg/limatype/filenames"
32 "github.com/lima-vm/lima/v2/pkg/limayaml"
33 "github.com/lima-vm/lima/v2/pkg/localpathutil"
34 "github.com/lima-vm/lima/v2/pkg/networks"
35 "github.com/lima-vm/lima/v2/pkg/networks/usernet"
36 "github.com/lima-vm/lima/v2/pkg/osutil"
37 "github.com/lima-vm/lima/v2/pkg/sshutil"
38 "github.com/lima-vm/lima/v2/pkg/strutil"
39)
40
41var netLookupIP = func(host string) []net.IP {
42 ips, err := net.LookupIP(host)
43 if err != nil {
44 logrus.Debugf("net.LookupIP %s: %s", host, err)
45 return nil
46 }
47
48 return ips
49}
50
51func setupEnv(instConfigEnv map[string]string, propagateProxyEnv bool, slirpGateway string) (map[string]string, error) {
52 // Start with the proxy variables from the system settings.
53 env, err := osutil.ProxySettings()
54 if err != nil {
55 return env, err
56 }
57 // env.* settings from lima.yaml override system settings without giving a warning
58 maps.Copy(env, instConfigEnv)
59 // Current process environment setting override both system settings and env.*
60 lowerVars := []string{"ftp_proxy", "http_proxy", "https_proxy", "no_proxy"}
61 upperVars := make([]string, len(lowerVars))
62 for i, name := range lowerVars {
63 upperVars[i] = strings.ToUpper(name)
64 }
65 if propagateProxyEnv {
66 for _, name := range append(lowerVars, upperVars...) {
67 if value, ok := os.LookupEnv(name); ok {
68 if _, ok := env[name]; ok && value != env[name] {
69 logrus.Infof("Overriding %#q value %#q with %#q from limactl process environment",
70 name, env[name], value)
71 }
72 env[name] = value
73 }
74 }
75 }
76 // Replace IP that IsLoopback in proxy settings with the gateway address
77 // Delete settings with empty values, so the user can choose to ignore system settings.
78 for _, name := range append(lowerVars, upperVars...) {
79 value, ok := env[name]
80 if ok && value == "" {
81 delete(env, name)
82 } else if ok && !strings.EqualFold(name, "no_proxy") {
83 u, err := url.Parse(value)
84 if err != nil {
85 logrus.Warnf("Ignoring invalid proxy %#q=%v: %s", name, value, err)
86 continue
87 }
88
89 for _, ip := range netLookupIP(u.Hostname()) {
90 if ip.IsLoopback() {
91 newHost := slirpGateway
92 if u.Port() != "" {
93 newHost = net.JoinHostPort(newHost, u.Port())
94 }
95 u.Host = newHost
96 value = u.String()
97 }
98 }
99 if value != env[name] {
100 logrus.Infof("Replacing %#q value %#q with %#q", name, env[name], value)
101 env[name] = value
102 }
103 }
104 }
105 // Make sure uppercase variants have the same value as lowercase ones.
106 // If both are set, the lowercase variant value takes precedence.
107 for _, lowerName := range lowerVars {
108 upperName := strings.ToUpper(lowerName)
109 if _, ok := env[lowerName]; ok {
110 if _, ok := env[upperName]; ok && env[lowerName] != env[upperName] {
111 logrus.Warnf("Changing %#q value from %#q to %#q to match %#q",
112 upperName, env[upperName], env[lowerName], lowerName)
113 }
114 env[upperName] = env[lowerName]
115 } else if _, ok := env[upperName]; ok {
116 env[lowerName] = env[upperName]
117 }
118 }
119 return env, nil
120}
121
122func templateArgs(ctx context.Context, bootScripts bool, instDir, name string, instConfig *limatype.LimaYAML, udpDNSLocalPort, tcpDNSLocalPort, vsockPort int, virtioPort string, noCloudInit, rosettaEnabled, rosettaBinFmt bool) (*TemplateArgs, error) {
123 if err := limayaml.Validate(instConfig, false); err != nil {
124 return nil, err
125 }
126 archive := "nerdctl-full.tgz"
127 var darwinOpts limatype.DarwinOpts
128 if *instConfig.OS == limatype.DARWIN {
129 if err := limayaml.Convert(instConfig.OsOpts[limatype.DARWIN], &darwinOpts, "osOpts.Darwin"); err != nil {
130 return nil, err
131 }
132 }
133 var suppressFirstLoginSetupPlist string
134 if darwinOpts.SuppressFirstLoginSetupPlist != nil {
135 suppressFirstLoginSetupPlist = *darwinOpts.SuppressFirstLoginSetupPlist
136 }
137 args := TemplateArgs{
138 Debug: debugutil.Debug,
139 OS: *instConfig.OS,
140 Arch: *instConfig.Arch,
141 BootScripts: bootScripts,
142 Name: name,
143 Hostname: hostname.FromInstName(name), // TODO: support customization
144 User: *instConfig.User.Name,
145 Comment: strutil.RemoveControlChars(*instConfig.User.Comment),
146 Home: *instConfig.User.Home,
147 Shell: *instConfig.User.Shell,
148 UID: *instConfig.User.UID,
149 PasswordlessSudo: *instConfig.User.PasswordlessSudo,
150 GuestInstallPrefix: *instConfig.GuestInstallPrefix,
151 UpgradePackages: *instConfig.UpgradePackages,
152 Containerd: Containerd{System: *instConfig.Containerd.System, User: *instConfig.Containerd.User, Archive: archive},
153 SlirpNICName: networks.SlirpNICName,
154
155 VMType: *instConfig.VMType,
156 VSockPort: vsockPort,
157 VirtioPort: virtioPort,
158 RosettaEnabled: rosettaEnabled,
159 RosettaBinFmt: rosettaBinFmt,
160 Plain: *instConfig.Plain,
161 TimeZone: *instConfig.TimeZone,
162 NoCloudInit: noCloudInit,
163 Param: instConfig.Param,
164 LegacyBIOS: *instConfig.Firmware.LegacyBIOS,
165 TPM: *instConfig.TPM,
166
167 SuppressFirstLoginSetup: darwinOpts.SuppressFirstLoginSetup != nil && *darwinOpts.SuppressFirstLoginSetup,
168 SuppressFirstLoginSetupPlist: suppressFirstLoginSetupPlist,
169 }
170
171 firstUsernetIndex := limayaml.FirstUsernetIndex(instConfig)
172 var subnet net.IP
173 var err error
174
175 if firstUsernetIndex != -1 {
176 usernetName := instConfig.Networks[firstUsernetIndex].Lima
177 subnet, err = usernet.Subnet(usernetName)
178 if err != nil {
179 return nil, err
180 }
181 args.SlirpGateway = usernet.GatewayIP(subnet)
182 args.SlirpDNS = usernet.GatewayIP(subnet)
183 } else {
184 subnet, _, err = net.ParseCIDR(networks.SlirpNetwork)
185 if err != nil {
186 return nil, err
187 }
188 args.SlirpGateway = usernet.GatewayIP(subnet)
189 // QEMU too has its own gvisor netstack (startUsernet), whose gateway
190 // answers DNS.
191 if *instConfig.VMType == limatype.VZ || *instConfig.VMType == limatype.QEMU {
192 args.SlirpDNS = usernet.GatewayIP(subnet)
193 } else {
194 args.SlirpDNS = usernet.DNSIP(subnet)
195 }
196 args.SlirpIPAddress = networks.SlirpIPAddress
197 }
198
199 // change instance id on every boot so network config will be processed again
200 args.IID = fmt.Sprintf("iid-%d", time.Now().Unix())
201
202 pubKeys, err := sshutil.DefaultPubKeys(ctx, *instConfig.SSH.LoadDotSSHPubKeys)
203 if err != nil {
204 return nil, err
205 }
206 if len(pubKeys) == 0 {
207 return nil, errors.New("no SSH key was found, run `ssh-keygen`")
208 }
209 for _, f := range pubKeys {
210 args.SSHPubKeys = append(args.SSHPubKeys, f.Content)
211 }
212
213 var fstype string
214 switch *instConfig.MountType {
215 case limatype.REVSSHFS:
216 fstype = "sshfs"
217 case limatype.NINEP:
218 fstype = "9p"
219 if *instConfig.OS == limatype.FREEBSD {
220 fstype = "p9fs"
221 }
222 case limatype.VIRTIOFS:
223 fstype = "virtiofs"
224 }
225 hostHome, err := localpathutil.Expand("~")
226 if err != nil {
227 return nil, err
228 }
229 for _, f := range instConfig.Mounts {
230 tag := limayaml.MountTag(f.Location, *f.MountPoint)
231 options := "rw"
232 if *instConfig.OS == limatype.LINUX {
233 options = "defaults"
234 }
235 switch fstype {
236 case "9p", "p9fs", "virtiofs":
237 options = "ro"
238 if *f.Writable {
239 options = "rw"
240 }
241 if fstype == "9p" {
242 options += ",trans=virtio"
243 options += fmt.Sprintf(",version=%s", *f.NineP.ProtocolVersion)
244 msize, err := units.RAMInBytes(*f.NineP.Msize)
245 if err != nil {
246 return nil, fmt.Errorf("failed to parse msize for %#q: %w", f.Location, err)
247 }
248 options += fmt.Sprintf(",msize=%d", msize)
249 options += fmt.Sprintf(",cache=%s", *f.NineP.Cache)
250 }
251 // don't fail the boot, if virtfs is not available
252 switch *instConfig.OS {
253 case limatype.LINUX:
254 options += ",nofail"
255 case limatype.FREEBSD:
256 options += ",failok"
257 }
258 }
259 args.Mounts = append(args.Mounts, Mount{Tag: tag, MountPoint: *f.MountPoint, Type: fstype, Options: options})
260 if f.Location == hostHome {
261 args.HostHomeMountPoint = *f.MountPoint
262 }
263 }
264
265 switch *instConfig.MountType {
266 case limatype.REVSSHFS:
267 args.MountType = "reverse-sshfs"
268 case limatype.NINEP:
269 args.MountType = "9p"
270 case limatype.VIRTIOFS:
271 args.MountType = "virtiofs"
272 }
273
274 for i, d := range instConfig.AdditionalDisks {
275 format := true
276 if d.Format != nil {
277 format = *d.Format
278 }
279 fstype := ""
280 if d.FSType != nil {
281 fstype = *d.FSType
282 }
283 args.Disks = append(args.Disks, Disk{
284 Name: d.Name,
285 Device: diskDeviceNameFromOrder(i),
286 Format: format,
287 FSType: fstype,
288 FSArgs: d.FSArgs,
289 })
290 }
291
292 args.Networks = append(args.Networks, Network{MACAddress: limayaml.MACAddress(instDir), Interface: networks.SlirpNICName, Metric: 200})
293 for i, nw := range instConfig.Networks {
294 if i == firstUsernetIndex {
295 continue
296 }
297 args.Networks = append(args.Networks, Network{MACAddress: nw.MACAddress, Interface: nw.Interface, Metric: *nw.Metric})
298 }
299
300 args.Env, err = setupEnv(instConfig.Env, *instConfig.PropagateProxyEnv, args.SlirpGateway)
301 if err != nil {
302 return nil, err
303 }
304
305 switch {
306 case len(instConfig.DNS) > 0:
307 for _, addr := range instConfig.DNS {
308 args.DNSAddresses = append(args.DNSAddresses, addr.String())
309 }
310 case firstUsernetIndex != -1 || *instConfig.VMType == limatype.VZ:
311 args.DNSAddresses = append(args.DNSAddresses, args.SlirpDNS)
312 case limayaml.HostResolverEnabled(instConfig):
313 args.UDPDNSLocalPort = udpDNSLocalPort
314 args.TCPDNSLocalPort = tcpDNSLocalPort
315 args.DNSAddresses = append(args.DNSAddresses, args.SlirpDNS)
316 default:
317 args.DNSAddresses, err = osutil.DNSAddresses()
318 if err != nil {
319 return nil, err
320 }
321 }
322
323 args.CACerts.RemoveDefaults = instConfig.CACertificates.RemoveDefaults
324
325 for _, path := range instConfig.CACertificates.Files {
326 expanded, err := localpathutil.Expand(path)
327 if err != nil {
328 return nil, err
329 }
330
331 content, err := os.ReadFile(expanded)
332 if err != nil {
333 return nil, err
334 }
335
336 cert := getCert(string(content))
337 args.CACerts.Trusted = append(args.CACerts.Trusted, cert)
338 }
339
340 for _, content := range instConfig.CACertificates.Certs {
341 cert := getCert(content)
342 args.CACerts.Trusted = append(args.CACerts.Trusted, cert)
343 }
344
345 // Remove empty caCerts (default values) from configuration yaml
346 if !*args.CACerts.RemoveDefaults && len(args.CACerts.Trusted) == 0 {
347 args.CACerts.RemoveDefaults = nil
348 args.CACerts.Trusted = nil
349 }
350
351 args.BootCmds = getBootCmds(instConfig.Provision)
352
353 for i, f := range instConfig.Provision {
354 if f.Mode == limatype.ProvisionModeDependency && *f.SkipDefaultDependencyResolution {
355 args.SkipDefaultDependencyResolution = true
356 }
357 if f.Mode == limatype.ProvisionModeData {
358 args.DataFiles = append(args.DataFiles, DataFile{
359 FileName: fmt.Sprintf("%08d", i),
360 Overwrite: strconv.FormatBool(*f.Overwrite),
361 Owner: *f.Owner,
362 Path: *f.Path,
363 Permissions: *f.Permissions,
364 })
365 }
366 if f.Mode == limatype.ProvisionModeYQ {
367 args.YQProvisions = append(args.YQProvisions, YQProvision{
368 FileName: fmt.Sprintf("%08d", i),
369 Format: *f.Format,
370 Owner: *f.Owner,
371 Path: *f.Path,
372 Permissions: *f.Permissions,
373 })
374 }
375 }
376
377 return &args, nil
378}
379
380func GenerateCloudConfig(ctx context.Context, instDir, name string, instConfig *limatype.LimaYAML) error {
381 // If VM type is Windows, delete existing cloud config file because cloud-config is not supported.
382 if instConfig.OS != nil && *instConfig.OS == limatype.WINDOWS {
383 if err := os.Remove(filepath.Join(instDir, filenames.CloudConfig)); err != nil && !errors.Is(err, os.ErrNotExist) {
384 return err
385 }
386 return nil
387 }
388
389 args, err := templateArgs(ctx, false, instDir, name, instConfig, 0, 0, 0, "", false, false, false)
390 if err != nil {
391 return err
392 }
393 // mounts are not included here
394 args.Mounts = nil
395 // resolv_conf is not included here
396 args.DNSAddresses = nil
397
398 if err := ValidateTemplateArgs(args); err != nil {
399 return err
400 }
401
402 config, err := ExecuteTemplateCloudConfig(args)
403 if err != nil {
404 return err
405 }
406
407 os.RemoveAll(filepath.Join(instDir, filenames.CloudConfig)) // delete existing
408 return os.WriteFile(filepath.Join(instDir, filenames.CloudConfig), config, 0o444)
409}
410
411// GenerateISO9660 generates the cidata ISO9660 image (or directory, for noCloudInit)
412// in instDir. It returns the instance ID, which changes on every boot.
413func GenerateISO9660(ctx context.Context, drv driver.Driver, instDir, name string, instConfig *limatype.LimaYAML, udpDNSLocalPort, tcpDNSLocalPort int, guestAgentBinary, nerdctlArchive string, vsockPort int, virtioPort string, noCloudInit, rosettaEnabled, rosettaBinFmt bool) (string, error) {
414 args, err := templateArgs(ctx, true, instDir, name, instConfig, udpDNSLocalPort, tcpDNSLocalPort, vsockPort, virtioPort, noCloudInit, rosettaEnabled, rosettaBinFmt)
415 if err != nil {
416 return "", err
417 }
418
419 if err := ValidateTemplateArgs(args); err != nil {
420 return "", err
421 }
422
423 layout, err := ExecuteTemplateCIDataISO(args)
424 if err != nil {
425 return "", err
426 }
427
428 if args.SuppressFirstLoginSetup {
429 // Presence of this file (not any cloud-config key) is what tells the guest-side
430 // fakecloudinit to suppress first-login setup; an empty file means "use the
431 // guest's built-in plist template" rather than the content of this file.
432 layout = append(layout, iso9660util.Entry{
433 Path: "setup-assistant.plist",
434 Reader: strings.NewReader(args.SuppressFirstLoginSetupPlist),
435 })
436 }
437
438 driverScripts, err := drv.BootScripts(ctx)
439 if err != nil {
440 return "", fmt.Errorf("failed to get boot scripts: %w", err)
441 }
442
443 for filename, content := range driverScripts {
444 layoutPath := path.Join("boot.Linux", filename)
445 if strings.Contains(filename, "/") {
446 // When the filename contains a slash, it must be in the format of "boot.<OS>/<SCRIPT>"
447 if !strings.HasPrefix(filename, "boot.") || strings.Count(filename, "/") != 1 {
448 return "", fmt.Errorf("invalid boot script filename %#q: must be in format 'boot.<OS>/<SCRIPT>'", filename)
449 }
450 layoutPath = filename
451 } else {
452 logrus.Warnf("Boot script filename %#q does not contain '/', treating it as a script for Linux and prefixing with 'boot.Linux/'", filename)
453 }
454 layout = append(layout, iso9660util.Entry{
455 Path: layoutPath,
456 Reader: strings.NewReader(string(content)),
457 })
458 }
459
460 layout, err = appendProvisionEntries(layout, instConfig.Provision)
461 if err != nil {
462 return "", err
463 }
464
465 if guestAgentBinary != "" {
466 var guestAgent io.ReadCloser
467 if strings.HasSuffix(guestAgentBinary, ".gz") {
468 logrus.Debugf("Decompressing %s", guestAgentBinary)
469 guestAgentGz, err := os.Open(guestAgentBinary)
470 if err != nil {
471 return "", err
472 }
473 defer guestAgentGz.Close()
474 guestAgent, err = gzip.NewReader(guestAgentGz)
475 if err != nil {
476 return "", err
477 }
478 } else {
479 guestAgent, err = os.Open(guestAgentBinary)
480 if err != nil {
481 return "", err
482 }
483 }
484
485 defer guestAgent.Close()
486 layout = append(layout, iso9660util.Entry{
487 Path: "lima-guestagent",
488 Reader: guestAgent,
489 })
490 }
491
492 if nerdctlArchive != "" {
493 nftgz := args.Containerd.Archive
494 nftgzR, err := os.Open(nerdctlArchive)
495 if err != nil {
496 return "", err
497 }
498 defer nftgzR.Close()
499 layout = append(layout, iso9660util.Entry{
500 // ISO9660 requires len(Path) <= 30
501 Path: nftgz,
502 Reader: nftgzR,
503 })
504 }
505
506 if noCloudInit {
507 layout = append(layout, iso9660util.Entry{
508 Path: "ssh_authorized_keys",
509 Reader: strings.NewReader(strings.Join(args.SSHPubKeys, "\n")),
510 })
511 return args.IID, writeCIDataDir(filepath.Join(instDir, filenames.CIDataISODir), layout)
512 }
513
514 var iso9660Options []iso9660util.WriteOpt
515 switch *instConfig.OS {
516 case limatype.DARWIN, limatype.FREEBSD:
517 // Darwin: Without Joliet, all the file names will be in upper case, and the hiphen will be replaced with underscore
518 // FreeBSD: Without Joliet, the files are not executable
519 iso9660Options = append(iso9660Options, iso9660util.WithJoliet())
520 }
521 return args.IID, iso9660util.Write(filepath.Join(instDir, filenames.CIDataISO), "cidata", layout, iso9660Options...)
522}
523
524func getCert(content string) Cert {
525 lines := []string{}
526 for line := range strings.SplitSeq(content, "\n") {
527 if line == "" {
528 continue
529 }
530 lines = append(lines, strings.TrimSpace(line))
531 }
532 // return lines
533 return Cert{Lines: lines}
534}
535
536func getBootCmds(p []limatype.Provision) []BootCmds {
537 var bootCmds []BootCmds
538 for _, f := range p {
539 if f.Mode == limatype.ProvisionModeBoot {
540 bootCmds = append(bootCmds, BootCmds{Lines: strings.Split(*f.Script, "\n")})
541 }
542 }
543 return bootCmds
544}
545
546func diskDeviceNameFromOrder(order int) string {
547 return fmt.Sprintf("vd%c", int('b')+order)
548}
549
550func writeCIDataDir(rootPath string, layout []iso9660util.Entry) error {
551 slices.SortFunc(layout, func(a, b iso9660util.Entry) int {
552 return strings.Compare(strings.ToLower(a.Path), strings.ToLower(b.Path))
553 })
554
555 if err := os.RemoveAll(rootPath); err != nil {
556 return err
557 }
558
559 for _, e := range layout {
560 if dir := path.Dir(e.Path); dir != "" && dir != "/" {
561 if err := os.MkdirAll(filepath.Join(rootPath, dir), 0o700); err != nil {
562 return err
563 }
564 }
565 f, err := os.OpenFile(filepath.Join(rootPath, e.Path), os.O_CREATE|os.O_RDWR, 0o700)
566 if err != nil {
567 return err
568 }
569 if _, err := io.Copy(f, e.Reader); err != nil {
570 _ = f.Close()
571 return err
572 }
573 _ = f.Close()
574 }
575
576 return nil
577}
578
579func appendProvisionEntries(layout []iso9660util.Entry, provisions []limatype.Provision) ([]iso9660util.Entry, error) {
580 for i, f := range provisions {
581 switch f.Mode {
582 case limatype.ProvisionModeSystem, limatype.ProvisionModeUser, limatype.ProvisionModeDependency:
583 layout = append(layout, iso9660util.Entry{
584 Path: fmt.Sprintf("provision.%s/%08d", f.Mode, i),
585 Reader: strings.NewReader(*f.Script),
586 })
587 // Boot commands are not treated as script files in cidata.iso.
588 // Instead of that, they are stored in TemplateArgs.BootCmds then embedded in bootCmd field in user-data.
589 // For Windows VM, there is no boot step where we can run commands.
590 case limatype.ProvisionModeBoot:
591 continue
592 case limatype.ProvisionModeData:
593 layout = append(layout, iso9660util.Entry{
594 Path: fmt.Sprintf("provision.%s/%08d", f.Mode, i),
595 Reader: strings.NewReader(*f.Content),
596 })
597 case limatype.ProvisionModeYQ:
598 layout = append(layout, iso9660util.Entry{
599 Path: fmt.Sprintf("provision.%s/%08d", f.Mode, i),
600 Reader: strings.NewReader(*f.Expression),
601 })
602 case limatype.ProvisionModeAnsible:
603 continue
604 default:
605 return nil, fmt.Errorf("unknown provision mode %#q", f.Mode)
606 }
607 }
608
609 return layout, nil
610}
611
612func GenerateWindowsISO(ctx context.Context, instDir, name string, instConfig *limatype.LimaYAML, udpDNSLocalPort, tcpDNSLocalPort, vsockPort int, virtioPort string, noCloudInit, rosettaEnabled, rosettaBinFmt bool) (string, error) {
613 args, err := templateArgs(ctx, true, instDir, name, instConfig, udpDNSLocalPort, tcpDNSLocalPort, vsockPort, virtioPort, noCloudInit, rosettaEnabled, rosettaBinFmt)
614 if err != nil {
615 return "", err
616 }
617
618 if err := ValidateTemplateArgs(args); err != nil {
619 return "", err
620 }
621
622 // The generated password is used only for an initial setup.
623 // After that, the password is overwritten.
624 if err := args.generateWindowsInitialPassword(); err != nil {
625 return "", err
626 }
627
628 // Check OS version (Windows 11 or server 2025). This differentiates autounattend.xml.
629 if err := args.checkWindowsVersion(instDir); err != nil {
630 return "", err
631 }
632
633 layout, err := ExecuteTemplateWindowsISO(args)
634 if err != nil {
635 return "", fmt.Errorf("failed to create Windows ISO entries: %w", err)
636 }
637
638 layout, err = appendProvisionEntries(layout, instConfig.Provision)
639 if err != nil {
640 return "", err
641 }
642
643 layout = append(layout, iso9660util.Entry{
644 Path: "ssh_authorized_keys",
645 Reader: strings.NewReader(strings.Join(args.SSHPubKeys, "\n")),
646 })
647
648 return args.IID, iso9660util.Write(filepath.Join(instDir, filenames.CIDataISO), "autounattend", layout, iso9660util.WithJoliet())
649}