Skip to content

Commit

Permalink
Merge pull request #27 from benc-uk:version-0.1.15
Browse files Browse the repository at this point in the history
version-0.1.15
  • Loading branch information
benc-uk authored Apr 6, 2020
2 parents bf7d8f6 + 4d5878f commit 3d0103e
Show file tree
Hide file tree
Showing 5 changed files with 406 additions and 410 deletions.
2 changes: 1 addition & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUN npm run build
FROM golang:1.14-alpine as go-build
WORKDIR /build
ARG goPackage="github.com/benc-uk/kubeview/cmd/server"
ARG version="0.1.13"
ARG version="0.1.15"
ARG buildInfo="Local manual build"

ENV PORT 8000
Expand Down
2 changes: 2 additions & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ func main() {
router.PathPrefix("/css").Handler(http.StripPrefix("/", fileServer))
router.PathPrefix("/img").Handler(http.StripPrefix("/", fileServer))
router.PathPrefix("/favicon.png").Handler(http.StripPrefix("/", fileServer))

// EVERYTHING else redirect to index.html
router.NotFoundHandler = http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
http.ServeFile(resp, req, staticDirectory+"/index.html")
})

log.Printf("### Serving static content from '%v'\n", staticDirectory)

// Start server
Expand Down
25 changes: 25 additions & 0 deletions cmd/server/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http"
"os"
"runtime"
"strings"

"github.com/benc-uk/go-starter/pkg/envhelper"
"github.com/gorilla/mux"
Expand Down Expand Up @@ -139,8 +140,19 @@ func routeScrapeData(resp http.ResponseWriter, req *http.Request) {
return
}

// Remove and hide Helm v3 release secrets, we're never going to show them
secrets.Items = filterSecrets(secrets.Items, func(v apiv1.Secret) bool {
return !strings.HasPrefix(v.ObjectMeta.Name, "sh.helm.release")
})

// Obfuscate & remove secret values
for _, secret := range secrets.Items {
// Inside 'last-applied-configuration'
if secret.ObjectMeta.Annotations["kubectl.kubernetes.io/last-applied-configuration"] != "" {
secret.ObjectMeta.Annotations["kubectl.kubernetes.io/last-applied-configuration"] = "__VALUE REDACTED__"
}

// And the data values of course
for key := range secret.Data {
secret.Data[key] = []byte("__VALUE REDACTED__")
}
Expand Down Expand Up @@ -180,3 +192,16 @@ func routeConfig(resp http.ResponseWriter, req *http.Request) {
resp.Header().Add("Content-Type", "application/json")
resp.Write([]byte(configJSON))
}

//
// Filter a slice of Secrets
//
func filterSecrets(secretList []apiv1.Secret, f func(apiv1.Secret) bool) []apiv1.Secret {
newSlice := make([]apiv1.Secret, 0)
for _, secret := range secretList {
if f(secret) {
newSlice = append(newSlice, secret)
}
}
return newSlice
}
Loading

0 comments on commit 3d0103e

Please sign in to comment.