Skip to content

Commit e6faeea

Browse files
committed
Merge branch '06/10/26/certs_as_string' into 06/10/26/ssl_modes
2 parents 767fc60 + 2516d01 commit e6faeea

9 files changed

Lines changed: 255 additions & 133 deletions

File tree

.github/workflows/analysis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Analysis
1+
name: Coverage
22

33
on:
44
push:
@@ -94,13 +94,13 @@ jobs:
9494
find . -type f -name "simplelogger.*" -exec rm -fv '{}' \;
9595
mvn -q --no-transfer-progress --batch-mode -DclickhouseVersion=$PREFERRED_LTS_VERSION \
9696
-DskipTests install
97-
- name: Analyze
97+
- name: Generate coverage report
9898
env:
9999
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
100100
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
101101
run: |
102102
mvn -fn --no-transfer-progress --batch-mode -DclickhouseVersion=$PREFERRED_LTS_VERSION \
103-
-Panalysis verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=ClickHouse_clickhouse-java
103+
-Pcoverage verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=ClickHouse_clickhouse-java
104104
continue-on-error: true
105105
- name: Generate and post coverage report
106106
env:

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,8 @@ performance/jmh-simple-results.json
6060
*.csv
6161
*.sql
6262
*.json
63+
64+
*.crt
65+
*.key
66+
*.srl
67+
*.csr

CONTRIBUTING.md

Lines changed: 208 additions & 107 deletions
Large diffs are not rendered by default.

clickhouse-client/src/test/java/com/clickhouse/client/config/ClickHouseDefaultSslContextProviderTest.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
11
package com.clickhouse.client.config;
22

3-
import java.io.ByteArrayOutputStream;
3+
import com.clickhouse.data.ClickHouseUtils;
4+
import org.testng.Assert;
5+
import org.testng.annotations.Test;
6+
47
import java.io.FileNotFoundException;
58
import java.io.InputStream;
69
import java.nio.charset.StandardCharsets;
710
import java.security.KeyStore;
811
import java.security.PrivateKey;
912

