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

Randomly generated SSH Password not set unless communicator type is explicitly set to ssh #415

Open
shubhang93 opened this issue May 15, 2024 · 3 comments
Labels

Comments

@shubhang93
Copy link

shubhang93 commented May 15, 2024

When filing a bug, please include the following headings if possible. Any
example text in this template can be deleted.

Overview of the Issue

The build variable Password returns an empty string if it's not explicitly set using the ssh_password option. When ssh_password is set it works fine.

Reproduction Steps

Steps to reproduce this issue

Plugin and Packer version

packer: v1.10.0
Plugin: v2.1.3

From packer version

Simplified Packer Buildfile

If the file is longer than a few dozen lines, please include the URL to the
gist of the log or use the Github detailed
format

instead of posting it directly in the issue.

build {
  sources = [
    "..."
  ]

  provisioner "shell" {
        script = "scripts/setup.sh"
	execute_command =  "chmod +x {{ .Path }}; {{ .Vars }}  bash -x -l '{{ .Path }}'"
	environment_vars = [
        "ROOT_PSSWD=${build.Password}",
	"USER_ID=${build.User}",
	"BUILD_ID=${build.ID}",
    ]
  }
}

setup.sh

echo "PASSWORD = ${ROOT_PSSWD}"

output

PASSWORD=<empty_string>

Operating system and Environment details

OS, Architecture, and any other information you can provide about the
environment.

Log Fragments and crash.log files

 azure-arm...: temp admin user: 'user'
 azure-arm... temp admin password: '22wlrlNpqTPw6yrDKwwUaxdtL9eta34q'

Set the env var PACKER_LOG=1 for maximum log detail.

Remote command exited with '1': chmod +x /tmp/script_7867.sh; BUILD_ID='ERR_ID_NOT_IMPLEMENTED_BY_BUILDER' C_FORCE_ROOT='True'  
ROOT_PSSWD='' bash -x -l '/tmp/script_7867.sh'
@shubhang93 shubhang93 added the bug label May 15, 2024
@JenGoldstrich
Copy link
Contributor

@shubhang93 I did some investigating and I believe that the root cause of this issue is that

if c.Comm.Type == "ssh" {
when communicator type aka the communicator field is unset, the plugin assumes you want to use SSH for Linux builds, whenever I build without communicator set to ssh I see an empty ssh password, but we print the admin password regardless which makes this appear as if the password is just not exposed.

Its important to note this is not a bug with the exposure of the password, but with the password itself not being set.

You should be able to set communicator in your template to ssh, and then this password will be correctly propagated to the communicator, and then you'll see it in the password variable, we will fix this in a future release so that the ssh password is correctly set regardless of if the communicator value is set as that is not meant to be required.

@JenGoldstrich JenGoldstrich changed the title temporary password not being exposed in the build vars with latest version of azure plugin SSH Password not set unless communicator type is explicitly set to ssh May 23, 2024
@JenGoldstrich JenGoldstrich changed the title SSH Password not set unless communicator type is explicitly set to ssh Randomly generated SSH Password not set unless communicator type is explicitly set to ssh May 23, 2024
@shubhang93
Copy link
Author

Thanks for the update !

@JenGoldstrich
Copy link
Contributor

Hey @shubhang93 Just an FYI I've reopened this issue cause I think its still worth fixing the issue you pointed out :], thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants