Skip to content

Commit e3c2f55

Browse files
authored
Merge pull request #1800 from mboersma/windows-password-generation
Force setting windows_admin_password for OVA and Nutanix
2 parents 4ab7b02 + 8368751 commit e3c2f55

File tree

9 files changed

+36
-29
lines changed

9 files changed

+36
-29
lines changed

images/capi/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ SCALEWAY_VALIDATE_TARGETS := $(addprefix validate-,$(SCALEWAY_BUILD_NAMES))
467467
$(NODE_OVA_LOCAL_BUILD_TARGETS): deps-ova set-ssh-password
468468
# This uses a packer file builder to input unattend variables into a JSON file to be consumed by the python script before running the vmware-iso provisioner
469469
$(if $(findstring windows,$@),$(PACKER) build $(PACKER_WINDOWS_NODE_FLAGS) -var-file="packer/ova/packer-common.json" -var-file="$(abspath packer/ova/$(subst build-node-ova-local-,,$@).json)" -only=file $(ABSOLUTE_PACKER_VAR_FILES) packer/ova/packer-windows.json,)
470-
$(if $(findstring windows,$@),hack/windows-ova-unattend.py --unattend-file='./packer/ova/windows/$(subst build-node-ova-local-,,$@)/autounattend.xml',)
470+
$(if $(findstring windows,$@),hack/windows-unattend.py --unattend-file='./packer/ova/windows/$(subst build-node-ova-local-,,$@)/autounattend.xml',)
471471
$(PACKER) build $(if $(findstring windows,$@),$(PACKER_WINDOWS_NODE_FLAGS),$(PACKER_NODE_FLAGS)) -var-file="packer/ova/packer-common.json" -var-file="$(abspath packer/ova/$(subst build-node-ova-local-,,$@).json)" -except=vsphere -only=vmware-iso $(ABSOLUTE_PACKER_VAR_FILES) packer/ova/packer-$(if $(findstring windows,$@),windows,node).json
472472

473473
.PHONY: $(NODE_OVA_LOCAL_VALIDATE_TARGETS)
@@ -486,7 +486,7 @@ $(NODE_OVA_LOCAL_BASE_BUILD_TARGETS): deps-ova set-ssh-password
486486
$(NODE_OVA_VSPHERE_BUILD_TARGETS): deps-ova set-ssh-password
487487
# This uses a packer file builder to input unattend variables into a JSON file to be consumed by the python script before running the vsphere provisioner
488488
$(if $(findstring windows,$@),$(PACKER) build $(PACKER_WINDOWS_NODE_FLAGS) -var-file="packer/ova/packer-common.json" -var-file="$(abspath packer/ova/$(subst build-node-ova-vsphere-,,$@).json)" -only=file $(ABSOLUTE_PACKER_VAR_FILES) packer/ova/packer-windows.json,)
489-
$(if $(findstring windows,$@),hack/windows-ova-unattend.py --unattend-file='./packer/ova/windows/$(subst build-node-ova-vsphere-,,$@)/autounattend.xml',)
489+
$(if $(findstring windows,$@),hack/windows-unattend.py --unattend-file='./packer/ova/windows/$(subst build-node-ova-vsphere-,,$@)/autounattend.xml',)
490490
$(PACKER) build $(if $(findstring windows,$@),$(PACKER_WINDOWS_NODE_FLAGS),$(PACKER_NODE_FLAGS)) -var-file="packer/ova/packer-common.json" -var-file="$(abspath packer/ova/$(subst build-node-ova-vsphere-,,$@).json)" -var-file="packer/ova/vsphere.json" -except=local -only=vsphere-iso $(ABSOLUTE_PACKER_VAR_FILES) -only=vsphere packer/ova/packer-$(if $(findstring windows,$@),windows,node).json
491491

492492
.PHONY: $(NODE_OVA_VSPHERE_BASE_BUILD_TARGETS)
@@ -624,6 +624,8 @@ $(NUTANIX_BUILD_TARGETS): deps-nutanix set-ssh-password
624624
$(eval NUTANIX_USERDATA:=$(shell cat $(abspath packer/nutanix/linux/cloud-init/$(subst -,/,$(if $(findstring ubuntu,$@),$(call GET_UBUNTU_DOTTED_SEMVER,$(subst build-nutanix-,,$@)),$(subst build-nutanix-,,$@)))/user-data) | base64 -w0))
625625
$(eval NUTANIX_VAR_FILE:=$(abspath packer/nutanix/$(subst build-nutanix-,,$@).json))
626626
jq '.user_data = "$(NUTANIX_USERDATA)"' $(NUTANIX_VAR_FILE) > $(NUTANIX_VAR_FILE).templated && mv $(NUTANIX_VAR_FILE).templated $(NUTANIX_VAR_FILE)
627+
# This uses a packer file builder to input unattend variables into a JSON file to be consumed by the python script before running the nutanix provisioner
628+
$(if $(findstring windows,$@),hack/windows-unattend.py --unattend-file='./packer/nutanix/windows/$(subst build-nutanix-,,$@)/autounattend.xml',)
627629
$(PACKER) build $(if $(findstring windows,$@),$(PACKER_WINDOWS_NODE_FLAGS),$(PACKER_NODE_FLAGS)) -var-file="packer/nutanix/nutanix.json" -var-file="$(abspath packer/nutanix/$(subst build-nutanix-,,$@).json)" $(ABSOLUTE_PACKER_VAR_FILES) packer/nutanix/packer$(if $(findstring windows,$@),-windows,).json
628630