10-
import com.clickhouse.data.ClickHouseUtils;
11-
12-
import org.testng.Assert;
13-
import org.testng.annotations.Test;
14-
1513
public class ClickHouseDefaultSslContextProviderTest {
1614
static String readTestResource(String name) throws Exception {
17-
ByteArrayOutputStream out = new ByteArrayOutputStream();
1815
try (InputStream in = ClickHouseUtils.getFileInputStream(name)) {
19-
byte[] buffer = new byte[2048];
20-
int read;
21-
while ((read = in.read(buffer)) != -1) {
22-
out.write(buffer, 0, read);
23-
}
16+
return new String(in.readAllBytes(), StandardCharsets.US_ASCII);
2417
}
25-
return new String(out.toByteArray(), StandardCharsets.US_ASCII);
2618
}
2719

2820
@Test(groups = { "unit" })

examples/client-v2/README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,12 @@ openssl req -newkey rsa:2048 -nodes \
141141
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
142142
-days 365 -out server.crt \
143143
-extfile <(printf "subjectAltName=DNS:localhost,IP:127.0.0.1")
144+
145+
# Only for demo purpose we make key readable by all. On production should be readable only by owner, not even by group.
146+
chmod a+r server.key
144147
```
145148

146-
2. Create a `config.d` overlay enabling the HTTPS interface, e.g. `zzz_ssl.xml`:
149+
2. Create a `config.d` overlay enabling the HTTPS interface, e.g. `my_ssl.xml`:
147150

148151
```xml
149152
<clickhouse>
@@ -167,11 +170,22 @@ openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
167170
docker run -d --name clickhouse-ssl -p 8443:8443 \
168171
-v "$PWD/server.crt:/etc/clickhouse-server/certs/server.crt:ro" \
169172
-v "$PWD/server.key:/etc/clickhouse-server/certs/server.key:ro" \
170-
-v "$PWD/zzz_ssl.xml:/etc/clickhouse-server/config.d/zzz_ssl.xml:ro" \
173+
-v "$PWD/my_ssl.xml:/etc/clickhouse-server/config.d/my_ssl.xml:ro" \
174+
-e CLICKHOUSE_PASSWORD="secret" \
171175
clickhouse/clickhouse-server:latest
172176
```
173177

174178
4. Run the example in standalone mode with `-DchHost=localhost -DchRootCert="$PWD/ca.crt"`.
175179

180+
```shell
181+
mvn exec:java -Dexec.mainClass="com.clickhouse.examples.client_v2.SSLExamples" \
182+
-DchHost="localhost" \
183+
-DchPort="8443" \
184+
-DchUser="default" \
185+
-DchPassword="secret" \
186+
-DchDatabase="default" \
187+
-DchRootCert="$PWD/ca.crt"
188+
```
189+
176190
The full description of the server-side TLS configuration is in the official documentation:
177191
[Configuring SSL-TLS](https://clickhouse.com/docs/en/guides/sre/configuring-ssl).

examples/client-v2/src/main/java/com/clickhouse/examples/client_v2/SSLExamples.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,7 @@ public static void main(String[] args) {
9090
SecureServerSupport.USER, SecureServerSupport.PASSWORD, server.getCaCertPath());
9191
} catch (Exception e) {
9292
log.error("Failed to run the SSL example against a local Docker server", e);
93-
Runtime.getRuntime().exit(-1);
9493
}
95-
// Explicit exit: testcontainers keeps non-daemon threads alive after the scenario is done.
96-
Runtime.getRuntime().exit(0);
9794
}
9895

9996
/**

examples/client-v2/src/main/java/com/clickhouse/examples/client_v2/SecureServerSupport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private SecureServerSupport(GenericContainer<?> container, Path certDir, Path co
8282
public static SecureServerSupport start(String image) throws Exception {
8383
Path certDir = Files.createTempDirectory("ch-ssl-example-certs-");
8484
Path confDir = Files.createTempDirectory("ch-ssl-example-config-");
85-
Path sslConfig = confDir.resolve("zzz_ssl.xml");
85+
Path sslConfig = confDir.resolve("custom_ca_ssl.xml");
8686

8787
log.info("Generating an ephemeral private CA and a server certificate in {}", certDir);
8888
generatePrivateCaAndServerCertificate(certDir);
@@ -100,7 +100,7 @@ public static SecureServerSupport start(String image) throws Exception {
100100
.withFileSystemBind(certDir.toAbsolutePath().toString(),
101101
"/etc/clickhouse-server/certs", BindMode.READ_ONLY)
102102
.withFileSystemBind(sslConfig.toAbsolutePath().toString(),
103-
"/etc/clickhouse-server/config.d/zzz_ssl.xml", BindMode.READ_ONLY)
103+
"/etc/clickhouse-server/config.d/custom_ca_ssl.xml", BindMode.READ_ONLY)
104104
.waitingFor(Wait.forHttp("/ping")
105105
.forPort(HTTP_PORT)
106106
.forStatusCode(200)

examples/jdbc/README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,12 @@ openssl req -newkey rsa:2048 -nodes \
8686
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
8787
-days 365 -out server.crt \
8888
-extfile <(printf "subjectAltName=DNS:localhost,IP:127.0.0.1")
89+
90+
# Only for demo purpose we make key readable by all. On production should be readable only by owner, not even by group.^M
91+
chmod a+r server.key
8992
```
9093

91-
2. Create a `config.d` overlay enabling the HTTPS interface, e.g. `zzz_ssl.xml`:
94+
2. Create a `config.d` overlay enabling the HTTPS interface, e.g. `my_ssl.xml`:
9295

9396
```xml
9497
<clickhouse>
@@ -112,12 +115,22 @@ openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
112115
docker run -d --name clickhouse-ssl -p 8443:8443 \
113116
-v "$PWD/server.crt:/etc/clickhouse-server/certs/server.crt:ro" \
114117
-v "$PWD/server.key:/etc/clickhouse-server/certs/server.key:ro" \
115-
-v "$PWD/zzz_ssl.xml:/etc/clickhouse-server/config.d/zzz_ssl.xml:ro" \
118+
-v "$PWD/my_ssl.xml:/etc/clickhouse-server/config.d/my_ssl.xml:ro" \
119+
-e CLICKHOUSE_PASSWORD="secret" \
116120
clickhouse/clickhouse-server:latest
117121
```
118122

119123
4. Run the example in standalone mode with
120124
`-DchUrl="jdbc:clickhouse://localhost:8443/default" -DchRootCert="$PWD/ca.crt"`.
121125

126+
```shell
127+
mvn exec:java -Dexec.mainClass="com.clickhouse.examples.jdbc.SSLExamples" \
128+
-DchUrl="jdbc:clickhouse:https://localhost:8443/default" \
129+
-DchUser="default" \
130+
-DchPassword="secret" \
131+
-DchRootCert="$PWD/ca.crt"
132+
```
133+
134+
122135
The full description of the server-side TLS configuration is in the official documentation:
123136
[Configuring SSL-TLS](https://clickhouse.com/docs/en/guides/sre/configuring-ssl).

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@
626626

627627
<profiles>
628628
<profile>
629-
<id>analysis</id>
629+
<id>coverage</id>
630630
<build>
631631
<plugins>
632632
<plugin>

0 commit comments

Comments
 (0)