repository-s3.asciidoc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. [[repository-s3]]
  2. === S3 repository
  3. You can use AWS S3 as a repository for {ref}/modules-snapshots.html[Snapshot/Restore].
  4. *If you are looking for a hosted solution of Elasticsearch on AWS, please visit
  5. https://www.elastic.co/cloud/.*
  6. [[repository-s3-usage]]
  7. ==== Getting started
  8. To register an S3 repository, specify the type as `s3` when creating
  9. the repository. The repository defaults to using
  10. https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html[ECS
  11. IAM Role] credentials for authentication. You can also use <<iam-kubernetes-service-accounts>> Kubernetes service accounts.
  12. The only mandatory setting is the bucket name:
  13. [source,console]
  14. ----
  15. PUT _snapshot/my_s3_repository
  16. {
  17. "type": "s3",
  18. "settings": {
  19. "bucket": "my-bucket"
  20. }
  21. }
  22. ----
  23. // TEST[skip:we don't have s3 setup while testing this]
  24. [[repository-s3-client]]
  25. ==== Client settings
  26. The client that you use to connect to S3 has a number of settings available.
  27. The settings have the form `s3.client.CLIENT_NAME.SETTING_NAME`. By default,
  28. `s3` repositories use a client named `default`, but this can be modified using
  29. the <<repository-s3-repository,repository setting>> `client`. For example:
  30. [source,console]
  31. ----
  32. PUT _snapshot/my_s3_repository
  33. {
  34. "type": "s3",
  35. "settings": {
  36. "bucket": "my-bucket",
  37. "client": "my-alternate-client"
  38. }
  39. }
  40. ----
  41. // TEST[skip:we don't have S3 setup while testing this]
  42. Most client settings can be added to the `elasticsearch.yml` configuration file
  43. with the exception of the secure settings, which you add to the {es} keystore.
  44. For more information about creating and updating the {es} keystore, see
  45. {ref}/secure-settings.html[Secure settings].
  46. For example, if you want to use specific credentials to access S3 then run the
  47. following commands to add these credentials to the keystore:
  48. [source,sh]
  49. ----
  50. bin/elasticsearch-keystore add s3.client.default.access_key
  51. bin/elasticsearch-keystore add s3.client.default.secret_key
  52. # a session token is optional so the following command may not be needed
  53. bin/elasticsearch-keystore add s3.client.default.session_token
  54. ----
  55. If instead you want to use the instance role or container role to access S3
  56. then you should leave these settings unset. You can switch from using specific
  57. credentials back to the default of using the instance role or container role by
  58. removing these settings from the keystore as follows:
  59. [source,sh]
  60. ----
  61. bin/elasticsearch-keystore remove s3.client.default.access_key
  62. bin/elasticsearch-keystore remove s3.client.default.secret_key
  63. # a session token is optional so the following command may not be needed
  64. bin/elasticsearch-keystore remove s3.client.default.session_token
  65. ----
  66. *All* client secure settings of this repository type are
  67. {ref}/secure-settings.html#reloadable-secure-settings[reloadable]. After you
  68. reload the settings, the internal `s3` clients, used to transfer the snapshot
  69. contents, will utilize the latest settings from the keystore. Any existing `s3`
  70. repositories, as well as any newly created ones, will pick up the new values
  71. stored in the keystore.
  72. NOTE: In-progress snapshot/restore tasks will not be preempted by a *reload* of
  73. the client's secure settings. The task will complete using the client as it was
  74. built when the operation started.
  75. The following list contains the available client settings. Those that must be
  76. stored in the keystore are marked as "secure" and are *reloadable*; the other
  77. settings belong in the `elasticsearch.yml` file.
  78. `access_key` ({ref}/secure-settings.html[Secure], {ref}/secure-settings.html#reloadable-secure-settings[reloadable])::
  79. An S3 access key. If set, the `secret_key` setting must also be specified.
  80. If unset, the client will use the instance or container role instead.
  81. `secret_key` ({ref}/secure-settings.html[Secure], {ref}/secure-settings.html#reloadable-secure-settings[reloadable])::
  82. An S3 secret key. If set, the `access_key` setting must also be specified.
  83. `session_token` ({ref}/secure-settings.html[Secure], {ref}/secure-settings.html#reloadable-secure-settings[reloadable])::
  84. An S3 session token. If set, the `access_key` and `secret_key` settings
  85. must also be specified.
  86. `endpoint`::
  87. The S3 service endpoint to connect to. This defaults to `s3.amazonaws.com`
  88. but the
  89. https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region[AWS
  90. documentation] lists alternative S3 endpoints. If you are using an
  91. <<repository-s3-compatible-services,S3-compatible service>> then you should
  92. set this to the service's endpoint.
  93. `protocol`::
  94. The protocol to use to connect to S3. Valid values are either `http` or
  95. `https`. Defaults to `https`. When using HTTPS, this repository type validates the
  96. repository's certificate chain using the JVM-wide truststore. Ensure that
  97. the root certificate authority is in this truststore using the JVM's
  98. `keytool` tool.
  99. `proxy.host`::
  100. The host name of a proxy to connect to S3 through.
  101. `proxy.port`::
  102. The port of a proxy to connect to S3 through.
  103. `proxy.username` ({ref}/secure-settings.html[Secure], {ref}/secure-settings.html#reloadable-secure-settings[reloadable])::
  104. The username to connect to the `proxy.host` with.
  105. `proxy.password` ({ref}/secure-settings.html[Secure], {ref}/secure-settings.html#reloadable-secure-settings[reloadable])::
  106. The password to connect to the `proxy.host` with.
  107. `read_timeout`::
  108. The socket timeout for connecting to S3. The value should specify the unit.
  109. For example, a value of `5s` specifies a 5 second timeout. The default value
  110. is 50 seconds.
  111. `max_retries`::
  112. The number of retries to use when an S3 request fails. The default value is
  113. `3`.
  114. `use_throttle_retries`::
  115. Whether retries should be throttled (i.e. should back off). Must be `true`
  116. or `false`. Defaults to `true`.
  117. `path_style_access`::
  118. Whether to force the use of the path style access pattern. If `true`, the
  119. path style access pattern will be used. If `false`, the access pattern will
  120. be automatically determined by the AWS Java SDK (See
  121. https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/AmazonS3Builder.html#setPathStyleAccessEnabled-java.lang.Boolean-[AWS
  122. documentation] for details). Defaults to `false`.
  123. [[repository-s3-path-style-deprecation]]
  124. NOTE: In versions `7.0`, `7.1`, `7.2` and `7.3` all bucket operations used the
  125. https://aws.amazon.com/blogs/aws/amazon-s3-path-deprecation-plan-the-rest-of-the-story/[now-deprecated]
  126. path style access pattern. If your deployment requires the path style access
  127. pattern then you should set this setting to `true` when upgrading.
  128. `disable_chunked_encoding`::
  129. Whether chunked encoding should be disabled or not. If `false`, chunked
  130. encoding is enabled and will be used where appropriate. If `true`, chunked
  131. encoding is disabled and will not be used, which may mean that snapshot
  132. operations consume more resources and take longer to complete. It should
  133. only be set to `true` if you are using a storage service that does not
  134. support chunked encoding. See the
  135. https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/AmazonS3Builder.html#disableChunkedEncoding--[AWS
  136. Java SDK documentation] for details. Defaults to `false`.
  137. `region`::
  138. Allows specifying the signing region to use. Specificing this setting manually should not be necessary for most use cases. Generally,
  139. the SDK will correctly guess the signing region to use. It should be considered an expert level setting to support S3-compatible APIs
  140. that require https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html[v4 signatures] and use a region other than the
  141. default `us-east-1`. Defaults to empty string which means that the SDK will try to automatically determine the correct signing region.
  142. `signer_override`::
  143. Allows specifying the name of the signature algorithm to use for signing requests by the S3 client. Specifying this setting should not
  144. be necessary for most use cases. It should be considered an expert level setting to support S3-compatible APIs that do not support the
  145. signing algorithm that the SDK automatically determines for them.
  146. See the
  147. https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/ClientConfiguration.html#setSignerOverride-java.lang.String-[AWS
  148. Java SDK documentation] for details. Defaults to empty string which means that no signing algorithm override will be used.
  149. [discrete]
  150. [[repository-s3-compatible-services]]
  151. ===== S3-compatible services
  152. There are a number of storage systems that provide an S3-compatible API, and
  153. the `repository-s3` type allows you to use these systems in place of AWS S3.
  154. To do so, you should set the `s3.client.CLIENT_NAME.endpoint` setting to the
  155. system's endpoint. This setting accepts IP addresses and hostnames and may
  156. include a port. For example, the endpoint may be `172.17.0.2` or
  157. `172.17.0.2:9000`.
  158. By default {es} communicates with your storage system using HTTPS, and
  159. validates the repository's certificate chain using the JVM-wide truststore.
  160. Ensure that the JVM-wide truststore includes an entry for your repository. If
  161. you wish to use unsecured HTTP communication instead of HTTPS, set
  162. `s3.client.CLIENT_NAME.protocol` to `http`.
  163. https://minio.io[MinIO] is an example of a storage system that provides an
  164. S3-compatible API. The `repository-s3` type allows {es} to work with
  165. MinIO-backed repositories as well as repositories stored on AWS S3. Other
  166. S3-compatible storage systems may also work with {es}, but these are not
  167. covered by the {es} test suite.
  168. Note that some storage systems claim to be S3-compatible but do not faithfully
  169. emulate S3's behaviour in full. The `repository-s3` type requires full
  170. compatibility with S3. In particular it must support the same set of API
  171. endpoints, return the same errors in case of failures, and offer consistency
  172. and performance at least as good as S3 even when accessed concurrently by
  173. multiple nodes. Incompatible error codes, consistency or performance may be
  174. particularly hard to track down since errors, consistency failures, and
  175. performance issues are usually rare and hard to reproduce.
  176. You can perform some basic checks of the suitability of your storage system
  177. using the {ref}/repo-analysis-api.html[repository analysis API]. If this API
  178. does not complete successfully, or indicates poor performance, then your
  179. storage system is not fully compatible with AWS S3 and therefore unsuitable for
  180. use as a snapshot repository. You will need to work with the supplier of your
  181. storage system to address any incompatibilities you encounter.
  182. [[repository-s3-repository]]
  183. ==== Repository settings
  184. The `s3` repository type supports a number of settings to customize how data is
  185. stored in S3. These can be specified when creating the repository. For example:
  186. [source,console]
  187. ----
  188. PUT _snapshot/my_s3_repository
  189. {
  190. "type": "s3",
  191. "settings": {
  192. "bucket": "my-bucket",
  193. "another_setting": "setting-value"
  194. }
  195. }
  196. ----
  197. // TEST[skip:we don't have S3 set up while testing this]
  198. The following settings are supported:
  199. `bucket`::
  200. (Required)
  201. Name of the S3 bucket to use for snapshots.
  202. +
  203. The bucket name must adhere to Amazon's
  204. https://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html#bucketnamingrules[S3
  205. bucket naming rules].
  206. `client`::
  207. The name of the <<repository-s3-client,S3 client>> to use to connect to S3.
  208. Defaults to `default`.
  209. `base_path`::
  210. Specifies the path to the repository data within its bucket. Defaults to an
  211. empty string, meaning that the repository is at the root of the bucket. The
  212. value of this setting should not start or end with a `/`.
  213. +
  214. NOTE: Don't set `base_path` when configuring a snapshot repository for {ECE}.
  215. {ECE} automatically generates the `base_path` for each deployment so that
  216. multiple deployments may share the same bucket.
  217. `chunk_size`::
  218. Big files can be broken down into chunks during snapshotting if needed.
  219. Specify the chunk size as a value and unit, for example:
  220. `1TB`, `1GB`, `10MB`. Defaults to the maximum size of a blob in the S3 which is `5TB`.
  221. `compress`::
  222. When set to `true` metadata files are stored in compressed format. This
  223. setting doesn't affect index files that are already compressed by default.
  224. Defaults to `true`.
  225. include::repository-shared-settings.asciidoc[]
  226. `server_side_encryption`::
  227. When set to `true` files are encrypted on server side using AES256
  228. algorithm. Defaults to `false`.
  229. `buffer_size`::
  230. Minimum threshold below which the chunk is uploaded using a single request.
  231. Beyond this threshold, the S3 repository will use the
  232. https://docs.aws.amazon.com/AmazonS3/latest/dev/uploadobjusingmpu.html[AWS
  233. Multipart Upload API] to split the chunk into several parts, each of
  234. `buffer_size` length, and to upload each part in its own request. Note that
  235. setting a buffer size lower than `5mb` is not allowed since it will prevent
  236. the use of the Multipart API and may result in upload errors. It is also not
  237. possible to set a buffer size greater than `5gb` as it is the maximum upload
  238. size allowed by S3. Defaults to `100mb` or `5%` of JVM heap, whichever is
  239. smaller.
  240. `canned_acl`::
  241. The S3 repository supports all
  242. https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl[S3
  243. canned ACLs] : `private`, `public-read`, `public-read-write`,
  244. `authenticated-read`, `log-delivery-write`, `bucket-owner-read`,
  245. `bucket-owner-full-control`. Defaults to `private`. You could specify a
  246. canned ACL using the `canned_acl` setting. When the S3 repository creates
  247. buckets and objects, it adds the canned ACL into the buckets and objects.
  248. `storage_class`::
  249. Sets the S3 storage class for objects stored in the snapshot repository.
  250. Values may be `standard`, `reduced_redundancy`, `standard_ia`, `onezone_ia`
  251. and `intelligent_tiering`. Defaults to `standard`. Changing this setting on
  252. an existing repository only affects the storage class for newly created
  253. objects, resulting in a mixed usage of storage classes. You may use an S3
  254. Lifecycle Policy to adjust the storage class of existing objects in your
  255. repository, but you must not transition objects to Glacier classes and you
  256. must not expire objects. If you use Glacier storage classes or object
  257. expiry then you may permanently lose access to your repository contents.
  258. For more information about S3 storage classes, see
  259. https://docs.aws.amazon.com/AmazonS3/latest/dev/storage-class-intro.html[AWS
  260. Storage Classes Guide]
  261. NOTE: The option of defining client settings in the repository settings as
  262. documented below is considered deprecated, and will be removed in a future
  263. version.
  264. In addition to the above settings, you may also specify all non-secure client
  265. settings in the repository settings. In this case, the client settings found in
  266. the repository settings will be merged with those of the named client used by
  267. the repository. Conflicts between client and repository settings are resolved
  268. by the repository settings taking precedence over client settings.
  269. For example:
  270. [source,console]
  271. ----
  272. PUT _snapshot/my_s3_repository
  273. {
  274. "type": "s3",
  275. "settings": {
  276. "client": "my-client",
  277. "bucket": "my-bucket",
  278. "endpoint": "my.s3.endpoint"
  279. }
  280. }
  281. ----
  282. // TEST[skip:we don't have s3 set up while testing this]
  283. This sets up a repository that uses all client settings from the client
  284. `my_client_name` except for the `endpoint` that is overridden to
  285. `my.s3.endpoint` by the repository settings.
  286. [[repository-s3-permissions]]
  287. ===== Recommended S3 permissions
  288. In order to restrict the Elasticsearch snapshot process to the minimum required
  289. resources, we recommend using Amazon IAM in conjunction with pre-existing S3
  290. buckets. Here is an example policy which will allow the snapshot access to an S3
  291. bucket named "snaps.example.com". This may be configured through the AWS IAM
  292. console, by creating a Custom Policy, and using a Policy Document similar to
  293. this (changing snaps.example.com to your bucket name).
  294. [source,js]
  295. ----
  296. {
  297. "Statement": [
  298. {
  299. "Action": [
  300. "s3:ListBucket",
  301. "s3:GetBucketLocation",
  302. "s3:ListBucketMultipartUploads",
  303. "s3:ListBucketVersions"
  304. ],
  305. "Effect": "Allow",
  306. "Resource": [
  307. "arn:aws:s3:::snaps.example.com"
  308. ]
  309. },
  310. {
  311. "Action": [
  312. "s3:GetObject",
  313. "s3:PutObject",
  314. "s3:DeleteObject",
  315. "s3:AbortMultipartUpload",
  316. "s3:ListMultipartUploadParts"
  317. ],
  318. "Effect": "Allow",
  319. "Resource": [
  320. "arn:aws:s3:::snaps.example.com/*"
  321. ]
  322. }
  323. ],
  324. "Version": "2012-10-17"
  325. }
  326. ----
  327. // NOTCONSOLE
  328. You may further restrict the permissions by specifying a prefix within the
  329. bucket, in this example, named "foo".
  330. [source,js]
  331. ----
  332. {
  333. "Statement": [
  334. {
  335. "Action": [
  336. "s3:ListBucket",
  337. "s3:GetBucketLocation",
  338. "s3:ListBucketMultipartUploads",
  339. "s3:ListBucketVersions"
  340. ],
  341. "Condition": {
  342. "StringLike": {
  343. "s3:prefix": [
  344. "foo/*"
  345. ]
  346. }
  347. },
  348. "Effect": "Allow",
  349. "Resource": [
  350. "arn:aws:s3:::snaps.example.com"
  351. ]
  352. },
  353. {
  354. "Action": [
  355. "s3:GetObject",
  356. "s3:PutObject",
  357. "s3:DeleteObject",
  358. "s3:AbortMultipartUpload",
  359. "s3:ListMultipartUploadParts"
  360. ],
  361. "Effect": "Allow",
  362. "Resource": [
  363. "arn:aws:s3:::snaps.example.com/foo/*"
  364. ]
  365. }
  366. ],
  367. "Version": "2012-10-17"
  368. }
  369. ----
  370. // NOTCONSOLE
  371. The bucket needs to exist to register a repository for snapshots. If you did not
  372. create the bucket then the repository registration will fail.
  373. ===== Cleaning up multi-part uploads
  374. {es} uses S3's multi-part upload process to upload larger blobs to the
  375. repository. The multi-part upload process works by dividing each blob into
  376. smaller parts, uploading each part independently, and then completing the
  377. upload in a separate step. This reduces the amount of data that {es} must
  378. re-send if an upload fails: {es} only needs to re-send the part that failed
  379. rather than starting from the beginning of the whole blob. The storage for each
  380. part is charged independently starting from the time at which the part was
  381. uploaded.
  382. If a multi-part upload cannot be completed then it must be aborted in order to
  383. delete any parts that were successfully uploaded, preventing further storage
  384. charges from accumulating. {es} will automatically abort a multi-part upload on
  385. failure, but sometimes the abort request itself fails. For example, if the
  386. repository becomes inaccessible or the instance on which {es} is running is
  387. terminated abruptly then {es} cannot complete or abort any ongoing uploads.
  388. You must make sure that failed uploads are eventually aborted to avoid
  389. unnecessary storage costs. You can use the
  390. https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListMultipartUploads.html[List
  391. multipart uploads API] to list the ongoing uploads and look for any which are
  392. unusually long-running, or you can
  393. https://docs.aws.amazon.com/AmazonS3/latest/userguide/mpu-abort-incomplete-mpu-lifecycle-config.html[configure
  394. a bucket lifecycle policy] to automatically abort incomplete uploads once they
  395. reach a certain age.
  396. [[repository-s3-aws-vpc]]
  397. [discrete]
  398. ==== AWS VPC bandwidth settings
  399. AWS instances resolve S3 endpoints to a public IP. If the Elasticsearch
  400. instances reside in a private subnet in an AWS VPC then all traffic to S3 will
  401. go through the VPC's NAT instance. If your VPC's NAT instance is a smaller
  402. instance size (e.g. a t2.micro) or is handling a high volume of network traffic
  403. your bandwidth to S3 may be limited by that NAT instance's networking bandwidth
  404. limitations. Instead we recommend creating a https://docs.aws.amazon.com/vpc/latest/userguide/vpc-endpoints.html[VPC endpoint]
  405. that enables connecting to S3 in instances that reside in a private subnet in
  406. an AWS VPC. This will eliminate any limitations imposed by the network
  407. bandwidth of your VPC's NAT instance.
  408. Instances residing in a public subnet in an AWS VPC will connect to S3 via the
  409. VPC's internet gateway and not be bandwidth limited by the VPC's NAT instance.
  410. [[iam-kubernetes-service-accounts]]
  411. [discrete]
  412. ==== Using IAM roles for Kubernetes service accounts for authentication
  413. If you want to use https://aws.amazon.com/blogs/opensource/introducing-fine-grained-iam-roles-service-accounts/[Kubernetes service accounts]
  414. for authentication, you need to add a symlink to the `$AWS_WEB_IDENTITY_TOKEN_FILE` environment variable
  415. (which should be automatically set by a Kubernetes pod) in the S3 repository config directory, so the repository
  416. can have the read access for the service account (a repository can't read any files outside its config directory).
  417. For example:
  418. [source,bash]
  419. ----
  420. mkdir -p "${ES_PATH_CONF}/repository-s3"
  421. ln -s $AWS_WEB_IDENTITY_TOKEN_FILE "${ES_PATH_CONF}/repository-s3/aws-web-identity-token-file"
  422. ----
  423. IMPORTANT: The symlink must be created on all data and master eligible nodes and be readable
  424. by the `elasticsearch` user. By default, {es} runs as user `elasticsearch` using uid:gid `1000:0`.
  425. If the symlink exists, it will be used by default by all S3 repositories that don't have explicit `client` credentials.