Repository navigation
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
|
The binary size has increased significantly due to Working on options:
|
Command.MarshalJSON kept encoding/json in every binary that uses help templates, as text/template makes the linker keep all exported methods. This grew the example binary from 2.3MB to 2.7MB, over the size limit. Remove it, and instead have a sensitive flag whose value is a pointer (GenericFlag, TextFlag) parse into a shallow copy of its default value. Its Value field then keeps the default, so encoding a command or a flag as JSON never shows the value the flag was set to. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A shallow copy of a sensitive flag's default shares any maps, slices or pointers inside it, so parsing could still write the set value into the default. Copy a value that implements encoding.TextMarshaler and encoding.TextUnmarshaler, as every TextFlag value does, by unmarshaling its text form into a new zero value. Fall back to a shallow copy for other values, or when the text form cannot be read back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What type of PR is this?
What this PR does / why we need it:
This PR adds the ability to mark a flag as 'sensitive' to prevent its value from being printed or returned by any function.
The idea for the feature came from my interest in developing a separate feature, which would allow a program to print a "canonical" command; since
clisupports reading values from--cli-flagsandENV_VARS, I wanted to be able to havedebug builds print out a full CLI (
progname --foo bar --baz bonk) by combining together all of the provided values from all provided sources into one version so that an identical command could be run e.g. outside of CI, or so that CI runscould print all the (raw) parameters they're using for debugging purposes.
This necessitated determining which values were secret or sensitive, which I implemented before realizing that the same feature is described in the v4 design doc
We also add one function of note:
(*Command).SensitiveValues; this function returns the current value of allSensitiveflags from this command and all subcommands; this is counterintuitive, but the goal is to provide a way for programs to know what values are sensitive and should be excluded from printing.A new example
ExampleCommand_SensitiveValuesinexamples_test.goimplements an exampleRedactingWriterwhich can be used to filter secrets out of log lines automatically before they are printed.It was considered to add this functionality directly (i.e. add
(*Command).ReplaceSensitiveor(*Command).RedactingWriterutility functions) but that feels like scope creep and might not cover common use cases; providing access toSensitiveValuesdirectly allows for anyone to implement redaction as they wish, or to implement any other functionality (e.g. matchingagainst a list of known-bad tokens, hashing the output instead, replacing the values with
*****of the same length, etc).Which issue(s) this PR fixes:
N/A (I can't find any for this feature)
Special notes for your reviewer:
The main thing to be aware of is that we were not able to mask values in all circumstances, but the exception is pretty niche: when encoding a
Flagdirectly to JSON rather than encodingCommand, theFlag's default value is leaked in the resulting JSON.In other words, if a developer chooses to encode a sensitive
Flagas JSON directly, the default value of a that flag can be leaked. It's my opinion that the default value of a flag, even one marked as 'sensitive', should probably not be considered sensitive in most cases; the value will appear ifstringsis run on the binary, and will also appear in the source code or linker flags of the binary as well.Testing
There are 10 test functions, one of which has three sub-cases, for a total of 12 tests for this functionality. The existing unit tests all pass unchaged as well.
I also ran
apidiffbetween this branch and currentmasterand it reports no incompatible changes.apidiff analysis from d5c06cb..11da192
Release Notes