Add redact struct tag for automatic field redaction during Unpack#224
Add redact struct tag for automatic field redaction during Unpack#224
Conversation
Co-authored-by: michel-laterman <82832767+michel-laterman@users.noreply.github.com>
Co-authored-by: michel-laterman <82832767+michel-laterman@users.noreply.github.com>
Co-authored-by: michel-laterman <82832767+michel-laterman@users.noreply.github.com>
There was a problem hiding this comment.
Implementation is easy to understand and tests are clear.
Redaction is for security so I'm wondering if makes sense for it to be the default behavior. Concretely, should we introduce a new Option to prevent redaction when parsing a config using the NewFrom and MustNewFrom constructors, rather than relying on the user to explicitly remember to call Redact() after constructing the Config object? I imagine we'd want to provide a way to access the unredacted fields as well.
|
Agree, the need to explicitly call For comparison, the collector version of this has an explicit type whose methods prevent the value from becoming visible, see here. This is much safer if we could do something like this instead, especially if we already know we must annotate every type anyway. Additionally, if I look at files included in diagnostics, they are marshalled to YAML and don't seem to pass through ucfg for example here. So I think I would like some clear examples of where we would insert the |
Co-authored-by: michel-laterman <82832767+michel-laterman@users.noreply.github.com>
…ming Co-authored-by: michel-laterman <82832767+michel-laterman@users.noreply.github.com>
Co-authored-by: michel-laterman <82832767+michel-laterman@users.noreply.github.com>
Co-authored-by: michel-laterman <82832767+michel-laterman@users.noreply.github.com>
blakerouse
left a comment
There was a problem hiding this comment.
I don't know if this is working as I would expect. I would not expect that when I perform a New that the content of Config to contain only the redacted values. I would have expected it to contain the actual values.
If I then use the config with Unpack into a structure, then I would expect that it perform the redaction unless the ShowRedacted is included in the option of the unpack.
ycombinator
left a comment
There was a problem hiding this comment.
Left a minor refactoring suggestion but LGTM overall.
Co-authored-by: michel-laterman <82832767+michel-laterman@users.noreply.github.com>
Co-authored-by: michel-laterman <82832767+michel-laterman@users.noreply.github.com>
redact struct tag with Unpack-time redaction for sensitive fields
Co-authored-by: michel-laterman <82832767+michel-laterman@users.noreply.github.com>
redact struct tag with Unpack-time redaction for sensitive fieldsredact struct tag for automatic redaction during Unpack
blakerouse
left a comment
There was a problem hiding this comment.
Looks better, very close. I have one more ask that I believe will required code changes.
Co-authored-by: michel-laterman <82832767+michel-laterman@users.noreply.github.com>
redact struct tag for automatic redaction during Unpack
blakerouse
left a comment
There was a problem hiding this comment.
Thanks for all the fixes and cleanups. This looks good!
Am I missing something, or is redacting during Unpack not going to solve the diagnostics redaction problem here? We get those configs long after they passed through Unpack and because the running agent/beat system needs the real values that original Unpack will have happened with the I can see how this works, and I can see why adding struct tags to control redaction seems useful, but I missing where in our code we would use this and it would solve a problem for us. We would need a place where we call Unpack and then immediately try to print the complete configuration? Where does that happen today? |
|
I think my main problem with this right now is every real use of Unpack is going to set |
|
@cmacknz that's a good point; i'll mark this as a draft for the time being, we can discuss the path forward/if this is even needed in the weekly meeting |
Adds a
redactstruct tag option that automatically redacts sensitive fields to"[REDACTED]"duringUnpack()operations. A newShowRedactedoption bypasses redaction when needed.Implementation
Struct tag parsing (
util.go):redactto supported tag optionsinline,validate, etc.Metadata tracking (
merge.go):Metastruct withRedacted boolfieldnormalizeValue()marks fields withredacttag in metadataRedaction at unpack (
reify.go):doReifyPrimitive(): Redacts primitive string/[]byte/[]rune fieldsreifySliceMerge(): Handles []byte and []rune redactionreifyValue(): Redacts when unpacking to map[string]interface{}metadata.Redactedflag andopts.showRedactedoptionShowRedacted option (
opts.go):Unpack()to show original unredacted valuesSupported Types
Redaction applies to fields of type:
string[]byte[]runetype Password string)Other types ignore the
redacttag.Usage
Tests
Added 11 tests covering:
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.