Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting elevated_user to build user dynamically breaks Powershell provisioner #132

Open
InsanesTheName opened this issue Oct 7, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@InsanesTheName
Copy link

Overview of the Issue

There seems to be some kind of templating/interpolation failure when using a build variable as the value for the elevated_user property of the powershell provisioner. The interpolation that is failing appears to be here:

$f.RegisterTaskDefinition($name, $t, 6, "{{.User}}", $password, $logon_type, $null) | Out-Null

Reproduction Steps

Run a build with the following provisioner:

{
    "type": "powershell",
    "script": "common/test.ps1",
    "environment_vars": [
        "TEST_PACKER_1={{build `User`}}",
        "TEST_PACKER_2={{build `Password`}}"
    ],
    "elevated_user": "{{build `User`}}",
    "elevated_password": "{{build `Password`}}"
}

Interestingly, with the example above, the environment variable TEST_PACKER_1 will be successfully set to the build username (so I don't believe it's an issue with that function), however, the script will fail to launch with the error below. Also, if the username is set explicitly (e.g. "elevated_user": "ExplicitUsername"), everything works fine.

Log Fragments

==> (AWS) Elevated_Test: Provisioning with powershell script: common/test.ps1
==> (AWS) Elevated_Test: (12,8):UserId:
==> (AWS) Elevated_Test: At C:\Windows\Temp\packer-elevated-shell-634090c0-1adf-5fb0-c9b2-82dad6d5bf56.ps1:60 char:1
==> (AWS) Elevated_Test: + $f.RegisterTaskDefinition($name, $t, 6, "{{.User}}", $password, $logo ...
==> (AWS) Elevated_Test: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
==> (AWS) Elevated_Test:     + CategoryInfo          : OperationStopped: (:) [], COMException
==> (AWS) Elevated_Test:     + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

As shown above, the value {{.User}} is being passed into Powershell directly, which is not intended behavior.

Operating system and Environment details

I'm able to reproduce this issue with Packer 1.6.6 and 1.8.3 on both Windows and Linux.
I'm able to reproduce in both amazon-ebs and azure-arm builders.

@InsanesTheName InsanesTheName added the bug Something isn't working label Oct 7, 2022
@InsanesTheName
Copy link
Author

bumping this ... can anyone advise?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant