get-started-security.asciidoc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[security-getting-started]]
  4. == Tutorial: Getting started with security
  5. In this tutorial, you learn how to secure a cluster by configuring users and
  6. roles in {es}, {kib}, {ls}, and {metricbeat}.
  7. [float]
  8. [[get-started-security-prerequisites]]
  9. === Before you begin
  10. . Install and configure {es}, {kib}, {ls}, and {metricbeat} as described in
  11. {stack-gs}/get-started-elastic-stack.html[Getting started with the {stack}].
  12. +
  13. --
  14. IMPORTANT: To complete this tutorial, you must install the default {es} and
  15. {kib} packages, which include role-based access control (RBAC) and native
  16. authentication {security-features}. When you install these products, they apply
  17. basic licenses with no expiration dates. All of the subsequent steps in this
  18. tutorial assume that you are using a basic license. For more information, see
  19. {subscriptions} and
  20. {stack-ov}/license-management.html[License-management].
  21. --
  22. . Stop {ls}. The method for starting and stopping {ls} varies depending on whether
  23. you are running it from the command line or running it as a service. For example,
  24. if you are running {ls} from the command line, you can stop it by entering
  25. `Ctrl-C`. See {logstash-ref}/shutdown.html[Shutting down {ls}].
  26. . Stop {metricbeat}. For example, enter `Ctrl-C` on the command line where it is
  27. running.
  28. . Launch the {kib} web interface by pointing your browser to port 5601. For
  29. example, http://127.0.0.1:5601[http://127.0.0.1:5601].
  30. [role="xpack"]
  31. [[get-started-enable-security]]
  32. === Enable {es} {security-features}
  33. include::get-started-enable-security.asciidoc[]
  34. . Enable single-node discovery in the `ES_PATH_CONF/elasticsearch.yml` file.
  35. +
  36. --
  37. This tutorial involves a single node cluster, but if you had multiple
  38. nodes, you would enable {es} {security-features} on every node in the cluster
  39. and configure Transport Layer Security (TLS) for internode-communication, which
  40. is beyond the scope of this tutorial. By enabling single-node discovery, we are
  41. postponing the configuration of TLS. For example, add the following setting:
  42. [source,yaml]
  43. ----
  44. discovery.type: single-node
  45. ----
  46. For more information, see
  47. {ref}/bootstrap-checks.html#single-node-discovery[Single-node discovery].
  48. --
  49. When you enable {es} {security-features}, basic authentication is enabled by
  50. default. To communicate with the cluster, you must specify a username and
  51. password. Unless you <<anonymous-access,enable anonymous access>>, all requests
  52. that don't include a user name and password are rejected.
  53. [role="xpack"]
  54. [[get-started-built-in-users]]
  55. === Create passwords for built-in users
  56. include::get-started-builtin-users.asciidoc[]
  57. You need these built-in users in subsequent steps, so choose passwords that you
  58. can remember!
  59. NOTE: This tutorial does not use the built-in `apm_system`, `logstash_system`,
  60. `beats_system`, and `remote_monitoring_user` users, which are typically
  61. associated with monitoring. For more information, see
  62. {logstash-ref}/ls-security.html#ls-monitoring-user[Configuring credentials for {ls} monitoring]
  63. and {metricbeat-ref}/monitoring.html[Monitoring {metricbeat}].
  64. [role="xpack"]
  65. [[get-started-kibana-user]]
  66. === Add the built-in user to {kib}
  67. include::get-started-kibana-users.asciidoc[]
  68. [role="xpack"]
  69. [[get-started-authentication]]
  70. === Configure authentication
  71. Now that you've set up the built-in users, you need to decide how you want to
  72. manage all the other users.
  73. The {stack} _authenticates_ users to ensure that they are valid. The
  74. authentication process is handled by _realms_. You can use one or more built-in
  75. realms, such as the native, file, LDAP, PKI, Active Directory, SAML, or Kerberos
  76. realms. Alternatively, you can create your own custom realms. In this tutorial,
  77. we'll use a native realm.
  78. In general, you configure realms by adding `xpack.security.authc.realms`
  79. settings in the `elasticsearch.yml` file. However, the native realm is available
  80. by default when no other realms are configured. Therefore, you don't need to do
  81. any extra configuration steps in this tutorial. You can jump straight to
  82. creating users!
  83. If you want to learn more about authentication and realms, see
  84. <<setting-up-authentication>>.
  85. [role="xpack"]
  86. [[get-started-users]]
  87. === Create users
  88. Let's create two users in the native realm.
  89. . Log in to {kib} with the `elastic` built-in user.
  90. . Go to the *Management / Security / Users* page:
  91. +
  92. --
  93. [role="screenshot"]
  94. image::security/images/management-builtin-users.jpg["User management screenshot in Kibana"]
  95. In this example, you can see a list of built-in users.
  96. --
  97. . Click *Create new user*. For example, create a user for yourself:
  98. +
  99. --
  100. [role="screenshot"]
  101. image::security/images/create-user.jpg["Creating a user in Kibana"]
  102. You'll notice that when you create a user, you can assign it a role. Don't
  103. choose a role yet--we'll come back to that in subsequent steps.
  104. --
  105. . Click *Create new user* and create a `logstash_internal` user.
  106. +
  107. --
  108. In {stack-gs}/get-started-elastic-stack.html[Getting started with the {stack}],
  109. you configured {ls} to listen for {metricbeat}
  110. input and to send the events to {es}. You therefore need to create a user
  111. that {ls} can use to communicate with {es}. For example:
  112. [role="screenshot"]
  113. image::security/images/create-logstash-user.jpg["Creating a {ls} user in {kib}"]
  114. --
  115. [role="xpack"]
  116. [[get-started-roles]]
  117. === Assign roles
  118. By default, all users can change their own passwords, get information about
  119. themselves, and run the `authenticate` API. If you want them to do more than
  120. that, you need to give them one or more _roles_.
  121. Each role defines a specific set of actions (such as read, create, or delete)
  122. that can be performed on specific secured resources (such as indices, aliases,
  123. documents, fields, or clusters). To help you get up and running, there are
  124. built-in roles.
  125. Go to the *Management / Security / Roles* page to see them:
  126. [role="screenshot"]
  127. image::security/images/management-roles.jpg["Role management screenshot in Kibana"]
  128. Select a role to see more information about its privileges. For example, select
  129. the `kibana_system` role to see its list of cluster and index privileges. To
  130. learn more, see <<privileges-list-indices>>.
  131. Let's assign the `kibana_user` role to your user. Go back to the
  132. *Management / Security / Users* page and select your user. Add the `kibana_user`
  133. role and save the change. For example:
  134. [role="screenshot"]
  135. image::security/images/assign-role.jpg["Assigning a role to a user in Kibana"]
  136. This user now has access to all features in {kib}. For more information about granting
  137. access to Kibana see {kibana-ref}/xpack-security-authorization.html[Kibana Authorization].
  138. If you completed all of the steps in
  139. {stack-gs}/get-started-elastic-stack.html[Getting started with the {stack}], you should
  140. have {metricbeat} data stored in {es}. Let's create two roles that grant
  141. different levels of access to that data.
  142. Go to the *Management / Security / Roles* page and click *Create role*.
  143. Create a `metricbeat_reader` role that has `read` and `view_index_metadata`
  144. privileges on the `metricbeat-*` indices:
  145. [role="screenshot"]
  146. image::security/images/create-reader-role.jpg["Creating a role in Kibana"]
  147. Create a `metricbeat_writer` role that has `manage_index_templates` and `monitor`
  148. cluster privileges, as well as `write`, `delete`, and `create_index` privileges
  149. on the `metricbeat-*` indices:
  150. [role="screenshot"]
  151. image::security/images/create-writer-role.jpg["Creating another role in Kibana"]
  152. Now go back to the *Management / Security / Users* page and assign these roles
  153. to the appropriate users. Assign the `metricbeat_reader` role to your personal
  154. user. Assign the `metricbeat_writer` role to the `logstash_internal` user.
  155. The list of users should now contain all of the built-in users as well as the
  156. two you created. It should also show the appropriate roles for your users:
  157. [role="screenshot"]
  158. image::security/images/management-users.jpg["User management screenshot in Kibana"]
  159. If you want to learn more about authorization and roles, see <<authorization>>.
  160. [role="xpack"]
  161. [[get-started-logstash-user]]
  162. === Add user information in {ls}
  163. In order for {ls} to send data successfully to {es}, you must configure its
  164. authentication credentials in the {ls} configuration file.
  165. . Configure {ls} to use the `logstash_internal` user and the password that you
  166. created:
  167. ** If you don't mind having passwords visible in your configuration file, add
  168. the following `user` and `password` settings in the `demo-metrics-pipeline.conf`
  169. file in your {ls} directory:
  170. +
  171. --
  172. [source,ruby]
  173. ----
  174. ...
  175. output {
  176. elasticsearch {
  177. hosts => "localhost:9200"
  178. manage_template => false
  179. index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
  180. user => "logstash_internal" <1>
  181. password => "your_password" <2>
  182. }
  183. }
  184. ----
  185. <1> Specify the `logstash_internal` user that you created earlier in this tutorial.
  186. <2> Specify the password that you chose for this user ID.
  187. --
  188. ** If you prefer not to put your user ID and password in the configuration file,
  189. store them in a keystore instead.
  190. +
  191. --
  192. Run the following commands to create the {ls}
  193. keystore and add the secure settings:
  194. ["source","sh",subs="attributes,callouts"]
  195. ----------------------------------------------------------------------
  196. set +o history
  197. export LOGSTASH_KEYSTORE_PASS=mypassword <1>
  198. set -o history
  199. ./bin/logstash-keystore create
  200. ./bin/logstash-keystore add ES_USER
  201. ./bin/logstash-keystore add ES_PWD
  202. ----------------------------------------------------------------------
  203. <1> You can optionally protect access to the {ls} keystore by storing a password
  204. in an environment variable called `LOGSTASH_KEYSTORE_PASS`. For more information,
  205. see {logstash-ref}/keystore.html#keystore-password[Keystore password].
  206. When prompted, specify the `logstash_internal` user and its password for the
  207. `ES_USER` and `ES_PWD` values.
  208. NOTE: The {ls} keystore differs from the {kib} keystore. Whereas the {kib}
  209. keystore enables you to store `kibana.yml` settings by name, the {ls} keystore
  210. enables you to create arbitrary names that you can reference in the {ls}
  211. configuration. To learn more, see
  212. {logstash-ref}/keystore.html[Secrets keystore for secure settings].
  213. You can now use these `ES_USER` and `ES_PWD` keys in your configuration
  214. file. For example, add the `user` and `password` settings in the
  215. `demo-metrics-pipeline.conf` file as follows:
  216. [source,ruby]
  217. ----
  218. ...
  219. output {
  220. elasticsearch {
  221. hosts => "localhost:9200"
  222. manage_template => false
  223. index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
  224. user => "${ES_USER}"
  225. password => "${ES_PWD}"
  226. }
  227. }
  228. ----
  229. --
  230. . Start {ls} by using the appropriate method for your environment.
  231. +
  232. --
  233. For example, to
  234. run {ls} from a command line, go to the {ls} directory and enter the following
  235. command:
  236. ["source","sh",subs="attributes,callouts"]
  237. ----------------------------------------------------------------------
  238. ./bin/logstash -f demo-metrics-pipeline.conf
  239. ----------------------------------------------------------------------
  240. To start {ls} as a service, see
  241. {logstash-ref}/running-logstash.html[Running {ls} as a service on Debian or RPM].
  242. --
  243. . If you were connecting directly from {metricbeat} to {es}, you would need
  244. to configure authentication credentials for the {es} output in the {metricbeat}
  245. configuration file. In
  246. {stack-gs}/get-started-elastic-stack.html[Getting started with the {stack}],
  247. however, you configured
  248. {metricbeat} to send the data to {ls} for additional parsing, so no extra
  249. settings are required in {metricbeat}. For more information, see
  250. {metricbeat-ref}/securing-metricbeat.html[Securing {metricbeat}].
  251. . Start {metricbeat} by using the appropriate method for your environment.
  252. +
  253. --
  254. For example, on macOS, run the following command from the {metricbeat} directory:
  255. ["source","sh",subs="attributes,callouts"]
  256. ----------------------------------------------------------------------
  257. ./metricbeat -e
  258. ----------------------------------------------------------------------
  259. For more methods, see {metricbeat-ref}/metricbeat-starting.html[Starting {metricbeat}].
  260. --
  261. Wait a few minutes for new data to be sent from {metricbeat} to {ls} and {es}.
  262. [role="xpack"]
  263. [[get-started-verify-users]]
  264. === View system metrics in {kib}
  265. Log in to {kib} with the user ID that has `metricbeat_reader` and `kibana_user`
  266. roles (for example, `jdoe`).
  267. These roles enable the user to see the system metrics in {kib} (for example, on
  268. the *Discover* page or in the
  269. http://localhost:5601/app/kibana#/dashboard/Metricbeat-system-overview[{metricbeat} system overview dashboard]).
  270. [float]
  271. [[gs-security-nextsteps]]
  272. === What's next?
  273. Congratulations! You've successfully set up authentication and authorization by
  274. using the native realm. You learned how to create user IDs and roles that
  275. prevent unauthorized access to the {stack}.
  276. Later, when you're ready to increase the number of nodes in your cluster, you'll
  277. want to encrypt communications across the {stack}. To learn how, read
  278. <<encrypting-communications>>.
  279. For more detailed information about securing the {stack}, see:
  280. * {ref}/configuring-security.html[Configuring security in {es}]. Encrypt
  281. inter-node communications, set passwords for the built-in users, and manage your
  282. users and roles.
  283. * {kibana-ref}/using-kibana-with-security.html[Configuring security in {kib}].
  284. Set the authentication credentials in {kib} and encrypt communications between
  285. the browser and the {kib} server.
  286. * {logstash-ref}/ls-security.html[Configuring security in Logstash]. Set the
  287. authentication credentials for Logstash and encrypt communications between
  288. Logstash and {es}.
  289. * <<beats,Configuring security in the Beats>>. Configure authentication
  290. credentials and encrypt connections to {es}.
  291. * {hadoop-ref}/security.html[Configuring {es} for Apache Hadoop to use secured transport].