repository-s3.asciidoc 15 KB

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