hashicorp / packer

Packer is a tool for creating identical machine images for multiple platforms from a single source configuration.
http://www.packer.io
Other
15.06k stars 3.32k forks source link

Bug: Temp PowerShell scripts hardcode to store under %TEMP% instead of using temp_path var location #7634

Closed vlinx closed 5 years ago

vlinx commented 5 years ago

2019/05/13 12:37:00 packer.exe: 2019/05/13 12:37:00 Setting cache directory: C:\gbstbsd\nebula\packer\centos-vb\packer_cache

2019/05/13 12:37:00 packer.exe: 2019/05/13 12:37:00 args: []string{"packer-builder-hyperv-iso"} 2019/05/13 12:37:00 packer.exe: 2019/05/13 12:37:00 Plugin minimum port: 10000 2019/05/13 12:37:00 packer.exe: 2019/05/13 12:37:00 Plugin maximum port: 25000 2019/05/13 12:37:00 packer.exe: 2019/05/13 12:37:00 Plugin address: tcp 127.0.0.1:10000 2019/05/13 12:37:00 packer.exe: 2019/05/13 12:37:00 Waiting for connection... 2019/05/13 12:37:00 packer.exe: 2019/05/13 12:37:00 Serving a plugin connection... 2019/05/13 12:37:00 Build debug mode: false 2019/05/13 12:37:00 Force build: false 2019/05/13 12:37:00 On error: 2019/05/13 12:37:00 Preparing build: hyperv-iso 2019/05/13 12:37:00 packer.exe: 2019/05/13 12:37:00 DiskSize: 25360 2019/05/13 12:37:00 packer.exe: 2019/05/13 12:37:00 DiskBlockSize: 32 2019/05/13 12:37:00 packer.exe: 2019/05/13 12:37:00 RamSize: 2048 2019/05/13 12:37:00 packer.exe: 2019/05/13 12:37:00 VMName: packer-demo 2019/05/13 12:37:00 packer.exe: 2019/05/13 12:37:00 Using switch internal_vSwitch 2019/05/13 12:37:00 packer.exe: 2019/05/13 12:37:00 SwitchName: internal_vSwitch

Warnings for build 'hyperv-iso': 2019/05/13 12:37:00 Waiting on builds to complete... 2019/05/13 12:37:00 Starting build run: hyperv-iso

2019/05/13 12:37:00 Running builder: hyperv-iso

2019/05/13 12:37:00 packer.exe: 2019/05/13 12:37:00 Enter method: verifyPSVersion

2019/05/13 12:37:00 [INFO] (telemetry) ending hyperv-iso 2019/05/13 12:37:00 ui error: Build 'hyperv-iso' errored: Failed creating Hyper-V driver: PowerShell error: CylancePROTECT Script Control has blocked access to this PowerShell script.Build 'hyperv-iso' errored: Failed creating Hyper-V driver: PowerShell error: CylancePROTECT Script Control has blocked access to this PowerShell script.

==> Some builds didn't complete successfully and had errors: 2019/05/13 12:37:00 Builds completed. Waiting on interrupt barrier... --> hyperv-iso: Failed creating Hyper-V driver: PowerShell error: CylancePROTECT Script Control has blocked access to this PowerShell script. 2019/05/13 12:37:00 machine readable: error-count []string{"1"}

2019/05/13 12:37:00 ui error: ==> Some builds didn't complete successfully and had errors: ==> Builds finished but no artifacts were created. 2019/05/13 12:37:00 machine readable: hyperv-iso,error []string{"Failed creating Hyper-V driver: PowerShell error: CylancePROTECT Script Control has blocked access to this PowerShell script."} 2019/05/13 12:37:00 ui error: --> hyperv-iso: Failed creating Hyper-V driver: PowerShell error: CylancePROTECT Script Control has blocked access to this PowerShell script. ==> Builds finished but no artifacts were created. 2019/05/13 12:37:00 [INFO] (telemetry) Finalizing. 2019/05/13 12:37:01 waiting for all plugin processes to complete... 2019/05/13 12:37:01 C:\Apps\Bin\packer.exe: plugin process exited



- The _simplest example template and scripts_ needed to reproduce the bug.
  use this example https://www.apcension.com/articles/Packer/
  temp_path sets to "c://scripts" as override
  "c://script" whitelisted by Cyclance Script Control
  %TEMP% script location has been blocked by Cylance Script Control
  I have tried to override the temp_path as “C:\\scripts”. However Packer binary is using %TEMP% to store temp PowerShell scripts regardless what temp_path is set to.
vlinx commented 5 years ago

You can override %TMP% to workaround this issue

λ set TMP=c:\scripts λ echo %TMP% c:\scripts

azr commented 5 years ago

Hello there, thanks for reporting. Yes the docs states( for windows ) :

TMP TEMP USERPROFILE - The location of the directory used for temporary files ( defaults to [...] %USERPROFILE%\AppData\Local\Temp on Windows Vista and above )

Looking into it.

azr commented 5 years ago

@vlinx On Windows, it uses GetTempPath, returning the first non-empty value from %TMP%, %TEMP%, %USERPROFILE%, or the Windows directory.

Are you sure TMP was not set at the time ? In which case I think TMP will have precedence.

vlinx commented 5 years ago

I have both of my %TMP% and %TEMP% set correctly. However I would like to use temp_path to override the value to "c:\scripts" while keeping %TMP% and %TEMP% as it is. What I am trying to accomplish here is to GetTempPath to return c:\scripts without manually modifing %TMP% and %TEMP%. Since modifing %TMP% and %TEMP% breaks other programs. https://www.packer.io/docs/builders/hyperv-iso.html#temp_path

azr commented 5 years ago

temp_path is The location under which Packer will create a directory to house all the VM files and folders during the build.

Looking at the code & tests, it looks like to me that everything is fine:

https://github.com/hashicorp/packer/blob/c4f3dccc148bed4241a3b19f3f1b89824bf39a50/builder/hyperv/common/step_create_build_dir.go#L33-L38

https://github.com/hashicorp/packer/blob/c4f3dccc148bed4241a3b19f3f1b89824bf39a50/builder/hyperv/common/step_create_build_dir.go#L47

ioutil.TempDir will use what's in temp_path if set and tmp.Dir uses GetTempPath (env vars) when temp_path is not set.

In your debug output something else fails even before we get to the step where temp_path is used as we can't find the debug output: Created build directory.

Your error is the following:

Failed creating Hyper-V driver: PowerShell error: CylancePROTECT Script Control has blocked access to this PowerShell script.

Looks like to me that CylancePROTECT is blocking you the access to the hyperv driver.

I'm going to close this issue as it seems to me it is a question more than a bug, I think the discussion list is the place to go for you 🙂. https://www.packer.io/community.html

Cheers !

ghost commented 4 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.