Skip to content

Commit 7e09916

Browse files
fix: add ACL-specific butane config with first-boot service workaround (#8447)
1 parent f5d1d88 commit 7e09916

5 files changed

Lines changed: 104 additions & 25 deletions

File tree

parts/linux/cloud-init/acl.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
variant: flatcar
2+
version: 1.1.0
3+
systemd:
4+
units:
5+
- name: ignition-bootcmds.service
6+
enabled: true
7+
contents: |
8+
[Unit]
9+
Description=Ignition Early Boot Commands
10+
DefaultDependencies=no
11+
After=local-fs.target
12+
Before=sysinit.target
13+
ConditionPathExists=/etc/ignition-bootcmds.sh
14+
15+
[Service]
16+
Type=oneshot
17+
ExecStart=-/etc/ignition-bootcmds.sh
18+
19+
[Install]
20+
WantedBy=sysinit.target
21+
22+
- name: ignition-file-extract.service
23+
enabled: true
24+
contents: |
25+
[Unit]
26+
Description=Extract Ignition file payload
27+
DefaultDependencies=no
28+
After=local-fs.target
29+
Before=sysinit.target ignition-bootcmds.service
30+
ConditionPathExists=/var/lib/ignition/ignition-files.tar
31+
32+
[Service]
33+
Type=oneshot
34+
ExecStart=tar -xvf /var/lib/ignition/ignition-files.tar -C /
35+
ExecStart=rm -f /var/lib/ignition/ignition-files.tar
36+
ExecStart=systemctl daemon-reload
37+
RemainAfterExit=yes
38+
39+
[Install]
40+
WantedBy=sysinit.target
41+
42+
# Workaround for ACL (Azure Container Linux):
43+
# After VHD build, /etc/machine-id is empty (not absent). systemd only
44+
# triggers ConditionFirstBoot=yes when machine-id is missing, so enabled
45+
# services like these don't start on first boot. On Flatcar, waagent's
46+
# CoreOS deprovisioning happens to remove machine-id, avoiding this issue.
47+
# Explicit symlinks ensure these services start regardless of first-boot state.
48+
storage:
49+
links:
50+
- path: /etc/systemd/system/sysinit.target.wants/ignition-bootcmds.service
51+
target: /etc/systemd/system/ignition-bootcmds.service
52+
overwrite: true
53+
- path: /etc/systemd/system/sysinit.target.wants/ignition-file-extract.service
54+
target: /etc/systemd/system/ignition-file-extract.service
55+
overwrite: true

parts/linux/cloud-init/nodecustomdata.yml

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,34 +34,34 @@ write_files:
3434
{{GetVariableProperty "cloudInitData" "provisionSource"}}
3535

3636

37-
{{if IsAzlOSGuard}}
37+
{{if IsACL }}
3838
- path: {{GetCSEHelpersScriptDistroFilepath}}
3939
permissions: "0744"
4040
encoding: gzip
4141
owner: root
4242
content: !!binary |
43-
{{GetVariableProperty "cloudInitData" "provisionSourceAzlOSGuard"}}
44-
{{- else if IsMariner}}
43+
{{GetVariableProperty "cloudInitData" "provisionSourceACL"}}
44+
{{- else if IsAzlOSGuard}}
4545
- path: {{GetCSEHelpersScriptDistroFilepath}}
4646
permissions: "0744"
4747
encoding: gzip
4848
owner: root
4949
content: !!binary |
50-
{{GetVariableProperty "cloudInitData" "provisionSourceMariner"}}
51-
{{- else if IsFlatcar }}
50+
{{GetVariableProperty "cloudInitData" "provisionSourceAzlOSGuard"}}
51+
{{- else if IsMariner}}
5252
- path: {{GetCSEHelpersScriptDistroFilepath}}
5353
permissions: "0744"
5454
encoding: gzip
5555
owner: root
5656
content: !!binary |
57-
{{GetVariableProperty "cloudInitData" "provisionSourceFlatcar"}}
58-
{{- else if IsACL }}
57+
{{GetVariableProperty "cloudInitData" "provisionSourceMariner"}}
58+
{{- else if IsFlatcar }}
5959
- path: {{GetCSEHelpersScriptDistroFilepath}}
6060
permissions: "0744"
6161
encoding: gzip
6262
owner: root
6363
content: !!binary |
64-
{{GetVariableProperty "cloudInitData" "provisionSourceACL"}}
64+
{{GetVariableProperty "cloudInitData" "provisionSourceFlatcar"}}
6565
{{- else }}
6666
- path: {{GetCSEHelpersScriptDistroFilepath}}
6767
permissions: "0744"
@@ -108,34 +108,34 @@ write_files:
108108
content: !!binary |
109109
{{GetVariableProperty "cloudInitData" "provisionSendLogs"}}
110110

111-
{{if IsAzlOSGuard}}
111+
{{if IsACL }}
112112
- path: {{GetCSEInstallScriptDistroFilepath}}
113113
permissions: "0744"
114114
encoding: gzip
115115
owner: root
116116
content: !!binary |
117-
{{GetVariableProperty "cloudInitData" "provisionInstallsAzlOSGuard"}}
118-
{{- else if IsMariner}}
117+
{{GetVariableProperty "cloudInitData" "provisionInstallsACL"}}
118+
{{- else if IsAzlOSGuard}}
119119
- path: {{GetCSEInstallScriptDistroFilepath}}
120120
permissions: "0744"
121121
encoding: gzip
122122
owner: root
123123
content: !!binary |
124-
{{GetVariableProperty "cloudInitData" "provisionInstallsMariner"}}
125-
{{- else if IsFlatcar }}
124+
{{GetVariableProperty "cloudInitData" "provisionInstallsAzlOSGuard"}}
125+
{{- else if IsMariner}}
126126
- path: {{GetCSEInstallScriptDistroFilepath}}
127127
permissions: "0744"
128128
encoding: gzip
129129
owner: root
130130
content: !!binary |
131-
{{GetVariableProperty "cloudInitData" "provisionInstallsFlatcar"}}
132-
{{- else if IsACL }}
131+
{{GetVariableProperty "cloudInitData" "provisionInstallsMariner"}}
132+
{{- else if IsFlatcar }}
133133
- path: {{GetCSEInstallScriptDistroFilepath}}
134134
permissions: "0744"
135135
encoding: gzip
136136
owner: root
137137
content: !!binary |
138-
{{GetVariableProperty "cloudInitData" "provisionInstallsACL"}}
138+
{{GetVariableProperty "cloudInitData" "provisionInstallsFlatcar"}}
139139
{{- else }}
140140
- path: {{GetCSEInstallScriptDistroFilepath}}
141141
permissions: "0744"
@@ -210,7 +210,8 @@ write_files:
210210
content: !!binary |
211211
{{GetVariableProperty "cloudInitData" "migPartitionScript"}}
212212

213-
{{if IsAzlOSGuard}}
213+
{{if IsACL}}
214+
{{- else if IsAzlOSGuard}}
214215
{{- else if IsMariner}}
215216
- path: /opt/azure/containers/mariner-package-update.sh
216217
permissions: "0544"

pkg/agent/baker.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,11 @@ func buildIgnitionTarball(entries []ignitionTarEntry) ([]byte, error) {
245245
return buf.Bytes(), nil
246246
}
247247

248-
func cloudInitToButane(customData cloudInit) flatcar1_1.Config {
248+
func cloudInitToButane(customData cloudInit, butaneYamlPath string) flatcar1_1.Config {
249249
butaneconfig := flatcar1_1.Config{}
250-
b, e := parts.Templates.ReadFile(kubernetesFlatcarNodeCustomDataYaml)
250+
b, e := parts.Templates.ReadFile(butaneYamlPath)
251251
if e != nil {
252-
panic(fmt.Errorf("yaml file %s does not exist", kubernetesFlatcarNodeCustomDataYaml))
252+
panic(fmt.Errorf("yaml file %s does not exist", butaneYamlPath))
253253
}
254254
if e = yaml.Unmarshal(b, &butaneconfig); e != nil {
255255
panic(fmt.Errorf("failed to unmarshal butane config: %w", e))
@@ -304,7 +304,11 @@ func (t *TemplateGenerator) getFlatcarLinuxNodeCustomDataJSONObject(config *data
304304
panic(fmt.Errorf("no write files found in customData"))
305305
}
306306

307-
var butaneconfig = cloudInitToButane(customData)
307+
butaneYamlPath := kubernetesFlatcarNodeCustomDataYaml
308+
if config.IsACL() {
309+
butaneYamlPath = kubernetesACLNodeCustomDataYaml
310+
}
311+
var butaneconfig = cloudInitToButane(customData, butaneYamlPath)
308312
ignition, report, e := butaneconfig.ToIgn3_4(butanecommon.TranslateOptions{})
309313
if e != nil {
310314
panic(fmt.Errorf("butane -> ignition: error: %w:\n%s", e, report.String()))

pkg/agent/baker_test.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,7 @@ var _ = Describe("cloudInitToButane", func() {
14041404

14051405
It("should convert bootcmds to a systemd unit and shell script", func() {
14061406
var config = cloudInit{BootCommands: []string{"echo hello world", "ls 'some dir'"}}
1407-
var butane = cloudInitToButane(config)
1407+
var butane = cloudInitToButane(config, kubernetesFlatcarNodeCustomDataYaml)
14081408
checkForUnit(butane)
14091409
Expect(butane.Storage.Files).To(HaveLen(1))
14101410
var file = butane.Storage.Files[0]
@@ -1447,7 +1447,7 @@ var _ = Describe("cloudInitToButane", func() {
14471447
Content: string(gzipped),
14481448
},
14491449
}}
1450-
var butane = cloudInitToButane(config)
1450+
var butane = cloudInitToButane(config, kubernetesFlatcarNodeCustomDataYaml)
14511451
Expect(butane.Storage.Files).To(HaveLen(1))
14521452
var file = butane.Storage.Files[0]
14531453
tarball, err := decodeButaneResource(file.Contents)
@@ -1476,7 +1476,7 @@ var _ = Describe("cloudInitToButane", func() {
14761476
Content: encoded,
14771477
},
14781478
}}
1479-
var butane = cloudInitToButane(config)
1479+
var butane = cloudInitToButane(config, kubernetesFlatcarNodeCustomDataYaml)
14801480
Expect(butane.Storage.Files).To(HaveLen(1))
14811481
var file = butane.Storage.Files[0]
14821482
tarball, err := decodeButaneResource(file.Contents)
@@ -1496,7 +1496,7 @@ var _ = Describe("cloudInitToButane", func() {
14961496

14971497
It("should create a system unit but not a shell script with no bootcmds", func() {
14981498
var config = cloudInit{BootCommands: []string{}}
1499-
var butane = cloudInitToButane(config)
1499+
var butane = cloudInitToButane(config, kubernetesFlatcarNodeCustomDataYaml)
15001500
checkForUnit(butane)
15011501
Expect(butane.Storage.Files).To(BeEmpty())
15021502
Expect(butane.Systemd.Units).NotTo(BeEmpty())
@@ -1511,6 +1511,24 @@ var _ = Describe("cloudInitToButane", func() {
15111511
}
15121512
Expect(found).To(BeTrue())
15131513
})
1514+
1515+
It("should include storage links for ACL butane config", func() {
1516+
var config = cloudInit{BootCommands: []string{"echo hello"}}
1517+
var butane = cloudInitToButane(config, kubernetesACLNodeCustomDataYaml)
1518+
checkForUnit(butane)
1519+
Expect(butane.Storage.Links).To(HaveLen(2))
1520+
Expect(butane.Storage.Links[0].Path).To(Equal("/etc/systemd/system/sysinit.target.wants/ignition-bootcmds.service"))
1521+
Expect(*butane.Storage.Links[0].Target).To(Equal("/etc/systemd/system/ignition-bootcmds.service"))
1522+
Expect(butane.Storage.Links[1].Path).To(Equal("/etc/systemd/system/sysinit.target.wants/ignition-file-extract.service"))
1523+
Expect(*butane.Storage.Links[1].Target).To(Equal("/etc/systemd/system/ignition-file-extract.service"))
1524+
})
1525+
1526+
It("should not include storage links for Flatcar butane config", func() {
1527+
var config = cloudInit{BootCommands: []string{"echo hello"}}
1528+
var butane = cloudInitToButane(config, kubernetesFlatcarNodeCustomDataYaml)
1529+
checkForUnit(butane)
1530+
Expect(butane.Storage.Links).To(BeEmpty())
1531+
})
15141532
})
15151533

15161534
func decodeButaneResource(resource base0_5.Resource) ([]byte, error) {

pkg/agent/const.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const (
4242
// cloud-init (i.e. ARM customData) source file references.
4343
const (
4444
kubernetesFlatcarNodeCustomDataYaml = "linux/cloud-init/flatcar.yml"
45+
kubernetesACLNodeCustomDataYaml = "linux/cloud-init/acl.yml"
4546
kubernetesNodeCustomDataYaml = "linux/cloud-init/nodecustomdata.yml"
4647
kubernetesCSECommandString = "linux/cloud-init/artifacts/cse_cmd.sh"
4748
kubernetesCSEStartScript = "linux/cloud-init/artifacts/cse_start.sh"

0 commit comments

Comments
 (0)