Slide 1

Slide 1 text

Elasticsearch 2 Security - Beyond Basic Authentication Hendrik Saly, codecentric AG

Slide 2

Slide 2 text

Elasticsearch Security No security within Elasticsearch by default Secure it by using proxies/tunnels let the application handle security using security plugins

Slide 3

Slide 3 text

Elasticsearch Security - by proxy Error prone (complex regex stuff) ES API changes must be manually maintained HTTP REST only No Document or Field level security

Slide 4

Slide 4 text

Elasticsearch Security - by application If user access Elasticsearch not directly but through an application Handle security within the application Make sure that only the application can access Elasticsearch (Firewall) No security applied to intra-cluster communication

Slide 5

Slide 5 text

Elasticsearch Security - by plugin thats what this talk is about Two plugins available Shield 2 (commercial, by elastic) Search Guard (open source, by floragunn) This talk focus on Shield

Slide 6

Slide 6 text

Elasticsearch Security - HTTP/REST and Transport HTTP/REST Transport protocol (raw tcp) also used for intra-cluster communication With basic authentication SSL/TLS is mandatory

Slide 7

Slide 7 text

Authentication & Authorization Authentication: Who am i Username/Principal (+ secret for a prove) Authorization: What i am allowed to do/see Roles/Groups with privileges/permissions assigned

Slide 8

Slide 8 text

What should be secured? Access to nodes restrict on TCP/IP Level (ip filtering) restrict by authentication Intra-cluster communication Limit actions (read, write, admin, … ) Limit access to specific documents (DLS) Limit access to specific fields (FLS)

Slide 9

Slide 9 text

Shield config # All cluster rights # All operations on all indices admin: cluster: all indices: '*': privileges: all # Only GET read action on index named events_index get_user: indices: 'events_index': privileges: 'indices:data/read/get' https://www.elastic.co/guide/en/shield/current/reference.html#privileges- list

Slide 10

Slide 10 text

Shield Realm Combines HTTP Authentication method (Basic/SPNEGO/… ) OR PKI Authentication via SSL/TLS Backend Authentication (Backend Authorization)

Slide 11

Slide 11 text

Shield Realm

Slide 12

Slide 12 text

PKI authentication Two-way SSL authentication via X.509 certificates Single-Sign On possible Root CA recommended SSL/TLS required Great for Machine-to-Machine communication Works in browser too

Slide 13

Slide 13 text

Generate certificates Assume there is a CA Server certificate for each node //Generate server certificate keytool -genkey -keystore keystore.jks \ -dname "CN=localhost, OU=SSL, O=Test, L=Test, C=DE" \ -ext san=dns:localhost,ip:127.0.0.1 \ //san -> Subject Alternative Names //https://www.digicert.com/subject-alternative-name.htm //Generate CSR keytool -certreq ... //let CA sign an import signed cert back into keystore //along with the root CA chain keytool -import ...

Slide 14

Slide 14 text

Generate certificates Client certificates for each client/user //Create a client key openssl genrsa -out client.key 2048 //Create a client certificate openssl req -key client.key -new -out client.req \ -subj "/C=DE/ST=TESTU/L=TESTU/O=TESTU/OU=TESTU/CN=Mister Spock" openssl x509 -req -in client.req \ ... \ -out client.crt //optional: create a PCKS12 certificate openssl pkcs12 -export -clcerts -in client.crt -inkey client.key -out client.p12 \ -password pass:p12pass

Slide 15

Slide 15 text

wget/curl Access PKI protected URLs wget -qO- \ --ca-cert=chain-ca.pem \ --certificate=client.crt \ --private-key=client.key \ https://localhost:9200/_logininfo?pretty curl -E client.crt \ --key client.key \ --cacert chain-ca.pem \ "https://localhost:9200/_logininfo?pretty"

Slide 16

Slide 16 text

Firefox

Slide 17

Slide 17 text

DEMO Setup PKI realm https://github.com/salyh/elasticsearch-beyond-basicauthentication

Slide 18

Slide 18 text

Kerberos/SPNEGO authentication Fits into Kerberos/AD infrastructure Enterprise grade security Single-Sign On possible No SSL/TLS required Works great with browsers

Slide 19

Slide 19 text

Kerberos Realm Supports HTTP/REST Supports Transport protocol No JAAS login.conf needed (but its used under the hood) as well as GSS-API (Generic Security Service Application Program Interface)

Slide 20

Slide 20 text

Kerberos Realm Access Kerberos protected URLs kinit [email protected] curl -k --negotiate -u : \ "https://localhost:9200/_logininfo?pretty"

Slide 21

Slide 21 text

Kerberos Realm Access Kerberos protected transport protocol //KerberizedClient "client wrapper" Client client = ...; KerberizedClient kc = new KerberizedClient(client, "[email protected]", "secret", "HTTP/[email protected]"); KerberizedClient kc = new KerberizedClient(client, "[email protected]", Paths.get("ticket.cc"), "HTTP/[email protected]");

Slide 22

Slide 22 text

DEMO Setup Kerberos realm https://github.com/salyh/elasticsearch-beyond-basicauthentication

Slide 23

Slide 23 text

Mapping Users to Roles CONF_DIR/shield/users/role_mapping.yml monitoring: - "cn=admins,dc=example,dc=com" user: - "cn=John Doe,cn=contractors,dc=example,dc=com" - "cn=users,dc=example,dc=com" - "cn=admins,dc=example,dc=com"

Slide 24

Slide 24 text

Document Level Security in Shield 2 Limit access to particular documents matching a query 1. role 2. index 3. privilege 4. query customer_care: (1) indices: '*': (2) privileges: read (3) query: '{"term" : {"department_id" : "12"}}'' (4)

Slide 25

Slide 25 text

Field Level Security in Shield 2 Limit access to fields within a document my_role: indices: '*': privileges: read fields: - customer.*

Slide 26

Slide 26 text

Limitations Shield is commercial and closed source No real separation between authentication and authorization Limited multirealm support XFF support unknown (for IP filtering) Shield config must be synchronized between nodes No nested LDAP roles

Slide 27

Slide 27 text

Alternatives Floragunn Search Guard Plugin Open Source (ASL2 License) Currently only ES 1.x supported and low activity Central configuration approach More flexible, more features

Slide 28

Slide 28 text

Whats probably next? SAML (Security Assertion Markup Language) OAuth 2 Waffle (native Windows authentication)

Slide 29

Slide 29 text

Links https://github.com/salyh/elasticsearch-beyond-basicauthentication https://github.com/codecentric/elasticsearch-shield-kerberos-realm https://www.elastic.co/guide/en/shield/current/pki.html https://www.elastic.co/guide/en/shield/current/custom-realms.html https://www.elastic.co/guide/en/shield/current/reference.html#ref- actions-list https://github.com/floragunncom/search-guard https://github.com/dblock/waffle

Slide 30

Slide 30 text

Thank you! Follow me on Twitter: This work is licensed under a [email protected] @hendrikdev22 Creative Commons Attribution 4.0 International License