hashicorp / hashicorp/packer-plugin-azure
The value of parameter linuxConfiguration.ssh.publicKeys.path is invalid
- Dominant language
- Go
- Stars
- 63
- Forks
- 103
- PR merge metrics
- No merged PRs in 30d
Description
_This issue was originally opened by @jtravell as hashicorp/packer#11104. It was migrated here as a result of the [Packer plugin split](https://github.com/hashicorp/packer/issues/8610#issuecomment-770034737). The original body of the issue is below._
We believe we found a bug in the packer azure-arm builder.
>**What specifically must be done to work around this bug so that we can successfully deploy the packer build?**
**ERROR MESSAGE:**
The following error message is breaking our build process using the azure-arm builder:
==> Some builds didn't complete successfully and had errors:
--> azure-arm: Code="DeploymentFailed" Message="At least one resource deployment operation failed.
Please list deployment operations for details.
Please see https://aka.ms/DeployOperations for usage details."
Details=[
{
"code":"BadRequest",
"message":"{\r\n
\"error\": {\r\n
\"code\": \"InvalidParameter\",\r\n
\"message\": \"The value of parameter linuxConfiguration.ssh.publicKeys.path is invalid.\",\r\n
\"target\": \"linuxConfiguration.ssh.publicKeys.path\"\r\n
}\r\n
}"
}
]
==> Builds finished but no artifacts were created.
2021/06/18 13:45:30 waiting for all plugin processes to complete...
2021/06/18 13:45:30 C:\projects\packer\binary\packer_1.7.3_windows_amd64\packer.exe: plugin process exited
2021/06/18 13:45:30 C:\projects\packer\binary\packer_1.7.3_windows_amd64\packer.exe: plugin process exited
You can see from the above message that we are using packer version `packer_1.7.3_windows_amd64`.
**BUILD COMMAND THAT BREAKS**
The command we are running that triggers the error is:
packer build -debug
-var "subscription_id=valid-subscription-id"
-var "tenant_id=valid-tenant-id"
-var "resource_group=valid-resource-group-name"
-var "new_image_name=valid-image-name"
-var "region=West US"
-var "init_script=C:\\path\\to\\valid-startup-script.sh"
-var-file="C:\path\to\valid-var-file.json"
C:\path\to\valid-packer-template.json
**API CALL THAT BREAKS ACCORDING TO DEBUG LOGS:**
When we step through the `packer build` command in debug mode, the packer resource group is created, but then the post call to the deployment API endpoint fails with the error message given above. There is never any virtual machine created, so we cannot putty into anything to diagnose, and there is no image created, so there are no remaining artifacts available to examine afterwards. The validated API call created by packer that results in the error is as follows:
2021/06/18 16:47:24 packer.exe plugin:
Azure response status="200 OK"
method="POST"
request="https://management.azure.com/subscriptions/our-valid-subscription-id/resourcegroups/pkr-Resource-Group-alpha-numeric-id/providers/Microsoft.Resources/deployments/packer-generated-deployment-name/validate?api-version=2018-02-01"
x-ms-request-id="unique-alpha-numeric-request-id"
body="{
\"id\":\"/subscriptions/our-valid-subscription-id/resourceGroups/pkr-Resource-Group-alpha-numeric-id/providers/Microsoft.Resources/deployments/packer-generated-deployment-name\",
\"name\":\"packer-generated-deployment-name\",
\"properties\":{
\"templateHash\":\"numeric-template-hash-redacted-for-security\",
\"parameters\":{
\"adminPassword\":{\"type\":\"String\",\"value\":\"\\\"our-user-supplied-password\\\"\\n\"},
\"adminUsername\":{\"type\":\"String\",\"value\":\"\\\"packer\\\"\\n\"},
\"dataDiskName\":{\"type\":\"String\",\"value\":\"packer-generated-datadisk-name\"},
\"dnsNameForPublicIP\":{\"type\":\"String\",\"value\":\"packer-generated-vm-name\"},
\"nicName\":{\"type\":\"String\",\"value\":\"packer-generated-nic-name\"},
\"nsgName\":{\"type\":\"String\",\"value\":\"packer-generated-nsg-name\"}
,\"osDiskName\":{\"type\":\"String\",\"value\":\"packer-generated-osdisk-name\"},
\"publicIPAddressName\":{\"type\":\"String\",\"value\":\"packer-generated-ip-name\"},
\"storageAccountBlobEndpoint\":{\"type\":\"String\",\"value\":\"\"},
\"subnetName\":{\"type\":\"String\",\"value\":\"packer-generated-subnet-name\"},
\"virtualNetworkName\":{\"type\":\"String\",\"value\":\"packer-generated-vnet-name\"},
\"vmName\":{\"type\":\"String\",\"value\":\"packer-generated-vm-name\"},
\"vmSize\":{\"type\":\"String\",\"value\":\"Standard_DS2_v2\"}
},
\"mode\":\"Incremental\",
\"provisioningState\":\"Succeeded\",
\"timestamp\":\"2021-06-18T23:47:24.8454197Z\",
\"duration\":\"PT0S\",
...other config omitted for brevity
\"validatedResources\":[
...other config omitted for brevity,
{
\"dependsOn\":[\"/subscriptions/our-valid-subscription-id/resourceGroups/pkr-Resource-Group-alpha-numeric-id/providers/Microsoft.Network/networkInterfaces/packer-generated-nic-name\"],
\"apiVersion\":\"2017-03-30\",
\"id\":\"/subscriptions/our-valid-subscription-id/resourceGroups/pkr-Resource-Group-alpha-numeric-id/providers/Microsoft.Compute/virtualMachines/packer-generated-vm-name\",
\"name\":\"packer-generated-vm-name\",
\"type\":\"Microsoft.Compute/virtualMachines\",
\"location\":\"westus\",
\"properties\":{
...other config redacted for brevity,
\"osProfile\":{
\"adminPassword\":\"\\\"our-user-supplied-password\\\"\\n\",
\"adminUsername\":\"\\\"packer\\\"\\n\",
\"computerName\":\"packer-generated-vm-name\",
\"linuxConfiguration\":{
\"ssh\":{
\"publicKeys\":[
{
\"keyData\":\"ssh-rsa raw/ssh/key/redacted/here packer Azure Deployment2021-06-18T16:47:18-07:00\",
\"path\":\"/home/\\\"packer\\\"\\n/.ssh/authorized_keys\"
}
]
}
}
},
...other config omitted for brevity
}
}
]
}
}"
You can see that the error corresponds with the `linuxConfiguration` block in the above api call.
**REDUCED API CALL FOR EASIER READING:**
To make it easier for you to help identify the root cause of this problem, we have further reduced the same above API call to include only the salient information as follows:
body="{
\"properties\":{
\"template\":{
\"$schema\":\"http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json\",
\"contentVersion\":\"1.0.0.0\",
\"parameters\":{
\"adminUsername\":{\"type\":\"string\"},
...other items omitted for clarity
},
\"resources\":[
\"properties\":{
\"osProfile\":{
\"adminUsername\":\"[parameters('adminUsername')]\",
\"linuxConfiguration\":{
\"ssh\":{
\"publicKeys\":[
{
\"keyData\":\"ssh-rsa ",
\"path\":\"[variables('sshKeyPath')]\"
}
]
}
},
...other items omitted for clarity
},
},
\"type\":\"Microsoft.Compute/virtualMachines\"}
],
\"variables\":{
\"sshKeyPath\":\"[concat('/home/',parameters('adminUsername'),'/.ssh/authorized_keys')]\",
...other items omitted for clarity
}
},
\"parameters\":{
\"adminUsername\":{\"value\":\"\\\"packer\\\"\\n\"},
...other items omitted for clarity
},
\"mode\":\"Incremental\"
}
}"
As you can see from the above, the line that seems to be breaking is as follows:
\"sshKeyPath\":\"[concat('/home/',parameters('adminUsername'),'/.ssh/authorized_keys')]\",
And you can read in the above that the value of `adminUsername` is set to `packer`.
>**What specifically needs to be changed to work around this bug?**
Contributor guide
Research direction
Start from the azure-arm builder's generated deployment template and inspect how the adminUsername parameter is passed into the sshKeyPath variable. Reproduce the validation failure using the command and reduced API call in the issue, then confirm that the generated linuxConfiguration.ssh.publicKeys.path is accepted by Azure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, go
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100