repository-s3.asciidoc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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. [[repository-s3-install]]
  6. [float]
  7. ==== Installation
  8. This plugin can be installed using the plugin manager:
  9. [source,sh]
  10. ----------------------------------------------------------------
  11. sudo bin/plugin install repository-s3
  12. ----------------------------------------------------------------
  13. The plugin must be installed on every node in the cluster, and each node must
  14. be restarted after installation.
  15. [[repository-s3-remove]]
  16. [float]
  17. ==== Removal
  18. The plugin can be removed with the following command:
  19. [source,sh]
  20. ----------------------------------------------------------------
  21. sudo bin/plugin remove repository-s3
  22. ----------------------------------------------------------------
  23. The node must be stopped before removing the plugin.
  24. [[repository-s3-usage]]
  25. ==== Getting started with AWS
  26. The plugin will default to using
  27. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html[IAM Role]
  28. credentials for authentication. These can be overridden by, in increasing
  29. order of precedence, system properties `aws.accessKeyId` and `aws.secretKey`,
  30. environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_KEY`, or the
  31. elasticsearch config using `cloud.aws.access_key` and `cloud.aws.secret_key`:
  32. [source,yaml]
  33. ----
  34. cloud:
  35. aws:
  36. access_key: AKVAIQBF2RECL7FJWGJQ
  37. secret_key: vExyMThREXeRMm/b/LRzEB8jWwvzQeXgjqMX+6br
  38. ----
  39. [[repository-s3-usage-security]]
  40. ===== Transport security
  41. By default this plugin uses HTTPS for all API calls to AWS endpoints. If you wish to configure HTTP you can set
  42. `cloud.aws.protocol` in the elasticsearch config. You can optionally override this setting per individual service
  43. via: `cloud.aws.ec2.protocol` or `cloud.aws.s3.protocol`.
  44. [source,yaml]
  45. ----
  46. cloud:
  47. aws:
  48. protocol: https
  49. s3:
  50. protocol: http
  51. ec2:
  52. protocol: https
  53. ----
  54. In addition, a proxy can be configured with the `proxy_host` and `proxy_port` settings (note that protocol can be
  55. `http` or `https`):
  56. [source,yaml]
  57. ----
  58. cloud:
  59. aws:
  60. protocol: https
  61. proxy_host: proxy1.company.com
  62. proxy_port: 8083
  63. ----
  64. You can also set different proxies for `ec2` and `s3`:
  65. [source,yaml]
  66. ----
  67. cloud:
  68. aws:
  69. s3:
  70. proxy_host: proxy1.company.com
  71. proxy_port: 8083
  72. ec2:
  73. proxy_host: proxy2.company.com
  74. proxy_port: 8083
  75. ----
  76. [[repository-s3-usage-region]]
  77. ===== Region
  78. The `cloud.aws.region` can be set to a region and will automatically use the relevant settings for both `ec2` and `s3`.
  79. The available values are:
  80. * `us-east` (`us-east-1`)
  81. * `us-west` (`us-west-1`)
  82. * `us-west-1`
  83. * `us-west-2`
  84. * `ap-southeast` (`ap-southeast-1`)
  85. * `ap-southeast-1`
  86. * `ap-southeast-2`
  87. * `ap-northeast` (`ap-northeast-1`)
  88. * `eu-west` (`eu-west-1`)
  89. * `eu-central` (`eu-central-1`)
  90. * `sa-east` (`sa-east-1`)
  91. * `cn-north` (`cn-north-1`)
  92. [[repository-s3-usage-signer]]
  93. ===== S3 Signer API
  94. If you are using a S3 compatible service, they might be using an older API to sign the requests.
  95. You can set your compatible signer API using `cloud.aws.signer` (or `cloud.aws.s3.signer`) with the right
  96. signer to use.
  97. If you are using a compatible S3 service which do not support Version 4 signing process, you may need to
  98. use `S3SignerType`, which is Signature Version 2.
  99. [[repository-s3-repository]]
  100. ==== S3 Repository
  101. The S3 repository is using S3 to store snapshots. The S3 repository can be created using the following command:
  102. [source,json]
  103. ----
  104. PUT _snapshot/my_s3_repository
  105. {
  106. "type": "s3",
  107. "settings": {
  108. "bucket": "my_bucket_name",
  109. "region": "us-west"
  110. }
  111. }
  112. ----
  113. // AUTOSENSE
  114. The following settings are supported:
  115. `bucket`::
  116. The name of the bucket to be used for snapshots. (Mandatory)
  117. `region`::
  118. The region where bucket is located. Defaults to US Standard
  119. `endpoint`::
  120. The endpoint to the S3 API. Defaults to AWS's default S3 endpoint. Note
  121. that setting a region overrides the endpoint setting.
  122. `protocol`::
  123. The protocol to use (`http` or `https`). Defaults to value of
  124. `cloud.aws.protocol` or `cloud.aws.s3.protocol`.
  125. `base_path`::
  126. Specifies the path within bucket to repository data. Defaults to
  127. value of `repositories.s3.base_path` or to root directory if not set.
  128. `access_key`::
  129. The access key to use for authentication. Defaults to value of
  130. `cloud.aws.access_key`.
  131. `secret_key`::
  132. The secret key to use for authentication. Defaults to value of
  133. `cloud.aws.secret_key`.
  134. `chunk_size`::
  135. Big files can be broken down into chunks during snapshotting if needed.
  136. The chunk size can be specified in bytes or by using size value notation,
  137. i.e. `1g`, `10m`, `5k`. Defaults to `100m`.
  138. `compress`::
  139. When set to `true` metadata files are stored in compressed format. This
  140. setting doesn't affect index files that are already compressed by default.
  141. Defaults to `false`.
  142. `server_side_encryption`::
  143. When set to `true` files are encrypted on server side using AES256
  144. algorithm. Defaults to `false`.
  145. `buffer_size`::
  146. Minimum threshold below which the chunk is uploaded using a single
  147. request. Beyond this threshold, the S3 repository will use the
  148. http://docs.aws.amazon.com/AmazonS3/latest/dev/uploadobjusingmpu.html[AWS Multipart Upload API]
  149. to split the chunk into several parts, each of `buffer_size` length, and
  150. to upload each part in its own request. Note that positioning a buffer
  151. size lower than `5mb` is not allowed since it will prevents the use of the
  152. Multipart API and may result in upload errors. Defaults to `5mb`.
  153. `max_retries`::
  154. Number of retries in case of S3 errors. Defaults to `3`.
  155. `read_only`::
  156. Makes repository read-only. coming[2.1.0] Defaults to `false`.
  157. The S3 repositories use the same credentials as the rest of the AWS services
  158. provided by this plugin (`discovery`). See <<repository-s3-usage>> for details.
  159. Multiple S3 repositories can be created. If the buckets require different
  160. credentials, then define them as part of the repository settings.
  161. [[repository-s3-permissions]]
  162. ===== Recommended S3 Permissions
  163. In order to restrict the Elasticsearch snapshot process to the minimum required resources, we recommend using Amazon
  164. IAM in conjunction with pre-existing S3 buckets. Here is an example policy which will allow the snapshot access to an
  165. S3 bucket named "snaps.example.com". This may be configured through the AWS IAM console, by creating a Custom Policy,
  166. and using a Policy Document similar to this (changing snaps.example.com to your bucket name).
  167. [source,js]
  168. ----
  169. {
  170. "Statement": [
  171. {
  172. "Action": [
  173. "s3:ListBucket",
  174. "s3:GetBucketLocation",
  175. "s3:ListBucketMultipartUploads",
  176. "s3:ListBucketVersions"
  177. ],
  178. "Effect": "Allow",
  179. "Resource": [
  180. "arn:aws:s3:::snaps.example.com"
  181. ]
  182. },
  183. {
  184. "Action": [
  185. "s3:GetObject",
  186. "s3:PutObject",
  187. "s3:DeleteObject",
  188. "s3:AbortMultipartUpload",
  189. "s3:ListMultipartUploadParts"
  190. ],
  191. "Effect": "Allow",
  192. "Resource": [
  193. "arn:aws:s3:::snaps.example.com/*"
  194. ]
  195. }
  196. ],
  197. "Version": "2012-10-17"
  198. }
  199. ----
  200. You may further restrict the permissions by specifying a prefix within the bucket, in this example, named "foo".
  201. [source,js]
  202. ----
  203. {
  204. "Statement": [
  205. {
  206. "Action": [
  207. "s3:ListBucket",
  208. "s3:GetBucketLocation",
  209. "s3:ListBucketMultipartUploads",
  210. "s3:ListBucketVersions"
  211. ],
  212. "Condition": {
  213. "StringLike": {
  214. "s3:prefix": [
  215. "foo/*"
  216. ]
  217. }
  218. },
  219. "Effect": "Allow",
  220. "Resource": [
  221. "arn:aws:s3:::snaps.example.com"
  222. ]
  223. },
  224. {
  225. "Action": [
  226. "s3:GetObject",
  227. "s3:PutObject",
  228. "s3:DeleteObject",
  229. "s3:AbortMultipartUpload",
  230. "s3:ListMultipartUploadParts"
  231. ],
  232. "Effect": "Allow",
  233. "Resource": [
  234. "arn:aws:s3:::snaps.example.com/foo/*"
  235. ]
  236. }
  237. ],
  238. "Version": "2012-10-17"
  239. }
  240. ----
  241. The bucket needs to exist to register a repository for snapshots. If you did not create the bucket then the repository
  242. registration will fail. If you want elasticsearch to create the bucket instead, you can add the permission to create a
  243. specific bucket like this:
  244. [source,js]
  245. ----
  246. {
  247. "Action": [
  248. "s3:CreateBucket"
  249. ],
  250. "Effect": "Allow",
  251. "Resource": [
  252. "arn:aws:s3:::snaps.example.com"
  253. ]
  254. }
  255. ----
  256. [[repository-s3-endpoint]]
  257. ===== Using other S3 endpoint
  258. If you are using any S3 api compatible service, you can set a global endpoint by setting `cloud.aws.s3.endpoint`
  259. to your URL provider. Note that this setting will be used for all S3 repositories.
  260. Different `endpoint`, `region` and `protocol` settings can be set on a per-repository basis
  261. See <<repository-s3-repository>> for details.
  262. [[repository-s3-testing]]
  263. ==== Testing AWS
  264. Integrations tests in this plugin require working AWS configuration and therefore disabled by default. Three buckets
  265. and two iam users have to be created. The first iam user needs access to two buckets in different regions and the final
  266. bucket is exclusive for the other iam user. To enable tests prepare a config file elasticsearch.yml with the following
  267. content:
  268. [source,yaml]
  269. ----
  270. cloud:
  271. aws:
  272. access_key: AKVAIQBF2RECL7FJWGJQ
  273. secret_key: vExyMThREXeRMm/b/LRzEB8jWwvzQeXgjqMX+6br
  274. repositories:
  275. s3:
  276. bucket: "bucket_name"
  277. region: "us-west-2"
  278. private-bucket:
  279. bucket: <bucket not accessible by default key>
  280. access_key: <access key>
  281. secret_key: <secret key>
  282. remote-bucket:
  283. bucket: <bucket in other region>
  284. region: <region>
  285. external-bucket:
  286. bucket: <bucket>
  287. access_key: <access key>
  288. secret_key: <secret key>
  289. endpoint: <endpoint>
  290. protocol: <protocol>
  291. ----
  292. Replace all occurrences of `access_key`, `secret_key`, `endpoint`, `protocol`, `bucket` and `region` with your settings.
  293. Please, note that the test will delete all snapshot/restore related files in the specified buckets.
  294. To run test:
  295. [source,sh]
  296. ----
  297. mvn -Dtests.aws=true -Dtests.config=/path/to/config/file/elasticsearch.yml clean test
  298. ----