-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #8277: vtctld logs leak pii http headers #9669
Fixes #8277: vtctld logs leak pii http headers #9669
Conversation
Signed-off-by: Vitaliy Mogilevskiy <[email protected]>
Signed-off-by: Vitaliy Mogilevskiy <[email protected]>
go/vt/workflow/long_polling.go
Outdated
HTTPHeaderRedactedMessage string = "*** redacted by sanitizeRequestHeader() ***" | ||
) | ||
|
||
var whiteListedHTTPHeaders = map[string]interface{}{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we tend to use "allowList" instead of "whitelist", as with #8630.
(Also thank you for listing the keys in alphabetical order. 😍)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good 👍
go/vt/workflow/long_polling.go
Outdated
@@ -157,9 +158,48 @@ func getID(url, base string) (int, error) { | |||
return i, nil | |||
} | |||
|
|||
const ( | |||
LogLevelDumpAllHTTPHeaders glog.Level = 50 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh, using the loglevel to determine behavior is very elegant!
Another way to do this that you may have already considered is to add a flag. Recently, I came across #9550 by @mattlord, which is similar in spirit in that it redacts sensitive information from the logs (bind variables, in this particular case). That PR introduces the sanitize_log_messages
flag on the vttablet
for this purpose.
I'd bias towards using a flag, since it's explicitly opt-in, and I can see an (admittedly imaginary) scenario where one would want debug logging on but to still redact the headers. However! I acknowledge there are definitely trade-offs in adding a flag. (vtctlds already have a billion flags, for example.)
I don't feel very strongly about this, but I'm curious what you think. :)
(@mattlord maybe you have an opinion too, since you've been thinking about this for #9469 🙇 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think that adding a flag with the same name and general behavior makes sense for vtctld
as well (I think we'll eventually add this to vtgate
too). Thank you for working on this! ❤️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good, it's good to be consistent with the rest of the project in how these toggles are implemented. Let me see how to wire that up with a flag 🚧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any objections on making this new flag ( dump_all_http_headers
) default's value = false
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
most likely it'll end-up being workflow_manager_sanitize_http_headers
with the default value = true
( to make default behavior safe out of the box )
how does that sound?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... with the goal to make default behavior safe out of the box
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm I do like making things safer by default, but because this is arguably a breaking change, it might be easier to start with a default of workflow_manager_sanitize_http_headers=false
. That way the behaviour is entirely opt-in. This is what #9550 does.
Either way, I would also suggest adding this to the release notes, which will be for Vitess 14.0, unless you feel strongly about backporting this to the current Vitess 13.0 release candidate. (FWIW it'll make no difference to Slack as we'll have to cherry pick this change to our fork anyhow, given that we're not yet ready for 13.0.) I don't think the release notes for 14.0 are being drafted yet, but I'll tag this PR with "release notes" so we don't forget! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok this is done
@@ -132,3 +134,87 @@ func TestLongPolling(t *testing.T) { | |||
cancel() | |||
wg.Wait() | |||
} | |||
|
|||
func TestSanitizeRequestHeader(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests are :chef-kiss: ...thank you!
Signed-off-by: Vitaliy Mogilevskiy <[email protected]>
Signed-off-by: Vitaliy Mogilevskiy <[email protected]>
Signed-off-by: Vitaliy Mogilevskiy <[email protected]>
1f839ca
to
96d79ed
Compare
Hmm it looks like at least some of the CI failures are related to this change. For example, https://github.com/vitessio/vitess/runs/5160694796?check_suite_focus=true
I wonder if this is somehow conflicting with |
@vmogilev so @mattlord kindly brought me up to speed on flags and offered some suggestions for this PR:
diff --git a/go/vt/vtctld/vtctld.go b/go/vt/vtctld/vtctld.go
index 8ddfd67f3e..948eb348a2 100644
--- a/go/vt/vtctld/vtctld.go
+++ b/go/vt/vtctld/vtctld.go
@@ -43,6 +43,7 @@ var (
enableRealtimeStats = flag.Bool("enable_realtime_stats", false, "Required for the Realtime Stats view. If set, vtctld will maintain a streaming RPC to each tablet (in all cells) to gather the realtime health stats.")
enableUI = flag.Bool("enable_vtctld_ui", true, "If true, the vtctld web interface will be enabled. Default is true.")
durabilityPolicy = flag.String("durability_policy", "none", "type of durability to enforce. Default is none. Other values are dictated by registered plugins")
+ sanitizeLogMessages bool
_ = flag.String("web_dir", "", "NOT USED, here for backward compatibility")
_ = flag.String("web_dir2", "", "NOT USED, here for backward compatibility")
@@ -60,6 +61,9 @@ func InitVtctld(ts *topo.Server) error {
return err
}
+ sanitizeLogMessages = flag.Lookup("sanitize_log_messages").Value.(flag.Getter).Get().(bool)
+
actionRepo := NewActionRepository(ts)
// keyspace actions
So perhaps we can update I don't think you'll need to modify your tests at all, since this PR is calling |
Ha, ok I'm back with an even more detailed example from @mattlord 💖 here's a way to more safely look up a flag (in our case, to use the existing flag): diff --git a/go/vt/vtctld/vtctld.go b/go/vt/vtctld/vtctld.go
index 8ddfd67f3e..26bdb8cf8c 100644
--- a/go/vt/vtctld/vtctld.go
+++ b/go/vt/vtctld/vtctld.go
@@ -43,6 +43,7 @@ var (
enableRealtimeStats = flag.Bool("enable_realtime_stats", false, "Required for the Realtime Stats view. If set, vtctld will maintain a streaming RPC to each tablet (in all cells) to gather the realtime health stats.")
enableUI = flag.Bool("enable_vtctld_ui", true, "If true, the vtctld web interface will be enabled. Default is true.")
durabilityPolicy = flag.String("durability_policy", "none", "type of durability to enforce. Default is none. Other values are dictated by registered plugins")
+ sanitizeLogMessages, sanitizeErrorMessages bool
_ = flag.String("web_dir", "", "NOT USED, here for backward compatibility")
_ = flag.String("web_dir2", "", "NOT USED, here for backward compatibility")
@@ -60,6 +61,23 @@ func InitVtctld(ts *topo.Server) error {
return err
}
+ slmFlag := flag.Lookup("sanitize_log_messages")
+ if slmFlag != nil {
+ getter, found := slmFlag.Value.(flag.Getter)
+ if found {
+ sanitizeLogMessages = getter.Get().(bool)
+ }
+ }
+ semFlag := flag.Lookup("sanitize_error_messages")
+ if semFlag != nil {
+ getter, found := semFlag.Value.(flag.Getter)
+ if found {
+ sanitizeErrorMessages = getter.Get().(bool)
+ }
+ }
+
+ log.Infof("Starting vtctld. Log sanitization: %v Error sanitization: %v", sanitizeLogMessages, sanitizeErrorMessages)
+
actionRepo := NewActionRepository(ts)
// keyspace actions Also, per suggestion (2) above, if we update the helptext for the existing |
Hi @doeg , thank you for helping with CI failures - good catch on the duplicate flag name. Small concern I'd like to run by you -- if we go with this shared flag solution, do you know if we'll be able to pull-in this change into our version of Vitess? My concern is around the bit where we now depend on something we don't yet have in our branch (flag defined in another commit/pkg). I also feel a bit weird about this indirect dependency, but if this is the pattern we already use - then perhaps it's warranted to repeat it here. |
Signed-off-by: Vitaliy Mogilevskiy <[email protected]>
It's unfortunate that vtctld depends on some vttablet packages. We don't use the Someday we will implement VEP-4 and clean all this up. |
between the two options:
I tend to favor 2) |
The second option sounds fine to me, but I defer to @mattlord and @deepthi as I work in the vtctld codebase too rarely to have formed any strong opinions. :) Both ways have their merits. Selfishly, I do like that a separate flag will make cherry picking this onto our old release more straightforward. (If Vitess's flag usage will change with vitessio/enhancements#8, perhaps more granular flags will make a migration to Cobra a tiny bit easier?) |
Signed-off-by: Vitaliy Mogilevskiy <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! Really appreciate the time and effort put into the tests. ❤️
Description
This PR fixes vtctld logging which is currently leaking http header values that can contain PII.
Related Issue(s)
Fixes #8277
Checklist
Deployment Notes