repository-s3.asciidoc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  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. https://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. https://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. https://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`. When using HTTPS, this plugin validates the
  101. repository's certificate chain using the JVM-wide truststore. Ensure that
  102. the root certificate authority is in this truststore using the JVM's
  103. `keytool` tool.
  104. `proxy.host`::
  105. The host name of a proxy to connect to S3 through.
  106. `proxy.port`::
  107. The port of a proxy to connect to S3 through.
  108. `proxy.username` ({ref}/secure-settings.html[Secure], {ref}/secure-settings.html#reloadable-secure-settings[reloadable])::
  109. The username to connect to the `proxy.host` with.
  110. `proxy.password` ({ref}/secure-settings.html[Secure], {ref}/secure-settings.html#reloadable-secure-settings[reloadable])::
  111. The password to connect to the `proxy.host` with.
  112. `read_timeout`::
  113. The socket timeout for connecting to S3. The value should specify the unit.
  114. For example, a value of `5s` specifies a 5 second timeout. The default value
  115. is 50 seconds.
  116. `max_retries`::
  117. The number of retries to use when an S3 request fails. The default value is
  118. `3`.
  119. `use_throttle_retries`::
  120. Whether retries should be throttled (i.e. should back off). Must be `true`
  121. or `false`. Defaults to `true`.
  122. `path_style_access`::
  123. Whether to force the use of the path style access pattern. If `true`, the
  124. path style access pattern will be used. If `false`, the access pattern will
  125. be automatically determined by the AWS Java SDK (See
  126. https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/AmazonS3Builder.html#setPathStyleAccessEnabled-java.lang.Boolean-[AWS
  127. documentation] for details). Defaults to `false`.
  128. [[repository-s3-path-style-deprecation]]
  129. NOTE: In versions `7.0`, `7.1`, `7.2` and `7.3` all bucket operations used the
  130. https://aws.amazon.com/blogs/aws/amazon-s3-path-deprecation-plan-the-rest-of-the-story/[now-deprecated]
  131. path style access pattern. If your deployment requires the path style access
  132. pattern then you should set this setting to `true` when upgrading.
  133. `disable_chunked_encoding`::
  134. Whether chunked encoding should be disabled or not. If `false`, chunked
  135. encoding is enabled and will be used where appropriate. If `true`, chunked
  136. encoding is disabled and will not be used, which may mean that snapshot
  137. operations consume more resources and take longer to complete. It should
  138. only be set to `true` if you are using a storage service that does not
  139. support chunked encoding. See the
  140. https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/AmazonS3Builder.html#disableChunkedEncoding--[AWS
  141. Java SDK documentation] for details. Defaults to `false`.
  142. `region`::
  143. Allows specifying the signing region to use. Specificing this setting manually should not be necessary for most use cases. Generally,
  144. the SDK will correctly guess the signing region to use. It should be considered an expert level setting to support S3-compatible APIs
  145. that require https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html[v4 signatures] and use a region other than the
  146. default `us-east-1`. Defaults to empty string which means that the SDK will try to automatically determine the correct signing region.
  147. `signer_override`::
  148. Allows specifying the name of the signature algorithm to use for signing requests by the S3 client. Specifying this setting should not
  149. be necessary for most use cases. It should be considered an expert level setting to support S3-compatible APIs that do not support the
  150. signing algorithm that the SDK automatically determines for them.
  151. See the
  152. https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/ClientConfiguration.html#setSignerOverride-java.lang.String-[AWS
  153. Java SDK documentation] for details. Defaults to empty string which means that no signing algorithm override will be used.
  154. [discrete]
  155. [[repository-s3-compatible-services]]
  156. ===== S3-compatible services
  157. There are a number of storage systems that provide an S3-compatible API, and
  158. the `repository-s3` plugin allows you to use these systems in place of AWS S3.
  159. To do so, you should set the `s3.client.CLIENT_NAME.endpoint` setting to the
  160. system's endpoint. This setting accepts IP addresses and hostnames and may
  161. include a port. For example, the endpoint may be `172.17.0.2` or
  162. `172.17.0.2:9000`. You may also need to set `s3.client.CLIENT_NAME.protocol` to
  163. `http` if the endpoint does not support HTTPS.
  164. https://minio.io[MinIO] is an example of a storage system that provides an
  165. S3-compatible API. The `repository-s3` plugin allows {es} to work with
  166. MinIO-backed repositories as well as repositories stored on AWS S3. Other
  167. S3-compatible storage systems may also work with {es}, but these are not
  168. covered by the {es} test suite.
  169. Note that some storage systems claim to be S3-compatible without correctly
  170. supporting the full S3 API. The `repository-s3` plugin requires full
  171. compatibility with S3. In particular it must support the same set of API
  172. endpoints, return the same errors in case of failures, and offer a consistency
  173. model no weaker than S3's when accessed concurrently by multiple nodes.
  174. Incompatible error codes and consistency models may be particularly hard to
  175. track down since errors and consistency failures are usually rare and hard to
  176. reproduce.
  177. You can perform some basic checks of the suitability of your storage system
  178. using the {ref}/repo-analysis-api.html[repository analysis API]. If this API
  179. does not complete successfully, or indicates poor performance, then your
  180. storage system is not fully compatible with AWS S3 and therefore unsuitable for
  181. use as a snapshot repository. You will need to work with the supplier of your
  182. storage system to address any incompatibilities you encounter.
  183. [[repository-s3-repository]]
  184. ==== Repository Settings
  185. The `s3` repository type supports a number of settings to customize how data is
  186. stored in S3. These can be specified when creating the repository. For example:
  187. [source,console]
  188. ----
  189. PUT _snapshot/my_s3_repository
  190. {
  191. "type": "s3",
  192. "settings": {
  193. "bucket": "my-bucket",
  194. "another_setting": "setting-value"
  195. }
  196. }
  197. ----
  198. // TEST[skip:we don't have S3 set up while testing this]
  199. The following settings are supported:
  200. `bucket`::
  201. (Required)
  202. Name of the S3 bucket to use for snapshots.
  203. +
  204. The bucket name must adhere to Amazon's
  205. https://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html#bucketnamingrules[S3
  206. bucket naming rules].
  207. `client`::
  208. The name of the <<repository-s3-client,S3 client>> to use to connect to S3.
  209. Defaults to `default`.
  210. `base_path`::
  211. Specifies the path to the repository data within its bucket. Defaults to an
  212. empty string, meaning that the repository is at the root of the bucket. The
  213. value of this setting should not start or end with a `/`.
  214. `chunk_size`::
  215. Big files can be broken down into chunks during snapshotting if needed.
  216. Specify the chunk size as a value and unit, for example:
  217. `1TB`, `1GB`, `10MB`. Defaults to the maximum size of a blob in the S3 which is `5TB`.
  218. `compress`::
  219. When set to `true` metadata files are stored in compressed format. This
  220. setting doesn't affect index files that are already compressed by default.
  221. Defaults to `true`.
  222. include::repository-shared-settings.asciidoc[]
  223. `server_side_encryption`::
  224. When set to `true` files are encrypted on server side using AES256
  225. algorithm. Defaults to `false`.
  226. `buffer_size`::
  227. Minimum threshold below which the chunk is uploaded using a single request.
  228. Beyond this threshold, the S3 repository will use the
  229. https://docs.aws.amazon.com/AmazonS3/latest/dev/uploadobjusingmpu.html[AWS
  230. Multipart Upload API] to split the chunk into several parts, each of
  231. `buffer_size` length, and to upload each part in its own request. Note that
  232. setting a buffer size lower than `5mb` is not allowed since it will prevent
  233. the use of the Multipart API and may result in upload errors. It is also not
  234. possible to set a buffer size greater than `5gb` as it is the maximum upload
  235. size allowed by S3. Defaults to `100mb` or `5%` of JVM heap, whichever is
  236. smaller.
  237. `canned_acl`::
  238. The S3 repository supports all
  239. https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl[S3
  240. canned ACLs] : `private`, `public-read`, `public-read-write`,
  241. `authenticated-read`, `log-delivery-write`, `bucket-owner-read`,
  242. `bucket-owner-full-control`. Defaults to `private`. You could specify a
  243. canned ACL using the `canned_acl` setting. When the S3 repository creates
  244. buckets and objects, it adds the canned ACL into the buckets and objects.
  245. `storage_class`::
  246. Sets the S3 storage class for objects stored in the snapshot repository.
  247. Values may be `standard`, `reduced_redundancy`, `standard_ia`, `onezone_ia`
  248. and `intelligent_tiering`. Defaults to `standard`.
  249. Changing this setting on an existing repository only affects the
  250. storage class for newly created objects, resulting in a mixed usage of
  251. storage classes. Additionally, S3 Lifecycle Policies can be used to manage
  252. the storage class of existing objects. Due to the extra complexity with the
  253. Glacier class lifecycle, it is not currently supported by the plugin. For
  254. more information about the different classes, see
  255. https://docs.aws.amazon.com/AmazonS3/latest/dev/storage-class-intro.html[AWS
  256. Storage Classes Guide]
  257. NOTE: The option of defining client settings in the repository settings as
  258. documented below is considered deprecated, and will be removed in a future
  259. version.
  260. In addition to the above settings, you may also specify all non-secure client
  261. settings in the repository settings. In this case, the client settings found in
  262. the repository settings will be merged with those of the named client used by
  263. the repository. Conflicts between client and repository settings are resolved
  264. by the repository settings taking precedence over client settings.
  265. For example:
  266. [source,console]
  267. ----
  268. PUT _snapshot/my_s3_repository
  269. {
  270. "type": "s3",
  271. "settings": {
  272. "client": "my-client",
  273. "bucket": "my-bucket",
  274. "endpoint": "my.s3.endpoint"
  275. }
  276. }
  277. ----
  278. // TEST[skip:we don't have s3 set up while testing this]
  279. This sets up a repository that uses all client settings from the client
  280. `my_client_name` except for the `endpoint` that is overridden to
  281. `my.s3.endpoint` by the repository settings.
  282. [[repository-s3-permissions]]
  283. ===== Recommended S3 Permissions
  284. In order to restrict the Elasticsearch snapshot process to the minimum required
  285. resources, we recommend using Amazon IAM in conjunction with pre-existing S3
  286. buckets. Here is an example policy which will allow the snapshot access to an S3
  287. bucket named "snaps.example.com". This may be configured through the AWS IAM
  288. console, by creating a Custom Policy, and using a Policy Document similar to
  289. this (changing snaps.example.com to your bucket name).
  290. [source,js]
  291. ----
  292. {
  293. "Statement": [
  294. {
  295. "Action": [
  296. "s3:ListBucket",
  297. "s3:GetBucketLocation",
  298. "s3:ListBucketMultipartUploads",
  299. "s3:ListBucketVersions"
  300. ],
  301. "Effect": "Allow",
  302. "Resource": [
  303. "arn:aws:s3:::snaps.example.com"
  304. ]
  305. },
  306. {
  307. "Action": [
  308. "s3:GetObject",
  309. "s3:PutObject",
  310. "s3:DeleteObject",
  311. "s3:AbortMultipartUpload",
  312. "s3:ListMultipartUploadParts"
  313. ],
  314. "Effect": "Allow",
  315. "Resource": [
  316. "arn:aws:s3:::snaps.example.com/*"
  317. ]
  318. }
  319. ],
  320. "Version": "2012-10-17"
  321. }
  322. ----
  323. // NOTCONSOLE
  324. You may further restrict the permissions by specifying a prefix within the
  325. bucket, in this example, named "foo".
  326. [source,js]
  327. ----
  328. {
  329. "Statement": [
  330. {
  331. "Action": [
  332. "s3:ListBucket",
  333. "s3:GetBucketLocation",
  334. "s3:ListBucketMultipartUploads",
  335. "s3:ListBucketVersions"
  336. ],
  337. "Condition": {
  338. "StringLike": {
  339. "s3:prefix": [
  340. "foo/*"
  341. ]
  342. }
  343. },
  344. "Effect": "Allow",
  345. "Resource": [
  346. "arn:aws:s3:::snaps.example.com"
  347. ]
  348. },
  349. {
  350. "Action": [
  351. "s3:GetObject",
  352. "s3:PutObject",
  353. "s3:DeleteObject",
  354. "s3:AbortMultipartUpload",
  355. "s3:ListMultipartUploadParts"
  356. ],
  357. "Effect": "Allow",
  358. "Resource": [
  359. "arn:aws:s3:::snaps.example.com/foo/*"
  360. ]
  361. }
  362. ],
  363. "Version": "2012-10-17"
  364. }
  365. ----
  366. // NOTCONSOLE
  367. The bucket needs to exist to register a repository for snapshots. If you did not
  368. create the bucket then the repository registration will fail.
  369. ===== Cleaning up multi-part uploads
  370. {es} uses S3's multi-part upload process to upload larger blobs to the
  371. repository. The multi-part upload process works by dividing each blob into
  372. smaller parts, uploading each part independently, and then completing the
  373. upload in a separate step. This reduces the amount of data that {es} must
  374. re-send if an upload fails: {es} only needs to re-send the part that failed
  375. rather than starting from the beginning of the whole blob. The storage for each
  376. part is charged independently starting from the time at which the part was
  377. uploaded.
  378. If a multi-part upload cannot be completed then it must be aborted in order to
  379. delete any parts that were successfully uploaded, preventing further storage
  380. charges from accumulating. {es} will automatically abort a multi-part upload on
  381. failure, but sometimes the abort request itself fails. For example, if the
  382. repository becomes inaccessible or the instance on which {es} is running is
  383. terminated abruptly then {es} cannot complete or abort any ongoing uploads.
  384. You must make sure that failed uploads are eventually aborted to avoid
  385. unnecessary storage costs. You can use the
  386. https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListMultipartUploads.html[List
  387. multipart uploads API] to list the ongoing uploads and look for any which are
  388. unusually long-running, or you can
  389. https://docs.aws.amazon.com/AmazonS3/latest/userguide/mpu-abort-incomplete-mpu-lifecycle-config.html[configure
  390. a bucket lifecycle policy] to automatically abort incomplete uploads once they
  391. reach a certain age.
  392. [[repository-s3-aws-vpc]]
  393. [discrete]
  394. ==== AWS VPC Bandwidth Settings
  395. AWS instances resolve S3 endpoints to a public IP. If the Elasticsearch
  396. instances reside in a private subnet in an AWS VPC then all traffic to S3 will
  397. go through the VPC's NAT instance. If your VPC's NAT instance is a smaller
  398. instance size (e.g. a t2.micro) or is handling a high volume of network traffic
  399. your bandwidth to S3 may be limited by that NAT instance's networking bandwidth
  400. limitations. Instead we recommend creating a https://docs.aws.amazon.com/vpc/latest/userguide/vpc-endpoints.html[VPC endpoint]
  401. that enables connecting to S3 in instances that reside in a private subnet in
  402. an AWS VPC. This will eliminate any limitations imposed by the network
  403. bandwidth of your VPC's NAT instance.
  404. Instances residing in a public subnet in an AWS VPC will connect to S3 via the
  405. VPC's internet gateway and not be bandwidth limited by the VPC's NAT instance.