A Simple to use golang masking tool to mask sensitive information from go-lang data-structures

Golang Masking Tool

License GolangVersion CircleCI Release Go Reference

Golang Masking Tool is a simple utility of creating a masker tool which you can use to mask sensitive information. You can use a variety of filters with custom masking types to assist you.

Inspired by two repositories -

  1. zlog
  2. Golang Masker

Both libraries were solving similar usecase but didn't cover all use cases I was looking for. Zlog is a libray that focuses more on logging and its filterating features are not exposed to be used separately. While Golang Masker doesn't cover all data types. Hence it didn't solve my use-cases.

So I combined both of them to create this library and sharing the best of both them. Added some more uses cases too.

Getting Started

$ go get -u github.com/anu1097/golang-masking-tool

Usage

Basic Example

Create Masking Instance

    var maskingInstance = NewMaskTool()

Filter Sensitive Data

By Specified Field

Default

	type myRecord struct {
		ID    string
		Phone string
	}
	record := myRecord{
		ID:    "userId",
		Phone: "090-0000-0000",
	}

	maskTool := NewMaskTool(filter.FieldFilter("Phone"))
	filteredData := maskTool.MaskDetails(record)

	// fmt.Println(filteredData)
	// {userId [filtered]}

Custom Mask Type

	type myRecord struct {
		ID         string
		Phone      string
		Url        string
		Email      string
		Name       string
		Address    string
		CreditCard string
	}
	record := myRecord{
		ID:         "userId",
		Phone:      "090-0000-0000",
		Url:        "http://admin:mysecretpassword@localhost:1234/uri",
		Email:      "[email protected]",
		Name:       "John Doe",
		Address:    "1 AB Road, Paradise",
		CreditCard: "4444-4444-4444-4444",
	}

	maskTool := NewMaskTool(
		filter.CustomFieldFilter("Phone", customMasker.MMobile),
		filter.CustomFieldFilter("Email", customMasker.MEmail),
		filter.CustomFieldFilter("Url", customMasker.MURL),
		filter.CustomFieldFilter("Name", customMasker.MName),
		filter.CustomFieldFilter("ID", customMasker.MID),
		filter.CustomFieldFilter("Address", customMasker.MAddress),
		filter.CustomFieldFilter("CreditCard", customMasker.MCreditCard),
	)
	filteredData := maskTool.MaskDetails(record)

	// fmt.Println(filteredData)
	// {userId**** 090-***0-0000 http://admin:xxxxx@localhost:1234/uri dum****@dummy.com J**n D**e 1 AB R****** 4444-4******44-4444}

By Specified Field-Prefix

Default

	type myRecord struct {
		ID          string
		SecurePhone string
	}
	record := myRecord{
		ID:          "userId",
		SecurePhone: "090-0000-0000",
	}

	maskTool := NewMaskTool(filter.FieldPrefixFilter("Secure"))
	filteredData := maskTool.MaskDetails(record)

	// fmt.Println(filteredData)
	// {userId [filtered]}

Custom

	maskTool := NewMaskTool(filter.CustomFieldPrefixFilter("Secure", customMasker.MMobile))
	filteredData := maskTool.MaskDetails(record)

	// fmt.Println(filteredData)
	// {userId 090-***0-0000}

By Specified Value

Default

	const issuedToken = "abcd1234"
	maskTool := NewMaskTool(filter.ValueFilter(issuedToken))
	record := "Authorization: Bearer " + issuedToken
	filteredData := maskTool.MaskDetails(record)

	// fmt.Println(filteredData)
	// Authorization: Bearer [filtered]

Custom Mask Type

	const issuedToken = "abcd1234"
	maskTool := NewMaskTool(filter.CustomValueFilter(issuedToken, customMasker.MPassword))
	record := "Authorization: Bearer " + issuedToken
	filteredData := maskTool.MaskDetails(record)

	// fmt.Println(filteredData)
	// Authorization: Bearer ************

By custom type

