Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

fix: Redact IPv6 addresses in "dial tcp" errors #1075

Merged
merged 1 commit into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions client/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import (
const ssoInvalidOrExpired = "failed to refresh cached credentials, the SSO session has expired or is invalid"

var (
ipv4Regex = `\d+\.\d+\.\d+\.\d+`
ipv6Regex = `(?:(?:[a-fA-F0-9]{0,4}:)){2,7}[a-fA-F0-9]{0,4}`
bracketedIpv6Regex = fmt.Sprintf(`\[%s\]`, ipv6Regex)

requestIdRegex = regexp.MustCompile(`\s([Rr]equest[ _]{0,1}(ID|Id|id):)\s[A-Za-z0-9-]+`)
hostIdRegex = regexp.MustCompile(`\sHostID: [A-Za-z0-9+/_=-]+`)
arnIdRegex = regexp.MustCompile(`(\s)(arn:aws[A-Za-z0-9-]*:)[^ \.\(\)\[\]\{\}\;\,]+(\s?)`)
Expand All @@ -27,7 +31,10 @@ var (
`\bread\s(udp|tcp)\s` + // "read udp "
`\S+:\d+->\S+:\d+`, // "192.168.1.2:5353->192.168.1.1:53"
)
dialRegex = regexp.MustCompile(`(\sdial\s)(tcp|udp)(\s)([0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3}:[0-9]{1,5})(:.+?)`)
dialRegex = regexp.MustCompile(
`\bdial\s(tcp|udp)\s` + // "dial tcp "
fmt.Sprintf(`(?:%s|%s):\d+`, ipv4Regex, bracketedIpv6Regex), // "192.168.1.2:123" or "[::1]:123"
)
encAuthRegex = regexp.MustCompile(`(\s)(Encoded authorization failure message:)\s[A-Za-z0-9_-]+`)
userRegex = regexp.MustCompile(`(\s)(is not authorized to perform: .+ on resource:\s)(user)\s.+`)
s3Regex = regexp.MustCompile(`(\s)(S3(Key|Bucket))=(.+?)([,;\s])`)
Expand Down Expand Up @@ -244,7 +251,7 @@ func removePII(aa []string, msg string) string {
msg = urlRegex.ReplaceAllString(msg, "${1}http${2}://xxxx${3}")
msg = lookupRegex.ReplaceAllString(msg, "lookup xxxx on xxxx:xx")
msg = readXonYRegex.ReplaceAllString(msg, "read $1 xxxx:xx->xxxx:xx")
msg = dialRegex.ReplaceAllString(msg, "${1}${2}${3}xxxx${5}")
msg = dialRegex.ReplaceAllString(msg, "dial $1 xxxx:xx")
msg = encAuthRegex.ReplaceAllString(msg, "${1}${2} xxxx")
msg = userRegex.ReplaceAllString(msg, "${1}${2}${3} xxxx")
msg = s3Regex.ReplaceAllString(msg, "${1}${2}=xxxx${5}")
Expand Down
6 changes: 5 additions & 1 deletion client/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ func TestRemovePII(t *testing.T) {
},
{
"operation error Direct Connect: DescribeVirtualInterfaces, exceeded maximum number of attempts, 10, https response error StatusCode: 0, RequestID: , request send failed, Post \"https://logs.eu-central-1.amazonaws.com/\": dial tcp 177.72.244.112:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.",
"operation error Direct Connect: DescribeVirtualInterfaces, exceeded maximum number of attempts, 10, https response error StatusCode: 0, RequestID: , request send failed, Post \"https://xxxx\": dial tcp xxxx: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.",
"operation error Direct Connect: DescribeVirtualInterfaces, exceeded maximum number of attempts, 10, https response error StatusCode: 0, RequestID: , request send failed, Post \"https://xxxx\": dial tcp xxxx:xx: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.",
},
{
`operation error Cognito Identity Provider: ListUserPools, exceeded maximum number of attempts, 10, https response error StatusCode: 0, RequestID: , request send failed, Post "https://cognito-idp.us-west-2.amazonaws.com/": dial tcp [2600:1f14:917:5700:4845:5c16:891b:7127]:443: connect: network is unreachable`,
`operation error Cognito Identity Provider: ListUserPools, exceeded maximum number of attempts, 10, https response error StatusCode: 0, RequestID: , request send failed, Post "https://xxxx": dial tcp xxxx:xx: connect: network is unreachable`,
},
{
"operation error EC2: DescribeSnapshotAttribute, https response error StatusCode: 400, RequestID: xxxx, api error InvalidSnapshot.NotFound: The snapshot 'snap-11111111111111111' does not exist.",
Expand Down