feat: parse secret text as multiple secrets

master
Marcus Noble 1 year ago
parent 9a02a817b9
commit 2ed79284e3
  1. 11
      README.md
  2. 25
      main.go

@ -39,11 +39,12 @@ kind: Secret
metadata:
name: example-secret
annotations:
kube-1password: 123456example7890 # [Required] This is the ID of the item within 1Password
kube-1password/vault: Kubernetes # The name of the Vault
kube-1password/username-key: "user" # The key the username should be saved as in the Secret resource (default: `username`)
kube-1password/password-key: "pass" # The key the password should be saved as in the Secret resource (default: `password`)
kube-1password/secret-text-key: "note" # The key the secret text should be saved as in the Secret resource (default: `secretText`)
kube-1password: 123456example7890 # [Required] This is the ID of the item within 1Password
kube-1password/vault: Kubernetes # The name of the Vault
kube-1password/username-key: "user" # The key the username should be saved as in the Secret resource (default: `username`)
kube-1password/password-key: "pass" # The key the password should be saved as in the Secret resource (default: `password`)
kube-1password/secret-text-key: "note" # The key the secret text should be saved as in the Secret resource (default: `secretText`)
kube-1password/secret-text-parse: "true" # Parse the secret texts as individual secret values in format `key=value` (default: ``)
type: Opaque
```

@ -6,6 +6,7 @@ import (
"log"
"os"
"os/user"
"strings"
"time"
"git.cloud.cluster.fun/AverageMarcus/kube-1password-secrets/internal/onepassword"
@ -16,11 +17,12 @@ import (
)
const (
idAnnotation = "kube-1password"
vaultAnnotation = "kube-1password/vault"
usernameAnnotation = "kube-1password/username-key"
passwordAnnotation = "kube-1password/password-key"
secretTextAnnotation = "kube-1password/secret-text-key"
idAnnotation = "kube-1password"
vaultAnnotation = "kube-1password/vault"
usernameAnnotation = "kube-1password/username-key"
passwordAnnotation = "kube-1password/password-key"
secretTextAnnotation = "kube-1password/secret-text-key"
secretTextParseAnnotation = "kube-1password/secret-text-parse"
)
func main() {
@ -68,7 +70,18 @@ func main() {
}
if item.SecretText != "" {
s.Data[keys["secretText"]] = []byte(item.SecretText)
if s.ObjectMeta.Annotations[secretTextParseAnnotation] != "" {
// Parse secret text as individual secrets
lines := strings.Split(item.SecretText, "\n")
for _, line := range lines {
parts := strings.Split(line, "=")
if len(parts) == 2 {
s.Data[parts[0]] = []byte(parts[1])
}
}
} else {
s.Data[keys["secretText"]] = []byte(item.SecretText)
}
}
if _, err := clientset.CoreV1().Secrets(s.GetNamespace()).Update(context.Background(), &s, metav1.UpdateOptions{}); err != nil {

Loading…
Cancel
Save