repository-s3.asciidoc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  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`.
  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. `region`::
  140. Allows specifying the signing region to use. Specificing this setting manually should not be necessary for most use cases. Generally,
  141. the SDK will correctly guess the signing region to use. It should be considered an expert level setting to support S3-compatible APIs
  142. that require https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html[v4 signatures] and use a region other than the
  143. default `us-east-1`. Defaults to empty string which means that the SDK will try to automatically determine the correct signing region.
  144. `signer_override`::
  145. Allows specifying the name of the signature algorithm to use for signing requests by the S3 client. Specifying this setting should not
  146. be necessary for most use cases. It should be considered an expert level setting to support S3-compatible APIs that do not support the
  147. signing algorithm that the SDK automatically determines for them.
  148. See the
  149. https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/ClientConfiguration.html#setSignerOverride-java.lang.String-[AWS
  150. Java SDK documentation] for details. Defaults to empty string which means that no signing algorithm override will be used.
  151. [discrete]
  152. [[repository-s3-compatible-services]]
  153. ===== S3-compatible services
  154. There are a number of storage systems that provide an S3-compatible API, and
  155. the `repository-s3` plugin allows you to use these systems in place of AWS S3.
  156. To do so, you should set the `s3.client.CLIENT_NAME.endpoint` setting to the
  157. system's endpoint. This setting accepts IP addresses and hostnames and may
  158. include a port. For example, the endpoint may be `172.17.0.2` or
  159. `172.17.0.2:9000`. You may also need to set `s3.client.CLIENT_NAME.protocol` to
  160. `http` if the endpoint does not support HTTPS.
  161. https://minio.io[Minio] is an example of a storage system that provides an
  162. S3-compatible API. The `repository-s3` plugin allows {es} to work with
  163. Minio-backed repositories as well as repositories stored on AWS S3. Other
  164. S3-compatible storage systems may also work with {es}, but these are not tested
  165. or supported.
  166. [[repository-s3-repository]]
  167. ==== Repository Settings
  168. The `s3` repository type supports a number of settings to customize how data is
  169. stored in S3. These can be specified when creating the repository. For example:
  170. [source,console]
  171. ----
  172. PUT _snapshot/my_s3_repository
  173. {
  174. "type": "s3",
  175. "settings": {
  176. "bucket": "my_bucket_name",
  177. "another_setting": "setting_value"
  178. }
  179. }
  180. ----
  181. // TEST[skip:we don't have S3 set up while testing this]
  182. The following settings are supported:
  183. `bucket`::
  184. The name of the bucket to be used for snapshots. (Mandatory)
  185. `client`::
  186. The name of the <<repository-s3-client,S3 client>> to use to connect to S3.
  187. Defaults to `default`.
  188. `base_path`::
  189. Specifies the path within bucket to repository data. Defaults to value of
  190. `repositories.s3.base_path` or to root directory if not set. Previously,
  191. the base_path could take a leading `/` (forward slash). However, this has
  192. been deprecated and setting the base_path now should omit the leading `/`.
  193. `chunk_size`::
  194. Big files can be broken down into chunks during snapshotting if needed.
  195. Specify the chunk size as a value and unit, for example:
  196. `1GB`, `10MB`, `5KB`, `500B`. Defaults to `1GB`.
  197. `compress`::
  198. When set to `true` metadata files are stored in compressed format. This
  199. setting doesn't affect index files that are already compressed by default.
  200. Defaults to `true`.
  201. include::repository-shared-settings.asciidoc[]
  202. `server_side_encryption`::
  203. When set to `true` files are encrypted on server side using AES256
  204. algorithm. Defaults to `false`.
  205. `buffer_size`::
  206. Minimum threshold below which the chunk is uploaded using a single request.
  207. Beyond this threshold, the S3 repository will use the
  208. https://docs.aws.amazon.com/AmazonS3/latest/dev/uploadobjusingmpu.html[AWS
  209. Multipart Upload API] to split the chunk into several parts, each of
  210. `buffer_size` length, and to upload each part in its own request. Note that
  211. setting a buffer size lower than `5mb` is not allowed since it will prevent
  212. the use of the Multipart API and may result in upload errors. It is also not
  213. possible to set a buffer size greater than `5gb` as it is the maximum upload
  214. size allowed by S3. Defaults to the minimum between `100mb` and `5%` of the
  215. heap size.
  216. `canned_acl`::
  217. The S3 repository supports all
  218. https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl[S3
  219. canned ACLs] : `private`, `public-read`, `public-read-write`,
  220. `authenticated-read`, `log-delivery-write`, `bucket-owner-read`,
  221. `bucket-owner-full-control`. Defaults to `private`. You could specify a
  222. canned ACL using the `canned_acl` setting. When the S3 repository creates
  223. buckets and objects, it adds the canned ACL into the buckets and objects.
  224. `storage_class`::
  225. Sets the S3 storage class for objects stored in the snapshot repository.
  226. Values may be `standard`, `reduced_redundancy`, `standard_ia`, `onezone_ia`
  227. and `intelligent_tiering`. Defaults to `standard`.
  228. Changing this setting on an existing repository only affects the
  229. storage class for newly created objects, resulting in a mixed usage of
  230. storage classes. Additionally, S3 Lifecycle Policies can be used to manage
  231. the storage class of existing objects. Due to the extra complexity with the
  232. Glacier class lifecycle, it is not currently supported by the plugin. For
  233. more information about the different classes, see
  234. https://docs.aws.amazon.com/AmazonS3/latest/dev/storage-class-intro.html[AWS
  235. Storage Classes Guide]
  236. NOTE: The option of defining client settings in the repository settings as
  237. documented below is considered deprecated, and will be removed in a future
  238. version.
  239. In addition to the above settings, you may also specify all non-secure client
  240. settings in the repository settings. In this case, the client settings found in
  241. the repository settings will be merged with those of the named client used by
  242. the repository. Conflicts between client and repository settings are resolved
  243. by the repository settings taking precedence over client settings.
  244. For example:
  245. [source,console]
  246. ----
  247. PUT _snapshot/my_s3_repository
  248. {
  249. "type": "s3",
  250. "settings": {
  251. "client": "my_client_name",
  252. "bucket": "my_bucket_name",
  253. "endpoint": "my.s3.endpoint"
  254. }
  255. }
  256. ----
  257. // TEST[skip:we don't have s3 set up while testing this]
  258. This sets up a repository that uses all client settings from the client
  259. `my_client_name` except for the `endpoint` that is overridden to
  260. `my.s3.endpoint` by the repository settings.
  261. [[repository-s3-permissions]]
  262. ===== Recommended S3 Permissions
  263. In order to restrict the Elasticsearch snapshot process to the minimum required
  264. resources, we recommend using Amazon IAM in conjunction with pre-existing S3
  265. buckets. Here is an example policy which will allow the snapshot access to an S3
  266. bucket named "snaps.example.com". This may be configured through the AWS IAM
  267. console, by creating a Custom Policy, and using a Policy Document similar to
  268. this (changing snaps.example.com to your bucket name).
  269. [source,js]
  270. ----
  271. {
  272. "Statement": [
  273. {
  274. "Action": [
  275. "s3:ListBucket",
  276. "s3:GetBucketLocation",
  277. "s3:ListBucketMultipartUploads",
  278. "s3:ListBucketVersions"
  279. ],
  280. "Effect": "Allow",
  281. "Resource": [
  282. "arn:aws:s3:::snaps.example.com"
  283. ]
  284. },
  285. {
  286. "Action": [
  287. "s3:GetObject",
  288. "s3:PutObject",
  289. "s3:DeleteObject",
  290. "s3:AbortMultipartUpload",
  291. "s3:ListMultipartUploadParts"
  292. ],
  293. "Effect": "Allow",
  294. "Resource": [
  295. "arn:aws:s3:::snaps.example.com/*"
  296. ]
  297. }
  298. ],
  299. "Version": "2012-10-17"
  300. }
  301. ----
  302. // NOTCONSOLE
  303. You may further restrict the permissions by specifying a prefix within the
  304. bucket, in this example, named "foo".
  305. [source,js]
  306. ----
  307. {
  308. "Statement": [
  309. {
  310. "Action": [
  311. "s3:ListBucket",
  312. "s3:GetBucketLocation",
  313. "s3:ListBucketMultipartUploads",
  314. "s3:ListBucketVersions"
  315. ],
  316. "Condition": {
  317. "StringLike": {
  318. "s3:prefix": [
  319. "foo/*"
  320. ]
  321. }
  322. },
  323. "Effect": "Allow",
  324. "Resource": [
  325. "arn:aws:s3:::snaps.example.com"
  326. ]
  327. },
  328. {
  329. "Action": [
  330. "s3:GetObject",
  331. "s3:PutObject",
  332. "s3:DeleteObject",
  333. "s3:AbortMultipartUpload",
  334. "s3:ListMultipartUploadParts"
  335. ],
  336. "Effect": "Allow",
  337. "Resource": [
  338. "arn:aws:s3:::snaps.example.com/foo/*"
  339. ]
  340. }
  341. ],
  342. "Version": "2012-10-17"
  343. }
  344. ----
  345. // NOTCONSOLE
  346. The bucket needs to exist to register a repository for snapshots. If you did not
  347. create the bucket then the repository registration will fail.
  348. [[repository-s3-aws-vpc]]
  349. [discrete]
  350. ==== AWS VPC Bandwidth Settings
  351. AWS instances resolve S3 endpoints to a public IP. If the Elasticsearch
  352. instances reside in a private subnet in an AWS VPC then all traffic to S3 will
  353. go through that VPC's NAT instance. If your VPC's NAT instance is a smaller
  354. instance size (e.g. a t1.micro) or is handling a high volume of network traffic
  355. your bandwidth to S3 may be limited by that NAT instance's networking bandwidth
  356. limitations.
  357. Instances residing in a public subnet in an AWS VPC will connect to S3 via the
  358. VPC's internet gateway and not be bandwidth limited by the VPC's NAT instance.