Default

	type password string
	type myRecord struct {
		ID       string
		Password password
	}
	record := myRecord{
		ID:       "userId",
		Password: "abcd1234",
	}
	maskTool := NewMaskTool(filter.CustomTypeFilter(password(""), customMasker.MPassword))
	filteredData := maskTool.MaskDetails(record)

	// fmt.Println(filteredData)
	// {userId [filtered]}

Custom Mask Type

	type password string
	type myRecord struct {
		ID       string
		Password password
	}
	record := myRecord{
		ID:       "userId",
		Password: "abcd1234",
	}

	maskTool := NewMaskTool(filter.CustomTypeFilter(password(""), customMasker.MPassword))
	filteredData := maskTool.MaskDetails(record)

	// fmt.Println(filteredData)
	// {userId ************}

By struct tag

Default

	type myRecord struct {
		ID    string
		EMail string `mask:"secret"` //Use secret for default filter
	}
	record := myRecord{
		ID:    "userId",
		EMail: "[email protected]",
	}

	maskTool := NewMaskTool(filter.TagFilter())
	filteredData := maskTool.MaskDetails(record)

	// fmt.Println(filteredData)
	// {userId [filtered]}

Custom Mask Type

	type myRecord struct {
		ID    string
		EMail string `mask:"email"`
		Phone string `mask:"mobile"`
	}
	record := myRecord{
		ID:    "userId",
		EMail: "[email protected]",
		Phone: "9191919191",
	}

	maskTool := NewMaskTool(filter.TagFilter(customMasker.MEmail, customMasker.MMobile))
	filteredData := maskTool.MaskDetails(record)

	// fmt.Println(filteredData)
	// {userId dum****@dummy.com 9191***191}

By Regex Pattern

Default Phone Filter

	type myRecord struct {
		ID    string
		Phone string
	}
	record := myRecord{
		ID:    "userId",
		Phone: "090-0000-0000",
	}
	maskTool := NewMaskTool(filter.PhoneFilter())
	filteredData := maskTool.MaskDetails(record)

	// fmt.Println(filteredData)
	// {userId [filtered]}

Custom Phone Filter

	type myRecord struct {
		ID    string
		Phone string
	}
	record := myRecord{
		ID:    "userId",
		Phone: "090-0000-0000",
	}
	maskTool := NewMaskTool((filter.CustomPhoneFilter(customMasker.MMobile)))
	filteredData := maskTool.MaskDetails(record)

	// fmt.Println(filteredData)
	//{userId 090-***0-0000}

Default Email Filter

	type myRecord struct {
		ID    string
		Email string
	}
	record := myRecord{
		ID:    "userId",
		Email: "[email protected]",
	}
	maskTool := NewMaskTool(filter.EmailFilter())
	filteredData := maskTool.MaskDetails(record)

	// fmt.Println(filteredData)
	// {userId [filtered]}

Custom Email Filter


	type myRecord struct {
		ID    string
		Email string
	}
	record := myRecord{
		ID:    "userId",
		Email: "[email protected]",
	}
	maskTool := NewMaskTool(filter.EmailFilter())
	filteredData := maskTool.MaskDetails(record)

	// fmt.Println(filteredData)
	// {userId dum****@dummy.com}

Custom Regex Filter

	customRegex := "^https:\\/\\/(dummy-backend.)[0-9a-z]*.com\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)$"
	type myRecord struct {
		ID   string
		Link string
	}
	record := myRecord{
		ID:   "userId",
		Link: "https://dummy-backend.getsimpl.com/v2/random",
	}
	maskTool := NewMaskTool(filter.CustomRegexFilter(customRegex))
	filteredData := maskTool.MaskDetails(record)

	// fmt.Println(filteredData)
	// {userId [filtered]}

Custom Regex Filter With Mask Type

	type myRecord struct {
		ID   string
		Link string
	}
	record := myRecord{
		ID:   "userId",
		Link: "https://dummy-backend.getsimpl.com/v2/random",
	}
	maskTool := NewMaskTool(filter.CustomRegexFilterWithMType(customRegex, customMasker.MPassword))
	filteredData := maskTool.MaskDetails(record)

	// fmt.Println(filteredData)
	// {userId ************}

