Implementing Security Features
1. Enabling X-Pack Security
| Configuration Option | Description | Default Value | Notes |
|---|---|---|---|
| xpack.security.enabled | Enables X-Pack security features including authentication and authorization. | false |
Must be set to true to enable security features. |
| xpack.security.transport.ssl.enabled | Enables SSL/TLS for transport layer communication between nodes. | false |
Recommended for production environments to secure inter-node communication. |
| xpack.security.http.ssl.enabled | Enables SSL/TLS for HTTP layer communication with the Elasticsearch cluster. | false |
Required for secure access to the Elasticsearch API over HTTPS. |
Example: Enabling X-Pack Security in elasticsearch.yml
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.http.ssl.enabled: true
Note: After enabling X-Pack security, you must set up users and roles using the Elasticsearch Security API or Kibana UI.
2. Setting Up TLS/SSL
Example: Configure Elasticsearch to use TLS/SSL
network.host: 0.0.0.0
http.port: 9200
xpack.security.http.ssl.enabled: true
xpack.security.http.ssl.keystore.path: certs/elastic-certificates.p12
xpack.security.http.ssl.truststore.path: certs/elastic-certificates.p12
| Property | Value | Description |
|---|---|---|
| xpack.security.http.ssl.enabled | true |
Enables HTTPS for the HTTP layer |
| xpack.security.http.ssl.keystore.path | certs/elastic-certificates.p12 |
Path to the keystore containing certificates |
| xpack.security.http.ssl.truststore.path | certs/elastic-certificates.p12 |
Path to the truststore containing CA certificates |
Note: Ensure that the keystore and truststore files are secured with appropriate permissions to prevent unauthorized access.
3. Encrypting Node Communication
| Property | Description | Default Value | Notes |
|---|---|---|---|
| xpack.security.http.ssl.enabled | Enables HTTPS for the HTTP layer | false | Required for secure communication |
| xpack.security.transport.ssl.enabled | Enables TLS for transport layer communication | false | Secures node-to-node communication |
| xpack.security.http.ssl.keystore.path | Path to the keystore file for HTTP SSL | not set | Must be a valid keystore file (JKS or PKCS#12) |
| xpack.security.transport.ssl.keystore.path | Path to the keystore file for transport layer SSL | not set | Must be a valid keystore file (JKS or PKCS#12) |
| xpack.security.http.ssl.truststore.path | Path to the truststore file for HTTP SSL | not set | Used to verify client certificates |
| xpack.security.transport.ssl.truststore.path | Path to the truststore file for transport layer SSL | not set | Used to verify node certificates |
Example: Enabling SSL for HTTP and Transport Layers
xpack:
security:
http:
ssl:
enabled: true
keystore:
path: "http.p12"
password: "changeit"
transport:
ssl:
enabled: true
keystore:
path: "transport.p12"
password: "changeit"
Note: Ensure that the keystore and truststore files are properly secured and accessible only to authorized users.
4. Encrypting HTTP Traffic
| Component | Encryption Method | Configuration | Notes |
|---|---|---|---|
| Elasticsearch | SSL/TLS |
xpack.security.http.ssl.enabled: true |
Enables HTTPS for Elasticsearch |
| Kibana | SSL/TLS |
server.ssl.enabled: true |
Enables HTTPS for Kibana |
| Logstash | SSL/TLS |
ssl.enabled: true |
Enables HTTPS for Logstash |
Example: Kibana SSL Configuration
server.ssl.enabled: true
server.ssl.certificate: /path/to/cert.pem
server.ssl.key: /path/to/key.pem
Example: Elasticsearch SSL Configuration
xpack.security.http.ssl.enabled: true
xpack.security.http.ssl.keystore.path: certs/elastic-certificates.p12
xpack.security.http.ssl.truststore.path: certs/elastic-certificates.p12
Note: Ensure certificates are valid and trusted by clients to avoid SSL handshake errors.
5. Creating Users and Roles
| Property | Description | Values |
|---|---|---|
| username | Name of the user | string |
| password | Password for the user | string |
| roles | Array of roles assigned to the user | array |
| elasticsearch | Permissions for Elasticsearch | object |
| kibana | Permissions for Kibana | object |
Example: Creating a User with Roles
PUT /_security/user/elastic_user
{
"password" : "secure_password",
"roles" : [ "superuser", "kibana_admin" ],
"full_name" : "Elastic User"
}
Example: Assigning Roles to a User
POST /_security/role/monitoring_role
{
"cluster" : [ "monitor" ],
"index" : [
{
"names" : [ "logs-*" ],
"privileges" : [ "read" ]
}
]
}
Note: Ensure that the user's roles have appropriate permissions to access the required resources in Elasticsearch and Kibana.
6. Configuring Authentication
| Option | Values | Description |
|---|---|---|
| xpack.security.authc.password_hashing.algorithm | bcrypt |
Algorithm used for hashing passwords. Default is bcrypt. |
| xpack.security.authc.password_hashing.iterations | 10000 |
Number of iterations for password hashing. Higher values increase security but impact performance. |
| xpack.security.authc.http.enabled | true |
Enables HTTP authentication mechanisms like Basic and Digest. |
| xpack.security.authc.token.enabled | true |
Enables JWT and API key token-based authentication. |
Example: Enabling Basic Authentication
xpack:
security:
authc:
http:
enabled: true
basic:
enabled: true
Example: Setting Up API Key Authentication
POST /_security/api_key
{
"name": "my-api-key",
"role_descriptors": {
"my-role": {
"cluster": ["monitor"],
"index": [
{
"names": ["logs-*"],
"privileges": ["read"]
}
]
}
}
}
7. Using API Keys
| Property | Description | Default | Notes |
|---|---|---|---|
| xpack.security.authc.api_key.enabled | Enables or disables API key authentication | false |
Set to true to enable API key support |
| xpack.security.authc.api_key.allow_expired | Allows usage of expired API keys | false |
Set to true to allow expired keys |
Example: Use API Key for Authentication
GET /_search
Authorization: "ApiKey <base64-encoded-api-key>"
Note: API keys are scoped to specific users and can be revoked at any time.
8. Implementing Role-Based Access Control
| Role | Permissions | Description |
|---|---|---|
| superuser | all |
Full access to all features and data |
| admin | read, write, manage |
Manage users and system settings; read/write data |
| user | read |
Read-only access to logs and dashboards |
| viewer | read, export |
Read logs and export data |
Example: Define Role in Elasticsearch
{
"elasticsearch": {
"roles": {
"log_analyst": {
"cluster": [
"monitor"
],
"index": [
{
"names": [
"logs-*"
],
"privileges": [
"read"
]
}
]
}
}
}
}
Example: Assign Role to User
PUT /_security/role/log_analyst
{
"cluster": [
"monitor"
],
"index": [
{
"names": [
"logs-*"
],
"privileges": [
"read"
]
}
]
}
PUT /_security/user/john_doe
{
"password": "secure_password",
"roles": [
"log_analyst"
]
}
Note: RBAC in the ELK Stack is managed through Elasticsearch Security features. Ensure roles are defined with minimal required permissions to follow the principle of least privilege.
9. Setting Document-Level Security
Document-level security in the ELK Stack allows you to restrict access to specific documents within an index based on user roles or attributes. This is particularly useful in multi-tenant environments where different users should only see a subset of data.
| Field | Description | Example |
|---|---|---|
| query | The query used to filter documents. This is a standard Elasticsearch query DSL. | { "term": { "department": "engineering" } } |
| roles | Array of roles that are allowed to access documents matching this query. | ["role_engineering", "role_admin"] |
Example: Define Document-Level Security Rule
{
"role_engineering": {
"index_permissions": [
"read"
],
"document_level_security": {
"query": {
"term": {
"department": "engineering"
}
}
}
}
}
Note: Document-level security is supported in Elasticsearch 6.0+ and requires the
elasticsearch role to be configured with appropriate permissions.
Warning: Misconfiguring document-level security can lead to unintended data exposure. Always test rules in a development environment before applying them in production.
10. Setting Field-Level Security
Field-level security in the ELK Stack allows you to restrict access to specific fields within documents based on user roles and permissions. This is particularly useful in environments where sensitive data must be hidden from certain users.
| Field | Description | Example |
|---|---|---|
| field | Name of the field to restrict access to | ssn |
| read | Boolean indicating whether the field is readable | false |
Note: Field-level security is configured at the role level in Kibana and requires appropriate permissions to be set up.
11. Configuring Audit Logging
| Property | Description | Default Value | Notes |
|---|---|---|---|
| elasticsearch.audit.enabled | Enables or disables audit logging | false |
Set to true to enable audit logging |
| elasticsearch.audit.log.file | Path to the audit log file | /var/log/elasticsearch/audit.log |
Must be writable by the Elasticsearch process |
| elasticsearch.audit.log.level | Log level for audit events | INFO |
Can be DEBUG, INFO, or WARN |
| elasticsearch.audit.log.include | Types of events to include in audit logs | all |
Options: all, access_denied, access_granted |
Example: Enable Audit Logging in elasticsearch.yml
elasticsearch:
audit:
enabled: true
log:
file: /var/log/elasticsearch/audit.log
level: INFO
include: all
Note: Audit logs can become very large. Ensure sufficient disk space and consider log rotation.
Warning: Audit logging can impact performance. Monitor system resources after enabling.
12. Using Token-Based Authentication
| Feature | Description | Implementation |
|---|---|---|
| JWT | JSON Web Tokens for stateless authentication | const jwt = require('jsonwebtoken'); |
| Token Expiry | Set expiration time for tokens (e.g., 1 hour) | jwt.sign(payload, secret, { expiresIn: '1h' }); |
| Token Validation | Verify token signature and expiration | jwt.verify(token, secret); |
Example: Token Generation
const jwt = require('jsonwebtoken');
const generateToken = (user) => {
const payload = {
id: user.id,
username: user.username
};
return jwt.sign(payload, process.env.JWT_SECRET, { expiresIn: '1h' });
};
module.exports = { generateToken };
Example: Token Verification
const jwt = require('jsonwebtoken');
const verifyToken = (token) => {
try {
return jwt.verify(token, process.env.JWT_SECRET);
} catch (err) {
throw new Error('Invalid or expired token');
}
};
module.exports = { verifyToken };
Note: Ensure
JWT_SECRET is securely stored and not exposed in client-side code.
Warning: Tokens should be transmitted over HTTPS to prevent interception.
| Token Type | Usage | Security Consideration |
|---|---|---|
access_token |
Used for API requests | Short-lived, refreshed regularly |
refresh_token |
Used to obtain new access tokens | Long-lived, stored securely (e.g., HTTP-only cookie) |