generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 8
support using secret names instead of UUID #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
maxkpower
wants to merge
5
commits into
main
Choose a base branch
from
SM-1768-support-using-secret-names-instead-of-uuid
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+638
โ8
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -166,7 +166,7 @@ var _ = Describe("BitwardenSecret Reconciler - Edge Case Tests", Ordered, func() | |||||
| for i := range largeNumOfSecrets { | ||||||
| identifier := sdk.SecretIdentifierResponse{ | ||||||
| ID: uuid.NewString(), | ||||||
| Key: uuid.NewString(), | ||||||
| Key: fmt.Sprintf("secret_%d", i), // Use secret name | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we make a new test for the useSecretName functionality and add that, rather than replacing this one?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| OrganizationID: fixture.OrgId, | ||||||
| } | ||||||
| largeSecretMap = append(largeSecretMap, operatorsv1.SecretMap{ | ||||||
|
|
@@ -233,4 +233,88 @@ var _ = Describe("BitwardenSecret Reconciler - Edge Case Tests", Ordered, func() | |||||
| Expect(condition.Status).To(Equal(metav1.ConditionTrue)) | ||||||
| Expect(updatedBwSecret.Status.LastSuccessfulSyncTime.Time).NotTo(BeZero()) | ||||||
| }) | ||||||
|
|
||||||
| It("should successfully sync using secret names (useSecretNames mode)", func() { | ||||||
| // Configure mocks with secret names instead of UUIDs | ||||||
| secretNamesData := []sdk.SecretResponse{} | ||||||
| for i := range 10 { | ||||||
| identifier := sdk.SecretIdentifierResponse{ | ||||||
| ID: uuid.NewString(), | ||||||
| Key: fmt.Sprintf("secret_%d", i), // Use secret names | ||||||
| OrganizationID: fixture.OrgId, | ||||||
| } | ||||||
| projectId := uuid.NewString() | ||||||
| secretNamesData = append(secretNamesData, sdk.SecretResponse{ | ||||||
| CreationDate: time.Now().String(), | ||||||
| ID: identifier.ID, | ||||||
| Key: identifier.Key, | ||||||
| Note: uuid.NewString(), | ||||||
| OrganizationID: fixture.OrgId, | ||||||
| ProjectID: &projectId, | ||||||
| RevisionDate: time.Now().String(), | ||||||
| Value: uuid.NewString(), | ||||||
| }) | ||||||
| } | ||||||
| secretNamesResponse := sdk.SecretsSyncResponse{ | ||||||
| HasChanges: true, | ||||||
| Secrets: secretNamesData, | ||||||
| } | ||||||
|
|
||||||
| fixture.SetupDefaultCtrlMocks(false, &secretNamesResponse) | ||||||
|
|
||||||
| _, err := fixture.CreateDefaultAuthSecret(namespace) | ||||||
| Expect(err).NotTo(HaveOccurred()) | ||||||
|
|
||||||
| // Create BitwardenSecret with useSecretNames enabled and no SecretMap | ||||||
| bwSecret, err := fixture.CreateBitwardenSecret( | ||||||
| testutils.BitwardenSecretName, | ||||||
| namespace, | ||||||
| fixture.OrgId, | ||||||
| testutils.SynchronizedSecretName, | ||||||
| testutils.AuthSecretName, | ||||||
| testutils.AuthSecretKey, | ||||||
| []operatorsv1.SecretMap{}, // No SecretMap needed with useSecretNames | ||||||
| false, // OnlyMappedSecrets | ||||||
| ) | ||||||
| Expect(err).NotTo(HaveOccurred()) | ||||||
| Expect(bwSecret).NotTo(BeNil()) | ||||||
|
|
||||||
| // Enable useSecretNames | ||||||
| bwSecret.Spec.UseSecretNames = true | ||||||
| err = fixture.K8sClient.Update(fixture.Ctx, bwSecret) | ||||||
| Expect(err).NotTo(HaveOccurred()) | ||||||
|
|
||||||
| // Trigger reconciliation | ||||||
| req := reconcile.Request{NamespacedName: types.NamespacedName{Name: testutils.BitwardenSecretName, Namespace: namespace}} | ||||||
| result, err := fixture.Reconciler.Reconcile(fixture.Ctx, req) | ||||||
|
|
||||||
| // Verify reconciliation succeeded | ||||||
| Expect(err).NotTo(HaveOccurred()) | ||||||
| Expect(result.RequeueAfter).To(Equal(time.Duration(fixture.Reconciler.RefreshIntervalSeconds) * time.Second)) | ||||||
|
|
||||||
| Eventually(func(g Gomega) { | ||||||
| // Verify created Kubernetes secret | ||||||
| createdTargetSecret := &corev1.Secret{} | ||||||
| g.Expect(fixture.K8sClient.Get(fixture.Ctx, types.NamespacedName{Name: testutils.SynchronizedSecretName, Namespace: namespace}, createdTargetSecret)).Should(Succeed()) | ||||||
|
|
||||||
| // Check secret metadata and type | ||||||
| g.Expect(createdTargetSecret.Labels[controller.LabelBwSecret]).To(Equal(string(bwSecret.UID))) | ||||||
| g.Expect(createdTargetSecret.Type).To(Equal(corev1.SecretTypeOpaque)) | ||||||
|
|
||||||
| // Verify all secrets are synced using their names as keys | ||||||
| g.Expect(len(createdTargetSecret.Data)).To(Equal(10)) | ||||||
| for i := range 10 { | ||||||
| expectedKey := fmt.Sprintf("secret_%d", i) | ||||||
| g.Expect(createdTargetSecret.Data).To(HaveKey(expectedKey)) | ||||||
| } | ||||||
|
|
||||||
| // Verify BitwardenSecret status | ||||||
| updatedBwSecret := &operatorsv1.BitwardenSecret{} | ||||||
| g.Expect(fixture.K8sClient.Get(fixture.Ctx, types.NamespacedName{Name: testutils.BitwardenSecretName, Namespace: namespace}, updatedBwSecret)).Should(Succeed()) | ||||||
| condition := apimeta.FindStatusCondition(updatedBwSecret.Status.Conditions, "SuccessfulSync") | ||||||
| g.Expect(condition).NotTo(BeNil()) | ||||||
| g.Expect(condition.Status).To(Equal(metav1.ConditionTrue)) | ||||||
| g.Expect(updatedBwSecret.Status.LastSuccessfulSyncTime.Time).NotTo(BeZero()) | ||||||
| }) | ||||||
| }) | ||||||
| }) | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.