By AllFields Filter

Default

	type child struct {
		Data string
	}
	s := "test"
	type myStruct struct {
		Func      func() time.Time
		Chan      chan int
		Bool      bool
		Bytes     []byte
		Strs      []string
		StrsPtr   []*string
		Interface interface{}
		Child     child
		ChildPtr  *child
		Data      string
	}
	data := &myStruct{
		Func:      time.Now,
		Chan:      make(chan int),
		Bool:      true,
		Bytes:     []byte("timeless"),
		Strs:      []string{"aa"},
		StrsPtr:   []*string{&s},
		Interface: &s,
		Child:     child{Data: "x"},
		ChildPtr:  &child{Data: "y"},
		Data:      "data",
	}
	mask := NewMaskingInstance(
		filter.AllFieldFilter(),
	)

	filteredData := mask.MaskDetails(data)

	// fmt.Println(filteredData)
	// {<nil> <nil> false [] [] [] <nil> {} 0x1400009b180 [filtered]}

With Custom Mask Type

	mask := NewMaskingInstance(
		filter.CustomAllFieldFilter(customMasker.MPassword),
	)
	filteredData := mask.MaskDetails(data)

	// fmt.Println(filteredData)
	// {<nil> <nil> false [] [] [] <nil> {} 0x1400009b180 ************}

Custom Mask Types

Type Const Tag Description
Name MName name mask the second letter and the third letter
Password MPassword password always return ************
Address MAddress addr keep first 6 letters, mask the rest
Email MEmail email keep domain and the first 3 letters
Mobile MMobile mobile mask 3 digits from the 4'th digit
Telephone MTelephone tel remove (, ), , - chart, and mask last 4 digits of telephone number, format to (??)????-????
ID MID id mask last 4 digits of ID number
CreditCard MCreditCard credit mask 6 digits from the 7'th digit
Secret MStruct secret Uses default filtered string. Use only with Struct Tag filter

Customise Masking Tool

Update Default Filter

	maskTool := NewMaskTool(filter.FieldFilter("Phone"))
	maskTool.SetFilteredLabel("CustomFilterString")
	// maskTool.GetFilteredLabel()
    // CustomFilterString

Update Custom Masker Character

	maskTool := NewMaskTool(filter.FieldFilter("Phone"))
	maskTool.UpdateCustomMaskingChar(customMasker.PCross)

Append More Filter

	maskTool := NewMaskTool(filter.FieldFilter("Phone"))
	maskTool.AppendFilters(filter.EmailFilter())

License

Owner
Anuraag Gupta
Full Stack Developer. React.JS, Angular Framework and Spring Boot, MERN stack enthusiast.
Anuraag Gupta
Similar Resources

Automatically capture all potentially useful information about each executed command (as well as its output) and get powerful querying mechanism

Automatically capture all potentially useful information about each executed command (as well as its output) and get powerful querying mechanism

nhi is a revolutionary tool which automatically captures all potentially useful information about each executed command and everything around, and delivers powerful querying mechanism.

Nov 29, 2022

Prometheus exporter for IAAS daily billing information

Prometheus exporter for IAAS daily billing information

Multi-iaas-daily-billing-exporter Multi-iaas-daily-billing-exporter enables to collect, unify and expose daily billing from AWS and GCP providers. The

Dec 14, 2021

Tackle Add-on to discover information from a source repository

Tackle Add-ons - Discovery - Languages This add-on explores the source code repository and finds the languages using GitHub Linguist. It's common that

Dec 24, 2021

API to get docker information from server.

Docker Access API API to get docker information from server. This api is written using Go language and used Gin Framework for API building. How to run

Dec 13, 2021

Cloud-Z gathers information and perform benchmarks on cloud instances in multiple cloud providers.

Cloud-Z Cloud-Z gathers information and perform benchmarks on cloud instances in multiple cloud providers. Cloud type, instance id, and type CPU infor

