↓ Skip to main content
Security

Elastic: _security API

·2 mins

Kibana is an effective way of managing users; but as a programmer you always need an API.

  • It helps to integrate with other applications you are building
  • Quick and clean way without any cosmetics
> GET /_security/_authenticate HTTP/1.1
> Host: myserver.elastic.node:9200
> Authorization: Basic ABCDEFGHIJKLMNOP==
> User-Agent: insomnia/7.1.1
> Accept: */*

< HTTP/1.1 200 OK
< content-type: application/json; charset=UTF-8
< content-length: 236

* Received 236 B chunk
* Connection #2 to host myserver.elastic.node left intact
GET https://myserver.elastic.node:9200/_security/_authenticate

I have added basic authentication to quickly check

{
  "username": "kibana",
  "roles": [
    "kibana_system"
  ],
  "full_name": null,
  "email": null,
  "metadata": {
    "_reserved": true
  },
  "enabled": true,
  "authentication_realm": {
    "name": "reserved",
    "type": "reserved"
  },
  "lookup_realm": {
    "name": "reserved",
    "type": "reserved"
  }
}
GET https://myserver.elastic.node:9200/_security/user/samarthya
{
  "error": {
    "root_cause": [
      {
        "type": "security_exception",
        "reason": "missing authentication credentials for REST request [/_security/user/samarthya]",
        "header": {
          "WWW-Authenticate": [
            "Bearer realm=\"security\"",
            "ApiKey",
            "Basic realm=\"security\" charset=\"UTF-8\""
          ]
        }
      }
    ],
    "type": "security_exception",
    "reason": "missing authentication credentials for REST request [/_security/user/samarthya]",
    "header": {
      "WWW-Authenticate": [
        "Bearer realm=\"security\"",
        "ApiKey",
        "Basic realm=\"security\" charset=\"UTF-8\""
      ]
    }
  },
  "status": 401
}

User credentials are cached in memory on each node to avoid connecting to a remote authentication service or hitting the disk for every incoming request.

POST https://myserver.elastic.node:9200/_security/realm/default_file/_clear_cache
{
  "_nodes": {
    "total": 3,
    "successful": 3,
    "failed": 0
  },
  "cluster_name": "abcd_user",
  "nodes": {
    "mrTQQhMPQfWPF6q_IGf5s5Q": {
      "name": "node3.elasticsearch.node"
    },
    "8P5-I2yKQEu0Sbxtq0J0QDg": {
      "name": "node2.elasticsearch.node"
    },
    "hEkSDlSxQoKw94WS7c-T0xw": {
      "name": "master.elasticsearch.node"
    }
  }
}
POST https://myserver.elastic.node:9200/_security/api_key
{
  "name": "blog-key",
  "expiration": "1d"
}
{
  "id": "RKoiMnIBLGvMX-heXl-O",
  "name": "blog-key",
  "expiration": 1590065412726,
  "api_key": "NODL7y_TSkinR1GIitRGFQ"
}

Points out

  • id - A unique id
  • name - Name we gave for the key
  • expiration - in ms
  • api_key - API key to be used
Author
Samarthya
Engineer, learner, tinkerer. This is my trophy shelf of everyday work and leisure.

Related

Metric Beat

All right, its been a busy week and finally some time at hand to write about something I have been doing. Mostly I am working on ELK stack these days, securing, validating, data analytics etc. Today, had the opportunity to go the Secure Elastic way, by enabling the TLS for secure communication within Nodes (Elastic cluster) and finally setup a Metric beat to get the status of the node.

Securing Elastic

·4 mins
Security is integral to every and all the tasks in a shared environment. In ELK if you have setup a cluster which is accessible to all; anyone can make modifications which may or may not impact the other users.

Security Analytics

* Header image from Elastic.co As we move towards the micro-service/container economy where there are heaps of products available in form of applications to be downloaded & installed on primarily two platforms Android and IOS, we just cant underline the security implications enough.