Authentication is off by default, and a Cassandra cluster with its native port reachable and no authentication is fully readable and writable by anyone who can connect. Enabling it is two configuration changes and one trap.
The changes: authenticator: PasswordAuthenticator and authorizer: CassandraAuthorizer. The trap: the system_auth keyspace defaults to RF=1, which means if the one node holding a user's credentials is down, that user cannot log in anywhere - including during the incident when you most need to. Set system_auth to RF=3 (or the number of nodes, up to a sensible limit) and repair it. This is the single most common Cassandra security misconfiguration and it turns a one-node outage into a total authentication outage.
Also: the default cassandra/cassandra superuser must be replaced, and the default superuser's queries run at QUORUM, which is another reason the system_auth replication matters.
Roles and permissions are role-based, with inheritance. Permissions are granted per keyspace, per table or on ALL KEYSPACES: SELECT, MODIFY, CREATE, ALTER, DROP, AUTHORIZE, DESCRIBE, EXECUTE. The practical shape: a role per application function, granted only on the tables that function touches, and AUTHORIZE withheld from everything except an administrative role - because AUTHORIZE lets a role grant permissions, including to itself.
TLS has two separate configurations. client_encryption_options for client-to-node, and server_encryption_options for node-to-node - and the second matters as much as the first, because unencrypted inter-node traffic carries all your data between hosts and, in a multi-datacentre deployment, between sites. require_client_auth adds certificate-based client authentication.
JMX is a security surface people forget. nodetool works over JMX, and JMX with no authentication and bound to a reachable interface is remote administrative access to the node, including flushall-equivalents and the ability to change settings. Bind it to localhost, or enable JMX authentication.
Monitoring. Cassandra exposes a large number of metrics; the ones that matter: read and write latency at p99 per table, pending compactions (a steadily growing number means compaction cannot keep up, which ends badly), dropped messages per type (MUTATION dropped means writes lost), hints created and not delivered, tombstones per read, SSTables per read, pending tasks in the thread pools (tpstats), repair recency per node (because the gc_grace_seconds contract depends on it), disk usage against the compaction headroom requirement, and clock offset, which is a correctness metric here.
Capacity planning has a Cassandra-specific shape: disk needs headroom for compaction (up to 50% with STCS), memory needs heap plus off-heap plus page cache (and a heap above about 16 GB usually hurts because of garbage collection pauses), and the node count follows from the replication factor and the per-node data ceiling - roughly 1 to 2 TB per node, because repair, compaction and replacement times all scale with it.
Rolling upgrades work and have a specific rule: do not run repair during an upgrade, and upgrade all nodes before running nodetool upgradesstables. Mixed-version clusters are supported for the duration of the upgrade and not as a steady state, and streaming between major versions is often not supported - which means a node replacement during an upgrade can fail.
Laboratory exercise 6 - make it defensible.
Enable authentication and authorisation, and fix the system_auth replication factor. Then demonstrate the trap: set it to RF=1, stop the node holding a user's credentials, and show the login failing cluster-wide. Then fix it and show the login working with a node down.
Implement least privilege: an application role with SELECT and MODIFY only on the tables it uses; a read-only reporting role; and an operations role with DESCRIBE and no data access. Test every denial.
Configure client-to-node and node-to-node TLS, and verify with a packet capture that inter-node traffic is encrypted.
Secure JMX and demonstrate that nodetool from another host is refused.
Configure monitoring with every metric above and a threshold for each, including clock offset and repair recency.
Produce a capacity plan from measurement: your data size per row, the replication factor, the compaction headroom, the per-node ceiling and the resulting node count.
Perform a rolling upgrade of one node to a newer patch version under load, and document the procedure including the ordering rules.
Deliverable: the security configuration, the system_auth trap demonstrated and fixed, the role definitions, a test script attempting every forbidden operation with its output, the TLS verification, the JMX denial, the alert definitions with thresholds, the measured capacity plan, and the upgrade procedure.
-- ==================================================================
-- AUTHENTICATION: off by default. And one trap.
-- ==================================================================
-- cassandra.yaml:
-- authenticator: PasswordAuthenticator
-- authorizer: CassandraAuthorizer
-- role_manager: CassandraRoleManager
-- roles_validity_in_ms: 2000 # cache; 0 disables
-- permissions_validity_in_ms: 2000
--
-- then: cqlsh -u cassandra -p cassandra
-- *** THE TRAP, AND IT IS THE COMMONEST CASSANDRA SECURITY
-- *** MISCONFIGURATION ***
SELECT keyspace_name, replication FROM system_schema.keyspaces
WHERE keyspace_name = 'system_auth';
-- {'class': 'SimpleStrategy', 'replication_factor': '1'}
--
-- RF=1 MEANS: if the ONE node holding a user's credentials is
-- down, THAT USER CANNOT LOG IN ANYWHERE - including during the
-- incident when you most need to. A one-node outage becomes a
-- TOTAL AUTHENTICATION OUTAGE.
--
-- FIX IT, on every cluster, before anything else:
ALTER KEYSPACE system_auth WITH replication = {
'class': 'NetworkTopologyStrategy', 'dc1': 3 };
-- then: nodetool repair system_auth
--
-- Demonstrate it both ways in the lab. It is a thirty-second
-- demonstration that changes how you inherit a cluster.
-- Replace the default superuser. It is a documented credential:
CREATE ROLE admin WITH PASSWORD = 'Str0ng#Admin'
AND LOGIN = true AND SUPERUSER = true;
-- log in as admin, then:
ALTER ROLE cassandra WITH PASSWORD = '<long random>' AND LOGIN = false;
-- ==================================================================
-- ROLES AND PERMISSIONS: a role per application function.
-- ==================================================================
CREATE ROLE feed_writer WITH LOGIN = false;
GRANT SELECT, MODIFY ON TABLE feed.events_by_user_day TO feed_writer;
GRANT SELECT, MODIFY ON TABLE feed.events_by_id TO feed_writer;
GRANT SELECT, MODIFY ON TABLE feed.events_by_kind_day TO feed_writer;
GRANT SELECT, MODIFY ON TABLE feed.event_counts_by_day TO feed_writer;
-- MODIFY covers INSERT, UPDATE and DELETE. There is no separate
-- DELETE permission, which is worth knowing before you assume you
-- have granted write-without-delete. You have not.
CREATE ROLE feed_reader WITH LOGIN = false;
GRANT SELECT ON KEYSPACE feed TO feed_reader;
-- An OPERATIONS role: schema visibility, NO DATA.
CREATE ROLE feed_ops WITH LOGIN = false;
GRANT DESCRIBE ON ALL KEYSPACES TO feed_ops;
CREATE ROLE app_user WITH PASSWORD = 'Str0ng#App' AND LOGIN = true;
GRANT feed_writer TO app_user;
-- *** NEVER GRANT AUTHORIZE *** except to an administrative role.
-- AUTHORIZE lets a role grant permissions - INCLUDING TO ITSELF,
-- which makes it equivalent to superuser by two steps.
-- GRANT ALL PERMISSIONS ON ALL KEYSPACES TO ... -- never
LIST ROLES;
LIST ALL PERMISSIONS OF app_user;
LIST ALL PERMISSIONS ON KEYSPACE feed;
-- VERIFY THE DENIALS. The assessed part - every one must fail:
-- cqlsh -u app_user -p ...
-- DROP TABLE feed.events_by_id; -> Unauthorized
-- CREATE TABLE feed.x (a int PRIMARY KEY); -> Unauthorized
-- SELECT * FROM system_auth.roles; -> Unauthorized
-- GRANT SELECT ON KEYSPACE feed TO app_user; -> Unauthorized
-- ALTER KEYSPACE feed WITH replication = ...; -> Unauthorized
-- ==================================================================
-- TLS: TWO separate configurations, and the second matters as much.
-- ==================================================================
-- cassandra.yaml:
--
-- client_encryption_options: # client <-> node
-- enabled: true
-- optional: false # false = enforce
-- keystore: /etc/cassandra/conf/server.keystore
-- keystore_password: ...
-- require_client_auth: true # certificate-based auth
-- truststore: /etc/cassandra/conf/server.truststore
--
-- server_encryption_options: # NODE <-> NODE
-- internode_encryption: all # none | dc | rack | all
-- keystore: ...
-- require_client_auth: true
--
-- *** INTER-NODE ENCRYPTION MATTERS AS MUCH AS CLIENT. ***
-- Unencrypted internode traffic carries ALL YOUR DATA between
-- hosts, and in a multi-DC deployment BETWEEN SITES. `internode_
-- encryption: dc` encrypts only cross-DC traffic, which is the
-- usual compromise.
--
-- cqlsh --ssl
-- Verify with a packet capture, not by reading the config.
-- ==================================================================
-- JMX: the security surface people forget.
-- ==================================================================
-- nodetool works over JMX. JMX with NO AUTHENTICATION bound to a
-- reachable interface IS REMOTE ADMINISTRATIVE ACCESS to the node -
-- including the ability to flush, truncate, change settings and
-- trigger compactions.
--
-- cassandra-env.sh:
-- LOCAL_JMX=yes # bind to localhost. Best.
-- or, for remote nodetool:
-- -Dcom.sun.management.jmxremote.authenticate=true
-- -Dcom.sun.management.jmxremote.password.file=/etc/cassandra/jmxremote.password
-- -Dcom.sun.management.jmxremote.ssl=true
--
-- Then prove it: nodetool -h <node> status FROM ANOTHER HOST must
-- be refused.
-- ==================================================================
-- MONITORING: what to alert on.
-- ==================================================================
-- nodetool tpstats # thread pools: PENDING and DROPPED
-- nodetool tablestats feed
-- nodetool compactionstats # PENDING TASKS
-- nodetool netstats
-- nodetool proxyhistograms # coordinator-level latency
-- nodetool gcstats
-- (and the JMX/Prometheus exporter for all of it)
--
-- read/write p99 per table the headline
-- PENDING COMPACTIONS STEADILY GROWING = compaction
-- cannot keep up. This ends badly:
-- SSTables accumulate, reads slow,
-- disk fills. One of the most
-- important Cassandra metrics.
-- DROPPED MUTATION messages > 0 = WRITES LOST (the coordinator
-- gave up). Not a latency problem -
-- a DATA problem.
-- hints created / not delivered rising = a replica is away
-- TOMBSTONES PER READ rising = Module 4 is happening
-- SSTables per read p99 > ~10 = review compaction
-- tpstats pending backpressure
-- REPAIR RECENCY PER NODE the gc_grace_seconds CONTRACT
-- depends on it. If you track one
-- operational fact, track this.
-- disk used vs compaction STCS may need 50% free
-- headroom
-- CLOCK OFFSET A CORRECTNESS METRIC HERE, not an
-- operational one (Module 3).
-- GC pause duration > 500 ms = heap or allocation
-- pressure; often an unbounded
-- partition
-- ==================================================================
-- CAPACITY PLANNING: the Cassandra-specific shape.
-- ==================================================================
-- DISK data x RF, PLUS compaction headroom (up to 50% STCS,
-- ~10% LCS), plus snapshots
-- MEMORY heap + off-heap (bloom filters, index summaries,
-- compression metadata) + PAGE CACHE for the hot data.
-- A HEAP ABOVE ~16 GB USUALLY HURTS - garbage collection
-- pauses grow and a long pause looks like a node failure
-- to the rest of the cluster. 8-16 GB with G1 is the
-- usual range.
-- NODES from RF and the PER-NODE DATA CEILING: roughly
-- 1-2 TB per node, because REPAIR TIME, COMPACTION TIME
-- AND REPLACEMENT TIME ALL SCALE WITH IT. A 10 TB node
-- is cheap to buy and takes days to replace.
--
-- measured example:
-- 1,000 bytes/row x 10,000,000,000 rows = 10 TB logical
-- x RF 3 = 30 TB replicated
-- + 50% STCS headroom = 45 TB
-- / 1.5 TB per node = 30 nodes
-- nodetool tablestats | grep -i "space used"
-- ==================================================================
-- ROLLING UPGRADES: supported, with specific rules.
-- ==================================================================
-- 1. snapshot everything
-- 2. *** DO NOT RUN REPAIR DURING THE UPGRADE ***
-- 3. nodetool drain, then stop, then upgrade, then start - ONE
-- NODE AT A TIME, waiting for UN before the next
-- 4. *** UPGRADE EVERY NODE BEFORE RUNNING upgradesstables ***
-- 5. then: nodetool upgradesstables (on each node, in turn)
-- 6. resume the repair schedule
--
-- Mixed-version clusters are supported FOR THE DURATION of the
-- upgrade, not as a steady state. And STREAMING BETWEEN MAJOR
-- VERSIONS IS OFTEN NOT SUPPORTED - so a node replacement during
-- an upgrade can fail, which is why step 3 goes quickly and
-- deliberately.
SELECT release_version FROM system.local;
-- nodetool describecluster # watch for schema disagreement
Discussion
No questions on this topic yet. Sign in to ask the first one.