-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Binaries for programs and plugins | ||
bin | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
GOFILES = $(shell find . -name '*.go' -not -path './vendor/*') | ||
GOPACKAGES = $(shell go list ./... | grep -v /vendor/) | ||
LOCAL_BIN = $(shell pwd)/bin | ||
|
||
default: build | ||
|
||
bin/gox: | ||
GOBIN=$(LOCAL_BIN) go get github.com/mitchellh/gox | ||
|
||
bin/redakt_linux_amd64 bin/redakt_darwin_amd64 bin/redakt_windows_amd64.exe: bin/gox $(GOFILES) | ||
$(LOCAL_BIN)/gox -osarch "linux/amd64 darwin/amd64 windows/amd64" -output "bin/redakt_{{.OS}}_{{.Arch}}" github.com/massiveco/redakt | ||
|
||
build: bin/redakt_linux_amd64 bin/redakt_darwin_amd64 bin/redakt_windows_amd64.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
# redakt | ||
|
||
Strip sensitive content out of YAML files | ||
|
||
## Example Usage | ||
|
||
> kustomize build | redakt --kind Namespace | kubectl diff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module github.com/massiveco/redakt | ||
|
||
require ( | ||
github.com/mitchellh/gox v1.0.0 // indirect | ||
gopkg.in/yaml.v2 v2.2.2 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
github.com/hashicorp/go-version v1.0.0 h1:21MVWPKDphxa7ineQQTrCU5brh7OuVVAzGOCnnCPtE8= | ||
github.com/hashicorp/go-version v1.0.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= | ||
github.com/mitchellh/gox v1.0.0 h1:7ENCygwtc/7barDq96k0JPZhvrpHO/7oihNahmrmAhg= | ||
github.com/mitchellh/gox v1.0.0/go.mod h1:ED6BioOGXMswlXa2zxfh/xdd5QhwYliBFn9V18Ap4z4= | ||
github.com/mitchellh/iochan v1.0.0 h1:C+X3KsSTLFVBr/tK1eYN/vs4rJcvsiLU338UhYPJWeY= | ||
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= | ||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"flag" | ||
"fmt" | ||
"os" | ||
|
||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
var redactedFlags redactFlags | ||
|
||
func init() { | ||
|
||
flag.Var(&redactedFlags, "kind", "Kubernetes kind to ignore") | ||
|
||
flag.Parse() | ||
} | ||
func main() { | ||
reader := bufio.NewScanner(os.Stdin) | ||
reader.Split(splitOnDashes) | ||
|
||
for reader.Scan() { | ||
manifest := reader.Text() | ||
obj := manifestStub{} | ||
yaml.Unmarshal([]byte(manifest), &obj) | ||
|
||
if contains(redactedFlags, obj.Kind) { | ||
continue | ||
} | ||
|
||
fmt.Fprint(os.Stdout, manifest) | ||
} | ||
fmt.Fprintln(os.Stdout) | ||
} | ||
|
||
// contains tells whether a contains x. | ||
func contains(a []string, x string) bool { | ||
for _, n := range a { | ||
if x == n { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
import "strings" | ||
|
||
type redactFlags []string | ||
|
||
func (rf *redactFlags) String() string { | ||
return strings.Join(*rf, ", ") | ||
} | ||
|
||
func (rf *redactFlags) Set(value string) error { | ||
*rf = append(*rf, value) | ||
return nil | ||
} | ||
|
||
type manifestStub struct { | ||
Kind string | ||
Metadata manifestMetadata | ||
} | ||
|
||
type manifestMetadata struct { | ||
Name string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
import "strings" | ||
|
||
var sep = []byte("---") | ||
|
||
func splitOnDashes(data []byte, atEOF bool) (int, []byte, error) { | ||
if atEOF && len(data) == 0 { | ||
return 0, nil, nil | ||
} | ||
if i := strings.Index(string(data), "---"); i >= 0 { | ||
return i + 3, append(data[0:i], sep...), nil | ||
} | ||
if atEOF { | ||
return len(data), data, nil | ||
} | ||
return 0, nil, nil | ||
} |