···33# To re-generate a bundle for another specific version without changing the standard setup, you can:
44# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
55# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
66-VERSION ?= 0.6.37
66+VERSION ?= 0.6.38
7788# CHANNELS define the bundle channels used in the bundle.
99# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
+2-2
helm/hsm-secrets-operator/Chart.yaml
···22name: hsm-secrets-operator
33description: A Kubernetes operator that bridges Pico HSM binary data storage with Kubernetes Secrets
44type: application
55-version: 0.6.37
66-appVersion: v0.6.37
55+version: 0.6.38
66+appVersion: v0.6.38
77icon: https://raw.githubusercontent.com/cncf/artwork/master/projects/kubernetes/icon/color/kubernetes-icon-color.svg
88home: https://github.com/evanjarrett/hsm-secrets-operator
99sources:
+39-12
internal/hsm/pkcs11_cgo.go
···316316317317 obj, err := session.ctx.CreateObject(session.session, template)
318318 if err != nil {
319319- return 0, fmt.Errorf("failed to create data object: %w", err)
319319+ // Enhanced error message with context
320320+ oidStatus := "none"
321321+ if derOID != nil {
322322+ oidStatus = fmt.Sprintf("%v (DER len=%d)", oid, len(derOID))
323323+ }
324324+ return 0, fmt.Errorf("failed to create data object (label=%s, dataType=%s, oid=%s, valueLen=%d): %w",
325325+ label, dataType, oidStatus, len(value), err)
320326 }
321327322328 return obj, nil
···345351 return fmt.Errorf("failed to find objects: %w", err)
346352 }
347353348348- // Delete each object that matches our path
349349- deletedCount := 0
354354+ // CRITICAL: Collect object handles to delete WHILE in search mode
355355+ // We must call FindObjectsFinal BEFORE destroying objects
356356+ type objectToDelete struct {
357357+ handle ObjectHandle
358358+ label string
359359+ }
360360+ objectsToDelete := make([]objectToDelete, 0)
361361+350362 for _, obj := range objs {
351363 // Get the label to check if this object matches our path
352364 labelAttr, err := session.ctx.GetAttributeValue(session.session, obj, []*pkcs11.Attribute{
···361373 }
362374363375 label := string(labelAttr[0].Value)
364364- // Only delete objects that match our path
376376+ // Only collect objects that match our path
365377 if !strings.HasPrefix(label, path) {
366378 continue
367379 }
368380369369- if err := session.ctx.DestroyObject(session.session, obj); err != nil {
370370- // Log error but continue with other objects
371371- continue
381381+ objectsToDelete = append(objectsToDelete, objectToDelete{
382382+ handle: obj,
383383+ label: label,
384384+ })
385385+ }
386386+387387+ // CRITICAL: Must call FindObjectsFinal to exit search mode BEFORE destroying objects
388388+ // DestroyObject requires the session to be in normal mode, not search mode
389389+ if err := session.ctx.FindObjectsFinal(session.session); err != nil {
390390+ return fmt.Errorf("failed to finalize object search (session may be in invalid state): %w", err)
391391+ }
392392+393393+ // Now destroy the collected objects (session is in normal mode)
394394+ deletedCount := 0
395395+ var deleteErrors []string
396396+ for _, obj := range objectsToDelete {
397397+ if err := session.ctx.DestroyObject(session.session, obj.handle); err != nil {
398398+ deleteErrors = append(deleteErrors, fmt.Sprintf("%s: %v", obj.label, err))
399399+ } else {
400400+ deletedCount++
372401 }
373373- deletedCount++
374402 }
375403376376- // CRITICAL: Must call FindObjectsFinal to release search operation
377377- // If this fails, the session remains in search mode and CreateObject will fail
378378- if err := session.ctx.FindObjectsFinal(session.session); err != nil {
379379- return fmt.Errorf("failed to finalize object search after deleting %d objects (session may be in invalid state): %w", deletedCount, err)
404404+ // Report any delete failures
405405+ if len(deleteErrors) > 0 {
406406+ return fmt.Errorf("failed to delete %d of %d objects: %s", len(deleteErrors), len(objectsToDelete), strings.Join(deleteErrors, "; "))
380407 }
381408382409 return nil
+11-1
internal/hsm/pkcs11_client.go
···234234 // First, delete any existing objects for this path to avoid duplicates
235235 // IMPORTANT: Do not ignore errors here - if FindObjectsFinal fails in delete,
236236 // the session will be in an invalid state and CreateObject will fail
237237+ c.logger.V(1).Info("Deleting existing objects before write", "path", path)
237238 if err := deleteSecretObjectsPKCS11(c.session, path); err != nil {
238239 return fmt.Errorf("failed to prepare HSM for write (delete existing objects): %w", err)
239240 }
241241+ c.logger.V(1).Info("Successfully deleted existing objects", "path", path)
240242241243 // Create data objects for each key-value pair
242244 for key, value := range data {
···277279 // Create metadata object label
278280 metadataLabel := path + metadataKeySuffix
279281282282+ c.logger.V(1).Info("Creating metadata object",
283283+ "path", path,
284284+ "label", metadataLabel,
285285+ "metadataSize", len(metadataJSON))
286286+280287 // Create the metadata object via helper
281288 handle, err := createObjectPKCS11(c.session, metadataLabel, metadataJSON)
282289 if err != nil {
···286293 // Cache the metadata object handle
287294 c.dataObjects[metadataLabel] = handle
288295289289- c.logger.V(2).Info("Created metadata object", "path", path, "label", metadataLabel)
296296+ c.logger.V(1).Info("Successfully created metadata object",
297297+ "path", path,
298298+ "label", metadataLabel,
299299+ "handle", handle)
290300 return nil
291301}
292302