Repository navigation
fix(no-ticket): escape the args in the terraformrc block - #543
Open
cloudsmith-iduffy wants to merge 5 commits into
Open
cloudsmith-iduffy wants to merge 5 commits into
cloudsmith-iduffy wants to merge 5 commits into
Conversation
The Terraform install wrote each helper arg into the HCL block without
escapes. A Windows path such as C:\Users\jo\config.ini is not valid
HCL, so Terraform rejected the full CLI config file. Escape backslashes
and quotes. Write `${` and control characters as Unicode escapes,
because HCL 1 does not decode escapes after `${`. Ignore braces in
quoted strings when the installer finds the block again.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Quotes in valid HCL comments prevent block detection, causing reinstall to append duplicate helper blocks and uninstall to leave them untouched.
1 open issue
What changed in this PR
This PR fixes Terraform credential-helper argument escaping, particularly for Windows configuration paths, and improves matching of helper blocks containing quoted braces.
Changes:
- Escape HCL-sensitive characters and reject invalid argument types.
- Update block matching and add regression tests for escaping and replacement.
- Register the shared
windowstest marker and document the fix.
| File | Description |
|---|---|
pyproject.toml |
Register the windows pytest marker. |
cloudsmith_cli/credential_helpers/terraform/terraformrc.py |
Escape arguments, validate types, and recognize quoted braces. |
cloudsmith_cli/cli/tests/test_credential_helper_terraform_installer.py |
Test escaping, invalid arguments, and block replacement. |
CHANGELOG.md |
Describe the Terraform fix and recovery instructions. |
Review effort: Balanced
Read HCL comments (#, // and /* */) as whole tokens when the CLI looks for the credentials_helper block. Before, a quote in a comment started a string, the match failed, and install added a second block while uninstall left the old one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cloudsmith-iduffy
marked this pull request as ready for review
October 24, 2026 17:53
cloudsmith-iduffy
requested review from
a team and
cloudsmith-bot
as code owners
October 24, 2026 17:53
cloudsmith-iduffy
enabled auto-merge (squash)
October 24, 2026 17:53
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
Author
|
@copilot resolve the merge conflicts on this branch. |
…mrc-escaping # Conflicts: # CHANGELOG.md Co-authored-by: cloudsmith-iduffy <178375997+cloudsmith-iduffy@users.noreply.github.com>
auto-merge was automatically disabled
October 29, 2026 11:04
Head branch was pushed to by a user without write access
Contributor
Merged the latest |
tigh-latte
approved these changes
Oct 29, 2026
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
cloudsmith credential-helper install terraformputs every helper arg into thecredentials_helper "cloudsmith"block as"<arg>", with no escaping. The args include the resolved--config-fileand--credentials-filepaths. On Windows those paths look likeC:\Users\jo\config.ini, and\Uis not a valid escape in HCL. Terraform then rejects the whole CLI config file, so every Terraform command fails, and the user's other settings in that file stop working too.Before:
After:
What changed in
terraformrc.py:render_blockescapes\and". It writes${and control characters as\uXXXXescapes.render_blockraisesTypeErrorfor a bare string or a non-string item. A bare string would otherwise render one arg per character._BLOCK_REignores a}inside a quoted string. Before this change, an arg with a}cut the match short, so the next install or uninstall left part of the old block behind. Run the install again to repair a block that an earlier version wrote.I checked the escaping against Terraform 1.16. Terraform reads the CLI config with HCL 1, not HCL 2, so the usual
$${and%%{escapes do not apply:${x}and%{x}are already literal.$${x}is not an escape: the helper gets$${x}as written.${, HCL 1 stops decoding escapes."${C:\\x}"reaches the helper with two backslashes.\u0024{decodes to${and does not start that mode, so the CLI writes${that way.To check this, I put a small helper into
~/.terraform.d/pluginsthat writes its argv to a file. Then I ranterraform initagainst a module on an unknown registry host. For a Windows path,",${,},{,%{, a newline, a control character, and non-ASCII text, the argv was the same as the Python list I passed torender_block.To reproduce the bug on macOS or Linux, use a directory whose name has a backslash in it:
On
master,terraform versionprintsillegal char escape. On this branch, it does not print an error.Type of Change
Additional Notes
windowsmarker. It still runs on Linux and macOS. This PR registers the marker with the same line as fix(no-ticket): print ASCII text in mcp configure, download and update #525 and fix(no-ticket): keep credentials.ini sections and save missing API keys #533. Those PRs add thewindows-latestCI job that runs-m "windows and not integration", so whichever merges first owns the line.🤖 Generated with Claude Code