repository-gcs.asciidoc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. [[repository-gcs]]
  2. === Google Cloud Storage Repository Plugin
  3. The GCS repository plugin adds support for using the https://cloud.google.com/storage/[Google Cloud Storage]
  4. service as a repository for {ref}/modules-snapshots.html[Snapshot/Restore].
  5. :plugin_name: repository-gcs
  6. include::install_remove.asciidoc[]
  7. [[repository-gcs-usage]]
  8. ==== Getting started
  9. The plugin uses the https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-clients/google-cloud-storage[Google Cloud Java Client for Storage]
  10. to connect to the Storage service. If you are using
  11. https://cloud.google.com/storage/[Google Cloud Storage] for the first time, you
  12. must connect to the https://console.cloud.google.com/[Google Cloud Platform Console]
  13. and create a new project. After your project is created, you must enable the
  14. Cloud Storage Service for your project.
  15. [[repository-gcs-creating-bucket]]
  16. ===== Creating a Bucket
  17. The Google Cloud Storage service uses the concept of a
  18. https://cloud.google.com/storage/docs/key-terms[bucket] as a container for all
  19. the data. Buckets are usually created using the
  20. https://console.cloud.google.com/[Google Cloud Platform Console]. The plugin
  21. does not automatically create buckets.
  22. To create a new bucket:
  23. 1. Connect to the https://console.cloud.google.com/[Google Cloud Platform Console].
  24. 2. Select your project.
  25. 3. Go to the https://console.cloud.google.com/storage/browser[Storage Browser].
  26. 4. Click the *Create Bucket* button.
  27. 5. Enter the name of the new bucket.
  28. 6. Select a storage class.
  29. 7. Select a location.
  30. 8. Click the *Create* button.
  31. For more detailed instructions, see the
  32. https://cloud.google.com/storage/docs/quickstart-console#create_a_bucket[Google Cloud documentation].
  33. [[repository-gcs-service-authentication]]
  34. ===== Service Authentication
  35. The plugin must authenticate the requests it makes to the Google Cloud Storage
  36. service. It is common for Google client libraries to employ a strategy named https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application[application default credentials].
  37. However, that strategy is **not** supported for use with Elasticsearch. The
  38. plugin operates under the Elasticsearch process, which runs with the security
  39. manager enabled. The security manager obstructs the "automatic" credential discovery.
  40. Therefore, you must configure <<repository-gcs-using-service-account,service account>>
  41. credentials even if you are using an environment that does not normally require
  42. this configuration (such as Compute Engine, Kubernetes Engine or App Engine).
  43. [[repository-gcs-using-service-account]]
  44. ===== Using a Service Account
  45. You have to obtain and provide https://cloud.google.com/iam/docs/overview#service_account[service account credentials]
  46. manually.
  47. For detailed information about generating JSON service account files, see the https://cloud.google.com/storage/docs/authentication?hl=en#service_accounts[Google Cloud documentation].
  48. Note that the PKCS12 format is not supported by this plugin.
  49. Here is a summary of the steps:
  50. 1. Connect to the https://console.cloud.google.com/[Google Cloud Platform Console].
  51. 2. Select your project.
  52. 3. Go to the https://console.cloud.google.com/permissions[Permission] tab.
  53. 4. Select the https://console.cloud.google.com/permissions/serviceaccounts[Service Accounts] tab.
  54. 5. Click *Create service account*.
  55. 6. After the account is created, select it and download a JSON key file.
  56. A JSON service account file looks like this:
  57. [source,js]
  58. ----
  59. {
  60. "type": "service_account",
  61. "project_id": "your-project-id",
  62. "private_key_id": "...",
  63. "private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
  64. "client_email": "service-account-for-your-repository@your-project-id.iam.gserviceaccount.com",
  65. "client_id": "...",
  66. "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  67. "token_uri": "https://accounts.google.com/o/oauth2/token",
  68. "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  69. "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/your-bucket@your-project-id.iam.gserviceaccount.com"
  70. }
  71. ----
  72. // NOTCONSOLE
  73. To provide this file to the plugin, it must be stored in the {ref}/secure-settings.html[Elasticsearch keystore]. You must
  74. add a `file` setting with the name `gcs.client.NAME.credentials_file` using the `add-file` subcommand.
  75. `NAME` is the name of the client configuration for the repository. The implicit client
  76. name is `default`, but a different client name can be specified in the
  77. repository settings with the `client` key.
  78. NOTE: Passing the file path via the GOOGLE_APPLICATION_CREDENTIALS environment
  79. variable is **not** supported.
  80. For example, if you added a `gcs.client.my_alternate_client.credentials_file`
  81. setting in the keystore, you can configure a repository to use those credentials
  82. like this:
  83. [source,console]
  84. ----
  85. PUT _snapshot/my_gcs_repository
  86. {
  87. "type": "gcs",
  88. "settings": {
  89. "bucket": "my_bucket",
  90. "client": "my_alternate_client"
  91. }
  92. }
  93. ----
  94. // TEST[skip:we don't have gcs setup while testing this]
  95. The `credentials_file` settings are {ref}/secure-settings.html#reloadable-secure-settings[reloadable].
  96. After you reload the settings, the internal `gcs` clients, which are used to
  97. transfer the snapshot contents, utilize the latest settings from the keystore.
  98. NOTE: Snapshot or restore jobs that are in progress are not preempted by a *reload*
  99. of the client's `credentials_file` settings. They complete using the client as
  100. it was built when the operation started.
  101. [[repository-gcs-client]]
  102. ==== Client Settings
  103. The client used to connect to Google Cloud Storage has a number of settings available.
  104. Client setting names are of the form `gcs.client.CLIENT_NAME.SETTING_NAME` and are specified
  105. inside `elasticsearch.yml`. The default client name looked up by a `gcs` repository is
  106. called `default`, but can be customized with the repository setting `client`.
  107. For example:
  108. [source,console]
  109. ----
  110. PUT _snapshot/my_gcs_repository
  111. {
  112. "type": "gcs",
  113. "settings": {
  114. "bucket": "my_bucket",
  115. "client": "my_alternate_client"
  116. }
  117. }
  118. ----
  119. // TEST[skip:we don't have gcs setup while testing this]
  120. Some settings are sensitive and must be stored in the
  121. {ref}/secure-settings.html[Elasticsearch keystore]. This is the case for the service account file:
  122. [source,sh]
  123. ----
  124. bin/elasticsearch-keystore add-file gcs.client.default.credentials_file /path/service-account.json
  125. ----
  126. The following are the available client settings. Those that must be stored in the keystore
  127. are marked as `Secure`.
  128. `credentials_file` ({ref}/secure-settings.html[Secure], {ref}/secure-settings.html#reloadable-secure-settings[reloadable])::
  129. The service account file that is used to authenticate to the Google Cloud Storage service.
  130. `endpoint`::
  131. The Google Cloud Storage service endpoint to connect to. This will be automatically
  132. determined by the Google Cloud Storage client but can be specified explicitly.
  133. `connect_timeout`::
  134. The timeout to establish a connection to the Google Cloud Storage service. The value should
  135. specify the unit. For example, a value of `5s` specifies a 5 second timeout. The value of `-1`
  136. corresponds to an infinite timeout. The default value is 20 seconds.
  137. `read_timeout`::
  138. The timeout to read data from an established connection. The value should
  139. specify the unit. For example, a value of `5s` specifies a 5 second timeout. The value of `-1`
  140. corresponds to an infinite timeout. The default value is 20 seconds.
  141. `application_name`::
  142. Name used by the client when it uses the Google Cloud Storage service. Setting
  143. a custom name can be useful to authenticate your cluster when requests
  144. statistics are logged in the Google Cloud Platform. Default to `repository-gcs`
  145. `project_id`::
  146. The Google Cloud project id. This will be automatically inferred from the credentials file but
  147. can be specified explicitly. For example, it can be used to switch between projects when the
  148. same credentials are usable for both the production and the development projects.
  149. [[repository-gcs-repository]]
  150. ==== Repository Settings
  151. The `gcs` repository type supports a number of settings to customize how data
  152. is stored in Google Cloud Storage.
  153. These can be specified when creating the repository. For example:
  154. [source,console]
  155. ----
  156. PUT _snapshot/my_gcs_repository
  157. {
  158. "type": "gcs",
  159. "settings": {
  160. "bucket": "my_other_bucket",
  161. "base_path": "dev"
  162. }
  163. }
  164. ----
  165. // TEST[skip:we don't have gcs set up while testing this]
  166. The following settings are supported:
  167. `bucket`::
  168. The name of the bucket to be used for snapshots. (Mandatory)
  169. `client`::
  170. The name of the client to use to connect to Google Cloud Storage.
  171. Defaults to `default`.
  172. `base_path`::
  173. Specifies the path within bucket to repository data. Defaults to
  174. the root of the bucket.
  175. `chunk_size`::
  176. Big files can be broken down into multiple smaller blobs in the blob store during snapshotting.
  177. It is not recommended to change this value from its default unless there is an explicit reason for limiting the
  178. size of blobs in the repository. Setting a value lower than the default can result in an increased number of API
  179. calls to the Google Cloud Storage Service during snapshot create as well as restore operations compared to using
  180. the default value and thus make both operations slower as well as more costly.
  181. Specify the chunk size as a value and unit, for example:
  182. `10MB`, `5KB`, `500B`. Defaults to the maximum size of a blob in the Google Cloud Storage Service which is `5TB`.
  183. `compress`::
  184. When set to `true` metadata files are stored in compressed format. This
  185. setting doesn't affect index files that are already compressed by default.
  186. Defaults to `true`.
  187. include::repository-shared-settings.asciidoc[]
  188. `application_name`::
  189. deprecated:[6.3.0, "This setting is now defined in the <<repository-gcs-client, client settings>>."]
  190. Name used by the client when it uses the Google Cloud Storage service.
  191. [[repository-gcs-bucket-permission]]
  192. ===== Recommended Bucket Permission
  193. The service account used to access the bucket must have the "Writer" access to the bucket:
  194. 1. Connect to the https://console.cloud.google.com/[Google Cloud Platform Console].
  195. 2. Select your project.
  196. 3. Go to the https://console.cloud.google.com/storage/browser[Storage Browser].
  197. 4. Select the bucket and "Edit bucket permission".
  198. 5. The service account must be configured as a "User" with "Writer" access.