629631
.PHONY: $(NUTANIX_VALIDATE_TARGETS)

images/capi/hack/windows-ova-unattend.py renamed to images/capi/hack/windows-unattend.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def main():
4848
help='The Unattend file')
4949
args = parser.parse_args()
5050

51-
print("windows-ova-unattend: cd %s" % args.build_dir)
51+
print("windows-unattend: cd %s" % args.build_dir)
5252

5353
# Load the packer manifest JSON
5454
data = None
@@ -61,26 +61,32 @@ def main():
6161
ET.register_namespace('', "urn:schemas-microsoft-com:unattend")
6262
ET.register_namespace('wcm', "http://schemas.microsoft.com/WMIConfig/2002/State")
6363
ET.register_namespace('xsi', "http://www.w3.org/2001/XMLSchema-instance")
64-
64+
6565
root = unattend.getroot()
6666

6767
if data.get("unattend_timezone"):
6868
modified=1
6969
setting = set_xmlstring(root, ".//*[@pass='oobeSystem']/*[@name='Microsoft-Windows-Shell-Setup']",'{urn:schemas-microsoft-com:unattend}TimeZone', data["unattend_timezone"])
70-
print("windows-ova-unattend: Setting Timezone to %s" % data["unattend_timezone"])
71-
72-
admin_password = data.get("admin_password")
73-
if admin_password:
70+
print("windows-unattend: Setting Timezone to %s" % data["unattend_timezone"])
71+
72+
# Setting a windows_admin_password is required
73+
BAD_PASSWORD = "S3cr3t0!"
74+
admin_password = os.environ.get("WINDOWS_ADMIN_PASSWORD") or data.get("admin_password")
75+
if not admin_password:
76+
raise ValueError("windows-unattend: No administrator password set, please set the environment variable WINDOWS_ADMIN_PASSWORD or provide it in the unattend.json file")
77+
elif admin_password == BAD_PASSWORD:
78+
raise ValueError("windows-unattend: The administrator password \"%s\" is disallowed, please set the environment variable WINDOWS_ADMIN_PASSWORD to a different value or provide it in the unattend.json file" % BAD_PASSWORD)
79+
else:
7480
modified=1
7581
set_xmlstring(root, ".//*[@pass='oobeSystem']/*[@name='Microsoft-Windows-Shell-Setup']/{*}UserAccounts/{*}AdministratorPassword",'{urn:schemas-microsoft-com:unattend}Value', admin_password)
7682
set_xmlstring(root, ".//*[@pass='oobeSystem']/*[@name='Microsoft-Windows-Shell-Setup']/{*}AutoLogon/{*}Password",'{urn:schemas-microsoft-com:unattend}Value', admin_password)
77-
print("windows-ova-unattend: Setting Administrator Password")
83+
print("windows-unattend: Setting Administrator Password")
7884

7985
if modified == 1:
80-
print("windows-ova-unattend: Updating %s ..." % args.unattend_file)
86+
print("windows-unattend: Updating %s ..." % args.unattend_file)
8187
unattend.write(args.unattend_file)
8288
else:
83-
print("windows-ova-unattend: skipping...")
89+
print("windows-unattend: skipping...")
8490

8591
if __name__ == "__main__":
8692
main()

images/capi/packer/nutanix/packer-windows.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"subnet_name": "{{user `nutanix_subnet_name`}}"
4646
},
4747
"winrm_insecure": true,
48-
"winrm_password": "S3cr3t0!",
48+
"winrm_password": "{{user `windows_admin_password`}}",
4949
"winrm_port": 5986,
5050
"winrm_timeout": "4h",
5151
"winrm_use_ssl": true,

images/capi/packer/nutanix/windows/windows-2022/autounattend.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
12
<!--*************************************************
23
Windows Server 2019 Answer File Generator
34
Created using Windows AFG found at:
@@ -6,8 +7,6 @@ Created using Windows AFG found at:
67
Installation Notes:
78
- This file need to be adapted based on your needs
89
**************************************************-->
9-
10-
<?xml version="1.0" encoding="utf-8"?>
1110
<unattend xmlns="urn:schemas-microsoft-com:unattend">
1211
<settings pass="windowsPE">
1312
<component name="Microsoft-Windows-PnpCustomizationsWinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"
@@ -141,7 +140,7 @@ Installation Notes:
141140
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
142141
<AutoLogon>
143142
<Password>
144-
<Value>S3cr3t0!</Value>
143+
<Value></Value>
145144
<PlainText>true</PlainText>
146145
</Password>
147146
<Enabled>true</Enabled>
@@ -248,7 +247,7 @@ Installation Notes:
248247
<TimeZone>Pacific Standard Time</TimeZone>
249248
<UserAccounts>
250249
<AdministratorPassword>
251-
<Value>S3cr3t0!</Value>
250+
<Value></Value>
252251
<PlainText>true</PlainText>
253252
</AdministratorPassword>
254253
<LocalAccounts>

