memory-bank/components/scrubber.md
The Scrubber component in Gitpod is a Go library that provides functionality for removing or masking sensitive information from data. It's designed to protect personally identifiable information (PII) and other sensitive data from being exposed in logs, error messages, and other outputs. The component offers various methods for scrubbing different types of data structures, including strings, key-value pairs, JSON, and Go structs.
The primary purposes of the Scrubber component are:
The Scrubber component is structured as a Go library with several key parts:
The component is designed to be used by other Gitpod components that need to sanitize data before logging, storing, or transmitting it.
The Scrubber interface provides several methods for scrubbing different types of data:
The component implements different sanitization strategies:
[redacted] or [redacted:keyname][redacted:md5:hash:keyname])The scrubber is configured with several lists and patterns:
When scrubbing structs, the component respects the scrub struct tag:
scrub:"ignore": Skip scrubbing this fieldscrub:"hash": Hash this field's valuescrub:"redact": Redact this field's valueThe component supports a TrustedValue interface that allows marking specific values to be exempted from scrubbing:
type TrustedValue interface {
IsTrustedValue()
}
// Scrub a single value
scrubbedValue := scrubber.Default.Value("[email protected]")
// Result: "[redacted:md5:hash]" or similar
// Scrub a value with key context
scrubbedValue := scrubber.Default.KeyValue("password", "secret123")
// Result: "[redacted]"
// Scrub a JSON structure
jsonData := []byte(`{"username": "johndoe", "email": "[email protected]"}`)
scrubbedJSON, err := scrubber.Default.JSON(jsonData)
// Result: {"username": "[redacted:md5:hash]", "email": "[redacted]"}
// Scrub a struct in-place
type User struct {
Username string
Email string `scrub:"redact"`
Password string
}
user := User{Username: "johndoe", Email: "[email protected]", Password: "secret123"}
err := scrubber.Default.Struct(&user)
// Result: user.Username is hashed, user.Email is redacted, user.Password is redacted
// Create a scrubbed copy of a struct
type User struct {
Username string
Email string `scrub:"redact"`
Password string
}
user := User{Username: "johndoe", Email: "[email protected]", Password: "secret123"}
scrubbedUser := scrubber.Default.DeepCopyStruct(user).(User)
// Original user is unchanged, scrubbedUser has sanitized values
The Scrubber component integrates with:
None specified in the component's build configuration.
github.com/hashicorp/golang-lru: For caching sanitization decisionsgithub.com/mitchellh/reflectwalk: For traversing complex data structuresThe component implements several security measures: