Skip to content

Commit 07990f1

Browse files
authored
Tde update key (#284)
1 parent efc5025 commit 07990f1

22 files changed

+1841
-2064
lines changed

.github/workflows/e2e.yaml

+4-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ jobs:
147147
region: ${{ steps.credentials.outputs.region }}
148148
aws_role_arn: ${{ secrets.AWS_ASSUME_ROLE_ARN }}
149149
- name: cleanup
150-
if: ${{ always() && matrix.test.cloud == 'aws' && matrix.test.name == 'private_endpoint' }}
150+
if: ${{ always() && matrix.test.cloud == 'aws' }}
151151
uses: ./.github/actions/cleanup-aws
152152
with:
153153
service_name: ${{steps.name.outputs.test_name}}
@@ -218,13 +218,15 @@ jobs:
218218
skip_build: "false"
219219
region: ${{ steps.credentials.outputs.region }}
220220
aws_role_arn: ${{ secrets.AWS_ASSUME_ROLE_ARN }}
221+
221222
- name: cleanup
222-
if: ${{ always() && matrix.test.cloud == 'aws' && matrix.test.name == 'private_endpoint' }}
223+
if: ${{ always() && matrix.test.cloud == 'aws' }}
223224
uses: ./.github/actions/cleanup-aws
224225
with:
225226
service_name: ${{steps.name.outputs.test_name}}
226227
aws_region: ${{ steps.credentials.outputs.region }}
227228
aws_role_arn: ${{ secrets.AWS_ASSUME_ROLE_ARN }}
229+
228230
- name: Mark error
229231
id: status
230232
if: failure()

.github/workflows/release.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ jobs:
136136
region: ${{ steps.credentials.outputs.region }}
137137
aws_role_arn: ${{ secrets.AWS_ASSUME_ROLE_ARN }}
138138

139+
- name: cleanup
140+
if: ${{ always() && matrix.test.cloud == 'aws' }}
141+
uses: ./.github/actions/cleanup-aws
142+
with:
143+
service_name: "[e2e]-${{ matrix.test.name }}-${{ matrix.tf_release }}-${{ matrix.test.cloud }}-${{ needs.token.outputs.token }}"
144+
aws_region: ${{ steps.credentials.outputs.region }}
145+
aws_role_arn: ${{ secrets.AWS_ASSUME_ROLE_ARN }}
146+
139147
- name: Mark error
140148
id: status
141149
if: failure()
@@ -190,6 +198,14 @@ jobs:
190198
region: ${{ steps.credentials.outputs.region }}
191199
aws_role_arn: ${{ secrets.AWS_ASSUME_ROLE_ARN }}
192200

201+
- name: cleanup
202+
if: ${{ always() && matrix.test.cloud == 'aws' }}
203+
uses: ./.github/actions/cleanup-aws
204+
with:
205+
service_name: "[upg]-${{ matrix.test.name }}-${{ matrix.tf_release }}-${{ matrix.test.cloud }}-${{ needs.token.outputs.token }}"
206+
aws_region: ${{ steps.credentials.outputs.region }}
207+
aws_role_arn: ${{ secrets.AWS_ASSUME_ROLE_ARN }}
208+
193209
- name: Mark error
194210
id: status
195211
if: failure()

docs/resources/service.md

+15-3
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,11 @@ resource "clickhouse_service" "service" {
5959
- `encryption_assumed_role_identifier` (String) Custom role identifier ARN.
6060
- `encryption_key` (String) Custom encryption key ARN.
6161
- `endpoints` (Attributes) Allow to enable and configure additional endpoints (read protocols) to expose on the ClickHouse service. (see [below for nested schema](#nestedatt--endpoints))
62-
- `has_transparent_data_encryption` (Boolean) If true, the Transparent Data Encryption (TDE) feature is enabled in the service. Only supported in AWS and GCP. Requires an organization with the Enterprise plan.
6362
- `idle_scaling` (Boolean) When set to true the service is allowed to scale down to zero when idle.
6463
- `idle_timeout_minutes` (Number) Set minimum idling timeout (in minutes). Must be greater than or equal to 5 minutes. Must be set if idle_scaling is enabled.
65-
- `max_replica_memory_gb` (Number) Maximum memory of a single replica during auto-scaling in Gb. Must be a multiple of 8. `max_replica_memory_gb` x `num_replicas` (default 3) must be lower than 360 for non paid services or 720 for paid services.
64+
- `max_replica_memory_gb` (Number) Maximum memory of a single replica during auto-scaling in Gb. Must be a multiple of 4 greater than or equal to 8. `max_replica_memory_gb` x `num_replicas` (default 3) must be lower than 360 for non paid services or 720 for paid services.
6665
- `max_total_memory_gb` (Number, Deprecated) Maximum total memory of all workers during auto-scaling in Gb. Must be a multiple of 12 and lower than 360 for non paid services or 720 for paid services.
67-
- `min_replica_memory_gb` (Number) Minimum memory of a single replica during auto-scaling in Gb. Must be a multiple of 8. `min_replica_memory_gb` x `num_replicas` (default 3) must be lower than 360 for non paid services or 720 for paid services.
66+
- `min_replica_memory_gb` (Number) Minimum memory of a single replica during auto-scaling in Gb. Must be a multiple of 4 greater than or equal to 8. `min_replica_memory_gb` x `num_replicas` (default 3) must be lower than 360 for non paid services or 720 for paid services.
6867
- `min_total_memory_gb` (Number, Deprecated) Minimum total memory of all workers during auto-scaling in Gb. Must be a multiple of 12 and greater than 24.
6968
- `num_replicas` (Number) Number of replicas for the service. Must be between 3 and 20. Contact support to enable this feature.
7069
- `password` (String, Sensitive) Password for the default user. One of either `password` or `password_hash` must be specified.
@@ -73,6 +72,7 @@ resource "clickhouse_service" "service" {
7372
- `readonly` (Boolean) Indicates if this service should be read only. Only allowed for secondary services, those which share data with another service (i.e. when `warehouse_id` field is set).
7473
- `release_channel` (String) Release channel to use for this service. Either 'default' or 'fast'. Switching from 'fast' to 'default' release channel is not supported.
7574
- `tier` (String) Tier of the service: 'development', 'production'. Required for organizations using the Legacy ClickHouse Cloud Tiers, must be omitted for organizations using the new ClickHouse Cloud Tiers.
75+
- `transparent_data_encryption` (Attributes) Configuration of the Transparent Data Encryption (TDE) feature. Requires an organization with the Enterprise plan. (see [below for nested schema](#nestedatt--transparent_data_encryption))
7676
- `warehouse_id` (String) ID of the warehouse to share the data with. Must be in the same cloud and region.
7777

7878
### Read-Only
@@ -155,6 +155,18 @@ Optional:
155155
- `allowed_origins` (String) Comma separated list of domain names to be allowed cross-origin resource sharing (CORS) access to the query API. Leave this field empty to restrict access to backend servers only
156156

157157

158+
<a id="nestedatt--transparent_data_encryption"></a>
159+
### Nested Schema for `transparent_data_encryption`
160+
161+
Optional:
162+
163+
- `enabled` (Boolean) If true, TDE is enabled for the service.
164+
165+
Read-Only:
166+
167+
- `role_id` (String) ID of Role to be used for granting access to the Encryption Key. This is an ARN for AWS services and a Service Account Identifier for GCP.
168+
169+
158170
<a id="nestedatt--private_endpoint_config"></a>
159171
### Nested Schema for `private_endpoint_config`
160172

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "clickhouse_service_transparent_data_encryption_key_association Resource - clickhouse"
4+
subcategory: ""
5+
description: |-
6+
You can use the clickhouse_service_transparent_data_encryption_key_association resource to associate your own Encryption Key with a Clickhouse Service with the Transparent Data Encryption (TDE) feature enabled.
7+
Please note that this feature requires an organization with the Enterprise plan.
8+
---
9+
10+
# clickhouse_service_transparent_data_encryption_key_association (Resource)
11+
12+
You can use the *clickhouse_service_transparent_data_encryption_key_association* resource to associate your own Encryption Key with a Clickhouse Service with the Transparent Data Encryption (TDE) feature enabled.
13+
Please note that this feature requires an organization with the `Enterprise` plan.
14+
15+
## Example Usage
16+
17+
```terraform
18+
resource "clickhouse_service" "service" {
19+
...
20+
}
21+
22+
resource "aws_kms_key" "enc" {
23+
...
24+
}
25+
26+
resource "clickhouse_service_transparent_data_encryption_key_association" "service_key_association" {
27+
service_id = clickhouse_service.service.id
28+
key_id = aws_kms_key.enc.arn
29+
}
30+
```
31+
32+
<!-- schema generated by tfplugindocs -->
33+
## Schema
34+
35+
### Required
36+
37+
- `key_id` (String) ID of the Encryption key to use for data encryption. Must be an ARN for AWS services or a Key Resource Path for GCP services.
38+
- `service_id` (String) ClickHouse Service ID
39+
40+
## Import
41+
42+
Import is supported using the following syntax:
43+
44+
```shell
45+
# Endpoint Attachments can be imported by specifying the clickhouse service UUID
46+
terraform import clickhouse_service_transparent_data_encryption_key_association.example xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
47+
```

examples/full/tde/aws/aws.tf

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
variable "aws_key" {
2+
type = string
3+
}
4+
5+
variable "aws_secret" {
6+
type = string
7+
}
8+
9+
variable "aws_session_token" {
10+
type = string
11+
default = ""
12+
}
13+
14+
locals {
15+
tags = {
16+
Role = "terraform-e2e-test"
17+
ServiceName = replace(var.service_name, "/[^-a-zA-Z0-9_.:/=+@ ]/", "_")
18+
}
19+
}
20+
21+
provider "aws" {
22+
region = var.region
23+
access_key = var.aws_key
24+
secret_key = var.aws_secret
25+
token = var.aws_session_token
26+
}
27+
28+
data "aws_caller_identity" "current" {}
29+
30+
data "aws_iam_policy_document" "policy" {
31+
# Allow root user on the account all access.
32+
statement {
33+
sid = "AllowRoot"
34+
35+
actions = ["kms:*"]
36+
resources = ["*"]
37+
principals {
38+
type = "AWS"
39+
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"]
40+
}
41+
}
42+
43+
# Allow user that runs terraform to manage the KMS key.
44+
statement {
45+
sid = "AllowAdmins"
46+
actions = [
47+
"kms:Create*",
48+
"kms:Describe*",
49+
"kms:Enable*",
50+
"kms:List*",
51+
"kms:Put*",
52+
"kms:Update*",
53+
"kms:Revoke*",
54+
"kms:Disable*",
55+
"kms:Get*",
56+
"kms:Delete*",
57+
"kms:TagResource",
58+
"kms:UntagResource",
59+
"kms:ScheduleKeyDeletion",
60+
"kms:CancelKeyDeletion",
61+
"kms:RotateKeyOnDemand",
62+
"kms:Encrypt",
63+
"kms:Decrypt",
64+
"kms:ReEncrypt*",
65+
"kms:DescribeKey",
66+
"kms:CreateGrant",
67+
"kms:ListGrants",
68+
"kms:RevokeGrant"
69+
]
70+
resources = ["*"]
71+
72+
principals {
73+
type = "AWS"
74+
identifiers = [data.aws_caller_identity.current.arn]
75+
}
76+
}
77+
78+
# Allow clickhouse's accounts to access the KMS key.
79+
statement {
80+
sid = "AllowClickHouse"
81+
actions = [
82+
"kms:Encrypt",
83+
"kms:Decrypt",
84+
"kms:ReEncrypt*",
85+
"kms:DescribeKey",
86+
]
87+
resources = ["*"]
88+
89+
principals {
90+
type = "AWS"
91+
identifiers = [clickhouse_service.service.transparent_data_encryption.role_id]
92+
}
93+
}
94+
}
95+
96+
resource "aws_kms_key" "enc" {
97+
customer_master_key_spec = "SYMMETRIC_DEFAULT"
98+
deletion_window_in_days = 7
99+
description = var.service_name
100+
enable_key_rotation = false
101+
is_enabled = true
102+
key_usage = "ENCRYPT_DECRYPT"
103+
multi_region = false
104+
105+
policy = data.aws_iam_policy_document.policy.json
106+
107+
tags = local.tags
108+
}

examples/full/tde/aws/main.tf

+8-17
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,6 @@ resource "clickhouse_service" "service" {
4848
}
4949
]
5050

51-
endpoints = {
52-
mysql = {
53-
enabled = true
54-
}
55-
}
56-
57-
query_api_endpoints = {
58-
api_key_ids = [
59-
data.clickhouse_api_key_id.self.id,
60-
]
61-
roles = [
62-
"sql_console_admin"
63-
]
64-
allowed_origins = null
65-
}
66-
6751
min_replica_memory_gb = 8
6852
max_replica_memory_gb = 120
6953

@@ -73,7 +57,14 @@ resource "clickhouse_service" "service" {
7357
backup_start_time = null
7458
}
7559

76-
has_transparent_data_encryption = true
60+
transparent_data_encryption = {
61+
enabled = true
62+
}
63+
}
64+
65+
resource "clickhouse_service_transparent_data_encryption_key_association" "service_key_association" {
66+
service_id = clickhouse_service.service.id
67+
key_id = aws_kms_key.enc.arn
7768
}
7869

7970
output "service_endpoints" {

examples/full/tde/aws/variables.tfvars.sample

+5
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
organization_id = "aee076c1-3f83-4637-95b1-ad5a0a825b71"
33
token_key = "avhj1U5QCdWAE9CA9"
44
token_secret = "4b1dROiHQEuSXJHlV8zHFd0S7WQj7CGxz5kGJeJnca"
5+
6+
# AWS
7+
aws_key = "key"
8+
aws_secret = "secret"
9+
aws_region = "us-west-2"

examples/full/tde/gcp/main.tf

+3-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ resource "clickhouse_service" "service" {
7171
backup_retention_period_in_hours = 48
7272
}
7373

74-
has_transparent_data_encryption = true
74+
transparent_data_encryption = {
75+
enabled = true
76+
}
7577
}
7678

7779
output "service_endpoints" {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Endpoint Attachments can be imported by specifying the clickhouse service UUID
2+
terraform import clickhouse_service_transparent_data_encryption_key_association.example xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
resource "clickhouse_service" "service" {
2+
...
3+
}
4+
5+
resource "aws_kms_key" "enc" {
6+
...
7+
}
8+
9+
resource "clickhouse_service_transparent_data_encryption_key_association" "service_key_association" {
10+
service_id = clickhouse_service.service.id
11+
key_id = aws_kms_key.enc.arn
12+
}

0 commit comments

Comments
 (0)