diff --git a/README.md b/README.md index 4d3d49b..55c798a 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/main.go b/main.go index a0d23c5..d8a7607 100644 --- a/main.go +++ b/main.go @@ -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 {