maulin-vasavada commented on a change in pull request #1027: URL: https://github.com/apache/cassandra/pull/1027#discussion_r696071705
########## 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 Review comment: @jonmeredith You are right. Only the mounted volumes gets updates (depending upon how you pull + kubelet sync configuration) and env variables [don't get updated in the running pods](https://kubernetes.io/docs/concepts/configuration/secret/#environment-variables-are-not-updated-after-a-secret-update). Given that I should change the K8s example to use a variable from a mounted volume but its little ugly since I've to read it like a file just for a single value! -- 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]

