repository-s3.asciidoc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. [[repository-s3]]
  2. === S3 Repository Plugin
  3. The S3 repository plugin adds support for using AWS S3 as a repository for
  4. {ref}/modules-snapshots.html[Snapshot/Restore].
  5. *If you are looking for a hosted solution of Elasticsearch on AWS, please visit
  6. http://www.elastic.co/cloud.*
  7. :plugin_name: repository-s3
  8. include::install_remove.asciidoc[]
  9. [[repository-s3-usage]]
  10. ==== Getting Started
  11. The plugin provides a repository type named `s3` which may be used when creating
  12. a repository. The repository defaults to using
  13. https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html[ECS
  14. IAM Role] or
  15. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html[EC2
  16. IAM Role] credentials for authentication. The only mandatory setting is the
  17. bucket name:
  18. [source,console]
  19. ----
  20. PUT _snapshot/my_s3_repository
  21. {
  22. "type": "s3",
  23. "settings": {
  24. "bucket": "my_bucket"
  25. }
  26. }
  27. ----
  28. // TEST[skip:we don't have s3 setup while testing this]
  29. [[repository-s3-client]]
  30. ==== Client Settings
  31. The client that you use to connect to S3 has a number of settings available.
  32. The settings have the form `s3.client.CLIENT_NAME.SETTING_NAME`. By default,
  33. `s3` repositories use a client named `default`, but this can be modified using
  34. the <<repository-s3-repository,repository setting>> `client`. For example:
  35. [source,console]
  36. ----
  37. PUT _snapshot/my_s3_repository
  38. {
  39. "type": "s3",
  40. "settings": {
  41. "bucket": "my_bucket",
  42. "client": "my_alternate_client"
  43. }
  44. }
  45. ----
  46. // TEST[skip:we don't have S3 setup while testing this]
  47. Most client settings can be added to the `elasticsearch.yml` configuration file
  48. with the exception of the secure settings, which you add to the {es} keystore.
  49. For more information about creating and updating the {es} keystore, see
  50. {ref}/secure-settings.html[Secure settings].
  51. For example, if you want to use specific credentials to access S3 then run the
  52. following commands to add these credentials to the keystore:
  53. [source,sh]
  54. ----
  55. bin/elasticsearch-keystore add s3.client.default.access_key
  56. bin/elasticsearch-keystore add s3.client.default.secret_key
  57. # a session token is optional so the following command may not be needed
  58. bin/elasticsearch-keystore add s3.client.default.session_token
  59. ----
  60. If instead you want to use the instance role or container role to access S3
  61. then you should leave these settings unset. You can switch from using specific
  62. credentials back to the default of using the instance role or container role by
  63. removing these settings from the keystore as follows:
  64. [source,sh]
  65. ----
  66. bin/elasticsearch-keystore remove s3.client.default.access_key
  67. bin/elasticsearch-keystore remove s3.client.default.secret_key
  68. # a session token is optional so the following command may not be needed
  69. bin/elasticsearch-keystore remove s3.client.default.session_token
  70. ----
  71. *All* client secure settings of this plugin are
  72. {ref}/secure-settings.html#reloadable-secure-settings[reloadable]. After you
  73. reload the settings, the internal `s3` clients, used to transfer the snapshot
  74. contents, will utilize the latest settings from the keystore. Any existing `s3`
  75. repositories, as well as any newly created ones, will pick up the new values
  76. stored in the keystore.
  77. NOTE: In-progress snapshot/restore tasks will not be preempted by a *reload* of
  78. the client's secure settings. The task will complete using the client as it was
  79. built when the operation started.
  80. The following list contains the available client settings. Those that must be
  81. stored in the keystore are marked as "secure" and are *reloadable*; the other
  82. settings belong in the `elasticsearch.yml` file.
  83. `access_key` ({ref}/secure-settings.html[Secure], {ref}/secure-settings.html#reloadable-secure-settings[reloadable])::
  84. An S3 access key. If set, the `secret_key` setting must also be specified.
  85. If unset, the client will use the instance or container role instead.
  86. `secret_key` ({ref}/secure-settings.html[Secure], {ref}/secure-settings.html#reloadable-secure-settings[reloadable])::
  87. An S3 secret key. If set, the `access_key` setting must also be specified.
  88. `session_token` ({ref}/secure-settings.html[Secure], {ref}/secure-settings.html#reloadable-secure-settings[reloadable])::
  89. An S3 session token. If set, the `access_key` and `secret_key` settings
  90. must also be specified.
  91. `endpoint`::
  92. The S3 service endpoint to connect to. This defaults to `s3.amazonaws.com`
  93. but the
  94. http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region[AWS
  95. documentation] lists alternative S3 endpoints. If you are using an
  96. <<repository-s3-compatible-services,S3-compatible service>> then you should
  97. set this to the service's endpoint.
  98. `protocol`::
  99. The protocol to use to connect to S3. Valid values are either `http` or
  100. `https`. Defaults to `https`.
  101. `proxy.host`::
  102. The host name of a proxy to connect to S3 through.
  103. `proxy.port`::
  104. The port of a proxy to connect to S3 through.
  105. `proxy.username` ({ref}/secure-settings.html[Secure], {ref}/secure-settings.html#reloadable-secure-settings[reloadable])::
  106. The username to connect to the `proxy.host` with.
  107. `proxy.password` ({ref}/secure-settings.html[Secure], {ref}/secure-settings.html#reloadable-secure-settings[reloadable])::
  108. The password to connect to the `proxy.host` with.
  109. `read_timeout`::
  110. The socket timeout for connecting to S3. The value should specify the unit.
  111. For example, a value of `5s` specifies a 5 second timeout. The default value
  112. is 50 seconds.
  113. `max_retries`::
  114. The number of retries to use when an S3 request fails. The default value is
  115. `3`.
  116. `use_throttle_retries`::
  117. Whether retries should be throttled (i.e. should back off). Must be `true`
  118. or `false`. Defaults to `true`.
  119. `path_style_access`::
  120. Whether to force the use of the path style access pattern. If `true`, the
  121. path style access pattern will be used. If `false`, the access pattern will
  122. be automatically determined by the AWS Java SDK (See
  123. https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/AmazonS3Builder.html#setPathStyleAccessEnabled-java.lang.Boolean-[AWS
  124. documentation] for details). Defaults to `false`.
  125. [[repository-s3-path-style-deprecation]]
  126. NOTE: In versions `7.0`, `7.1`, `7.2` and `7.3` all bucket operations used the
  127. https://aws.amazon.com/blogs/aws/amazon-s3-path-deprecation-plan-the-rest-of-the-story/[now-deprecated]
  128. path style access pattern. If your deployment requires the path style access
  129. pattern then you should set this setting to `true` when upgrading.
  130. `disable_chunked_encoding`::
  131. Whether chunked encoding should be disabled or not. If `false`, chunked
  132. encoding is enabled and will be used where appropriate. If `true`, chunked
  133. encoding is disabled and will not be used, which may mean that snapshot
  134. operations consume more resources and take longer to complete. It should
  135. only be set to `true` if you are using a storage service that does not
  136. support chunked encoding. See the
  137. https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/AmazonS3Builder.html#disableChunkedEncoding--[AWS
  138. Java SDK documentation] for details. Defaults to `false`.
  139. [float]
  140. [[repository-s3-compatible-services]]
  141. ===== S3-compatible services
  142. There are a number of storage systems that provide an S3-compatible API, and
  143. the `repository-s3` plugin allows you to use these systems in place of AWS S3.
  144. To do so, you should set the `s3.client.CLIENT_NAME.endpoint` setting to the
  145. system's endpoint. This setting accepts IP addresses and hostnames and may
  146. include a port. For example, the endpoint may be `172.17.0.2` or
  147. `172.17.0.2:9000`. You may also need to set `s3.client.CLIENT_NAME.protocol` to
  148. `http` if the endpoint does not support HTTPS.
  149. https://minio.io[Minio] is an example of a storage system that provides an
  150. S3-compatible API. The `repository-s3` plugin allows {es} to work with
  151. Minio-backed repositories as well as repositories stored on AWS S3. Other
  152. S3-compatible storage systems may also work with {es}, but these are not tested
  153. or supported.
  154. [[repository-s3-repository]]
  155. ==== Repository Settings
  156. The `s3` repository type supports a number of settings to customize how data is
  157. stored in S3. These can be specified when creating the repository. For example:
  158. [source,console]
  159. ----
  160. PUT _snapshot/my_s3_repository
  161. {
  162. "type": "s3",
  163. "settings": {
  164. "bucket": "my_bucket_name",
  165. "another_setting": "setting_value"
  166. }
  167. }
  168. ----
  169. // TEST[skip:we don't have S3 set up while testing this]
  170. The following settings are supported:
  171. `bucket`::
  172. The name of the bucket to be used for snapshots. (Mandatory)
  173. `client`::
  174. The name of the <<repository-s3-client,S3 client>> to use to connect to S3.
  175. Defaults to `default`.
  176. `base_path`::
  177. Specifies the path within bucket to repository data. Defaults to value of
  178. `repositories.s3.base_path` or to root directory if not set. Previously,
  179. the base_path could take a leading `/` (forward slash). However, this has
  180. been deprecated and setting the base_path now should omit the leading `/`.
  181. `chunk_size`::
  182. Big files can be broken down into chunks during snapshotting if needed.
  183. Specify the chunk size as a value and unit, for example:
  184. `1GB`, `10MB`, `5KB`, `500B`. Defaults to `1GB`.
  185. `compress`::
  186. When set to `true` metadata files are stored in compressed format. This
  187. setting doesn't affect index files that are already compressed by default.
  188. Defaults to `true`.
  189. include::repository-shared-settings.asciidoc[]
  190. `server_side_encryption`::
  191. When set to `true` files are encrypted on server side using AES256
  192. algorithm. Defaults to `false`.
  193. `buffer_size`::
  194. Minimum threshold below which the chunk is uploaded using a single request.
  195. Beyond this threshold, the S3 repository will use the
  196. http://docs.aws.amazon.com/AmazonS3/latest/dev/uploadobjusingmpu.html[AWS
  197. Multipart Upload API] to split the chunk into several parts, each of
  198. `buffer_size` length, and to upload each part in its own request. Note that
  199. setting a buffer size lower than `5mb` is not allowed since it will prevent
  200. the use of the Multipart API and may result in upload errors. It is also not
  201. possible to set a buffer size greater than `5gb` as it is the maximum upload
  202. size allowed by S3. Defaults to the minimum between `100mb` and `5%` of the
  203. heap size.
  204. `canned_acl`::
  205. The S3 repository supports all
  206. http://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl[S3
  207. canned ACLs] : `private`, `public-read`, `public-read-write`,
  208. `authenticated-read`, `log-delivery-write`, `bucket-owner-read`,
  209. `bucket-owner-full-control`. Defaults to `private`. You could specify a
  210. canned ACL using the `canned_acl` setting. When the S3 repository creates
  211. buckets and objects, it adds the canned ACL into the buckets and objects.
  212. `storage_class`::
  213. Sets the S3 storage class for objects stored in the snapshot repository.
  214. Values may be `standard`, `reduced_redundancy`, `standard_ia`, `onezone_ia`
  215. and `intelligent_tiering`. Defaults to `standard`.
  216. Changing this setting on an existing repository only affects the
  217. storage class for newly created objects, resulting in a mixed usage of
  218. storage classes. Additionally, S3 Lifecycle Policies can be used to manage
  219. the storage class of existing objects. Due to the extra complexity with the
  220. Glacier class lifecycle, it is not currently supported by the plugin. For
  221. more information about the different classes, see
  222. http://docs.aws.amazon.com/AmazonS3/latest/dev/storage-class-intro.html[AWS
  223. Storage Classes Guide]
  224. NOTE: The option of defining client settings in the repository settings as
  225. documented below is considered deprecated, and will be removed in a future
  226. version.
  227. In addition to the above settings, you may also specify all non-secure client
  228. settings in the repository settings. In this case, the client settings found in
  229. the repository settings will be merged with those of the named client used by
  230. the repository. Conflicts between client and repository settings are resolved
  231. by the repository settings taking precedence over client settings.
  232. For example:
  233. [source,console]
  234. ----
  235. PUT _snapshot/my_s3_repository
  236. {
  237. "type": "s3",
  238. "settings": {
  239. "client": "my_client_name",
  240. "bucket": "my_bucket_name",
  241. "endpoint": "my.s3.endpoint"
  242. }
  243. }
  244. ----
  245. // TEST[skip:we don't have s3 set up while testing this]
  246. This sets up a repository that uses all client settings from the client
  247. `my_client_name` except for the `endpoint` that is overridden to
  248. `my.s3.endpoint` by the repository settings.
  249. [[repository-s3-permissions]]
  250. ===== Recommended S3 Permissions
  251. In order to restrict the Elasticsearch snapshot process to the minimum required
  252. resources, we recommend using Amazon IAM in conjunction with pre-existing S3
  253. buckets. Here is an example policy which will allow the snapshot access to an S3
  254. bucket named "snaps.example.com". This may be configured through the AWS IAM
  255. console, by creating a Custom Policy, and using a Policy Document similar to
  256. this (changing snaps.example.com to your bucket name).
  257. [source,js]
  258. ----
  259. {
  260. "Statement": [
  261. {
  262. "Action": [
  263. "s3:ListBucket",
  264. "s3:GetBucketLocation",
  265. "s3:ListBucketMultipartUploads",
  266. "s3:ListBucketVersions"
  267. ],
  268. "Effect": "Allow",
  269. "Resource": [
  270. "arn:aws:s3:::snaps.example.com"
  271. ]
  272. },
  273. {
  274. "Action": [
  275. "s3:GetObject",
  276. "s3:PutObject",
  277. "s3:DeleteObject",
  278. "s3:AbortMultipartUpload",
  279. "s3:ListMultipartUploadParts"
  280. ],
  281. "Effect": "Allow",
  282. "Resource": [
  283. "arn:aws:s3:::snaps.example.com/*"
  284. ]
  285. }
  286. ],
  287. "Version": "2012-10-17"
  288. }
  289. ----
  290. // NOTCONSOLE
  291. You may further restrict the permissions by specifying a prefix within the
  292. bucket, in this example, named "foo".
  293. [source,js]
  294. ----
  295. {
  296. "Statement": [
  297. {
  298. "Action": [
  299. "s3:ListBucket",
  300. "s3:GetBucketLocation",
  301. "s3:ListBucketMultipartUploads",
  302. "s3:ListBucketVersions"
  303. ],
  304. "Condition": {
  305. "StringLike": {
  306. "s3:prefix": [
  307. "foo/*"
  308. ]
  309. }
  310. },
  311. "Effect": "Allow",
  312. "Resource": [
  313. "arn:aws:s3:::snaps.example.com"
  314. ]
  315. },
  316. {
  317. "Action": [
  318. "s3:GetObject",
  319. "s3:PutObject",
  320. "s3:DeleteObject",
  321. "s3:AbortMultipartUpload",
  322. "s3:ListMultipartUploadParts"
  323. ],
  324. "Effect": "Allow",
  325. "Resource": [
  326. "arn:aws:s3:::snaps.example.com/foo/*"
  327. ]
  328. }
  329. ],
  330. "Version": "2012-10-17"
  331. }
  332. ----
  333. // NOTCONSOLE
  334. The bucket needs to exist to register a repository for snapshots. If you did not
  335. create the bucket then the repository registration will fail.
  336. [[repository-s3-aws-vpc]]
  337. [float]
  338. ==== AWS VPC Bandwidth Settings
  339. AWS instances resolve S3 endpoints to a public IP. If the Elasticsearch
  340. instances reside in a private subnet in an AWS VPC then all traffic to S3 will
  341. go through that VPC's NAT instance. If your VPC's NAT instance is a smaller
  342. instance size (e.g. a t1.micro) or is handling a high volume of network traffic
  343. your bandwidth to S3 may be limited by that NAT instance's networking bandwidth
  344. limitations.
  345. Instances residing in a public subnet in an AWS VPC will connect to S3 via the
  346. VPC's internet gateway and not be bandwidth limited by the VPC's NAT instance.