Certificate Types and Generation
This section covers the types of certificates used in Cassandra deployments and provides procedures for generating them.
Certificate Types
Section titled “Certificate Types”Server Certificates
Section titled “Server Certificates”Server certificates identify Cassandra nodes to clients and other nodes. Each node requires its own certificate with a unique identity.
Requirements:
- Subject or SAN must match the node’s hostname or IP address
- Extended Key Usage:
serverAuth - Key Usage:
digitalSignature,keyEncipherment
Client Certificates
Section titled “Client Certificates”Client certificates identify applications connecting to Cassandra. Required when mutual TLS (mTLS) is enabled.
Requirements:
- Subject identifies the client application or user
- Extended Key Usage:
clientAuth - Key Usage:
digitalSignature
CA Certificates
Section titled “CA Certificates”Certificate Authority certificates sign server and client certificates. CA certificates are placed in truststores.
Types:
- Root CA: Self-signed, trust anchor
- Intermediate CA: Signed by Root, signs end-entity certificates
Certificate Generation
Section titled “Certificate Generation”Option 1: Self-Signed Certificates (Development)
Section titled “Option 1: Self-Signed Certificates (Development)”Self-signed certificates are appropriate for development and testing only.
#!/bin/bashNODE_NAME="cassandra-node-1"VALIDITY_DAYS=365KEY_SIZE=2048
# Generate private key and self-signed certificateopenssl req -x509 -newkey rsa:${KEY_SIZE} \ -keyout ${NODE_NAME}-key.pem \ -out ${NODE_NAME}-cert.pem \ -days ${VALIDITY_DAYS} \ -nodes \ -subj "/CN=${NODE_NAME}"
# Create PKCS12 keystoreopenssl pkcs12 -export \ -in ${NODE_NAME}-cert.pem \ -inkey ${NODE_NAME}-key.pem \ -out ${NODE_NAME}-keystore.p12 \ -name ${NODE_NAME} \ -password pass:cassandra
# Create truststore with the certificatekeytool -import \ -file ${NODE_NAME}-cert.pem \ -keystore truststore.jks \ -storepass cassandra \ -noprompt \ -alias ${NODE_NAME}Option 2: Private CA (Production)
Section titled “Option 2: Private CA (Production)”A private CA provides centralized certificate management for production deployments.
Step 1: Create Root CA
Section titled “Step 1: Create Root CA”#!/bin/bashCA_DIR="./ca"mkdir -p ${CA_DIR}/{certs,crl,newcerts,private}touch ${CA_DIR}/index.txtecho 1000 > ${CA_DIR}/serial
# Generate Root CA private keyopenssl genrsa -aes256 -out ${CA_DIR}/private/ca-key.pem 4096chmod 400 ${CA_DIR}/private/ca-key.pem
# Generate Root CA certificateopenssl req -config openssl-ca.cnf \ -key ${CA_DIR}/private/ca-key.pem \ -new -x509 -days 3650 -sha256 \ -extensions v3_ca \ -out ${CA_DIR}/certs/ca-cert.pem \ -subj "/C=US/ST=California/O=Example Corp/CN=Example Root CA"
chmod 444 ${CA_DIR}/certs/ca-cert.pemStep 2: Create Intermediate CA (Optional but Recommended)
Section titled “Step 2: Create Intermediate CA (Optional but Recommended)”#!/bin/bashINT_DIR="./ca/intermediate"mkdir -p ${INT_DIR}/{certs,crl,csr,newcerts,private}touch ${INT_DIR}/index.txtecho 1000 > ${INT_DIR}/serial
# Generate Intermediate CA private keyopenssl genrsa -aes256 -out ${INT_DIR}/private/intermediate-key.pem 4096chmod 400 ${INT_DIR}/private/intermediate-key.pem
# Generate CSR for Intermediate CAopenssl req -config openssl-intermediate.cnf \ -new -sha256 \ -key ${INT_DIR}/private/intermediate-key.pem \ -out ${INT_DIR}/csr/intermediate.csr \ -subj "/C=US/ST=California/O=Example Corp/CN=Example Intermediate CA"
# Sign with Root CAopenssl ca -config openssl-ca.cnf \ -extensions v3_intermediate_ca \ -days 1825 -notext -md sha256 \ -in ${INT_DIR}/csr/intermediate.csr \ -out ${INT_DIR}/certs/intermediate-cert.pem
# Create certificate chaincat ${INT_DIR}/certs/intermediate-cert.pem \ ./ca/certs/ca-cert.pem > ${INT_DIR}/certs/ca-chain.pemStep 3: Generate Node Certificates
Section titled “Step 3: Generate Node Certificates”#!/bin/bashNODE_NAME=$1if [ -z "$NODE_NAME" ]; then echo "Usage: $0 <node-name>" exit 1fi
INT_DIR="./ca/intermediate"CERT_DIR="./certs/${NODE_NAME}"mkdir -p ${CERT_DIR}
# Generate node private keyopenssl genrsa -out ${CERT_DIR}/${NODE_NAME}-key.pem 2048chmod 400 ${CERT_DIR}/${NODE_NAME}-key.pem
# Create SAN configurationcat > ${CERT_DIR}/san.cnf << EOF[req]distinguished_name = req_distinguished_namereq_extensions = v3_req
[req_distinguished_name]CN = ${NODE_NAME}
[v3_req]basicConstraints = CA:FALSEkeyUsage = digitalSignature, keyEnciphermentextendedKeyUsage = serverAuth, clientAuthsubjectAltName = @alt_names
[alt_names]DNS.1 = ${NODE_NAME}DNS.2 = ${NODE_NAME}.example.comDNS.3 = localhostIP.1 = 127.0.0.1EOF
# Generate CSR with SANopenssl req -new \ -key ${CERT_DIR}/${NODE_NAME}-key.pem \ -out ${CERT_DIR}/${NODE_NAME}.csr \ -config ${CERT_DIR}/san.cnf \ -subj "/C=US/ST=California/O=Example Corp/CN=${NODE_NAME}"
# Sign with Intermediate CAopenssl x509 -req \ -in ${CERT_DIR}/${NODE_NAME}.csr \ -CA ${INT_DIR}/certs/intermediate-cert.pem \ -CAkey ${INT_DIR}/private/intermediate-key.pem \ -CAcreateserial \ -out ${CERT_DIR}/${NODE_NAME}-cert.pem \ -days 365 \ -sha256 \ -extensions v3_req \ -extfile ${CERT_DIR}/san.cnf
# Create certificate chain for nodecat ${CERT_DIR}/${NODE_NAME}-cert.pem \ ${INT_DIR}/certs/intermediate-cert.pem > ${CERT_DIR}/${NODE_NAME}-chain.pemStep 4: Create Keystores and Truststores
Section titled “Step 4: Create Keystores and Truststores”#!/bin/bashNODE_NAME=$1CERT_DIR="./certs/${NODE_NAME}"STORE_PASS="cassandra"
# Create PKCS12 keystore with certificate chainopenssl pkcs12 -export \ -in ${CERT_DIR}/${NODE_NAME}-chain.pem \ -inkey ${CERT_DIR}/${NODE_NAME}-key.pem \ -out ${CERT_DIR}/${NODE_NAME}-keystore.p12 \ -name ${NODE_NAME} \ -password pass:${STORE_PASS}
# Convert to JKS if neededkeytool -importkeystore \ -srckeystore ${CERT_DIR}/${NODE_NAME}-keystore.p12 \ -srcstoretype PKCS12 \ -srcstorepass ${STORE_PASS} \ -destkeystore ${CERT_DIR}/${NODE_NAME}-keystore.jks \ -deststoretype JKS \ -deststorepass ${STORE_PASS}
# Create truststore with CA chainkeytool -import \ -file ./ca/intermediate/certs/ca-chain.pem \ -keystore ${CERT_DIR}/truststore.jks \ -storepass ${STORE_PASS} \ -noprompt \ -alias ca-chainOpenSSL Configuration Files
Section titled “OpenSSL Configuration Files”Root CA Configuration (openssl-ca.cnf)
Section titled “Root CA Configuration (openssl-ca.cnf)”[ ca ]default_ca = CA_default
[ CA_default ]dir = ./cacerts = $dir/certscrl_dir = $dir/crlnew_certs_dir = $dir/newcertsdatabase = $dir/index.txtserial = $dir/serialprivate_key = $dir/private/ca-key.pemcertificate = $dir/certs/ca-cert.pemcrl = $dir/crl/ca.crl.pemcrlnumber = $dir/crlnumberdefault_md = sha256default_days = 375preserve = nopolicy = policy_loose
[ policy_loose ]countryName = optionalstateOrProvinceName = optionallocalityName = optionalorganizationName = optionalorganizationalUnitName = optionalcommonName = suppliedemailAddress = optional
[ req ]default_bits = 4096distinguished_name = req_distinguished_namestring_mask = utf8onlydefault_md = sha256
[ req_distinguished_name ]countryName = Country NamestateOrProvinceName = StatelocalityName = LocalityorganizationName = OrganizationcommonName = Common Name
[ v3_ca ]subjectKeyIdentifier = hashauthorityKeyIdentifier = keyid:always,issuerbasicConstraints = critical, CA:truekeyUsage = critical, digitalSignature, cRLSign, keyCertSign
[ v3_intermediate_ca ]subjectKeyIdentifier = hashauthorityKeyIdentifier = keyid:always,issuerbasicConstraints = critical, CA:true, pathlen:0keyUsage = critical, digitalSignature, cRLSign, keyCertSignCertificate Verification
Section titled “Certificate Verification”Verify Certificate Chain
Section titled “Verify Certificate Chain”# Verify server certificate against CA chainopenssl verify -CAfile ca-chain.pem server-cert.pem
# Verify with verbose outputopenssl verify -CAfile ca-chain.pem -verbose server-cert.pemVerify Certificate Details
Section titled “Verify Certificate Details”# View certificate contentsopenssl x509 -in server-cert.pem -noout -text
# Check expirationopenssl x509 -in server-cert.pem -noout -dates
# Check subject and issueropenssl x509 -in server-cert.pem -noout -subject -issuer
# Check SANsopenssl x509 -in server-cert.pem -noout -ext subjectAltNameVerify Keystore
Section titled “Verify Keystore”# List keystore contentskeytool -list -v -keystore keystore.jks -storepass cassandra
# Verify private key matches certificateopenssl x509 -noout -modulus -in cert.pem | openssl md5openssl rsa -noout -modulus -in key.pem | openssl md5# Both should output the same hashPEM File Support (Cassandra 4.0+)
Section titled “PEM File Support (Cassandra 4.0+)”Cassandra 4.0 introduced native PEM file support, eliminating the need for JKS or PKCS12 conversion.
Configuration with PEM Files
Section titled “Configuration with PEM Files”server_encryption_options: internode_encryption: all keystore: /etc/cassandra/certs/node-key.pem keystore_password: "" truststore: /etc/cassandra/certs/ca-chain.pem truststore_password: ""Combined PEM File
Section titled “Combined PEM File”Create a single PEM file containing both key and certificate:
cat node-key.pem node-cert.pem > node-combined.pemRelated Documentation
Section titled “Related Documentation”- Encryption Overview - Why encryption is essential
- PKI Fundamentals - Certificate concepts
- Hostname Verification - SAN configuration
- Cassandra Configuration - Using certificates in Cassandra