Repository navigation
Conversation
The env var file upload reused a single strings.Reader across retry attempts. When an attempt failed after the communicator had read some or all of it (e.g. a transient WinRM error during winrmcp's restore or cleanup step), the retry uploaded a truncated or empty file and reported success, so the next script ran without its environment_vars. Create the reader inside the retry closure so every attempt uploads the full content, matching the script upload which rewinds its file.
|
Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement Learn more about why HashiCorp requires a CLA and what the CLA includes Have you signed the CLA already but the status is still pending? Recheck it. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The PowerShell provisioner uploads the env var file (
remote_env_var_path) inside a retry loop, but it created thestrings.Readerfor that upload once, before the loop. If anUploadattempt failed after reading part or all of the reader, the retry sent only what was left: a truncated or empty file. The retry then reported success. The script dot-sourced the empty file without error and ran with noenvironment_varsset, then failed later with an unrelated-looking null-argument error.With WinRM this is not only theoretical:
winrmcpreads the whole input before its restore and temp-file cleanup steps. A transient failure in either step fails theUploadwith the reader already at EOF, and the retry writes an empty destination file.This PR creates the reader inside the retry closure, so every attempt uploads the full text. This matches the script upload in the same file (
f.Seek(0, 0)on each attempt) and theshellprovisioner's env var file upload. Nothing else changes.I checked the other uploads on these paths:
elevated_userpath also goes throughprepareEnvVars→uploadEnvVars, so this fix covers it.guestexec.GenerateElevatedRunnerin packer-plugin-sdk does oneUploadwith no retry, so it is not affected.Tests
TestProvision_uploadEnvVarsRetryuses a mock communicator whose firstUploadreads some bytes (one case) or all bytes (another case) and then returns an error. The test checks that the secondUploadreceives the full env var text. Both cases fail without the fix: the retry sends the unread tail in the first case and an empty string in the second. Both pass with the fix.Backward compatibility: no config or template changes. The only change in behavior is that a retried env var upload now writes the full file.
Resolved Issues
Closes #13734
Rollback Plan
If a change needs to be reverted, we will roll out an update to the code within
7 days.
Changes to Security Controls
None. No changes to access controls, encryption, or logging.