Elasticsearch: TLS and three roles for an owned index
Configure Elasticsearch 9 with verified TLS and separate reader, writer and lifecycle roles, then check documents, aliases, denials and reboot persistence.
A search client does not need the same permissions as the process that creates an index and switches an alias. On a disposable Debian 13 VM, we separated these duties for Elasticsearch 9.5.5, exercised them with real HTTPS requests, then performed an ordinary reboot together with the rest of the test environment.
The package came from the official signed 9.x repository. We selected the major version from the local Article dependencies: PHP client 9.5 and Elastica 9. This is the basis of a new training environment, not a copy of working-server settings. Connecting the application itself to these roles remains a separate step.
Owned configuration before the first start
The /etc/solution200-elasticsearch configuration directory was prepared before the package postinst ran. ES_PATH_CONF in the environment alone is insufficient if the package /etc/default/elasticsearch sets the default path again. We explicitly aligned both values and disabled automatic security configuration. This lets us manage our own TLS, users and directories while keeping security enabled. Configuration locations are explained in the Elasticsearch documentation.
HTTP on port 9200 and transport on port 9300 are loopback-only and use TLS. The client trusts a specific CA and verifies the node identity. During preparation, the CA certificate key usage needed correction to critical keyCertSign,cRLSign. The CA private key, node key and certificate, credentials and index data were retained; certificate verification was never disabled. Passwords were not passed in process arguments.
Reader, writer and lifecycle
| Role | Index privileges | Purpose |
|---|---|---|
| reader | read, view_index_metadata | Search and index metadata |
| writer | read, write, view_index_metadata | Document operations in an existing index |
| lifecycle | manage, read, write | Index creation, mapping, aliases and deletion of owned indices |
All three roles are restricted to article_demo_* and have an empty cluster permission list. Here is the lifecycle role body, without users or password data:
{
"cluster": [],
"indices": [{
"names": ["article_demo_*"],
"privileges": ["manage", "read", "write"],
"allow_restricted_indices": false
}],
"applications": [],
"run_as": []
}
Here, manage is an index privilege. It covers much more than aliases, including mapping and index deletion, so it belongs to a separate lifecycle identity. There is no named manage_aliases privilege; a policy cannot rely on an invented name. The writer can change documents but cannot delete an index. The full permission list and boundaries are in the privileges reference.
Mapping first, then a document and alias
Lifecycle created an index with one shard, no replicas and a strict mapping. The small test environment uses a keyword title field: this exercises permissions and persistence rather than supplying a complete editorial search schema.
PUT /article_demo_documents
{
"settings": {"number_of_shards": 1, "number_of_replicas": 0},
"mappings": {
"dynamic": "strict",
"properties": {"title": {"type": "keyword"}}
}
}
The writer stored a document whose title is survives-normal-reboot. Lifecycle added an alias, after which the reader found exactly one expected document through it:
POST /_aliases
{
"actions": [{"add": {
"index": "article_demo_documents",
"alias": "article_demo_current"
}}]
}
These are authenticated request excerpts; transport setup and credentials are omitted. Lifecycle also successfully deleted a separate disposable index. This exercised each role's positive capabilities, including an operation deliberately denied to the writer.
Reader attempts to write a document, and writer attempts to create or delete an index or change a role, returned 403. Lifecycle received 403 for deleting a foreign index, aliasing it, and security administration. All three roles were denied foreign-index reads and cluster health access. A wrong password returned 401. The foreign_control document remained unchanged.
Memory and an executable temporary directory
For the idle environment with approximately 2 GiB of memory, heap was set to 256 MiB and cgroup MemoryMax to 896 MiB. These are measured training settings without application load, not a sizing recommendation for a working search service. Heap is only part of JVM and native memory use.
Native libraries need a temporary directory on a filesystem that permits execution. We explicitly set ES_TMPDIR=/var/lib/solution200-elasticsearch/tmp, checked mount options and created an owned Elasticsearch directory with mode 0700. No global mount settings were changed. The executable temporary-directory requirement belongs in preparation before starting the service.
Process readiness and shard recovery are separate events
The Type=notify service reported readiness, but the first search check after the ordinary reboot did not yet meet the expected condition. We waited for actual index recovery and continued reading without recreating users, indices or the document. Search through the alias returned the expected record, authentication confirmed persisted native users and roles, and cluster health became green with no initializing shards or unassigned primary shards.
GET /_cluster/health in this check used the separate operational user setup_ops with the superuser role. It did not use reader, writer or lifecycle: their cluster lists remained empty and the same request returned 403. The Cluster health API requires the monitor or manage cluster privilege; see Cluster health API.
We then checked the writer's index-deletion denial, foreign-index boundaries, wrong-password refusal and unchanged control document again. TLS verification remained enabled. JDK displayed the loopback listeners as IPv4-mapped IPv6; the check normalized the address while retaining the exact loopback requirement rather than accepting a wildcard. Services were observed after the new boot without starting them again. This is the manual fixture’s result after reboot. The CLI run follows below; full Article integration remains a later stage.
A separate CLI run: configuration, startup and tenant
We then repeated this stage through the CLI on a clean verification VM alongside Nginx, PHP, MySQL and Redis. Elasticsearch retains three separate transactions: configuration, activation and site. Server passwords and keys are created only inside the VM in protected files; plaintext passwords are absent from plans and journals.
The .deb package from Elastic’s official APT repository with signed metadata contains vendor configs with mode 0660, and log4j2.properties exceeds 16 KiB. The CLI explicitly checks those exact signed members, retains bounded original proof and creates its own runtime copies with mode 0640. It also checks the actual native launcher and JVM process: systemd readiness alone does not establish the required identity, cgroup, loopback listeners and HTTPS with CA and hostname verification.
Site-plan creates the new article_demo namespace. Reader, writer and indexer have empty cluster privileges; indexer covers the lifecycle duties described in the manual stage. setup_ops reads green health. Positive and negative tenant controls run once during apply; the subsequent site-verify reads retained outcomes and current policies/documents without repeating creation or deletion.
This is the complete separate verification command. PRIVATE_DIR is an absolute directory for private operator artifacts; key and plan SHA256 values come from previously checked files. There is no approve-privileges flag here: this is a read. Services in this CLI run started in the current boot; its result is not new reboot evidence.
The CLI profile uses its own article_cli-* pattern with a hyphen before the wildcard. Its writer receives write and view_index_metadata; reader reads documents. This explicitly describes this run’s profile, including its differences from the manual article_demo_* setup. The original unfinished check of another namespace is retained; the new site-plan neither adopts nor overwrites its state.
elasticsearch9-profile.json defines the service profile:
{
"schema_version": 1,
"role": "elasticsearch9",
"memory_max_mib": 896,
"heap_mib": 256
}
site-article-cli.json defines the new namespace:
{
"schema_version": 1,
"namespace": "article_cli"
}
deploy-cli host data elasticsearch9 site-verify \
--env-file "$PRIVATE_DIR/administrator.env" \
--request-file "$PRIVATE_DIR/request.json" \
--data-file "$PRIVATE_DIR/elasticsearch9-profile.json" \
--key-file "$PRIVATE_DIR/elasticsearch9.gpg" \
--key-sha256 "$ELASTIC_KEY_SHA256" \
--dependencies-file "$PRIVATE_DIR/elasticsearch9-site-deps.json" \
--site-file "$PRIVATE_DIR/site-article-cli.json" \
--plan-file "$PRIVATE_DIR/elasticsearch9-site-article-cli-plan.json" \
--plan-sha256 "$ES_SITE_PLAN_SHA256"
This is a reduced summary of actual activation/site journals, rather than raw JSON from an individual HTTPS response.
{
"activation": "committed",
"site": "committed",
"version": "9.5.5",
"tls": {
"trusted_ca": true,
"hostname_verified": true
},
"health": {
"status": "green",
"checked_as": "setup_ops"
},
"namespace": "article_cli",
"cluster_health_denied_for": [
"reader",
"writer",
"indexer"
],
"foreign_reads_denied_for": [
"reader",
"writer",
"indexer"
]
}
A separate CLI step for starting and enabling the existing service
After rebooting the combined CLI fixture, this service was stopped and disabled. We did not replay its original activation: for MySQL that sequence also initializes the data directory and secures root. The new startup transaction uses existing data and checks the original completed journals, all nine package-history nodes, unchanged configuration and independently confirmed current boot.
Before starting, the CLI compares exact configuration and private-file images, including Elasticsearch TLS material. A new drop-in adds Requires and After dependencies on the owned firewall. The CLI starts the service once, verifies its actual process, signed binary, loopback listeners and authenticated native protocol, then creates the exact enable link after readiness succeeds.
The commands below use generalized private paths. PRIVATE_DIR is an absolute private directory; install-request retains the installation boot, while current-console-request independently confirms the current boot. The public PHP key admits the original combined history; data-service keys are retained in history-references. The plan SHA is checked before apply.
STARTUP_ARGS=(
--env-file "$PRIVATE_DIR/administrator.env"
--request-file "$PRIVATE_DIR/install-request.json"
--fpm-file "$PRIVATE_DIR/php-profile.json"
--key-file "$PRIVATE_DIR/php-archive-keyring.gpg"
--key-sha256 "$PHP_PUBLIC_KEY_SHA256"
--references-file "$PRIVATE_DIR/history-references.json"
--current-request-file "$PRIVATE_DIR/current-console-request.json"
--data-activations-file "$PRIVATE_DIR/data-activations.json"
--firewall-pin-file "$PRIVATE_DIR/firewall-pin.json"
)
The sysctl.d documentation describes file ordering and same-name precedence.
Why the Elasticsearch kernel setting changed after reboot
On this fixture, vm.max_map_count returned to 262144 after reboot. The original 80-deploy-cli-elasticsearch9.conf still contained 1048576, but systemd-analyze cat-config sysctl.d showed a later /usr/lib/sysctl.d/elasticsearch.conf setting 262144. The first startup plan refused without writes. File ordering caused the change; the original configuration had not disappeared.
A separate kernel transaction created a new /etc/sysctl.d/elasticsearch.conf containing vm.max_map_count=1048576. The same filename under /etc takes precedence over the package file under /usr/lib. One explicit sysctl -w was followed by independent reads of the effective configuration and kernel value. The package file and original 80-* file were preserved. Only then did a new startup plan admit the state; the previous refusal remains separate evidence.
deploy-cli host runtime-startup elasticsearch9 kernel-plan \
"${STARTUP_ARGS[@]}" --plan-file "$PRIVATE_DIR/es-kernel-plan.json"
deploy-cli host runtime-startup elasticsearch9 kernel-apply \
"${STARTUP_ARGS[@]}" --plan-file "$PRIVATE_DIR/es-kernel-plan.json" \
--plan-sha256 "$APPROVED_KERNEL_PLAN_SHA256" --approve-privileges
After the kernel transaction succeeded, we planned and started the service:
deploy-cli host runtime-startup elasticsearch9 plan \
"${STARTUP_ARGS[@]}" --plan-file "$PRIVATE_DIR/elasticsearch9-startup-plan.json"
deploy-cli host runtime-startup elasticsearch9 apply \
"${STARTUP_ARGS[@]}" --plan-file "$PRIVATE_DIR/elasticsearch9-startup-plan.json" \
--plan-sha256 "$APPROVED_STARTUP_PLAN_SHA256" --approve-privileges
This is a reduced summary of the actual journal and independent verification over a new SSH connection, rather than the literal output of one command:
{
"unit": "deploy-cli-elasticsearch9.service",
"state": "active/running",
"startup": "enabled",
"journal_steps": 8,
"protocol": {
"cluster_nodes": 1,
"health": "green",
"health_identity": "setup_ops",
"hostname_verified": true,
"trusted_ca": true,
"version": "9.5.5",
"wrong_password_status": 401
}
}
An action recorded as pending is never dispatched again on a subsequent invocation. A completed journal is verified through reads only. Original configuration, credentials, package state and previous journals remained unchanged after this step. This was the separate start/enable stage; acceptance of the combined reboot follows below.
Access controls and data after the combined reboot
After separate start/enable, we performed an ordinary reboot of the local educational VM together with PHP-FPM, Nginx and timers. An independent serial console confirmed the new boot. The CLI checked the original journal and configuration, then rebuilt current processes, listeners and protocol replies. The original STARTUP_ARGS are retained; the new console request is passed separately.
deploy-cli host runtime-startup elasticsearch9 boot-verify "${STARTUP_ARGS[@]}" \
--plan-file "$PRIVATE_DIR/elasticsearch9-startup-plan.json" \
--plan-sha256 "$APPROVED_STARTUP_PLAN_SHA256" \
--manifest-sha256 "$COMMITTED_STARTUP_MANIFEST_SHA256" \
--new-boot-request-file "$PRIVATE_DIR/new-boot-console-request.json" \
--output-file "$PRIVATE_DIR/elasticsearch9-new-boot-proof.json" \
--kernel-plan-file "$PRIVATE_DIR/es-kernel-plan.json" \
--kernel-plan-sha256 "$ES_KERNEL_PLAN_SHA256" \
--kernel-manifest-sha256 "$ES_KERNEL_MANIFEST_SHA256"
Elasticsearch returned automatically as active/running and enabled. TLS, hostname and CA were verified; setup_ops obtained green cluster health. Three application roles retained 403 denials for cluster health and an unrelated index, while control documents remained available to their owners. After reboot, vm.max_map_count was 1048576; the separate /etc/sysctl.d/elasticsearch.conf overriding the same-name vendor file was preserved. Data, certificates, roles and credentials were not initialized again.
The frame below belongs to the earlier start/enable stage before the combined reboot. The new post-reboot result is described above; the two stages remain distinct.