在本系列的第二部分中,我们讨论了保护数据传输安全的途径,并讲解了如何在Apache Cassandra 4.0中配置TLS/mTLS。在第三部分中,我们将研究如何为Apache Cassandra 4.1+定制化TLS/mTLS,以克服TLS配置的挑战。
我们如何在4.1中使TLS配置变得更好
在Apache Cassandra 4.1中,我们加强了TLS/mTLS配置,允许自定义的方式来构建SSLContext,并且我们提供了一个默认的实现,以便向后兼容。我们引入了一个新的配置,ssl_context_factory,在这里你可以指定自定义类,用来构建Java/Netty SSL库所需的SSLContext对象。你还可以通过简单的键值对向它添加自定义属性。所有这些都是在保留了4.0版之前的热加载安全证书的能力的情况下实现的。
为了演示自定义配置,我们用流行的云原生解决方案Kubernetes为例。Kubernetes允许配置Secrets来存储敏感数据。我们使用K8s Secrets来存储keystore和truststore,以及它们各自的密码。我们假设Apache Cassandra已经在K8s环境中运行。
集成与Kubernetes Secrets
我们将keystore和truststore的密码作为K8s环境变量从K8s Secrets中加载。keystore和truststore文件是由K8s Secrets加载的。下面这个YAML文件反映了这些设置。这个例子还通过允许名为keystore/truststore-last-updatedtime的秘密来保持安全证书的热加载能力。你可以通过kubectl命令更新这些Secrets的时间戳值,实现将热加载安全凭证,就像基于文件系统的安全凭证。
K8s Pod配置例子
apiVersion: v1
kind: Pod
metadata:
name: my-cassandra-pod
labels:
app: my-cassandra-app
spec:
containers:
- name: my-cassandra-app
image: my-cassandrda-app:latest
imagePullPolicy: Always
env:
- name: KEYSTORE_PASSWORD
valueFrom:
secretKeyRef:
name: my-ssl-store
key: keystore-password
- name: TRUSTSTORE_PASSWORD
valueFrom:
secretKeyRef:
name: my-ssl-store
key: truststore-password
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: keystore-last-updatedtime
path: keystore-last-updatedtime
- key: cassandra_ssl_truststore
path: truststore
- key: truststore-last-updatedtime
path: truststore-last-updatedtime
我们以Apache Cassandra 4.1中的“KubernetesSecretsSslContextFactory”类为例,说明如何通过Kubernetes Secrets定制由pod定义(上文)加载的TLS配置。
K8s Secrets的自定义TLS配置例子
这里我们使用了server_encryption_options的配置,同样也可以将其用于client_encryption_options:
server_encryption_options:
internode_encryption: none
ssl_context_factory:
class_name: `org.apache.cassandra.security.KubernetesSecretsSslContextFactory
parameters:
KEYSTORE_PASSWORD_ENV_VAR: KEYSTORE_PASSWORD
KEYSTORE_UPDATED_TIMESTAMP_PATH: /etc/my-ssl-store/keystore-last-updatedtime
TRUSTSTORE_PASSWORD_ENV_VAR: TRUSTSTORE_PASSWORD
TRUSTSTORE_UPDATED_TIMESTAMP_PATH: /etc/my-ssl-store/truststore-last-updatedtime
keystore: /etc/my-ssl-store/keystore
truststore: /etc/my-ssl-store/truststore
可以了!恭喜你,Apache Cassandra服务器现在已经与Kubernetes Secrets集成了TLS配置。上面的例子是建立在可扩展的类层次上的,如下所示。你可以在三个不同的层次上进行扩展,并使用组合来实现你需要的混合解决方案。


未来工作
在有能力定制TLS配置的基础上,社区正在努力支持其他流行的安全证书格式,如PEM(最初是 “Privacy Enhanced Mail”)。
在Apache Cassandra社区中,我们的目标是提供最好的软件,并随着用例和需求的增长和演变而不断加强它。我希望这个特殊的增强功能使Cassandra的运维生活更轻松,同时支持数据安全的行业标准。
更新:原始博客已经更新,以正确反映Apache Cassandra 4.1版本的SSL Context定制功能的。Apache Cassandra 4.1的变更是在2022年5月冻结,在2022年7月发布。
原文标题:Tightening security for Apache Cassandra: Part 3
原文作者:Maulin Vasavada
原文地址:https://cassandra.apache.org/_/blog/Tightening-Security-for-Apache-Cassandra-Part-3.html




