This is an automated email from the ASF dual-hosted git repository.

xiangfu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new c58488cb3e Add an interface for SecretStore (#15226)
c58488cb3e is described below

commit c58488cb3e0267b0165a4b84324e3b3599c36de6
Author: Nayanika Upadhyay <70254357+nayanik...@users.noreply.github.com>
AuthorDate: Sat Mar 29 15:20:46 2025 -0700

    Add an interface for SecretStore (#15226)
    
    Address comments
    
    Co-authored-by: Nayanika <nayan...@nayanikas-mbp.wyvern-sun.ts.net>
---
 .../apache/pinot/spi/secretstore/SecretStore.java  | 94 ++++++++++++++++++++++
 .../spi/secretstore/SecretStoreException.java      | 94 ++++++++++++++++++++++
 2 files changed, 188 insertions(+)

diff --git 
a/pinot-spi/src/main/java/org/apache/pinot/spi/secretstore/SecretStore.java 
b/pinot-spi/src/main/java/org/apache/pinot/spi/secretstore/SecretStore.java
new file mode 100644
index 0000000000..4bde44490a
--- /dev/null
+++ b/pinot-spi/src/main/java/org/apache/pinot/spi/secretstore/SecretStore.java
@@ -0,0 +1,94 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.spi.secretstore;
+
+import java.util.List;
+
+/**
+ * Interface for managing secrets in Apache Pinot.
+ *
+ * This interface abstracts away the details of the underlying secret storage 
mechanism,
+ * allowing Pinot to work with various secret management systems like AWS 
Secrets Manager,
+ * HashiCorp Vault, or other custom implementations.
+ *
+ * Implementations of this interface should handle all aspects of secret 
management including
+ * secure storage, retrieval, and cleanup of sensitive information such as 
connection credentials.
+ * All implementations must be thread-safe.
+ */
+public interface SecretStore {
+
+    /**
+     * Stores a secret in the secret management system.
+     *
+     * @param secretKey A unique identifier for the secret, typically 
following a hierarchical
+     *                   naming pattern (e.g., 
"pinot/tables/myTable/credentials")
+     * @param secretValue The actual secret value to be securely stored
+     * @return A reference key that can be used later to retrieve the secret
+     * @throws SecretStoreException If the secret cannot be stored due to 
connectivity issues,
+     *                             permission problems, or other errors
+     */
+    String storeSecret(String secretKey, String secretValue) throws 
SecretStoreException;
+
+    /**
+     * Retrieves a secret from the secret management system.
+     *
+     * @param secretKey The reference key obtained when the secret was stored
+     * @return The actual secret value
+     * @throws SecretStoreException If the secret cannot be retrieved or 
doesn't exist
+     */
+    String getSecret(String secretKey) throws SecretStoreException;
+
+    /**
+     * Updates an existing secret with a new value.
+     *
+     * @param secretKey The reference key for the secret to be updated
+     * @param newSecretValue The new value to store
+     * @throws SecretStoreException If the secret cannot be updated or doesn't 
exist
+     */
+    void updateSecret(String secretKey, String newSecretValue) throws 
SecretStoreException;
+
+    /**
+     * Deletes a secret when it is no longer needed.
+     *
+     * This method should be called when the associated resource (e.g., a 
table or connection)
+     * is being deleted to ensure proper cleanup of sensitive information.
+     *
+     * @param secretKey The reference key for the secret to be deleted
+     * @throws SecretStoreException If the secret cannot be deleted or doesn't 
exist
+     */
+    void deleteSecret(String secretKey) throws SecretStoreException;
+
+    /**
+     * Checks if a secret exists in the secret management system.
+     *
+     * @param secretKey The reference key for the secret
+     * @return true if the secret exists, false otherwise
+     * @throws SecretStoreException If the check cannot be performed
+     */
+    boolean exists(String secretKey) throws SecretStoreException;
+
+    /**
+     * Lists all secrets with a given prefix.
+     *
+     * @param prefix The prefix to filter secrets by
+     * @return A list of secret keys matching the prefix
+     * @throws SecretStoreException If the secret list cannot be retrieved
+     */
+    List<String> listSecrets(String prefix) throws SecretStoreException;
+}
diff --git 
a/pinot-spi/src/main/java/org/apache/pinot/spi/secretstore/SecretStoreException.java
 
b/pinot-spi/src/main/java/org/apache/pinot/spi/secretstore/SecretStoreException.java
new file mode 100644
index 0000000000..5ca8a7f862
--- /dev/null
+++ 
b/pinot-spi/src/main/java/org/apache/pinot/spi/secretstore/SecretStoreException.java
@@ -0,0 +1,94 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.spi.secretstore;
+
+/**
+ * Exception thrown when operations on the {@link SecretStore} fail.
+ * This exception encapsulates errors that may occur during secret storage,
+ * retrieval, updating, or deletion operations.
+ */
+public class SecretStoreException extends RuntimeException {
+
+    /**
+     * Creates a new SecretStoreException with the specified message.
+     *
+     * @param message the detail message
+     */
+    public SecretStoreException(String message) {
+        super(message);
+    }
+
+    /**
+     * Creates a new SecretStoreException with the specified message and cause.
+     *
+     * @param message the detail message
+     * @param cause the cause of the exception
+     */
+    public SecretStoreException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    /**
+     * Creates a new SecretStoreException with the specified cause.
+     *
+     * @param cause the cause of the exception
+     */
+    public SecretStoreException(Throwable cause) {
+        super(cause);
+    }
+
+    /**
+     * Exception thrown when a requested secret cannot be found.
+     */
+    public static class SecretNotFoundException extends SecretStoreException {
+        public SecretNotFoundException(String secretKey) {
+            super("Secret not found: " + secretKey);
+        }
+
+        public SecretNotFoundException(String secretKey, Throwable cause) {
+            super("Secret not found: " + secretKey, cause);
+        }
+    }
+
+    /**
+     * Exception thrown when permission is denied for a secret store operation.
+     */
+    public static class SecretPermissionException extends SecretStoreException 
{
+        public SecretPermissionException(String secretKey) {
+            super("Permission denied for secret: " + secretKey);
+        }
+
+        public SecretPermissionException(String secretKey, Throwable cause) {
+            super("Permission denied for secret: " + secretKey, cause);
+        }
+    }
+
+    /**
+     * Exception thrown when the secret store is unavailable or cannot be 
reached.
+     */
+    public static class SecretStoreConnectionException extends 
SecretStoreException {
+        public SecretStoreConnectionException(String message) {
+            super("Failed to connect to secret store: " + message);
+        }
+
+        public SecretStoreConnectionException(String message, Throwable cause) 
{
+            super("Failed to connect to secret store: " + message, cause);
+        }
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to