Skip to content

Commit

Permalink
read key from env
Browse files Browse the repository at this point in the history
  • Loading branch information
bakito committed Mar 1, 2024
1 parent 74eb7f3 commit 6ce6746
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions cmd/decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ var (
Aliases: []string{"uor"},
Short: "Decrypt secrets in exported resource files",
RunE: func(cmd *cobra.Command, args []string) error {

Check failure on line 22 in cmd/decrypt.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
if k, ok := os.LookupEnv(types.EnvAesKey); ok {
aesKey = k
}

if aesKey == "" {
fmt.Println("Please the aes key: ")
key, err := term.ReadPassword(int(os.Stdin.Fd()))
Expand Down
9 changes: 8 additions & 1 deletion pkg/types/encrypted.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ import (
"errors"
"fmt"
"io"
"os"
"strings"

"github.com/bakito/kubexporter/pkg/utils"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/cli-runtime/pkg/genericclioptions"
)

const prefix = "AES@"
const (
prefix = "AES@"
EnvAesKey = "KUBEXPORTER_AES_KEY"
)

type Encrypted struct {
AesKey string `json:"aesKey" yaml:"aesKey"`
Expand All @@ -25,6 +29,9 @@ type Encrypted struct {
}

func (e *Encrypted) Setup() (err error) {
if k, ok := os.LookupEnv(EnvAesKey); ok {
e.AesKey = k
}
if e.AesKey != "" {
e.gcm, err = setupAES(e.AesKey)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/masked.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package types

import (
"crypto/md5" // #nosec G501 we are ok with md5
"crypto/md5" // #nosec G501 we are ok with md5

Check failure on line 4 in pkg/types/masked.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default (gci)
"crypto/sha1" // #nosec G505 we are ok with sha1
"crypto/sha256"
"fmt"
Expand Down

0 comments on commit 6ce6746

Please sign in to comment.