maulin-vasavada commented on a change in pull request #1027:
URL: https://github.com/apache/cassandra/pull/1027#discussion_r695303276



##########
File path: 
examples/ssl-factory/src/org/apache/cassandra/security/K8SecretsSslContextFactory.java
##########
@@ -0,0 +1,260 @@
+/*
+ * 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.cassandra.security;
+
+import java.util.Map;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Custom {@link ISslContextFactory} implementation based on Kubernetes 
Secrets. It allows the keystore and
+ * truststore paths to be configured from the K8 secrets via volumeMount and 
passwords via K8 secrets environment
+ * variables.
+ *
+ * When keystore or truststore is updated, this implementation can detect that 
based on updated K8 secrets
+ * environment variable ({@code KEYSTORE_UPDATED_TIMESTAMP_ENV_VAR} for the 
keystore and {@code
+ * TRUSTSTORE_UPDATED_TIMESTAMP_ENV_VAR} for the truststore. The values in 
those timestamp variables is expected to
+ * be numeric values. Most obvious choice might be to just use time in 
milliseconds but any other strategy would work
+ * as well, as far as the comparison of those values can be done in a 
consistent/predictable manner. Again, those
+ * values don't have to necessarily reflect actual file's update timestamps, 
using the actual file's timestamps is
+ * just one of the valid options to signal updates.
+ *
+ * Defaults:
+ * <pre>
+ *     keystore path = /etc/my-ssl-store/keystore
+ *     keystore password = cassandra
+ *     truststore path = /etc/my-ssl-store/truststore
+ *     truststore password = cassandra
+ * </pre>
+ *
+ * Customization: In order to customize the K8 secret configuration, override 
appropriate values in the below cassandra
+ * configuration. The similar configuration can be applied to {@code 
client_encryption_options}.
+ * <pre>
+ *     server_encryption_options:
+ *       internode_encryption: none
+ *       ssl_context_factory:
+ *         class_name: org.apache.cassandra.security.K8SecretsSslContextFactory
+ *         parameters:
+ *           KEYSTORE_PATH: /etc/my-ssl-store/keystore
+ *           KEYSTORE_PASSWORD_ENV_VAR: KEYSTORE_PASSWORD
+ *           KEYSTORE_UPDATED_TIMESTAMP_ENV_VAR: KEYSTORE_LAST_UPDATEDTIME
+ *           TRUSTSTORE_PATH: /etc/my-ssl-store/truststore
+ *           TRUSTSTORE_PASSWORD_ENV_VAR: TRUSTSTORE_PASSWORD
+ *           TRUSTSTORE_UPDATED_TIMESTAMP_ENV_VAR: TRUSTSTORE_LAST_UPDATEDTIME
+ * </pre>
+ *
+ * Below is the corresponding sample YAML configuration for K8 env.
+ * <pre>
+ * apiVersion: v1
+ * kind: Pod
+ * metadata:
+ *   name: my-pod
+ *   labels:
+ *     app: my-app
+ * spec:
+ *   containers:
+ *   - name: my-app
+ *     image: my-app:latest
+ *     imagePullPolicy: Always
+ *     env:
+ *       - name: KEYSTORE_PASSWORD
+ *         valueFrom:
+ *           secretKeyRef:
+ *             name: my-ssl-store
+ *             key: keystore-password
+ *       - name: KEYSTORE_LAST_UPDATEDTIME
+ *         valueFrom:
+ *           secretKeyRef:
+ *             name: my-ssl-store
+ *             key: keystore-last-updatedtime
+ *       - name: TRUSTSTORE_PASSWORD
+ *         valueFrom:
+ *           secretKeyRef:
+ *             name: my-ssl-store
+ *             key: truststore-password
+ *       - name: TRUSTSTORE_LAST_UPDATEDTIME
+ *         valueFrom:
+ *           secretKeyRef:
+ *             name: my-ssl-store
+ *             key: truststore-last-updatedtime
+ *     volumeMounts:
+ *     - name: my-ssl-store
+ *       mountPath: "/etc/my-ssl-store"
+ *       readOnly: true
+ *   volumes:
+ *   - name: my-ssl-store
+ *     secret:
+ *       secretName: my-ssl-store
+ *       items:
+ *         - key: cassandra_ssl_keystore
+ *           path: keystore
+ *         - key: cassandra_ssl_truststore
+ *           path: truststore
+ * </pre>
+ */
+public class K8SecretsSslContextFactory extends FileBasedSslContextFactory

Review comment:
       I think `K8s` is the right name. However instead of 
`K8SSecretsSslContextFactory` I prefer `KubernetesSecretsSslContextFactory`. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to