images/capi/packer/ova/packer-windows.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@
261261
"output_dir": "./output/{{user `build_version`}}",
262262
"prepull": null,
263263
"unattend_timezone": "Pacific Standard Time",
264-
"windows_admin_password": "S3cr3t0!",
264+
"windows_admin_password": "{{user `windows_admin_password`}}",
265265
"windows_service_manager": null,
266266
"windows_updates_categories": null,
267267
"windows_updates_kbs": null

images/capi/packer/ova/windows/windows-2019-efi/autounattend.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Installation Notes:
121121
</component>
122122
</settings>
123123
<settings pass="specialize">
124-
<component name="Microsoft-Windows-Deployment" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"
124+
<component name="Microsoft-Windows-Deployment" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"
125125
xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"
126126
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
127127
<RunSynchronous>
@@ -169,7 +169,7 @@ Installation Notes:
169169
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
170170
<AutoLogon>
171171
<Password>
172-
<Value>S3cr3t0!</Value>
172+
<Value></Value>
173173
<PlainText>true</PlainText>
174174
</Password>
175175
<Enabled>true</Enabled>
@@ -251,7 +251,7 @@ Installation Notes:
251251
<TimeZone>Pacific Standard Time</TimeZone>
252252
<UserAccounts>
253253
<AdministratorPassword>
254-
<Value>S3cr3t0!</Value>
254+
<Value></Value>
255255
<PlainText>true</PlainText>
256256
</AdministratorPassword>
257257
<LocalAccounts>

images/capi/packer/ova/windows/windows-2019/autounattend.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Installation Notes:
113113
</component>
114114
</settings>
115115
<settings pass="specialize">
116-
<component name="Microsoft-Windows-Deployment" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"
116+
<component name="Microsoft-Windows-Deployment" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"
117117
xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"
118118
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
119119
<RunSynchronous>
@@ -161,7 +161,7 @@ Installation Notes:
161161
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
162162
<AutoLogon>
163163
<Password>
164-
<Value>S3cr3t0!</Value>
164+
<Value></Value>
165165
<PlainText>true</PlainText>
166166
</Password>
167167
<Enabled>true</Enabled>
@@ -243,7 +243,7 @@ Installation Notes:
243243
<TimeZone>Pacific Standard Time</TimeZone>
244244
<UserAccounts>
245245
<AdministratorPassword>
246-
<Value>S3cr3t0!</Value>
246+
<Value></Value>
247247
<PlainText>true</PlainText>
248248
</AdministratorPassword>
249249
<LocalAccounts>

images/capi/packer/ova/windows/windows-2022-efi/autounattend.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Installation Notes:
121121
</component>
122122
</settings>
123123
<settings pass="specialize">
124-
<component name="Microsoft-Windows-Deployment" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"
124+
<component name="Microsoft-Windows-Deployment" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"
125125
xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"
126126
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
127127
<RunSynchronous>
@@ -169,7 +169,7 @@ Installation Notes:
169169
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
170170
<AutoLogon>
171171
<Password>
172-
<Value>S3cr3t0!</Value>
172+
<Value></Value>
173173
<PlainText>true</PlainText>
174174
</Password>
175175
<Enabled>true</Enabled>
@@ -251,7 +251,7 @@ Installation Notes:
251251
<TimeZone>Pacific Standard Time</TimeZone>
252252
<UserAccounts>
253253
<AdministratorPassword>
254-
<Value>S3cr3t0!</Value>
254+
<Value></Value>
255255
<PlainText>true</PlainText>
256256
</AdministratorPassword>
257257
<LocalAccounts>

images/capi/packer/ova/windows/windows-2022/autounattend.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Installation Notes:
113113
</component>
114114
</settings>
115115
<settings pass="specialize">
116-
<component name="Microsoft-Windows-Deployment" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"
116+
<component name="Microsoft-Windows-Deployment" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"
117117
xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"
118118
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
119119
<RunSynchronous>
@@ -161,7 +161,7 @@ Installation Notes:
161161
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
162162
<AutoLogon>
163163
<Password>
164-
<Value>S3cr3t0!</Value>
164+
<Value></Value>
165165
<PlainText>true</PlainText>
166166
</Password>
167167
<Enabled>true</Enabled>
@@ -243,7 +243,7 @@ Installation Notes:
243243
<TimeZone>Pacific Standard Time</TimeZone>
244244
<UserAccounts>
245245
<AdministratorPassword>
246-
<Value>S3cr3t0!</Value>
246+
<Value></Value>
247247
<PlainText>true</PlainText>
248248
</AdministratorPassword>
249249
<LocalAccounts>

0 commit comments

Comments
 (0)