AI Hints
Home›Elasticsearch Tutorial›Data Streams, Snapshots and Security
Elasticsearch · Lesson 111 of 120

Security Basics

Users, roles and keys.

⏱ 2 min read▶ Video at 1:44:48🎓 Free
Watch this lesson in the Elasticsearch courseWatch on YouTube ↗Full Elasticsearch course

Our practice cluster has security turned off, to keep things simple. A real cluster must never run like that. Security is on by default since version eight, with passwords and encryption.

  • Practice: off
  • Real: always on
  • On by default

Roles, users and API keys

A role grants read access to the products index only. A user gets that role. And for apps, an API key is better than a password, and can have its own limits.

Dev Tools Consoletext
POST _security/role/shop_reader
{ "indices": [ { "names": ["products"], "privileges": ["read"] } ] }

POST _security/user/web_app
{ "password": "a-long-random-password", "roles": ["shop_reader"] }

POST _security/api_key
{ "name": "search-service",
  "role_descriptors": { "search_only": {
    "indices": [ { "names": ["products"], "privileges": ["read"] } ] } } }

Security checklist

Keep security on, with TLS encryption. Give each app the smallest role it needs. Use API keys for services. Never put Elasticsearch directly on the internet. And keep it up to date.

keyvalue
TLSencrypt traffic
Least privilegesmall roles
API keysfor services
Networknever public

Summary

Real clusters use security, with roles, users and API keys, following least privilege. Next, monitoring your cluster.

Key takeaways
  • Roles
  • Users
  • API keys
Next up: Monitoring — is it healthy?