mirror of
				https://github.com/1Password/onepassword-operator.git
				synced 2025-10-31 11:49:40 +00:00 
			
		
		
		
	Compare commits
	
		
			1 Commits
		
	
	
		
			release/v1
			...
			update-pat
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 1590dd9b89 | 
							
								
								
									
										17
									
								
								CHANGELOG.md
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								CHANGELOG.md
									
									
									
									
									
								
							| @@ -12,23 +12,6 @@ | |||||||
|  |  | ||||||
| --- | --- | ||||||
|  |  | ||||||
| [//]: # (START/v1.2.0) |  | ||||||
| # v1.2.0 |  | ||||||
|  |  | ||||||
| ## Features |  | ||||||
|   * Support secrets provisioned through FromEnv. {#74} |  | ||||||
|   * Support configuration of Kubernetes Secret type. {#87} |  | ||||||
|   * Improved logging. (#72) |  | ||||||
| --- |  | ||||||
|  |  | ||||||
| [//]: # (START/v1.1.0) |  | ||||||
| # v1.1.0 |  | ||||||
|  |  | ||||||
| ## Fixes |  | ||||||
|  * Fix normalization for keys in a Secret's `data` section to allow upper- and lower-case alphanumeric characters. {#66} |  | ||||||
|  |  | ||||||
| --- |  | ||||||
|  |  | ||||||
| [//]: # (START/v1.0.2) | [//]: # (START/v1.0.2) | ||||||
| # v1.0.2 | # v1.0.2 | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										29
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								README.md
									
									
									
									
									
								
							| @@ -2,7 +2,7 @@ | |||||||
|  |  | ||||||
| The 1Password Connect Kubernetes Operator provides the ability to integrate Kubernetes with 1Password. This Operator manages `OnePasswordItem` Custom Resource Definitions (CRDs) that define the location of an Item stored in 1Password. The `OnePasswordItem` CRD, when created, will be used to compose a Kubernetes Secret containing the contents of the specified item. | The 1Password Connect Kubernetes Operator provides the ability to integrate Kubernetes with 1Password. This Operator manages `OnePasswordItem` Custom Resource Definitions (CRDs) that define the location of an Item stored in 1Password. The `OnePasswordItem` CRD, when created, will be used to compose a Kubernetes Secret containing the contents of the specified item. | ||||||
|  |  | ||||||
| The 1Password Connect Kubernetes Operator also allows for Kubernetes Secrets to be composed from a 1Password Item through annotation of an Item Path on a deployment. | The 1Password Connect Kubernetes Operator also allows for Kubernetes Secrets to be composed from a 1Password Item through annotation of an Item Reference on a deployment. | ||||||
|  |  | ||||||
| The 1Password Connect Kubernetes Operator will continually check for updates from 1Password for any Kubernetes Secret that it has generated. If a Kubernetes Secret is updated, any Deployment using that secret can be automatically restarted. | The 1Password Connect Kubernetes Operator will continually check for updates from 1Password for any Kubernetes Secret that it has generated. If a Kubernetes Secret is updated, any Deployment using that secret can be automatically restarted. | ||||||
|  |  | ||||||
| @@ -30,13 +30,14 @@ If 1Password Connect is already running, you can skip this step. This guide will | |||||||
| Encode the 1password-credentials.json file you generated in the prerequisite steps and save it to a file named op-session: | Encode the 1password-credentials.json file you generated in the prerequisite steps and save it to a file named op-session: | ||||||
|  |  | ||||||
| ```bash | ```bash | ||||||
| cat 1password-credentials.json | base64 | \ | $ cat 1password-credentials.json | base64 | \ | ||||||
|   tr '/+' '_-' | tr -d '=' | tr -d '\n' > op-session |   tr '/+' '_-' | tr -d '=' | tr -d '\n' > op-session | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| Create a Kubernetes secret from the op-session file: | Create a Kubernetes secret from the op-session file: | ||||||
| ```bash | ```bash | ||||||
| kubectl create secret generic op-credentials --from-file=1password-credentials.json=op-session |  | ||||||
|  | $  kubectl create secret generic op-credentials --from-file=1password-credentials.json | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| Add the following environment variable to the onepassword-connect-operator container in `deploy/operator.yaml`: | Add the following environment variable to the onepassword-connect-operator container in `deploy/operator.yaml`: | ||||||
| @@ -52,12 +53,12 @@ Adding this environment variable will have the operator automatically deploy a d | |||||||
| "Create a Connect token for the operator and save it as a Kubernetes Secret:  | "Create a Connect token for the operator and save it as a Kubernetes Secret:  | ||||||
|  |  | ||||||
| ```bash | ```bash | ||||||
| kubectl create secret generic onepassword-token --from-literal=token=<OP_CONNECT_TOKEN>" | $ kubectl create secret generic onepassword-token --from-literal=token=<OP_CONNECT_TOKEN>" | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| If you do not have a token for the operator, you can generate a token and save it to kubernetes with the following command: | If you do not have a token for the operator, you can generate a token and save it to kubernetes with the following command: | ||||||
| ```bash | ```bash | ||||||
| kubectl create secret generic onepassword-token --from-literal=token=$(op create connect token <server> op-k8s-operator --vault <vault>) | $ kubectl create secret generic onepassword-token --from-literal=token=$(op create connect token <server> op-k8s-operator --vault <vault>) | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| [More information on generating a token can be found here](https://support.1password.com/secrets-automation/#appendix-issue-additional-access-tokens) | [More information on generating a token can be found here](https://support.1password.com/secrets-automation/#appendix-issue-additional-access-tokens) | ||||||
| @@ -67,13 +68,13 @@ kubectl create secret generic onepassword-token --from-literal=token=$(op create | |||||||
| We must create a service account, role, and role binding and Kubernetes. Examples can be found in the `/deploy` folder. | We must create a service account, role, and role binding and Kubernetes. Examples can be found in the `/deploy` folder. | ||||||
|  |  | ||||||
| ```bash | ```bash | ||||||
| kubectl apply -f deploy/permissions.yaml | $ kubectl apply -f deploy/permissions.yaml | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| **Create Custom One Password Secret Resource** | **Create Custom One Password Secret Resource** | ||||||
|  |  | ||||||
| ```bash | ```bash | ||||||
| kubectl apply -f deploy/crds/onepassword.com_onepassworditems_crd.yaml | $ kubectl apply -f deploy/crds/onepassword.com_onepassworditems_crd.yaml | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| **Deploying the Operator** | **Deploying the Operator** | ||||||
| @@ -105,19 +106,19 @@ kind: OnePasswordItem | |||||||
| metadata: | metadata: | ||||||
|   name: <item_name> #this name will also be used for naming the generated kubernetes secret |   name: <item_name> #this name will also be used for naming the generated kubernetes secret | ||||||
| spec: | spec: | ||||||
|   itemPath: "vaults/<vault_id_or_title>/items/<item_id_or_title>"  |   itemReference: "op://<vault_id_or_title>/<item_id_or_title>"  | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| Deploy the OnePasswordItem to Kubernetes: | Deploy the OnePasswordItem to Kubernetes: | ||||||
|  |  | ||||||
| ```bash | ```bash | ||||||
| kubectl apply -f <your_item>.yaml | $ kubectl apply -f <your_item>.yaml | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| To test that the Kubernetes Secret check that the following command returns a secret: | To test that the Kubernetes Secret check that the following command returns a secret: | ||||||
|  |  | ||||||
| ```bash | ```bash | ||||||
| kubectl get secret <secret_name> | $ kubectl get secret <secret_name> | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| Note: Deleting the `OnePasswordItem` that you've created will automatically delete the created Kubernetes Secret. | Note: Deleting the `OnePasswordItem` that you've created will automatically delete the created Kubernetes Secret. | ||||||
| @@ -130,20 +131,20 @@ kind: Deployment | |||||||
| metadata: | metadata: | ||||||
|   name: deployment-example |   name: deployment-example | ||||||
|   annotations: |   annotations: | ||||||
|     operator.1password.io/item-path: "vaults/<vault_id_or_title>/items/<item_id_or_title>" |     operator.1password.io/item-reference: "op://<vault>/<item>" | ||||||
|     operator.1password.io/item-name: "<secret_name>" |     operator.1password.io/item-name: "<secret_name>" | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| Applying this yaml file will create a Kubernetes Secret with the name `<secret_name>` and contents from the location specified at the specified Item Path. | Applying this yaml file will create a Kubernetes Secret with the name `<secret_name>` and contents from the location specified at the specified Item Reference. | ||||||
|  |  | ||||||
| Note: Deleting the Deployment that you've created will automatically delete the created Kubernetes Secret only if the deployment is still annotated with `operator.1password.io/item-path` and `operator.1password.io/item-name` and no other deployment is using the secret. | Note: Deleting the Deployment that you've created will automatically delete the created Kubernetes Secret only if the deployment is still annotated with `operator.1password.io/item-reference` and `operator.1password.io/item-name` and no other deployment is using the secret. | ||||||
|  |  | ||||||
| If a 1Password Item that is linked to a Kubernetes Secret is updated within the POLLING_INTERVAL the associated Kubernetes Secret will be updated. However, if you do not want a specific secret to be updated you can add the tag `operator.1password.io:ignore-secret` to the item stored in 1Password. While this tag is in place, any updates made to an item will not trigger an update to the associated secret in Kubernetes. | If a 1Password Item that is linked to a Kubernetes Secret is updated within the POLLING_INTERVAL the associated Kubernetes Secret will be updated. However, if you do not want a specific secret to be updated you can add the tag `operator.1password.io:ignore-secret` to the item stored in 1Password. While this tag is in place, any updates made to an item will not trigger an update to the associated secret in Kubernetes. | ||||||
|  |  | ||||||
| --- | --- | ||||||
| **NOTE** | **NOTE** | ||||||
|  |  | ||||||
| If multiple 1Password vaults/items have the same `title` when using a title in the access path, the desired action will be performed on the oldest vault/item.  | If multiple 1Password vaults/items have the same `title` when using a title in the access reference, the desired action will be performed on the oldest vault/item.  | ||||||
|  |  | ||||||
| Titles and field names that include white space and other characters that are not a valid [DNS subdomain name](https://kubernetes.io/docs/concepts/configuration/secret/) will create Kubernetes secrets that have titles and fields in the following format: | Titles and field names that include white space and other characters that are not a valid [DNS subdomain name](https://kubernetes.io/docs/concepts/configuration/secret/) will create Kubernetes secrets that have titles and fields in the following format: | ||||||
|  - Invalid characters before the first alphanumeric character and after the last alphanumeric character will be removed |  - Invalid characters before the first alphanumeric character and after the last alphanumeric character will be removed | ||||||
|   | |||||||
| @@ -179,9 +179,7 @@ func main() { | |||||||
| 				return | 				return | ||||||
| 			case <-ticker.C: | 			case <-ticker.C: | ||||||
| 				err := updatedSecretsPoller.UpdateKubernetesSecretsTask() | 				err := updatedSecretsPoller.UpdateKubernetesSecretsTask() | ||||||
| 				if err != nil { | 				log.Error(err, "Error occured during update secret task") | ||||||
| 					log.Error(err, "error running update kubernetes secret task") |  | ||||||
| 				} |  | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	}() | 	}() | ||||||
|   | |||||||
| @@ -33,13 +33,10 @@ spec: | |||||||
|           spec: |           spec: | ||||||
|             description: OnePasswordItemSpec defines the desired state of OnePasswordItem |             description: OnePasswordItemSpec defines the desired state of OnePasswordItem | ||||||
|             properties: |             properties: | ||||||
|               itemPath: |               itemReference: | ||||||
|                 type: string |                 type: string | ||||||
|             type: object |             type: object | ||||||
|           status: |           status: | ||||||
|             description: OnePasswordItemStatus defines the observed state of OnePasswordItem |             description: OnePasswordItemStatus defines the observed state of OnePasswordItem | ||||||
|             type: object |             type: object | ||||||
|           type: |  | ||||||
|             description: 'Kubernetes secret type. More info: https://kubernetes.io/docs/concepts/configuration/secret/#secret-types' |  | ||||||
|             type: string |  | ||||||
|         type: object |         type: object | ||||||
|   | |||||||
| @@ -3,4 +3,4 @@ kind: OnePasswordItem | |||||||
| metadata: | metadata: | ||||||
|   name: example |   name: example | ||||||
| spec: | spec: | ||||||
|   itemPath: "vaults/<vault_id>/items/<item_id>" |   itemReference: "op://<vault_id>/<item_id>" | ||||||
|   | |||||||
| @@ -16,6 +16,7 @@ spec: | |||||||
|       containers: |       containers: | ||||||
|         - name: onepassword-connect-operator |         - name: onepassword-connect-operator | ||||||
|           image: 1password/onepassword-operator |           image: 1password/onepassword-operator | ||||||
|  |           imagePullPolicy: Never | ||||||
|           command: ["/manager"] |           command: ["/manager"] | ||||||
|           env: |           env: | ||||||
|             - name: WATCH_NAMESPACE |             - name: WATCH_NAMESPACE | ||||||
|   | |||||||
| @@ -8,7 +8,7 @@ import ( | |||||||
|  |  | ||||||
| // OnePasswordItemSpec defines the desired state of OnePasswordItem | // OnePasswordItemSpec defines the desired state of OnePasswordItem | ||||||
| type OnePasswordItemSpec struct { | type OnePasswordItemSpec struct { | ||||||
| 	ItemPath string `json:"itemPath,omitempty"` | 	ItemReference string `json:"itemReference,omitempty"` | ||||||
| } | } | ||||||
|  |  | ||||||
| // OnePasswordItemStatus defines the observed state of OnePasswordItem | // OnePasswordItemStatus defines the observed state of OnePasswordItem | ||||||
| @@ -26,7 +26,6 @@ type OnePasswordItemStatus struct { | |||||||
| type OnePasswordItem struct { | type OnePasswordItem struct { | ||||||
| 	metav1.TypeMeta   `json:",inline"` | 	metav1.TypeMeta   `json:",inline"` | ||||||
| 	metav1.ObjectMeta `json:"metadata,omitempty"` | 	metav1.ObjectMeta `json:"metadata,omitempty"` | ||||||
| 	Type              string `json:"type,omitempty"` |  | ||||||
|  |  | ||||||
| 	Spec   OnePasswordItemSpec   `json:"spec,omitempty"` | 	Spec   OnePasswordItemSpec   `json:"spec,omitempty"` | ||||||
| 	Status OnePasswordItemStatus `json:"status,omitempty"` | 	Status OnePasswordItemStatus `json:"status,omitempty"` | ||||||
|   | |||||||
| @@ -191,18 +191,15 @@ func (r *ReconcileDeployment) HandleApplyingDeployment(namespace string, annotat | |||||||
| 	reqLog := log.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name) | 	reqLog := log.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name) | ||||||
|  |  | ||||||
| 	secretName := annotations[op.NameAnnotation] | 	secretName := annotations[op.NameAnnotation] | ||||||
| 	secretLabels := map[string]string(nil) |  | ||||||
| 	secretType := "" |  | ||||||
|  |  | ||||||
| 	if len(secretName) == 0 { | 	if len(secretName) == 0 { | ||||||
| 		reqLog.Info("No 'item-name' annotation set. 'item-path' and 'item-name' must be set as annotations to add new secret.") | 		reqLog.Info("No 'item-name' annotation set. 'item-reference' and 'item-name' must be set as annotations to add new secret.") | ||||||
| 		return nil | 		return nil | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	item, err := op.GetOnePasswordItemByPath(r.opConnectClient, annotations[op.ItemPathAnnotation]) | 	item, err := op.GetOnePasswordItemByReference(r.opConnectClient, annotations[op.ItemReferenceAnnotation]) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return fmt.Errorf("Failed to retrieve item: %v", err) | 		return fmt.Errorf("Failed to retrieve item: %v", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return kubeSecrets.CreateKubernetesSecretFromItem(r.kubeClient, secretName, namespace, item, annotations[op.RestartDeploymentsAnnotation], secretLabels, secretType, annotations) | 	return kubeSecrets.CreateKubernetesSecretFromItem(r.kubeClient, secretName, namespace, item, annotations[op.RestartDeploymentsAnnotation]) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -52,7 +52,7 @@ var ( | |||||||
| 		"password": []byte(password), | 		"password": []byte(password), | ||||||
| 		"username": []byte(username), | 		"username": []byte(username), | ||||||
| 	} | 	} | ||||||
| 	itemPath = fmt.Sprintf("vaults/%v/items/%v", vaultId, itemId) | 	ItemReference = fmt.Sprintf("op://%v/%v", vaultId, itemId) | ||||||
| ) | ) | ||||||
|  |  | ||||||
| var ( | var ( | ||||||
| @@ -76,7 +76,7 @@ var tests = []testReconcileItem{ | |||||||
| 					finalizer, | 					finalizer, | ||||||
| 				}, | 				}, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					op.ItemPathAnnotation: itemPath, | 					op.ItemReferenceAnnotation: ItemReference, | ||||||
| 					op.NameAnnotation:          name, | 					op.NameAnnotation:          name, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| @@ -90,7 +90,7 @@ var tests = []testReconcileItem{ | |||||||
| 				Name:      "another-deployment", | 				Name:      "another-deployment", | ||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					op.ItemPathAnnotation: itemPath, | 					op.ItemReferenceAnnotation: ItemReference, | ||||||
| 					op.NameAnnotation:          name, | 					op.NameAnnotation:          name, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| @@ -152,7 +152,7 @@ var tests = []testReconcileItem{ | |||||||
| 					finalizer, | 					finalizer, | ||||||
| 				}, | 				}, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					op.ItemPathAnnotation: itemPath, | 					op.ItemReferenceAnnotation: ItemReference, | ||||||
| 					op.NameAnnotation:          name, | 					op.NameAnnotation:          name, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| @@ -166,7 +166,7 @@ var tests = []testReconcileItem{ | |||||||
| 				Name:      "another-deployment", | 				Name:      "another-deployment", | ||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					op.ItemPathAnnotation: itemPath, | 					op.ItemReferenceAnnotation: ItemReference, | ||||||
| 					op.NameAnnotation:          name, | 					op.NameAnnotation:          name, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| @@ -235,7 +235,7 @@ var tests = []testReconcileItem{ | |||||||
| 					finalizer, | 					finalizer, | ||||||
| 				}, | 				}, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					op.ItemPathAnnotation: itemPath, | 					op.ItemReferenceAnnotation: ItemReference, | ||||||
| 					op.NameAnnotation:          name, | 					op.NameAnnotation:          name, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| @@ -258,7 +258,7 @@ var tests = []testReconcileItem{ | |||||||
| 		}, | 		}, | ||||||
| 	}, | 	}, | ||||||
| 	{ | 	{ | ||||||
| 		testName: "Test Do not update if Annotations have not changed", | 		testName: "Test Do not update if OnePassword Item Version has not changed", | ||||||
| 		deploymentResource: &appsv1.Deployment{ | 		deploymentResource: &appsv1.Deployment{ | ||||||
| 			TypeMeta: metav1.TypeMeta{ | 			TypeMeta: metav1.TypeMeta{ | ||||||
| 				Kind:       deploymentKind, | 				Kind:       deploymentKind, | ||||||
| @@ -268,10 +268,9 @@ var tests = []testReconcileItem{ | |||||||
| 				Name:      name, | 				Name:      name, | ||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					op.ItemPathAnnotation: itemPath, | 					op.ItemReferenceAnnotation: ItemReference, | ||||||
| 					op.NameAnnotation:          name, | 					op.NameAnnotation:          name, | ||||||
| 				}, | 				}, | ||||||
| 				Labels: map[string]string{}, |  | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 		existingSecret: &corev1.Secret{ | 		existingSecret: &corev1.Secret{ | ||||||
| @@ -280,8 +279,6 @@ var tests = []testReconcileItem{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					op.VersionAnnotation: fmt.Sprint(version), | 					op.VersionAnnotation: fmt.Sprint(version), | ||||||
| 					op.ItemPathAnnotation: itemPath, |  | ||||||
| 					op.NameAnnotation:     name, |  | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| @@ -293,10 +290,7 @@ var tests = []testReconcileItem{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					op.VersionAnnotation: fmt.Sprint(version), | 					op.VersionAnnotation: fmt.Sprint(version), | ||||||
| 					op.ItemPathAnnotation: itemPath, |  | ||||||
| 					op.NameAnnotation:     name, |  | ||||||
| 				}, | 				}, | ||||||
| 				Labels: map[string]string(nil), |  | ||||||
| 			}, | 			}, | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| 		}, | 		}, | ||||||
| @@ -316,7 +310,7 @@ var tests = []testReconcileItem{ | |||||||
| 				Name:      name, | 				Name:      name, | ||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					op.ItemPathAnnotation: itemPath, | 					op.ItemReferenceAnnotation: ItemReference, | ||||||
| 					op.NameAnnotation:          name, | 					op.NameAnnotation:          name, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| @@ -329,7 +323,6 @@ var tests = []testReconcileItem{ | |||||||
| 					op.VersionAnnotation: "456", | 					op.VersionAnnotation: "456", | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Type: corev1.SecretType(""), |  | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| 		}, | 		}, | ||||||
| 		expectedError: nil, | 		expectedError: nil, | ||||||
| @@ -341,7 +334,6 @@ var tests = []testReconcileItem{ | |||||||
| 					op.VersionAnnotation: fmt.Sprint(version), | 					op.VersionAnnotation: fmt.Sprint(version), | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Type: corev1.SecretType(""), |  | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| 		}, | 		}, | ||||||
| 		opItem: map[string]string{ | 		opItem: map[string]string{ | ||||||
| @@ -360,7 +352,7 @@ var tests = []testReconcileItem{ | |||||||
| 				Name:      name, | 				Name:      name, | ||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					op.ItemPathAnnotation: itemPath, | 					op.ItemReferenceAnnotation: ItemReference, | ||||||
| 					op.NameAnnotation:          name, | 					op.NameAnnotation:          name, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| @@ -375,7 +367,6 @@ var tests = []testReconcileItem{ | |||||||
| 					op.VersionAnnotation: fmt.Sprint(version), | 					op.VersionAnnotation: fmt.Sprint(version), | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Type: corev1.SecretType(""), |  | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| 		}, | 		}, | ||||||
| 		opItem: map[string]string{ | 		opItem: map[string]string{ | ||||||
|   | |||||||
| @@ -144,15 +144,12 @@ func (r *ReconcileOnePasswordItem) removeOnePasswordFinalizerFromOnePasswordItem | |||||||
|  |  | ||||||
| func (r *ReconcileOnePasswordItem) HandleOnePasswordItem(resource *onepasswordv1.OnePasswordItem, request reconcile.Request) error { | func (r *ReconcileOnePasswordItem) HandleOnePasswordItem(resource *onepasswordv1.OnePasswordItem, request reconcile.Request) error { | ||||||
| 	secretName := resource.GetName() | 	secretName := resource.GetName() | ||||||
| 	labels := resource.Labels | 	autoRestart := resource.Annotations[op.RestartDeploymentsAnnotation] | ||||||
| 	annotations := resource.Annotations |  | ||||||
| 	secretType := resource.Type |  | ||||||
| 	autoRestart := annotations[op.RestartDeploymentsAnnotation] |  | ||||||
|  |  | ||||||
| 	item, err := onepassword.GetOnePasswordItemByPath(r.opConnectClient, resource.Spec.ItemPath) | 	item, err := onepassword.GetOnePasswordItemByReference(r.opConnectClient, resource.Spec.ItemReference) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return fmt.Errorf("Failed to retrieve item: %v", err) | 		return fmt.Errorf("Failed to retrieve item: %v", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return kubeSecrets.CreateKubernetesSecretFromItem(r.kubeClient, secretName, resource.Namespace, item, autoRestart, labels, secretType, annotations) | 	return kubeSecrets.CreateKubernetesSecretFromItem(r.kubeClient, secretName, resource.Namespace, item, autoRestart) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -5,7 +5,6 @@ import ( | |||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"testing" | 	"testing" | ||||||
|  |  | ||||||
| 	"github.com/1Password/onepassword-operator/pkg/kubernetessecrets" |  | ||||||
| 	"github.com/1Password/onepassword-operator/pkg/mocks" | 	"github.com/1Password/onepassword-operator/pkg/mocks" | ||||||
| 	op "github.com/1Password/onepassword-operator/pkg/onepassword" | 	op "github.com/1Password/onepassword-operator/pkg/onepassword" | ||||||
|  |  | ||||||
| @@ -56,7 +55,7 @@ var ( | |||||||
| 		"password": []byte(password), | 		"password": []byte(password), | ||||||
| 		"username": []byte(username), | 		"username": []byte(username), | ||||||
| 	} | 	} | ||||||
| 	itemPath = fmt.Sprintf("vaults/%v/items/%v", vaultId, itemId) | 	itemReference = fmt.Sprintf("op://%v/%v", vaultId, itemId) | ||||||
| ) | ) | ||||||
|  |  | ||||||
| var ( | var ( | ||||||
| @@ -80,7 +79,7 @@ var tests = []testReconcileItem{ | |||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: onepasswordv1.OnePasswordItemSpec{ | 			Spec: onepasswordv1.OnePasswordItemSpec{ | ||||||
| 				ItemPath: itemPath, | 				ItemReference: itemReference, | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 		existingSecret: &corev1.Secret{ | 		existingSecret: &corev1.Secret{ | ||||||
| @@ -112,7 +111,7 @@ var tests = []testReconcileItem{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: onepasswordv1.OnePasswordItemSpec{ | 			Spec: onepasswordv1.OnePasswordItemSpec{ | ||||||
| 				ItemPath: itemPath, | 				ItemReference: itemReference, | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 		existingSecret: &corev1.Secret{ | 		existingSecret: &corev1.Secret{ | ||||||
| @@ -121,7 +120,6 @@ var tests = []testReconcileItem{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					op.VersionAnnotation: fmt.Sprint(version), | 					op.VersionAnnotation: fmt.Sprint(version), | ||||||
| 					op.ItemPathAnnotation: itemPath, |  | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| @@ -133,7 +131,6 @@ var tests = []testReconcileItem{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					op.VersionAnnotation: fmt.Sprint(version), | 					op.VersionAnnotation: fmt.Sprint(version), | ||||||
| 					op.ItemPathAnnotation: itemPath, |  | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| @@ -153,14 +150,9 @@ var tests = []testReconcileItem{ | |||||||
| 			ObjectMeta: metav1.ObjectMeta{ | 			ObjectMeta: metav1.ObjectMeta{ | ||||||
| 				Name:      name, | 				Name:      name, | ||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ |  | ||||||
| 					op.VersionAnnotation:  fmt.Sprint(version), |  | ||||||
| 					op.ItemPathAnnotation: itemPath, |  | ||||||
| 				}, |  | ||||||
| 				Labels: map[string]string{}, |  | ||||||
| 			}, | 			}, | ||||||
| 			Spec: onepasswordv1.OnePasswordItemSpec{ | 			Spec: onepasswordv1.OnePasswordItemSpec{ | ||||||
| 				ItemPath: itemPath, | 				ItemReference: itemReference, | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 		existingSecret: &corev1.Secret{ | 		existingSecret: &corev1.Secret{ | ||||||
| @@ -169,9 +161,7 @@ var tests = []testReconcileItem{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					op.VersionAnnotation: "456", | 					op.VersionAnnotation: "456", | ||||||
| 					op.ItemPathAnnotation: itemPath, |  | ||||||
| 				}, | 				}, | ||||||
| 				Labels: map[string]string{}, |  | ||||||
| 			}, | 			}, | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| 		}, | 		}, | ||||||
| @@ -182,63 +172,8 @@ var tests = []testReconcileItem{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					op.VersionAnnotation: fmt.Sprint(version), | 					op.VersionAnnotation: fmt.Sprint(version), | ||||||
| 					op.ItemPathAnnotation: itemPath, |  | ||||||
| 				}, |  | ||||||
| 				Labels: map[string]string{}, |  | ||||||
| 			}, |  | ||||||
| 			Data: expectedSecretData, |  | ||||||
| 		}, |  | ||||||
| 		opItem: map[string]string{ |  | ||||||
| 			userKey: username, |  | ||||||
| 			passKey: password, |  | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 	{ |  | ||||||
| 		testName: "Test Updating Type of Existing Kubernetes Secret using OnePasswordItem", |  | ||||||
| 		customResource: &onepasswordv1.OnePasswordItem{ |  | ||||||
| 			TypeMeta: metav1.TypeMeta{ |  | ||||||
| 				Kind:       onePasswordItemKind, |  | ||||||
| 				APIVersion: onePasswordItemAPIVersion, |  | ||||||
| 			}, |  | ||||||
| 			ObjectMeta: metav1.ObjectMeta{ |  | ||||||
| 				Name:      name, |  | ||||||
| 				Namespace: namespace, |  | ||||||
| 				Annotations: map[string]string{ |  | ||||||
| 					op.VersionAnnotation:  fmt.Sprint(version), |  | ||||||
| 					op.ItemPathAnnotation: itemPath, |  | ||||||
| 				}, |  | ||||||
| 				Labels: map[string]string{}, |  | ||||||
| 			}, |  | ||||||
| 			Spec: onepasswordv1.OnePasswordItemSpec{ |  | ||||||
| 				ItemPath: itemPath, |  | ||||||
| 			}, |  | ||||||
| 			Type: string(corev1.SecretTypeBasicAuth), |  | ||||||
| 		}, |  | ||||||
| 		existingSecret: &corev1.Secret{ |  | ||||||
| 			ObjectMeta: metav1.ObjectMeta{ |  | ||||||
| 				Name:      name, |  | ||||||
| 				Namespace: namespace, |  | ||||||
| 				Annotations: map[string]string{ |  | ||||||
| 					op.VersionAnnotation:  fmt.Sprint(version), |  | ||||||
| 					op.ItemPathAnnotation: itemPath, |  | ||||||
| 				}, |  | ||||||
| 				Labels: map[string]string{}, |  | ||||||
| 			}, |  | ||||||
| 			Type: corev1.SecretTypeBasicAuth, |  | ||||||
| 			Data: expectedSecretData, |  | ||||||
| 		}, |  | ||||||
| 		expectedError: nil, |  | ||||||
| 		expectedResultSecret: &corev1.Secret{ |  | ||||||
| 			ObjectMeta: metav1.ObjectMeta{ |  | ||||||
| 				Name:      name, |  | ||||||
| 				Namespace: namespace, |  | ||||||
| 				Annotations: map[string]string{ |  | ||||||
| 					op.VersionAnnotation:  fmt.Sprint(version), |  | ||||||
| 					op.ItemPathAnnotation: itemPath, |  | ||||||
| 				}, |  | ||||||
| 				Labels: map[string]string{}, |  | ||||||
| 			}, |  | ||||||
| 			Type: corev1.SecretTypeBasicAuth, |  | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| 		}, | 		}, | ||||||
| 		opItem: map[string]string{ | 		opItem: map[string]string{ | ||||||
| @@ -258,9 +193,8 @@ var tests = []testReconcileItem{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: onepasswordv1.OnePasswordItemSpec{ | 			Spec: onepasswordv1.OnePasswordItemSpec{ | ||||||
| 				ItemPath: itemPath, | 				ItemReference: itemReference, | ||||||
| 			}, | 			}, | ||||||
| 			Type: "custom", |  | ||||||
| 		}, | 		}, | ||||||
| 		existingSecret: nil, | 		existingSecret: nil, | ||||||
| 		expectedError:  nil, | 		expectedError:  nil, | ||||||
| @@ -272,51 +206,6 @@ var tests = []testReconcileItem{ | |||||||
| 					op.VersionAnnotation: fmt.Sprint(version), | 					op.VersionAnnotation: fmt.Sprint(version), | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Type: corev1.SecretType("custom"), |  | ||||||
| 			Data: expectedSecretData, |  | ||||||
| 		}, |  | ||||||
| 		opItem: map[string]string{ |  | ||||||
| 			userKey: username, |  | ||||||
| 			passKey: password, |  | ||||||
| 		}, |  | ||||||
| 	}, |  | ||||||
| 	{ |  | ||||||
| 		testName: "Error if secret type is changed", |  | ||||||
| 		customResource: &onepasswordv1.OnePasswordItem{ |  | ||||||
| 			TypeMeta: metav1.TypeMeta{ |  | ||||||
| 				Kind:       onePasswordItemKind, |  | ||||||
| 				APIVersion: onePasswordItemAPIVersion, |  | ||||||
| 			}, |  | ||||||
| 			ObjectMeta: metav1.ObjectMeta{ |  | ||||||
| 				Name:      name, |  | ||||||
| 				Namespace: namespace, |  | ||||||
| 			}, |  | ||||||
| 			Spec: onepasswordv1.OnePasswordItemSpec{ |  | ||||||
| 				ItemPath: itemPath, |  | ||||||
| 			}, |  | ||||||
| 			Type: "custom", |  | ||||||
| 		}, |  | ||||||
| 		existingSecret: &corev1.Secret{ |  | ||||||
| 			ObjectMeta: metav1.ObjectMeta{ |  | ||||||
| 				Name:      name, |  | ||||||
| 				Namespace: namespace, |  | ||||||
| 				Annotations: map[string]string{ |  | ||||||
| 					op.VersionAnnotation: fmt.Sprint(version), |  | ||||||
| 				}, |  | ||||||
| 			}, |  | ||||||
| 			Type: corev1.SecretTypeOpaque, |  | ||||||
| 			Data: expectedSecretData, |  | ||||||
| 		}, |  | ||||||
| 		expectedError: kubernetessecrets.ErrCannotUpdateSecretType, |  | ||||||
| 		expectedResultSecret: &corev1.Secret{ |  | ||||||
| 			ObjectMeta: metav1.ObjectMeta{ |  | ||||||
| 				Name:      name, |  | ||||||
| 				Namespace: namespace, |  | ||||||
| 				Annotations: map[string]string{ |  | ||||||
| 					op.VersionAnnotation: fmt.Sprint(version), |  | ||||||
| 				}, |  | ||||||
| 			}, |  | ||||||
| 			Type: corev1.SecretTypeOpaque, |  | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| 		}, | 		}, | ||||||
| 		opItem: map[string]string{ | 		opItem: map[string]string{ | ||||||
| @@ -336,7 +225,7 @@ var tests = []testReconcileItem{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: onepasswordv1.OnePasswordItemSpec{ | 			Spec: onepasswordv1.OnePasswordItemSpec{ | ||||||
| 				ItemPath: itemPath, | 				ItemReference: itemReference, | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 		existingSecret: nil, | 		existingSecret: nil, | ||||||
| @@ -368,7 +257,7 @@ var tests = []testReconcileItem{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 			}, | 			}, | ||||||
| 			Spec: onepasswordv1.OnePasswordItemSpec{ | 			Spec: onepasswordv1.OnePasswordItemSpec{ | ||||||
| 				ItemPath: itemPath, | 				ItemReference: itemReference, | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 		existingSecret: nil, | 		existingSecret: nil, | ||||||
| @@ -385,7 +274,7 @@ var tests = []testReconcileItem{ | |||||||
| 				"password":       []byte(password), | 				"password":       []byte(password), | ||||||
| 				"username":       []byte(username), | 				"username":       []byte(username), | ||||||
| 				"first-host":     []byte(firstHost), | 				"first-host":     []byte(firstHost), | ||||||
| 				"AWS-Access-Key": []byte(awsKey), | 				"aws-access-key": []byte(awsKey), | ||||||
| 				"ice-cream-type": []byte(iceCream), | 				"ice-cream-type": []byte(iceCream), | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| @@ -397,47 +286,6 @@ var tests = []testReconcileItem{ | |||||||
| 			"😄 ice-cream type": iceCream, | 			"😄 ice-cream type": iceCream, | ||||||
| 		}, | 		}, | ||||||
| 	}, | 	}, | ||||||
| 	{ |  | ||||||
| 		testName: "Secret from 1Password item with `-`, `_` and `.`", |  | ||||||
| 		customResource: &onepasswordv1.OnePasswordItem{ |  | ||||||
| 			TypeMeta: metav1.TypeMeta{ |  | ||||||
| 				Kind:       onePasswordItemKind, |  | ||||||
| 				APIVersion: onePasswordItemAPIVersion, |  | ||||||
| 			}, |  | ||||||
| 			ObjectMeta: metav1.ObjectMeta{ |  | ||||||
| 				Name:      "!.my_sECReT.it3m%-_", |  | ||||||
| 				Namespace: namespace, |  | ||||||
| 			}, |  | ||||||
| 			Spec: onepasswordv1.OnePasswordItemSpec{ |  | ||||||
| 				ItemPath: itemPath, |  | ||||||
| 			}, |  | ||||||
| 		}, |  | ||||||
| 		existingSecret: nil, |  | ||||||
| 		expectedError:  nil, |  | ||||||
| 		expectedResultSecret: &corev1.Secret{ |  | ||||||
| 			ObjectMeta: metav1.ObjectMeta{ |  | ||||||
| 				Name:      "my-secret.it3m", |  | ||||||
| 				Namespace: namespace, |  | ||||||
| 				Annotations: map[string]string{ |  | ||||||
| 					op.VersionAnnotation: fmt.Sprint(version), |  | ||||||
| 				}, |  | ||||||
| 			}, |  | ||||||
| 			Data: map[string][]byte{ |  | ||||||
| 				"password":          []byte(password), |  | ||||||
| 				"username":          []byte(username), |  | ||||||
| 				"first-host":        []byte(firstHost), |  | ||||||
| 				"AWS-Access-Key":    []byte(awsKey), |  | ||||||
| 				"-_ice_cream.type.": []byte(iceCream), |  | ||||||
| 			}, |  | ||||||
| 		}, |  | ||||||
| 		opItem: map[string]string{ |  | ||||||
| 			userKey:               username, |  | ||||||
| 			passKey:               password, |  | ||||||
| 			"first host":          firstHost, |  | ||||||
| 			"AWS Access Key":      awsKey, |  | ||||||
| 			"😄 -_ice_cream.type.": iceCream, |  | ||||||
| 		}, |  | ||||||
| 	}, |  | ||||||
| } | } | ||||||
|  |  | ||||||
| func TestReconcileOnePasswordItem(t *testing.T) { | func TestReconcileOnePasswordItem(t *testing.T) { | ||||||
|   | |||||||
| @@ -7,10 +7,6 @@ import ( | |||||||
| 	"regexp" | 	"regexp" | ||||||
| 	"strings" | 	"strings" | ||||||
|  |  | ||||||
| 	"reflect" |  | ||||||
|  |  | ||||||
| 	errs "errors" |  | ||||||
|  |  | ||||||
| 	"github.com/1Password/connect-sdk-go/onepassword" | 	"github.com/1Password/connect-sdk-go/onepassword" | ||||||
| 	"github.com/1Password/onepassword-operator/pkg/utils" | 	"github.com/1Password/onepassword-operator/pkg/utils" | ||||||
| 	corev1 "k8s.io/api/core/v1" | 	corev1 "k8s.io/api/core/v1" | ||||||
| @@ -27,36 +23,27 @@ const OnepasswordPrefix = "operator.1password.io" | |||||||
| const NameAnnotation = OnepasswordPrefix + "/item-name" | const NameAnnotation = OnepasswordPrefix + "/item-name" | ||||||
| const VersionAnnotation = OnepasswordPrefix + "/item-version" | const VersionAnnotation = OnepasswordPrefix + "/item-version" | ||||||
| const restartAnnotation = OnepasswordPrefix + "/last-restarted" | const restartAnnotation = OnepasswordPrefix + "/last-restarted" | ||||||
| const ItemPathAnnotation = OnepasswordPrefix + "/item-path" | const ItemReferenceAnnotation = OnepasswordPrefix + "/item-reference" | ||||||
| const RestartDeploymentsAnnotation = OnepasswordPrefix + "/auto-restart" | const RestartDeploymentsAnnotation = OnepasswordPrefix + "/auto-restart" | ||||||
|  |  | ||||||
| var ErrCannotUpdateSecretType = errs.New("Cannot change secret type. Secret type is immutable") |  | ||||||
|  |  | ||||||
| var log = logf.Log | var log = logf.Log | ||||||
|  |  | ||||||
| func CreateKubernetesSecretFromItem(kubeClient kubernetesClient.Client, secretName, namespace string, item *onepassword.Item, autoRestart string, labels map[string]string, secretType string, secretAnnotations map[string]string) error { | func CreateKubernetesSecretFromItem(kubeClient kubernetesClient.Client, secretName, namespace string, item *onepassword.Item, autoRestart string) error { | ||||||
|  |  | ||||||
| 	itemVersion := fmt.Sprint(item.Version) | 	itemVersion := fmt.Sprint(item.Version) | ||||||
|  | 	annotations := map[string]string{ | ||||||
| 	// If secretAnnotations is nil we create an empty map so we can later assign values for the OP Annotations in the map | 		VersionAnnotation:       itemVersion, | ||||||
| 	if secretAnnotations == nil { | 		ItemReferenceAnnotation: fmt.Sprintf("op://%v/%v", item.Vault.ID, item.ID), | ||||||
| 		secretAnnotations = map[string]string{} |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	secretAnnotations[VersionAnnotation] = itemVersion |  | ||||||
| 	secretAnnotations[ItemPathAnnotation] = fmt.Sprintf("vaults/%v/items/%v", item.Vault.ID, item.ID) |  | ||||||
|  |  | ||||||
| 	if autoRestart != "" { | 	if autoRestart != "" { | ||||||
| 		_, err := utils.StringToBool(autoRestart) | 		_, err := utils.StringToBool(autoRestart) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			log.Error(err, "Error parsing %v annotation on Secret %v. Must be true or false. Defaulting to false.", RestartDeploymentsAnnotation, secretName) | 			log.Error(err, "Error parsing %v annotation on Secret %v. Must be true or false. Defaulting to false.", RestartDeploymentsAnnotation, secretName) | ||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
| 		secretAnnotations[RestartDeploymentsAnnotation] = autoRestart | 		annotations[RestartDeploymentsAnnotation] = autoRestart | ||||||
| 	} | 	} | ||||||
|  | 	secret := BuildKubernetesSecretFromOnePasswordItem(secretName, namespace, annotations, *item) | ||||||
| 	// "Opaque" and "" secret types are treated the same by Kubernetes. |  | ||||||
| 	secret := BuildKubernetesSecretFromOnePasswordItem(secretName, namespace, secretAnnotations, labels, secretType, *item) |  | ||||||
|  |  | ||||||
| 	currentSecret := &corev1.Secret{} | 	currentSecret := &corev1.Secret{} | ||||||
| 	err := kubeClient.Get(context.Background(), types.NamespacedName{Name: secret.Name, Namespace: secret.Namespace}, currentSecret) | 	err := kubeClient.Get(context.Background(), types.NamespacedName{Name: secret.Name, Namespace: secret.Namespace}, currentSecret) | ||||||
| @@ -67,17 +54,9 @@ func CreateKubernetesSecretFromItem(kubeClient kubernetesClient.Client, secretNa | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	currentAnnotations := currentSecret.Annotations | 	if currentSecret.Annotations[VersionAnnotation] != itemVersion { | ||||||
| 	currentLabels := currentSecret.Labels |  | ||||||
| 	currentSecretType := string(currentSecret.Type) |  | ||||||
| 	if !reflect.DeepEqual(currentSecretType, secretType) { |  | ||||||
| 		return ErrCannotUpdateSecretType |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	if !reflect.DeepEqual(currentAnnotations, secretAnnotations) || !reflect.DeepEqual(currentLabels, labels) { |  | ||||||
| 		log.Info(fmt.Sprintf("Updating Secret %v at namespace '%v'", secret.Name, secret.Namespace)) | 		log.Info(fmt.Sprintf("Updating Secret %v at namespace '%v'", secret.Name, secret.Namespace)) | ||||||
| 		currentSecret.ObjectMeta.Annotations = secretAnnotations | 		currentSecret.ObjectMeta.Annotations = annotations | ||||||
| 		currentSecret.ObjectMeta.Labels = labels |  | ||||||
| 		currentSecret.Data = secret.Data | 		currentSecret.Data = secret.Data | ||||||
| 		return kubeClient.Update(context.Background(), currentSecret) | 		return kubeClient.Update(context.Background(), currentSecret) | ||||||
| 	} | 	} | ||||||
| @@ -86,16 +65,14 @@ func CreateKubernetesSecretFromItem(kubeClient kubernetesClient.Client, secretNa | |||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func BuildKubernetesSecretFromOnePasswordItem(name, namespace string, annotations map[string]string, labels map[string]string, secretType string, item onepassword.Item) *corev1.Secret { | func BuildKubernetesSecretFromOnePasswordItem(name, namespace string, annotations map[string]string, item onepassword.Item) *corev1.Secret { | ||||||
| 	return &corev1.Secret{ | 	return &corev1.Secret{ | ||||||
| 		ObjectMeta: metav1.ObjectMeta{ | 		ObjectMeta: metav1.ObjectMeta{ | ||||||
| 			Name:        formatSecretName(name), | 			Name:        formatSecretName(name), | ||||||
| 			Namespace:   namespace, | 			Namespace:   namespace, | ||||||
| 			Annotations: annotations, | 			Annotations: annotations, | ||||||
| 			Labels:      labels, |  | ||||||
| 		}, | 		}, | ||||||
| 		Data: BuildKubernetesSecretData(item.Fields), | 		Data: BuildKubernetesSecretData(item.Fields), | ||||||
| 		Type: corev1.SecretType(secretType), |  | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -103,17 +80,16 @@ func BuildKubernetesSecretData(fields []*onepassword.ItemField) map[string][]byt | |||||||
| 	secretData := map[string][]byte{} | 	secretData := map[string][]byte{} | ||||||
| 	for i := 0; i < len(fields); i++ { | 	for i := 0; i < len(fields); i++ { | ||||||
| 		if fields[i].Value != "" { | 		if fields[i].Value != "" { | ||||||
| 			key := formatSecretDataName(fields[i].Label) | 			key := formatSecretName(fields[i].Label) | ||||||
| 			secretData[key] = []byte(fields[i].Value) | 			secretData[key] = []byte(fields[i].Value) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	return secretData | 	return secretData | ||||||
| } | } | ||||||
|  |  | ||||||
| // formatSecretName rewrites a value to be a valid Secret name. | // formatSecretName rewrites a value to be a valid Secret name or Secret data key. | ||||||
| // | // | ||||||
| // The Secret meta.name and data keys must be valid DNS subdomain names | // The Secret meta.name and data keys must be valid DNS subdomain names (https://kubernetes.io/docs/concepts/configuration/secret/#overview-of-secrets) | ||||||
| // (https://kubernetes.io/docs/concepts/configuration/secret/#overview-of-secrets) |  | ||||||
| func formatSecretName(value string) string { | func formatSecretName(value string) string { | ||||||
| 	if errs := kubeValidate.IsDNS1123Subdomain(value); len(errs) == 0 { | 	if errs := kubeValidate.IsDNS1123Subdomain(value); len(errs) == 0 { | ||||||
| 		return value | 		return value | ||||||
| @@ -121,18 +97,7 @@ func formatSecretName(value string) string { | |||||||
| 	return createValidSecretName(value) | 	return createValidSecretName(value) | ||||||
| } | } | ||||||
|  |  | ||||||
| // formatSecretDataName rewrites a value to be a valid Secret data key. | var invalidDNS1123Chars = regexp.MustCompile("[^a-z0-9-]+") | ||||||
| // |  | ||||||
| // The Secret data keys must consist of alphanumeric numbers, `-`, `_` or `.` |  | ||||||
| // (https://kubernetes.io/docs/concepts/configuration/secret/#overview-of-secrets) |  | ||||||
| func formatSecretDataName(value string) string { |  | ||||||
| 	if errs := kubeValidate.IsConfigMapKey(value); len(errs) == 0 { |  | ||||||
| 		return value |  | ||||||
| 	} |  | ||||||
| 	return createValidSecretDataName(value) |  | ||||||
| } |  | ||||||
|  |  | ||||||
| var invalidDNS1123Chars = regexp.MustCompile("[^a-z0-9-.]+") |  | ||||||
|  |  | ||||||
| func createValidSecretName(value string) string { | func createValidSecretName(value string) string { | ||||||
| 	result := strings.ToLower(value) | 	result := strings.ToLower(value) | ||||||
| @@ -143,19 +108,5 @@ func createValidSecretName(value string) string { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// first and last character MUST be alphanumeric | 	// first and last character MUST be alphanumeric | ||||||
| 	return strings.Trim(result, "-.") | 	return strings.Trim(result, "-") | ||||||
| } |  | ||||||
|  |  | ||||||
| var invalidDataChars = regexp.MustCompile("[^a-zA-Z0-9-._]+") |  | ||||||
| var invalidStartEndChars = regexp.MustCompile("(^[^a-zA-Z0-9-._]+|[^a-zA-Z0-9-._]+$)") |  | ||||||
|  |  | ||||||
| func createValidSecretDataName(value string) string { |  | ||||||
| 	result := invalidStartEndChars.ReplaceAllString(value, "") |  | ||||||
| 	result = invalidDataChars.ReplaceAllString(result, "-") |  | ||||||
|  |  | ||||||
| 	if len(result) > kubeValidate.DNS1123SubdomainMaxLength { |  | ||||||
| 		result = result[0:kubeValidate.DNS1123SubdomainMaxLength] |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	return result |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -6,10 +6,11 @@ import ( | |||||||
| 	"strings" | 	"strings" | ||||||
| 	"testing" | 	"testing" | ||||||
|  |  | ||||||
|  | 	kubeValidate "k8s.io/apimachinery/pkg/util/validation" | ||||||
|  |  | ||||||
| 	"github.com/1Password/connect-sdk-go/onepassword" | 	"github.com/1Password/connect-sdk-go/onepassword" | ||||||
| 	corev1 "k8s.io/api/core/v1" | 	corev1 "k8s.io/api/core/v1" | ||||||
| 	"k8s.io/apimachinery/pkg/types" | 	"k8s.io/apimachinery/pkg/types" | ||||||
| 	kubeValidate "k8s.io/apimachinery/pkg/util/validation" |  | ||||||
| 	"k8s.io/client-go/kubernetes" | 	"k8s.io/client-go/kubernetes" | ||||||
| 	"sigs.k8s.io/controller-runtime/pkg/client/fake" | 	"sigs.k8s.io/controller-runtime/pkg/client/fake" | ||||||
| ) | ) | ||||||
| @@ -31,13 +32,7 @@ func TestCreateKubernetesSecretFromOnePasswordItem(t *testing.T) { | |||||||
| 	item.ID = "h46bb3jddvay7nxopfhvlwg35q" | 	item.ID = "h46bb3jddvay7nxopfhvlwg35q" | ||||||
|  |  | ||||||
| 	kubeClient := fake.NewFakeClient() | 	kubeClient := fake.NewFakeClient() | ||||||
| 	secretLabels := map[string]string{} | 	err := CreateKubernetesSecretFromItem(kubeClient, secretName, namespace, &item, restartDeploymentAnnotation) | ||||||
| 	secretAnnotations := map[string]string{ |  | ||||||
| 		"testAnnotation": "exists", |  | ||||||
| 	} |  | ||||||
| 	secretType := "" |  | ||||||
|  |  | ||||||
| 	err := CreateKubernetesSecretFromItem(kubeClient, secretName, namespace, &item, restartDeploymentAnnotation, secretLabels, secretType, secretAnnotations) |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		t.Errorf("Unexpected error: %v", err) | 		t.Errorf("Unexpected error: %v", err) | ||||||
| 	} | 	} | ||||||
| @@ -48,11 +43,7 @@ func TestCreateKubernetesSecretFromOnePasswordItem(t *testing.T) { | |||||||
| 		t.Errorf("Secret was not created: %v", err) | 		t.Errorf("Secret was not created: %v", err) | ||||||
| 	} | 	} | ||||||
| 	compareFields(item.Fields, createdSecret.Data, t) | 	compareFields(item.Fields, createdSecret.Data, t) | ||||||
| 	compareAnnotationsToItem(createdSecret.Annotations, item, t) | 	compareAnnotationsToItem(item.Vault.ID, item.ID, createdSecret.Annotations, item, t) | ||||||
|  |  | ||||||
| 	if createdSecret.Annotations["testAnnotation"] != "exists" { |  | ||||||
| 		t.Errorf("Expected testAnnotation to be merged with existing annotations, but wasn't.") |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
|  |  | ||||||
| func TestUpdateKubernetesSecretFromOnePasswordItem(t *testing.T) { | func TestUpdateKubernetesSecretFromOnePasswordItem(t *testing.T) { | ||||||
| @@ -66,12 +57,7 @@ func TestUpdateKubernetesSecretFromOnePasswordItem(t *testing.T) { | |||||||
| 	item.ID = "h46bb3jddvay7nxopfhvlwg35q" | 	item.ID = "h46bb3jddvay7nxopfhvlwg35q" | ||||||
|  |  | ||||||
| 	kubeClient := fake.NewFakeClient() | 	kubeClient := fake.NewFakeClient() | ||||||
| 	secretLabels := map[string]string{} | 	err := CreateKubernetesSecretFromItem(kubeClient, secretName, namespace, &item, restartDeploymentAnnotation) | ||||||
| 	secretAnnotations := map[string]string{} |  | ||||||
| 	secretType := "" |  | ||||||
|  |  | ||||||
| 	err := CreateKubernetesSecretFromItem(kubeClient, secretName, namespace, &item, restartDeploymentAnnotation, secretLabels, secretType, secretAnnotations) |  | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		t.Errorf("Unexpected error: %v", err) | 		t.Errorf("Unexpected error: %v", err) | ||||||
| 	} | 	} | ||||||
| @@ -82,7 +68,7 @@ func TestUpdateKubernetesSecretFromOnePasswordItem(t *testing.T) { | |||||||
| 	newItem.Version = 456 | 	newItem.Version = 456 | ||||||
| 	newItem.Vault.ID = "hfnjvi6aymbsnfc2xeeoheizda" | 	newItem.Vault.ID = "hfnjvi6aymbsnfc2xeeoheizda" | ||||||
| 	newItem.ID = "h46bb3jddvay7nxopfhvlwg35q" | 	newItem.ID = "h46bb3jddvay7nxopfhvlwg35q" | ||||||
| 	err = CreateKubernetesSecretFromItem(kubeClient, secretName, namespace, &newItem, restartDeploymentAnnotation, secretLabels, secretType, secretAnnotations) | 	err = CreateKubernetesSecretFromItem(kubeClient, secretName, namespace, &newItem, restartDeploymentAnnotation) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		t.Errorf("Unexpected error: %v", err) | 		t.Errorf("Unexpected error: %v", err) | ||||||
| 	} | 	} | ||||||
| @@ -93,7 +79,7 @@ func TestUpdateKubernetesSecretFromOnePasswordItem(t *testing.T) { | |||||||
| 		t.Errorf("Secret was not found: %v", err) | 		t.Errorf("Secret was not found: %v", err) | ||||||
| 	} | 	} | ||||||
| 	compareFields(newItem.Fields, updatedSecret.Data, t) | 	compareFields(newItem.Fields, updatedSecret.Data, t) | ||||||
| 	compareAnnotationsToItem(updatedSecret.Annotations, newItem, t) | 	compareAnnotationsToItem(newItem.Vault.ID, newItem.ID, updatedSecret.Annotations, newItem, t) | ||||||
| } | } | ||||||
| func TestBuildKubernetesSecretData(t *testing.T) { | func TestBuildKubernetesSecretData(t *testing.T) { | ||||||
| 	fields := generateFields(5) | 	fields := generateFields(5) | ||||||
| @@ -115,10 +101,8 @@ func TestBuildKubernetesSecretFromOnePasswordItem(t *testing.T) { | |||||||
| 	} | 	} | ||||||
| 	item := onepassword.Item{} | 	item := onepassword.Item{} | ||||||
| 	item.Fields = generateFields(5) | 	item.Fields = generateFields(5) | ||||||
| 	labels := map[string]string{} |  | ||||||
| 	secretType := "" |  | ||||||
|  |  | ||||||
| 	kubeSecret := BuildKubernetesSecretFromOnePasswordItem(name, namespace, annotations, labels, secretType, item) | 	kubeSecret := BuildKubernetesSecretFromOnePasswordItem(name, namespace, annotations, item) | ||||||
| 	if kubeSecret.Name != strings.ToLower(name) { | 	if kubeSecret.Name != strings.ToLower(name) { | ||||||
| 		t.Errorf("Expected name value: %v but got: %v", name, kubeSecret.Name) | 		t.Errorf("Expected name value: %v but got: %v", name, kubeSecret.Name) | ||||||
| 	} | 	} | ||||||
| @@ -138,9 +122,7 @@ func TestBuildKubernetesSecretFixesInvalidLabels(t *testing.T) { | |||||||
| 	annotations := map[string]string{ | 	annotations := map[string]string{ | ||||||
| 		"annotationKey": "annotationValue", | 		"annotationKey": "annotationValue", | ||||||
| 	} | 	} | ||||||
| 	labels := map[string]string{} |  | ||||||
| 	item := onepassword.Item{} | 	item := onepassword.Item{} | ||||||
| 	secretType := "" |  | ||||||
|  |  | ||||||
| 	item.Fields = []*onepassword.ItemField{ | 	item.Fields = []*onepassword.ItemField{ | ||||||
| 		{ | 		{ | ||||||
| @@ -153,7 +135,7 @@ func TestBuildKubernetesSecretFixesInvalidLabels(t *testing.T) { | |||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	kubeSecret := BuildKubernetesSecretFromOnePasswordItem(name, namespace, annotations, labels, secretType, item) | 	kubeSecret := BuildKubernetesSecretFromOnePasswordItem(name, namespace, annotations, item) | ||||||
|  |  | ||||||
| 	// Assert Secret's meta.name was fixed | 	// Assert Secret's meta.name was fixed | ||||||
| 	if kubeSecret.Name != expectedName { | 	if kubeSecret.Name != expectedName { | ||||||
| @@ -171,44 +153,7 @@ func TestBuildKubernetesSecretFixesInvalidLabels(t *testing.T) { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func TestCreateKubernetesTLSSecretFromOnePasswordItem(t *testing.T) { | func compareAnnotationsToItem(actualVaultId, actualItemId string, annotations map[string]string, item onepassword.Item, t *testing.T) { | ||||||
| 	secretName := "tls-test-secret-name" |  | ||||||
| 	namespace := "test" |  | ||||||
|  |  | ||||||
| 	item := onepassword.Item{} |  | ||||||
| 	item.Fields = generateFields(5) |  | ||||||
| 	item.Version = 123 |  | ||||||
| 	item.Vault.ID = "hfnjvi6aymbsnfc2xeeoheizda" |  | ||||||
| 	item.ID = "h46bb3jddvay7nxopfhvlwg35q" |  | ||||||
|  |  | ||||||
| 	kubeClient := fake.NewFakeClient() |  | ||||||
| 	secretLabels := map[string]string{} |  | ||||||
| 	secretAnnotations := map[string]string{ |  | ||||||
| 		"testAnnotation": "exists", |  | ||||||
| 	} |  | ||||||
| 	secretType := "kubernetes.io/tls" |  | ||||||
|  |  | ||||||
| 	err := CreateKubernetesSecretFromItem(kubeClient, secretName, namespace, &item, restartDeploymentAnnotation, secretLabels, secretType, secretAnnotations) |  | ||||||
| 	if err != nil { |  | ||||||
| 		t.Errorf("Unexpected error: %v", err) |  | ||||||
| 	} |  | ||||||
| 	createdSecret := &corev1.Secret{} |  | ||||||
| 	err = kubeClient.Get(context.Background(), types.NamespacedName{Name: secretName, Namespace: namespace}, createdSecret) |  | ||||||
|  |  | ||||||
| 	if err != nil { |  | ||||||
| 		t.Errorf("Secret was not created: %v", err) |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	if createdSecret.Type != corev1.SecretTypeTLS { |  | ||||||
| 		t.Errorf("Expected secretType to be of tyype corev1.SecretTypeTLS, got %s", string(createdSecret.Type)) |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
|  |  | ||||||
| func compareAnnotationsToItem(annotations map[string]string, item onepassword.Item, t *testing.T) { |  | ||||||
| 	actualVaultId, actualItemId, err := ParseVaultIdAndItemIdFromPath(annotations[ItemPathAnnotation]) |  | ||||||
| 	if err != nil { |  | ||||||
| 		t.Errorf("Was unable to parse Item Path") |  | ||||||
| 	} |  | ||||||
| 	if actualVaultId != item.Vault.ID { | 	if actualVaultId != item.Vault.ID { | ||||||
| 		t.Errorf("Expected annotation vault id to be %v but was %v", item.Vault.ID, actualVaultId) | 		t.Errorf("Expected annotation vault id to be %v but was %v", item.Vault.ID, actualVaultId) | ||||||
| 	} | 	} | ||||||
| @@ -248,16 +193,8 @@ func generateFields(numToGenerate int) []*onepassword.ItemField { | |||||||
| 	return fields | 	return fields | ||||||
| } | } | ||||||
|  |  | ||||||
| func ParseVaultIdAndItemIdFromPath(path string) (string, string, error) { |  | ||||||
| 	splitPath := strings.Split(path, "/") |  | ||||||
| 	if len(splitPath) == 4 && splitPath[0] == "vaults" && splitPath[2] == "items" { |  | ||||||
| 		return splitPath[1], splitPath[3], nil |  | ||||||
| 	} |  | ||||||
| 	return "", "", fmt.Errorf("%q is not an acceptable path for One Password item. Must be of the format: `vaults/{vault_id}/items/{item_id}`", path) |  | ||||||
| } |  | ||||||
|  |  | ||||||
| func validLabel(v string) bool { | func validLabel(v string) bool { | ||||||
| 	if err := kubeValidate.IsConfigMapKey(v); len(err) > 0 { | 	if err := kubeValidate.IsDNS1123Subdomain(v); len(err) > 0 { | ||||||
| 		return false | 		return false | ||||||
| 	} | 	} | ||||||
| 	return true | 	return true | ||||||
|   | |||||||
| @@ -9,7 +9,7 @@ import ( | |||||||
|  |  | ||||||
| const ( | const ( | ||||||
| 	OnepasswordPrefix            = "operator.1password.io" | 	OnepasswordPrefix            = "operator.1password.io" | ||||||
| 	ItemPathAnnotation           = OnepasswordPrefix + "/item-path" | 	ItemReferenceAnnotation      = OnepasswordPrefix + "/item-reference" | ||||||
| 	NameAnnotation               = OnepasswordPrefix + "/item-name" | 	NameAnnotation               = OnepasswordPrefix + "/item-name" | ||||||
| 	VersionAnnotation            = OnepasswordPrefix + "/item-version" | 	VersionAnnotation            = OnepasswordPrefix + "/item-version" | ||||||
| 	RestartAnnotation            = OnepasswordPrefix + "/last-restarted" | 	RestartAnnotation            = OnepasswordPrefix + "/last-restarted" | ||||||
|   | |||||||
| @@ -22,7 +22,7 @@ func TestFilterAnnotations(t *testing.T) { | |||||||
| 	if len(filteredAnnotations) != 2 { | 	if len(filteredAnnotations) != 2 { | ||||||
| 		t.Errorf("Unexpected number of filtered annotations returned. Expected 2, got %v", len(filteredAnnotations)) | 		t.Errorf("Unexpected number of filtered annotations returned. Expected 2, got %v", len(filteredAnnotations)) | ||||||
| 	} | 	} | ||||||
| 	_, found := filteredAnnotations[ItemPathAnnotation] | 	_, found := filteredAnnotations[ItemReferenceAnnotation] | ||||||
| 	if !found { | 	if !found { | ||||||
| 		t.Errorf("One Password Annotation was filtered when it should not have been") | 		t.Errorf("One Password Annotation was filtered when it should not have been") | ||||||
| 	} | 	} | ||||||
| @@ -87,7 +87,7 @@ func TestGetNoAnnotationsForDeployment(t *testing.T) { | |||||||
|  |  | ||||||
| func getValidAnnotations() map[string]string { | func getValidAnnotations() map[string]string { | ||||||
| 	return map[string]string{ | 	return map[string]string{ | ||||||
| 		ItemPathAnnotation: "vaults/b3e4c7fc-8bf7-4c22-b8bb-147539f10e4f/items/b3e4c7fc-8bf7-4c22-b8bb-147539f10e4f", | 		ItemReferenceAnnotation: "op://b3e4c7fc-8bf7-4c22-b8bb-147539f10e4f/b3e4c7fc-8bf7-4c22-b8bb-147539f10e4f", | ||||||
| 		NameAnnotation:          "secretName", | 		NameAnnotation:          "secretName", | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,8 +1,6 @@ | |||||||
| package onepassword | package onepassword | ||||||
|  |  | ||||||
| import ( | import corev1 "k8s.io/api/core/v1" | ||||||
| 	corev1 "k8s.io/api/core/v1" |  | ||||||
| ) |  | ||||||
|  |  | ||||||
| func AreContainersUsingSecrets(containers []corev1.Container, secrets map[string]*corev1.Secret) bool { | func AreContainersUsingSecrets(containers []corev1.Container, secrets map[string]*corev1.Secret) bool { | ||||||
| 	for i := 0; i < len(containers); i++ { | 	for i := 0; i < len(containers); i++ { | ||||||
| @@ -15,15 +13,6 @@ func AreContainersUsingSecrets(containers []corev1.Container, secrets map[string | |||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		envFromVariables := containers[i].EnvFrom |  | ||||||
| 		for j := 0; j < len(envFromVariables); j++ { |  | ||||||
| 			if envFromVariables[j].SecretRef != nil { |  | ||||||
| 				_, ok := secrets[envFromVariables[j].SecretRef.Name] |  | ||||||
| 				if ok { |  | ||||||
| 					return true |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
| 	return false | 	return false | ||||||
| } | } | ||||||
| @@ -39,15 +28,6 @@ func AppendUpdatedContainerSecrets(containers []corev1.Container, secrets map[st | |||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		envFromVariables := containers[i].EnvFrom |  | ||||||
| 		for j := 0; j < len(envFromVariables); j++ { |  | ||||||
| 			if envFromVariables[j].SecretRef != nil { |  | ||||||
| 				secret, ok := secrets[envFromVariables[j].SecretRef.LocalObjectReference.Name] |  | ||||||
| 				if ok { |  | ||||||
| 					updatedDeploymentSecrets[secret.Name] = secret |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
| 	return updatedDeploymentSecrets | 	return updatedDeploymentSecrets | ||||||
| } | } | ||||||
|   | |||||||
| @@ -4,10 +4,9 @@ import ( | |||||||
| 	"testing" | 	"testing" | ||||||
|  |  | ||||||
| 	corev1 "k8s.io/api/core/v1" | 	corev1 "k8s.io/api/core/v1" | ||||||
| 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |  | ||||||
| ) | ) | ||||||
|  |  | ||||||
| func TestAreContainersUsingSecretsFromEnv(t *testing.T) { | func TestAreContainersUsingSecrets(t *testing.T) { | ||||||
| 	secretNamesToSearch := map[string]*corev1.Secret{ | 	secretNamesToSearch := map[string]*corev1.Secret{ | ||||||
| 		"onepassword-database-secret": &corev1.Secret{}, | 		"onepassword-database-secret": &corev1.Secret{}, | ||||||
| 		"onepassword-api-key":         &corev1.Secret{}, | 		"onepassword-api-key":         &corev1.Secret{}, | ||||||
| @@ -19,26 +18,7 @@ func TestAreContainersUsingSecretsFromEnv(t *testing.T) { | |||||||
| 		"some_other_key", | 		"some_other_key", | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	containers := generateContainersWithSecretRefsFromEnv(containerSecretNames) | 	containers := generateContainers(containerSecretNames) | ||||||
|  |  | ||||||
| 	if !AreContainersUsingSecrets(containers, secretNamesToSearch) { |  | ||||||
| 		t.Errorf("Expected that containers were using secrets but they were not detected.") |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
|  |  | ||||||
| func TestAreContainersUsingSecretsFromEnvFrom(t *testing.T) { |  | ||||||
| 	secretNamesToSearch := map[string]*corev1.Secret{ |  | ||||||
| 		"onepassword-database-secret": {}, |  | ||||||
| 		"onepassword-api-key":         {}, |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	containerSecretNames := []string{ |  | ||||||
| 		"onepassword-database-secret", |  | ||||||
| 		"onepassword-api-key", |  | ||||||
| 		"some_other_key", |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	containers := generateContainersWithSecretRefsFromEnvFrom(containerSecretNames) |  | ||||||
|  |  | ||||||
| 	if !AreContainersUsingSecrets(containers, secretNamesToSearch) { | 	if !AreContainersUsingSecrets(containers, secretNamesToSearch) { | ||||||
| 		t.Errorf("Expected that containers were using secrets but they were not detected.") | 		t.Errorf("Expected that containers were using secrets but they were not detected.") | ||||||
| @@ -47,39 +27,17 @@ func TestAreContainersUsingSecretsFromEnvFrom(t *testing.T) { | |||||||
|  |  | ||||||
| func TestAreContainersNotUsingSecrets(t *testing.T) { | func TestAreContainersNotUsingSecrets(t *testing.T) { | ||||||
| 	secretNamesToSearch := map[string]*corev1.Secret{ | 	secretNamesToSearch := map[string]*corev1.Secret{ | ||||||
| 		"onepassword-database-secret": {}, | 		"onepassword-database-secret": &corev1.Secret{}, | ||||||
| 		"onepassword-api-key":         {}, | 		"onepassword-api-key":         &corev1.Secret{}, | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	containerSecretNames := []string{ | 	containerSecretNames := []string{ | ||||||
| 		"some_other_key", | 		"some_other_key", | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	containers := generateContainersWithSecretRefsFromEnv(containerSecretNames) | 	containers := generateContainers(containerSecretNames) | ||||||
|  |  | ||||||
| 	if AreContainersUsingSecrets(containers, secretNamesToSearch) { | 	if AreContainersUsingSecrets(containers, secretNamesToSearch) { | ||||||
| 		t.Errorf("Expected that containers were not using secrets but they were detected.") | 		t.Errorf("Expected that containers were not using secrets but they were detected.") | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func TestAppendUpdatedContainerSecretsParsesEnvFromEnv(t *testing.T) { |  | ||||||
| 	secretNamesToSearch := map[string]*corev1.Secret{ |  | ||||||
| 		"onepassword-database-secret": {}, |  | ||||||
| 		"onepassword-api-key":         {ObjectMeta: metav1.ObjectMeta{Name: "onepassword-api-key"}}, |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	containerSecretNames := []string{ |  | ||||||
| 		"onepassword-api-key", |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	containers := generateContainersWithSecretRefsFromEnvFrom(containerSecretNames) |  | ||||||
|  |  | ||||||
| 	updatedDeploymentSecrets := map[string]*corev1.Secret{} |  | ||||||
| 	updatedDeploymentSecrets = AppendUpdatedContainerSecrets(containers, secretNamesToSearch, updatedDeploymentSecrets) |  | ||||||
|  |  | ||||||
| 	secretKeyName := "onepassword-api-key" |  | ||||||
|  |  | ||||||
| 	if updatedDeploymentSecrets[secretKeyName] != secretNamesToSearch[secretKeyName] { |  | ||||||
| 		t.Errorf("Expected that updated Secret from envfrom is found.") |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
|   | |||||||
| @@ -39,7 +39,7 @@ func TestIsDeploymentUsingSecretsUsingContainers(t *testing.T) { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	deployment := &appsv1.Deployment{} | 	deployment := &appsv1.Deployment{} | ||||||
| 	deployment.Spec.Template.Spec.Containers = generateContainersWithSecretRefsFromEnv(containerSecretNames) | 	deployment.Spec.Template.Spec.Containers = generateContainers(containerSecretNames) | ||||||
| 	if !IsDeploymentUsingSecrets(deployment, secretNamesToSearch) { | 	if !IsDeploymentUsingSecrets(deployment, secretNamesToSearch) { | ||||||
| 		t.Errorf("Expected that deployment was using secrets but they were not detected.") | 		t.Errorf("Expected that deployment was using secrets but they were not detected.") | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -11,11 +11,16 @@ import ( | |||||||
|  |  | ||||||
| var logger = logf.Log.WithName("retrieve_item") | var logger = logf.Log.WithName("retrieve_item") | ||||||
|  |  | ||||||
| func GetOnePasswordItemByPath(opConnectClient connect.Client, path string) (*onepassword.Item, error) { | const ( | ||||||
| 	vaultValue, itemValue, err := ParseVaultAndItemFromPath(path) | 	secretReferencePrefix = "op://" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | func GetOnePasswordItemByReference(opConnectClient connect.Client, reference string) (*onepassword.Item, error) { | ||||||
|  | 	vaultValue, itemValue, err := ParseReference(reference) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	vaultId, err := getVaultId(opConnectClient, vaultValue) | 	vaultId, err := getVaultId(opConnectClient, vaultValue) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| @@ -33,12 +38,28 @@ func GetOnePasswordItemByPath(opConnectClient connect.Client, path string) (*one | |||||||
| 	return item, nil | 	return item, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func ParseVaultAndItemFromPath(path string) (string, string, error) { | func ParseReference(reference string) (string, string, error) { | ||||||
| 	splitPath := strings.Split(path, "/") | 	if !strings.HasPrefix(reference, secretReferencePrefix) { | ||||||
| 	if len(splitPath) == 4 && splitPath[0] == "vaults" && splitPath[2] == "items" { | 		return "", "", fmt.Errorf("secret reference should start with `op://`") | ||||||
| 		return splitPath[1], splitPath[3], nil |  | ||||||
| 	} | 	} | ||||||
| 	return "", "", fmt.Errorf("%q is not an acceptable path for One Password item. Must be of the format: `vaults/{vault_id}/items/{item_id}`", path) | 	path := strings.TrimPrefix(reference, secretReferencePrefix) | ||||||
|  |  | ||||||
|  | 	splitPath := strings.Split(path, "/") | ||||||
|  | 	if len(splitPath) != 2 { | ||||||
|  | 		return "", "", fmt.Errorf("Invalid secret reference : %s. Secret references should match op://<vault>/<item>", reference) | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	vault := splitPath[0] | ||||||
|  | 	if vault == "" { | ||||||
|  | 		return "", "", fmt.Errorf("Invalid secret reference : %s. Vault can't be empty.", reference) | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	item := splitPath[1] | ||||||
|  | 	if item == "" { | ||||||
|  | 		return "", "", fmt.Errorf("Invalid secret reference : %s. Item can't be empty.", reference) | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	return vault, item, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func getVaultId(client connect.Client, vaultIdentifier string) (string, error) { | func getVaultId(client connect.Client, vaultIdentifier string) (string, error) { | ||||||
|   | |||||||
| @@ -17,7 +17,8 @@ func generateVolumes(names []string) []corev1.Volume { | |||||||
| 	} | 	} | ||||||
| 	return volumes | 	return volumes | ||||||
| } | } | ||||||
| func generateContainersWithSecretRefsFromEnv(names []string) []corev1.Container { |  | ||||||
|  | func generateContainers(names []string) []corev1.Container { | ||||||
| 	containers := []corev1.Container{} | 	containers := []corev1.Container{} | ||||||
| 	for i := 0; i < len(names); i++ { | 	for i := 0; i < len(names); i++ { | ||||||
| 		container := corev1.Container{ | 		container := corev1.Container{ | ||||||
| @@ -39,16 +40,3 @@ func generateContainersWithSecretRefsFromEnv(names []string) []corev1.Container | |||||||
| 	} | 	} | ||||||
| 	return containers | 	return containers | ||||||
| } | } | ||||||
|  |  | ||||||
| func generateContainersWithSecretRefsFromEnvFrom(names []string) []corev1.Container { |  | ||||||
| 	containers := []corev1.Container{} |  | ||||||
| 	for i := 0; i < len(names); i++ { |  | ||||||
| 		container := corev1.Container{ |  | ||||||
| 			EnvFrom: []corev1.EnvFromSource{ |  | ||||||
| 				{SecretRef: &corev1.SecretEnvSource{LocalObjectReference: corev1.LocalObjectReference{Name: names[i]}}}, |  | ||||||
| 			}, |  | ||||||
| 		} |  | ||||||
| 		containers = append(containers, container) |  | ||||||
| 	} |  | ||||||
| 	return containers |  | ||||||
| } |  | ||||||
|   | |||||||
| @@ -110,16 +110,15 @@ func (h *SecretUpdateHandler) updateKubernetesSecrets() (map[string]map[string]* | |||||||
| 	for i := 0; i < len(secrets.Items); i++ { | 	for i := 0; i < len(secrets.Items); i++ { | ||||||
| 		secret := secrets.Items[i] | 		secret := secrets.Items[i] | ||||||
|  |  | ||||||
| 		itemPath := secret.Annotations[ItemPathAnnotation] | 		itemReference := secret.Annotations[ItemReferenceAnnotation] | ||||||
| 		currentVersion := secret.Annotations[VersionAnnotation] | 		currentVersion := secret.Annotations[VersionAnnotation] | ||||||
| 		if len(itemPath) == 0 || len(currentVersion) == 0 { | 		if len(itemReference) == 0 || len(currentVersion) == 0 { | ||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		item, err := GetOnePasswordItemByPath(h.opConnectClient, secret.Annotations[ItemPathAnnotation]) | 		item, err := GetOnePasswordItemByReference(h.opConnectClient, secret.Annotations[ItemReferenceAnnotation]) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			log.Error(err, "failed to retrieve 1Password item at path \"%s\" for secret \"%s\"", secret.Annotations[ItemPathAnnotation], secret.Name) | 			return nil, fmt.Errorf("Failed to retrieve item: %v", err) | ||||||
| 			continue |  | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		itemVersion := fmt.Sprint(item.Version) | 		itemVersion := fmt.Sprint(item.Version) | ||||||
| @@ -132,7 +131,7 @@ func (h *SecretUpdateHandler) updateKubernetesSecrets() (map[string]map[string]* | |||||||
| 			} | 			} | ||||||
| 			log.Info(fmt.Sprintf("Updating kubernetes secret '%v'", secret.GetName())) | 			log.Info(fmt.Sprintf("Updating kubernetes secret '%v'", secret.GetName())) | ||||||
| 			secret.Annotations[VersionAnnotation] = itemVersion | 			secret.Annotations[VersionAnnotation] = itemVersion | ||||||
| 			updatedSecret := kubeSecrets.BuildKubernetesSecretFromOnePasswordItem(secret.Name, secret.Namespace, secret.Annotations, secret.Labels, string(secret.Type), *item) | 			updatedSecret := kubeSecrets.BuildKubernetesSecretFromOnePasswordItem(secret.Name, secret.Namespace, secret.Annotations, *item) | ||||||
| 			h.client.Update(context.Background(), updatedSecret) | 			h.client.Update(context.Background(), updatedSecret) | ||||||
| 			if updatedSecrets[secret.Namespace] == nil { | 			if updatedSecrets[secret.Namespace] == nil { | ||||||
| 				updatedSecrets[secret.Namespace] = make(map[string]*corev1.Secret) | 				updatedSecrets[secret.Namespace] = make(map[string]*corev1.Secret) | ||||||
|   | |||||||
| @@ -51,7 +51,7 @@ var ( | |||||||
| 		"password": []byte(password), | 		"password": []byte(password), | ||||||
| 		"username": []byte(username), | 		"username": []byte(username), | ||||||
| 	} | 	} | ||||||
| 	itemPath = fmt.Sprintf("vaults/%v/items/%v", vaultId, itemId) | 	itemReference = fmt.Sprintf("op://%v/%v", vaultId, itemId) | ||||||
| ) | ) | ||||||
|  |  | ||||||
| var defaultNamespace = &corev1.Namespace{ | var defaultNamespace = &corev1.Namespace{ | ||||||
| @@ -74,7 +74,7 @@ var tests = []testUpdateSecretTask{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					NameAnnotation:          "unlrelated secret", | 					NameAnnotation:          "unlrelated secret", | ||||||
| 					ItemPathAnnotation: itemPath, | 					ItemReferenceAnnotation: itemReference, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| @@ -84,7 +84,7 @@ var tests = []testUpdateSecretTask{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					VersionAnnotation:       "old version", | 					VersionAnnotation:       "old version", | ||||||
| 					ItemPathAnnotation: itemPath, | 					ItemReferenceAnnotation: itemReference, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| @@ -96,7 +96,7 @@ var tests = []testUpdateSecretTask{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					VersionAnnotation:       fmt.Sprint(itemVersion), | 					VersionAnnotation:       fmt.Sprint(itemVersion), | ||||||
| 					ItemPathAnnotation: itemPath, | 					ItemReferenceAnnotation: itemReference, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| @@ -150,7 +150,7 @@ var tests = []testUpdateSecretTask{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					VersionAnnotation:       "old version", | 					VersionAnnotation:       "old version", | ||||||
| 					ItemPathAnnotation: itemPath, | 					ItemReferenceAnnotation: itemReference, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| @@ -162,7 +162,7 @@ var tests = []testUpdateSecretTask{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					VersionAnnotation:       fmt.Sprint(itemVersion), | 					VersionAnnotation:       fmt.Sprint(itemVersion), | ||||||
| 					ItemPathAnnotation: itemPath, | 					ItemReferenceAnnotation: itemReference, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| @@ -186,7 +186,7 @@ var tests = []testUpdateSecretTask{ | |||||||
| 				Name:      name, | 				Name:      name, | ||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					ItemPathAnnotation: itemPath, | 					ItemReferenceAnnotation: itemReference, | ||||||
| 					NameAnnotation:          name, | 					NameAnnotation:          name, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| @@ -197,7 +197,7 @@ var tests = []testUpdateSecretTask{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					VersionAnnotation:       "old version", | 					VersionAnnotation:       "old version", | ||||||
| 					ItemPathAnnotation: itemPath, | 					ItemReferenceAnnotation: itemReference, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| @@ -209,7 +209,7 @@ var tests = []testUpdateSecretTask{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					VersionAnnotation:       fmt.Sprint(itemVersion), | 					VersionAnnotation:       fmt.Sprint(itemVersion), | ||||||
| 					ItemPathAnnotation: itemPath, | 					ItemReferenceAnnotation: itemReference, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| @@ -256,7 +256,7 @@ var tests = []testUpdateSecretTask{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					VersionAnnotation:       "old version", | 					VersionAnnotation:       "old version", | ||||||
| 					ItemPathAnnotation: itemPath, | 					ItemReferenceAnnotation: itemReference, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| @@ -268,7 +268,7 @@ var tests = []testUpdateSecretTask{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					VersionAnnotation:       fmt.Sprint(itemVersion), | 					VersionAnnotation:       fmt.Sprint(itemVersion), | ||||||
| 					ItemPathAnnotation: itemPath, | 					ItemReferenceAnnotation: itemReference, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| @@ -292,7 +292,7 @@ var tests = []testUpdateSecretTask{ | |||||||
| 				Name:      name, | 				Name:      name, | ||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					ItemPathAnnotation: itemPath, | 					ItemReferenceAnnotation: itemReference, | ||||||
| 					NameAnnotation:          name, | 					NameAnnotation:          name, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| @@ -303,7 +303,7 @@ var tests = []testUpdateSecretTask{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					VersionAnnotation:       fmt.Sprint(itemVersion), | 					VersionAnnotation:       fmt.Sprint(itemVersion), | ||||||
| 					ItemPathAnnotation: itemPath, | 					ItemReferenceAnnotation: itemReference, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| @@ -315,7 +315,7 @@ var tests = []testUpdateSecretTask{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					VersionAnnotation:       fmt.Sprint(itemVersion), | 					VersionAnnotation:       fmt.Sprint(itemVersion), | ||||||
| 					ItemPathAnnotation: itemPath, | 					ItemReferenceAnnotation: itemReference, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| @@ -370,7 +370,7 @@ var tests = []testUpdateSecretTask{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					VersionAnnotation:       "old version", | 					VersionAnnotation:       "old version", | ||||||
| 					ItemPathAnnotation: itemPath, | 					ItemReferenceAnnotation: itemReference, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| @@ -382,7 +382,7 @@ var tests = []testUpdateSecretTask{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					VersionAnnotation:       fmt.Sprint(itemVersion), | 					VersionAnnotation:       fmt.Sprint(itemVersion), | ||||||
| 					ItemPathAnnotation: itemPath, | 					ItemReferenceAnnotation: itemReference, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| @@ -439,7 +439,7 @@ var tests = []testUpdateSecretTask{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					VersionAnnotation:            "old version", | 					VersionAnnotation:            "old version", | ||||||
| 					ItemPathAnnotation:           itemPath, | 					ItemReferenceAnnotation:      itemReference, | ||||||
| 					RestartDeploymentsAnnotation: "true", | 					RestartDeploymentsAnnotation: "true", | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| @@ -452,7 +452,7 @@ var tests = []testUpdateSecretTask{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					VersionAnnotation:            fmt.Sprint(itemVersion), | 					VersionAnnotation:            fmt.Sprint(itemVersion), | ||||||
| 					ItemPathAnnotation:           itemPath, | 					ItemReferenceAnnotation:      itemReference, | ||||||
| 					RestartDeploymentsAnnotation: "true", | 					RestartDeploymentsAnnotation: "true", | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| @@ -510,7 +510,7 @@ var tests = []testUpdateSecretTask{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					VersionAnnotation:            "old version", | 					VersionAnnotation:            "old version", | ||||||
| 					ItemPathAnnotation:           itemPath, | 					ItemReferenceAnnotation:      itemReference, | ||||||
| 					RestartDeploymentsAnnotation: "false", | 					RestartDeploymentsAnnotation: "false", | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| @@ -523,7 +523,7 @@ var tests = []testUpdateSecretTask{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					VersionAnnotation:            fmt.Sprint(itemVersion), | 					VersionAnnotation:            fmt.Sprint(itemVersion), | ||||||
| 					ItemPathAnnotation:           itemPath, | 					ItemReferenceAnnotation:      itemReference, | ||||||
| 					RestartDeploymentsAnnotation: "false", | 					RestartDeploymentsAnnotation: "false", | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| @@ -581,7 +581,7 @@ var tests = []testUpdateSecretTask{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					VersionAnnotation:       "old version", | 					VersionAnnotation:       "old version", | ||||||
| 					ItemPathAnnotation: itemPath, | 					ItemReferenceAnnotation: itemReference, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| @@ -593,7 +593,7 @@ var tests = []testUpdateSecretTask{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					VersionAnnotation:       fmt.Sprint(itemVersion), | 					VersionAnnotation:       fmt.Sprint(itemVersion), | ||||||
| 					ItemPathAnnotation: itemPath, | 					ItemReferenceAnnotation: itemReference, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| @@ -658,7 +658,7 @@ var tests = []testUpdateSecretTask{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					VersionAnnotation:       "old version", | 					VersionAnnotation:       "old version", | ||||||
| 					ItemPathAnnotation: itemPath, | 					ItemReferenceAnnotation: itemReference, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| @@ -670,7 +670,7 @@ var tests = []testUpdateSecretTask{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					VersionAnnotation:       fmt.Sprint(itemVersion), | 					VersionAnnotation:       fmt.Sprint(itemVersion), | ||||||
| 					ItemPathAnnotation: itemPath, | 					ItemReferenceAnnotation: itemReference, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| @@ -731,7 +731,7 @@ var tests = []testUpdateSecretTask{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					VersionAnnotation:       "old version", | 					VersionAnnotation:       "old version", | ||||||
| 					ItemPathAnnotation: itemPath, | 					ItemReferenceAnnotation: itemReference, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
| @@ -743,7 +743,7 @@ var tests = []testUpdateSecretTask{ | |||||||
| 				Namespace: namespace, | 				Namespace: namespace, | ||||||
| 				Annotations: map[string]string{ | 				Annotations: map[string]string{ | ||||||
| 					VersionAnnotation:       fmt.Sprint(itemVersion), | 					VersionAnnotation:       fmt.Sprint(itemVersion), | ||||||
| 					ItemPathAnnotation: itemPath, | 					ItemReferenceAnnotation: itemReference, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			Data: expectedSecretData, | 			Data: expectedSecretData, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user