types.go 4.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. Copyright © The ESO Authors
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. https://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. // Package common provides the v2 provider interface for out-of-tree providers communicating via gRPC.
  14. package common
  15. import (
  16. "context"
  17. corev1 "k8s.io/api/core/v1"
  18. esv1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"
  19. pb "github.com/external-secrets/external-secrets/proto/provider"
  20. )
  21. // Provider is the interface that v2 out-of-tree providers must satisfy.
  22. // Unlike v1 providers which are compiled into ESO, v2 providers run as separate services
  23. // and communicate with ESO via gRPC.
  24. type Provider interface {
  25. // GetSecret retrieves a single secret from the provider.
  26. // If the secret doesn't exist, it should return an error.
  27. // At least one of providerRef or compatibilityStore must be provided.
  28. // If both are present, compatibilityStore takes precedence for read operations.
  29. // sourceNamespace is the namespace of the ExternalSecret.
  30. GetSecret(ctx context.Context, ref esv1.ExternalSecretDataRemoteRef, providerRef *pb.ProviderReference, compatibilityStore *pb.CompatibilityStore, sourceNamespace string) ([]byte, error)
  31. // GetSecretMap retrieves multiple key/value pairs from a single secret object.
  32. // At least one of providerRef or compatibilityStore must be provided.
  33. // If both are present, compatibilityStore takes precedence for read operations.
  34. // sourceNamespace is the namespace of the ExternalSecret.
  35. GetSecretMap(
  36. ctx context.Context,
  37. ref esv1.ExternalSecretDataRemoteRef,
  38. providerRef *pb.ProviderReference,
  39. compatibilityStore *pb.CompatibilityStore,
  40. sourceNamespace string,
  41. ) (map[string][]byte, error)
  42. // GetAllSecrets retrieves multiple secrets based on find criteria.
  43. // Returns a map of secret names to their byte values.
  44. // At least one of providerRef or compatibilityStore must be provided.
  45. // If both are present, compatibilityStore takes precedence for read operations.
  46. // sourceNamespace is the namespace of the ExternalSecret.
  47. GetAllSecrets(ctx context.Context, find esv1.ExternalSecretFind, providerRef *pb.ProviderReference, compatibilityStore *pb.CompatibilityStore, sourceNamespace string) (map[string][]byte, error)
  48. // PushSecret writes a secret to the provider.
  49. // The secret is the Kubernetes Secret object to push, and pushSecretData contains the push configuration.
  50. // At least one of providerRef or compatibilityStore must be provided.
  51. // sourceNamespace is the namespace of the PushSecret.
  52. PushSecret(
  53. ctx context.Context,
  54. secret *corev1.Secret,
  55. pushSecretData *pb.PushSecretData,
  56. providerRef *pb.ProviderReference,
  57. compatibilityStore *pb.CompatibilityStore,
  58. sourceNamespace string,
  59. ) error
  60. // DeleteSecret deletes a secret from the provider.
  61. // At least one of providerRef or compatibilityStore must be provided.
  62. // sourceNamespace is the namespace of the PushSecret.
  63. DeleteSecret(ctx context.Context, remoteRef *pb.PushSecretRemoteRef, providerRef *pb.ProviderReference, compatibilityStore *pb.CompatibilityStore, sourceNamespace string) error
  64. // SecretExists checks if a secret exists in the provider.
  65. // At least one of providerRef or compatibilityStore must be provided.
  66. // sourceNamespace is the namespace of the PushSecret.
  67. SecretExists(ctx context.Context, remoteRef *pb.PushSecretRemoteRef, providerRef *pb.ProviderReference, compatibilityStore *pb.CompatibilityStore, sourceNamespace string) (bool, error)
  68. // Validate checks if the provider is properly configured and can communicate with the backend.
  69. // This is called by the SecretStore controller during reconciliation.
  70. // At least one of providerRef or compatibilityStore must be provided.
  71. // sourceNamespace is the namespace of the requesting store.
  72. Validate(ctx context.Context, providerRef *pb.ProviderReference, compatibilityStore *pb.CompatibilityStore, sourceNamespace string) error
  73. // Capabilities returns what operations the provider supports (ReadOnly, WriteOnly, ReadWrite).
  74. // The providerRef references the provider configuration CRD, and sourceNamespace is the namespace of the Provider.
  75. Capabilities(ctx context.Context, providerRef *pb.ProviderReference, sourceNamespace string) (pb.SecretStoreCapabilities, error)
  76. // Close cleans up any resources held by the provider client.
  77. Close(ctx context.Context) error
  78. }