8000 logs obfuscation by simagix · Pull Request #23 · simagix/hatchet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

logs obfuscation #23

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

Merged
merged 1 commit into from
May 1, 2023
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,12 @@ Hatchet has the ability to download files from AWS S3. When downloading files, H
hatchet -s3 [--endpoint-url {test endpoint}] {bucket}/{key name}
```

## Logs Obfuscation
Use Hatchet to obfuscate logs. It automatically obfuscates the values of the matched patterns under the "attr" field, such as SSN, credit card numbers, phone numbers, email addresses, IP addresses, FQDNs, port numbers, namespaces, and other numbers. Note that, for example, replacing "host.example.com" with "rose.taipei.com" in the log file will consistently replace all other occurrences of "host.example.com" with "rose.taipei.com". To obfuscate logs and redirect them to a file, use the following syntax:

```bash
hatchet -obfuscate {log file} > {output file}
```

## License
[Apache-2.0 License](LICENSE)
19 changes: 19 additions & 0 deletions hatchet.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ package hatchet
import (
"database/sql"
"encoding/base64"
"encoding/json"
"flag"
"fmt"
"log"
"net"
"net/http"
"os"
"regexp"
"strings"

Expand All @@ -27,6 +29,7 @@ func Run(fullVersion string) {
digest := flag.Bool("digest", false, "HTTP digest")
endpoint := flag.String("endpoint-url", "", "AWS endpoint")
legacy := flag.Bool("legacy", false, "view logs in legacy format")
infile := flag.String("obfuscate", "", "obfuscate logs")
port := flag.Int("port", 3721, "web server port number")
profile := flag.String("aws-profile", "default", "AWS profile name")
s3 := flag.Bool("s3", false, "files from AWS S3")
Expand All @@ -42,6 +45,22 @@ func Run(fullVersion string) {
if *ver {
fmt.Println(fullVersion)
return
} else if *infile != "" {
obs := NewObfuscation()
if err := obs.ObfuscateFile(*infile); err != nil {
log.Fatal(err)
}

if *verbose { // write obfuscation info out
data, err := json.Marshal(*obs)
if err != nil {
log.Fatal(err)
}
if err = os.WriteFile(*infile+".json", data, 0644); err != nil {
log.Fatal(err)
}
}
return
}
if !*legacy {
log.Println(fullVersion)
Expand Down
2 changes: 1 addition & 1 deletion logv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ func (ptr *Logv2) PrintSummary() error {
summaries = append(summaries, buffer.String())
if lines < len(ops) {
summaries = append(summaries,
fmt.Sprintf(`+ %v: slowest %d of %d ops displayed`, ptr.hatchetName, lines, len(ops)))
fmt.Sprintf(`+ %v: slowest %d of %d ops displayed`, ptr.hatchetName, lines+1, len(ops)))
}
fmt.Println(strings.Join(summaries, "\n"))
return err
Expand Down
Loading
0