Jun 8, 2022

SMART information of local storage devices as Prometheus metrics

hpessa-exporter Overview Openshift's hpessa-exporter allows users to export SMART information of local storage devices as Prometheus metrics, by using

Feb 10, 2022

Simple tool to generate dockerconfigjon. This use snippets from kubectl.

gen-dockercfg Simple tool to generate dockerconfigjon. This use snippets from kubectl. Usage: gen-dockercfg -email string Registry email -pas

Jan 7, 2022

Terraform utility provider for constructing bash scripts that use data from a Terraform module

Terraform Bash Provider This is a Terraform utility provider which aims to robustly generate Bash scripts which refer to data that originated in Terra

Sep 6, 2022

A simple tool who pulls data from Online.net API and parse them to a Prometheus format

Dedibox backup monitoring A simple tool who reads API from Online.net and parse them into a Prometheus-compatible format. Conceived to be lightweight,

Aug 16, 2022
Simple example using Git actions + Argo CD + K8S + Docker and GO lang

CICD-simple_example Simple example using Git actions + Argo CD + K8S + Docker and GO lang Intro Pre reqs Have an ArgoCD account and Installed. Docker

Oct 28, 2021
A Go based deployment tool that allows the users to deploy the web application on the server using SSH information and pem file.

A Go based deployment tool that allows the users to deploy the web application on the server using SSH information and pem file. This application is intend for non tecnhincal users they can just open the GUI and given the server details just deploy.

Oct 16, 2021
Openshift's hpessa-exporter allows users to export SMART information of local storage devices as Prometheus metrics, by using HPE Smart Storage Administrator tool

hpessa-exporter Overview Openshift's hpessa-exporter allows users to export SMART information of local storage devices as Prometheus metrics, by using

Jan 17, 2022
Using the Golang search the Marvel Characters. This project is a web based golang application that shows the information of superheroes using Marvel api.
Using the Golang search the Marvel Characters. This project is a web based golang application that shows the information of superheroes using Marvel api.

marvel-universe-web using the Golang search the Marvel Universe Characters About The Project This project is a web based golang application that shows

Oct 10, 2021
Fancy Git Clone that preserves directory structures

git go-clone This is fancy wrapper around git clone that preserves directory structures. For example, if you have some complex organization, and you w

Sep 24, 2021
Go lang IDE. Built with GopherSauce
Go lang IDE. Built with GopherSauce

IDE runs as a server and is accessed via web browser. Being a web server, the IDE boasts a web (HTML) interface is accessible from any device on your network.Compared to Microsoft VS Code and Eclipse CHE, this IDE is very minimalistic

Nov 28, 2022
Go(lang) Environment Variable Parsing / Unmarshaler / Decoder

Go(lang) Environment Variable Parsing / Unmarshaler / Decoder

Aug 8, 2022
💧 Visual Data Preparation (VDP) is an open-source tool to seamlessly integrate Vision AI with the modern data stack
💧 Visual Data Preparation (VDP) is an open-source tool to seamlessly integrate Vision AI with the modern data stack

Website | Community | Blog Get Early Access Visual Data Preparation (VDP) is an open-source tool to streamline the end-to-end visual data processing p

Jan 5, 2023
Kubei is a flexible Kubernetes runtime scanner, scanning images of worker and Kubernetes nodes providing accurate vulnerabilities assessment, for more information checkout:
Kubei is a flexible Kubernetes runtime scanner, scanning images of worker and Kubernetes nodes providing accurate vulnerabilities assessment, for more information checkout:

Kubei is a vulnerabilities scanning and CIS Docker benchmark tool that allows users to get an accurate and immediate risk assessment of their kubernet

Dec 30, 2022
A kubectl plugin for getting endoflife information about your cluster.
A kubectl plugin for getting endoflife information about your cluster.

kubectl-endoflife A kubectl plugin that checks your clusters for component compatibility and Kubernetes version end of life. This plugin is meant to a

Jul 21, 2022