Repository navigation
Conversation
wowi42
left a comment
There was a problem hiding this comment.
Thanks for adding this. Being able to use HiddenValue naturally in templates is useful, and the rendered value reaches the upload correctly.
I spotted two things that I think we should fix before merging.
First, with DIFF enabled, the unmasked content reaches files.put, which logs the desired lines through generate_color_diff. That can print plaintext secrets with pyinfra --diff. Could we suppress or redact those diffs when hidden inputs are present, and add coverage showing that the secret is uploaded but absent from the logs?
Second, this truthiness check can skip a valid callable finalizer whose __bool__ returns False:
if user_finalize:
v = user_finalize(v)Using if user_finalize is not None: would preserve the previous callable API behavior.
Thanks again for contributing this.
|
To support logs content coverage, I opened a PR in pyinfra-testing repo |
There was a problem hiding this comment.
The template change can expose hidden values in diff logs. That needs fixing before this can merge.
Issues
- Secrets leak through diff logs.
files.templateturns the rendered output into a plainStringIOand passes it tofiles.put(src/pyinfra/operations/files.py:1491-1504). WithDIFFenabled,putlogs the desired lines on both create and change (src/pyinfra/operations/files.py:1192-1193andsrc/pyinfra/operations/files.py:1241-1242). A template containing{{ secret }}therefore prints the raw secret. Suppress or redact these diffs when hidden values are present, and add regression coverage that checks both the uploaded content and the logs. - Falsey custom finalizers are skipped.
src/pyinfra/api/util.py:176usesif user_finalize:. A callable whose__bool__returnsFalsewas valid before this change but is no longer called. Useif user_finalize is not None:and add a regression test for this case.
Done at PyCon FR.
|
I would like to highlight that current implementation will also expose the secret, since the user is forced to use .unwrap() anyway. Please see the linked PR in the test library repo so that I can submit fixes for diffs with the test coverage For the falsey |
|
@wowi42 Hello. I just realized that I opened related PR to the wrong repo (my own fork). Sorry about it. I reopened it here pyinfra-dev/pyinfra-testing#5, could you take a look before I fix log assertions in this PR? |
HiddenValueis already allowed to be passed as-is to environment variables (#1853). I think it's sensible to be able to pass it to templates as wellCurrent workaround is to call
.unmask()in the template body, which leaks knowledge of secrets and pyinfra api. Existing templates with.unmask()calls will not be broken by this change3.xat this time)scripts/dev-test.sh)scripts/dev-lint.sh)conventional commits format
AI disclosure
Codex has been used for code review and test generation, implementation changes were done by hand