repository-s3.asciidoc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. [[repository-s3]]
  2. === S3 Repository Plugin
  3. The S3 repository plugin adds support for using 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 http://www.elastic.co/cloud.*
  6. :plugin_name: repository-s3
  7. include::install_remove.asciidoc[]
  8. [[repository-s3-usage]]
  9. ==== Getting started with AWS
  10. The plugin will default to using
  11. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html[IAM Role]
  12. credentials for authentication. These can be overridden by, in increasing
  13. order of precedence, system properties `aws.accessKeyId` and `aws.secretKey`,
  14. environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_KEY`, or the
  15. elasticsearch config using `cloud.aws.access_key` and `cloud.aws.secret_key` or
  16. if you wish to set credentials specifically for s3 `cloud.aws.s3.access_key` and `cloud.aws.s3.secret_key`:
  17. [source,yaml]
  18. ----
  19. cloud:
  20. aws:
  21. access_key: AKVAIQBF2RECL7FJWGJQ
  22. secret_key: vExyMThREXeRMm/b/LRzEB8jWwvzQeXgjqMX+6br
  23. ----
  24. [[repository-s3-usage-security]]
  25. ===== Transport security
  26. By default this plugin uses HTTPS for all API calls to AWS endpoints. If you wish to configure HTTP you can set
  27. `cloud.aws.protocol` in the elasticsearch config. You can optionally override this setting per individual service
  28. via: `cloud.aws.ec2.protocol` or `cloud.aws.s3.protocol`.
  29. [source,yaml]
  30. ----
  31. cloud:
  32. aws:
  33. protocol: https
  34. s3:
  35. protocol: http
  36. ec2:
  37. protocol: https
  38. ----
  39. In addition, a proxy can be configured with the `proxy.host`, `proxy.port`, `proxy.username` and `proxy.password` settings
  40. (note that protocol can be `http` or `https`):
  41. [source,yaml]
  42. ----
  43. cloud:
  44. aws:
  45. protocol: https
  46. proxy:
  47. host: proxy1.company.com
  48. port: 8083
  49. username: myself
  50. password: theBestPasswordEver!
  51. ----
  52. You can also set different proxies for `ec2` and `s3`:
  53. [source,yaml]
  54. ----
  55. cloud:
  56. aws:
  57. s3:
  58. proxy:
  59. host: proxy1.company.com
  60. port: 8083
  61. username: myself1
  62. password: theBestPasswordEver1!
  63. ec2:
  64. proxy:
  65. host: proxy2.company.com
  66. port: 8083
  67. username: myself2
  68. password: theBestPasswordEver2!
  69. ----
  70. [[repository-s3-usage-region]]
  71. ===== Region
  72. The `cloud.aws.region` can be set to a region and will automatically use the relevant settings for both `ec2` and `s3`.
  73. You can specifically set it for s3 only using `cloud.aws.s3.region`.
  74. The available values are:
  75. * `us-east` (`us-east-1`) for US East (N. Virginia)
  76. * `us-east-2` for US East (Ohio)
  77. * `us-west` (`us-west-1`) for US West (N. California)
  78. * `us-west-2` for US West (Oregon)
  79. * `ap-south` (`ap-south-1`) for Asia Pacific (Mumbai)
  80. * `ap-southeast` (`ap-southeast-1`) for Asia Pacific (Singapore)
  81. * `ap-southeast-2` for Asia Pacific (Sydney)
  82. * `ap-northeast` (`ap-northeast-1`) for Asia Pacific (Tokyo)
  83. * `ap-northeast-2` (`ap-northeast-2`) for Asia Pacific (Seoul)
  84. * `eu-west` (`eu-west-1`) for EU (Ireland)
  85. * `eu-west-2` (`eu-west-2`) for EU (London)
  86. * `eu-central` (`eu-central-1`) for EU (Frankfurt)
  87. * `sa-east` (`sa-east-1`) for South America (São Paulo)
  88. * `cn-north` (`cn-north-1`) for China (Beijing)
  89. * `ca-central` (`ca-central-1`) for Canada (Central)
  90. [[repository-s3-usage-signer]]
  91. ===== S3 Signer API
  92. If you are using a S3 compatible service, they might be using an older API to sign the requests.
  93. You can set your compatible signer API using `cloud.aws.signer` (or `cloud.aws.s3.signer`) with the right
  94. signer to use.
  95. If you are using a compatible S3 service which do not support Version 4 signing process, you may need to
  96. use `S3SignerType`, which is Signature Version 2.
  97. ===== Read timeout
  98. Read timeout determines the amount of time to wait for data to be transferred over an established,
  99. open connection before the connection is timed out. Defaults to AWS SDK default value (`50s`).
  100. It can be configured with `cloud.aws.read_timeout` (or `cloud.aws.s3.read_timeout`) setting:
  101. [source, yaml]
  102. ----
  103. cloud.aws.read_timeout: 30s
  104. ----
  105. [[repository-s3-repository]]
  106. ==== S3 Repository
  107. The S3 repository is using S3 to store snapshots. The S3 repository can be created using the following command:
  108. [source,js]
  109. ----
  110. PUT _snapshot/my_s3_repository
  111. {
  112. "type": "s3",
  113. "settings": {
  114. "bucket": "my_bucket_name",
  115. "region": "us-west"
  116. }
  117. }
  118. ----
  119. // CONSOLE
  120. // TEST[skip:we don't have s3 set up while testing this]
  121. The following settings are supported:
  122. `bucket`::
  123. The name of the bucket to be used for snapshots. (Mandatory)
  124. `region`::
  125. The region where bucket is located. Defaults to US Standard
  126. `endpoint`::
  127. The endpoint to the S3 API. Defaults to AWS's default S3 endpoint. Note
  128. that setting a region overrides the endpoint setting.
  129. `protocol`::
  130. The protocol to use (`http` or `https`). Defaults to value of
  131. `cloud.aws.protocol` or `cloud.aws.s3.protocol`.
  132. `base_path`::
  133. Specifies the path within bucket to repository data. Defaults to
  134. value of `repositories.s3.base_path` or to root directory if not set.
  135. Previously, the base_path could take a leading `/` (forward slash).
  136. However, this has been deprecated and setting the base_path now should
  137. omit the leading `/`.
  138. `access_key`::
  139. The access key to use for authentication. Defaults to value of
  140. `cloud.aws.access_key`.
  141. `secret_key`::
  142. The secret key to use for authentication. Defaults to value of
  143. `cloud.aws.secret_key`.
  144. `chunk_size`::
  145. Big files can be broken down into chunks during snapshotting if needed.
  146. The chunk size can be specified in bytes or by using size value notation,
  147. i.e. `1gb`, `10mb`, `5kb`. Defaults to `1gb`.
  148. `compress`::
  149. When set to `true` metadata files are stored in compressed format. This
  150. setting doesn't affect index files that are already compressed by default.
  151. Defaults to `false`.
  152. `server_side_encryption`::
  153. When set to `true` files are encrypted on server side using AES256
  154. algorithm. Defaults to `false`.
  155. `buffer_size`::
  156. Minimum threshold below which the chunk is uploaded using a single
  157. request. Beyond this threshold, the S3 repository will use the
  158. http://docs.aws.amazon.com/AmazonS3/latest/dev/uploadobjusingmpu.html[AWS Multipart Upload API]
  159. to split the chunk into several parts, each of `buffer_size` length, and
  160. to upload each part in its own request. Note that setting a buffer
  161. size lower than `5mb` is not allowed since it will prevents the use of the
  162. Multipart API and may result in upload errors. Defaults to the minimum
  163. between `100mb` and `5%` of the heap size.
  164. `max_retries`::
  165. Number of retries in case of S3 errors. Defaults to `3`.
  166. `use_throttle_retries`::
  167. Set to `true` if you want to throttle retries. Defaults to AWS SDK default value (`false`).
  168. `readonly`::
  169. Makes repository read-only. Defaults to `false`.
  170. `canned_acl`::
  171. The S3 repository supports all http://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl[S3 canned ACLs]
  172. : `private`, `public-read`, `public-read-write`, `authenticated-read`, `log-delivery-write`,
  173. `bucket-owner-read`, `bucket-owner-full-control`. Defaults to `private`.
  174. You could specify a canned ACL using the `canned_acl` setting. When the S3 repository
  175. creates buckets and objects, it adds the canned ACL into the buckets and objects.
  176. `storage_class`::
  177. Sets the S3 storage class type for the backup files. Values may be
  178. `standard`, `reduced_redundancy`, `standard_ia`. Defaults to `standard`.
  179. Due to the extra complexity with the Glacier class lifecycle, it is not
  180. currently supported by the plugin. For more information about the
  181. different classes, see http://docs.aws.amazon.com/AmazonS3/latest/dev/storage-class-intro.html[AWS Storage Classes Guide]
  182. `path_style_access`::
  183. Activate path style access for http://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html[virtual hosting of buckets].
  184. The default behaviour is to detect which access style to use based on the configured endpoint (an IP will result
  185. in path-style access) and the bucket being accessed (some buckets are not valid DNS names).
  186. Note that you can define S3 repository settings for all S3 repositories in `elasticsearch.yml` configuration file.
  187. They are all prefixed with `repositories.s3.`. For example, you can define compression for all S3 repositories
  188. by setting `repositories.s3.compress: true` in `elasticsearch.yml`.
  189. The S3 repositories use the same credentials as the rest of the AWS services
  190. provided by this plugin (`discovery`). See <<repository-s3-usage>> for details.
  191. Multiple S3 repositories can be created. If the buckets require different
  192. credentials, then define them as part of the repository settings.
  193. [[repository-s3-permissions]]
  194. ===== Recommended S3 Permissions
  195. In order to restrict the Elasticsearch snapshot process to the minimum required resources, we recommend using Amazon
  196. IAM in conjunction with pre-existing S3 buckets. Here is an example policy which will allow the snapshot access to an
  197. S3 bucket named "snaps.example.com". This may be configured through the AWS IAM console, by creating a Custom Policy,
  198. and using a Policy Document similar to this (changing snaps.example.com to your bucket name).
  199. [source,js]
  200. ----
  201. {
  202. "Statement": [
  203. {
  204. "Action": [
  205. "s3:ListBucket",
  206. "s3:GetBucketLocation",
  207. "s3:ListBucketMultipartUploads",
  208. "s3:ListBucketVersions"
  209. ],
  210. "Effect": "Allow",
  211. "Resource": [
  212. "arn:aws:s3:::snaps.example.com"
  213. ]
  214. },
  215. {
  216. "Action": [
  217. "s3:GetObject",
  218. "s3:PutObject",
  219. "s3:DeleteObject",
  220. "s3:AbortMultipartUpload",
  221. "s3:ListMultipartUploadParts"
  222. ],
  223. "Effect": "Allow",
  224. "Resource": [
  225. "arn:aws:s3:::snaps.example.com/*"
  226. ]
  227. }
  228. ],
  229. "Version": "2012-10-17"
  230. }
  231. ----
  232. // NOTCONSOLE
  233. You may further restrict the permissions by specifying a prefix within the bucket, in this example, named "foo".
  234. [source,js]
  235. ----
  236. {
  237. "Statement": [
  238. {
  239. "Action": [
  240. "s3:ListBucket",
  241. "s3:GetBucketLocation",
  242. "s3:ListBucketMultipartUploads",
  243. "s3:ListBucketVersions"
  244. ],
  245. "Condition": {
  246. "StringLike": {
  247. "s3:prefix": [
  248. "foo/*"
  249. ]
  250. }
  251. },
  252. "Effect": "Allow",
  253. "Resource": [
  254. "arn:aws:s3:::snaps.example.com"
  255. ]
  256. },
  257. {
  258. "Action": [
  259. "s3:GetObject",
  260. "s3:PutObject",
  261. "s3:DeleteObject",
  262. "s3:AbortMultipartUpload",
  263. "s3:ListMultipartUploadParts"
  264. ],
  265. "Effect": "Allow",
  266. "Resource": [
  267. "arn:aws:s3:::snaps.example.com/foo/*"
  268. ]
  269. }
  270. ],
  271. "Version": "2012-10-17"
  272. }
  273. ----
  274. // NOTCONSOLE
  275. The bucket needs to exist to register a repository for snapshots. If you did not create the bucket then the repository
  276. registration will fail. If you want elasticsearch to create the bucket instead, you can add the permission to create a
  277. specific bucket like this:
  278. [source,js]
  279. ----
  280. {
  281. "Action": [
  282. "s3:CreateBucket"
  283. ],
  284. "Effect": "Allow",
  285. "Resource": [
  286. "arn:aws:s3:::snaps.example.com"
  287. ]
  288. }
  289. ----
  290. // NOTCONSOLE
  291. [[repository-s3-endpoint]]
  292. ===== Using other S3 endpoint
  293. If you are using any S3 api compatible service, you can set a global endpoint by setting `cloud.aws.s3.endpoint`
  294. to your URL provider. Note that this setting will be used for all S3 repositories.
  295. Different `endpoint`, `region` and `protocol` settings can be set on a per-repository basis
  296. See <<repository-s3-repository>> for details.
  297. [[repository-s3-aws-vpc]]
  298. [float]
  299. ==== AWS VPC Bandwidth Settings
  300. AWS instances resolve S3 endpoints to a public IP. If the elasticsearch instances reside in a private subnet in an AWS VPC then all traffic to S3 will go through that VPC's NAT instance. If your VPC's NAT instance is a smaller instance size (e.g. a t1.micro) or is handling a high volume of network traffic your bandwidth to S3 may be limited by that NAT instance's networking bandwidth limitations.
  301. Instances residing in a public subnet in an AWS VPC will connect to S3 via the VPC's internet gateway and not be bandwidth limited by the VPC's NAT instance.
  302. [[repository-s3-testing]]
  303. ==== Testing AWS
  304. Integrations tests in this plugin require working AWS configuration and therefore disabled by default. Three buckets
  305. and two iam users have to be created. The first iam user needs access to two buckets in different regions and the final
  306. bucket is exclusive for the other iam user. To enable tests prepare a config file elasticsearch.yml with the following
  307. content:
  308. [source,yaml]
  309. ----
  310. cloud:
  311. aws:
  312. access_key: AKVAIQBF2RECL7FJWGJQ
  313. secret_key: vExyMThREXeRMm/b/LRzEB8jWwvzQeXgjqMX+6br
  314. repositories:
  315. s3:
  316. bucket: "bucket_name"
  317. region: "us-west-2"
  318. private-bucket:
  319. bucket: <bucket not accessible by default key>
  320. access_key: <access key>
  321. secret_key: <secret key>
  322. remote-bucket:
  323. bucket: <bucket in other region>
  324. region: <region>
  325. external-bucket:
  326. bucket: <bucket>
  327. access_key: <access key>
  328. secret_key: <secret key>
  329. endpoint: <endpoint>
  330. protocol: <protocol>
  331. ----
  332. Replace all occurrences of `access_key`, `secret_key`, `endpoint`, `protocol`, `bucket` and `region` with your settings.
  333. Please, note that the test will delete all snapshot/restore related files in the specified buckets.
  334. To run test:
  335. [source,sh]
  336. ----
  337. mvn -Dtests.aws=true -Dtests.config=/path/to/config/file/elasticsearch.yml clean test
  338. ----