Skip to content

Commit f919802

Browse files
committed
modify yaml
1 parent 1919005 commit f919802

2 files changed

Lines changed: 157 additions & 107 deletions

File tree

.github/workflows/sslTesting.yml

Lines changed: 101 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -29,161 +29,174 @@ jobs:
2929
run: |
3030
mkdir -p /tmp/ssl-certs
3131
cd /tmp/ssl-certs
32-
33-
# Root CA
32+
33+
# Generate Root CA
3434
openssl genrsa -out rootCA.key 4096
35-
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 365 \
36-
-subj "/C=US/ST=CA/L=SF/O=DB/OU=Test/CN=Root" \
37-
-out rootCA.crt
38-
39-
# Intermediate CA
35+
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 365 -out rootCA.crt \
36+
-subj "/C=US/ST=California/L=San Francisco/O=Databricks Test/OU=Testing/CN=Databricks Test Root CA"
37+
38+
# Generate Intermediate CA
4039
openssl genrsa -out intermediateCA.key 4096
41-
openssl req -new -key intermediateCA.key \
42-
-subj "/C=US/ST=CA/L=SF/O=DB/OU=Test/CN=Intermediate" \
43-
-out intermediateCA.csr
44-
45-
cat > intermediate_ext.cnf <<EOF
40+
openssl req -new -key intermediateCA.key -out intermediateCA.csr \
41+
-subj "/C=US/ST=California/L=San Francisco/O=Databricks Test/OU=Testing/CN=Databricks Test Intermediate CA"
42+
43+
# Create extension file for intermediate CA
44+
cat > intermediate_ext.cnf << EOF
4645
[ v3_ca ]
4746
subjectKeyIdentifier = hash
4847
authorityKeyIdentifier = keyid:always,issuer
4948
basicConstraints = critical, CA:true, pathlen:0
5049
keyUsage = critical, digitalSignature, cRLSign, keyCertSign
5150
EOF
5251
52+
# Sign Intermediate CA with Root CA
5353
openssl x509 -req -in intermediateCA.csr -CA rootCA.crt -CAkey rootCA.key \
54-
-CAcreateserial -out intermediateCA.crt -days 365 -sha256 \
55-
-extfile intermediate_ext.cnf -extensions v3_ca
56-
57-
# CA database for revocation
58-
touch index.txt
59-
echo 1000 > serial
60-
echo 1000 > crlnumber
61-
62-
cat > ca.cnf <<EOF
63-
[ ca ]
64-
default_ca = dca
65-
[ dca ]
66-
dir = /tmp/ssl-certs
67-
database = \$dir/index.txt
68-
new_certs_dir = \$dir
69-
certificate = \$dir/intermediateCA.crt
70-
private_key = \$dir/intermediateCA.key
71-
serial = \$dir/serial
72-
crlnumber = \$dir/crlnumber
73-
default_md = sha256
74-
policy = policy_any
75-
x509_extensions = v3_req
76-
crl_extensions = crl_ext
77-
default_days = 365
78-
default_crl_days = 365
79-
unique_subject = no
80-
[ policy_any ]
81-
commonName = supplied
54+
-CAcreateserial -out intermediateCA.crt -days 365 -sha256 \
55+
-extfile intermediate_ext.cnf -extensions v3_ca
56+
57+
# Generate Squid Proxy Certificate
58+
openssl genrsa -out squid.key 2048
59+
openssl req -new -key squid.key -out squid.csr \
60+
-subj "/C=US/ST=California/L=San Francisco/O=Databricks Test/OU=Testing/CN=localhost"
61+
62+
# Create extension file for Squid certificate
63+
cat > squid_ext.cnf << EOF
8264
[ v3_req ]
83-
basicConstraints = CA:FALSE
84-
keyUsage = digitalSignature, keyEncipherment
85-
extendedKeyUsage = serverAuth
86-
subjectAltName = @alt_names
87-
authorityInfoAccess = OCSP;URI:http://ocsp.invalid/none
88-
crlDistributionPoints = URI:file:///tmp/ssl-certs/intermediateCA.crl
89-
[ alt_names ]
65+
basicConstraints = CA:FALSE
66+
keyUsage = digitalSignature, keyEncipherment
67+
extendedKeyUsage = serverAuth
68+
subjectAltName = @alt_names
69+
70+
[alt_names]
9071
DNS.1 = localhost
91-
IP.1 = 127.0.0.1
92-
[ crl_ext ]
93-
authorityKeyIdentifier = keyid,issuer
72+
IP.1 = 127.0.0.1
9473
EOF
9574
96-
# Squid leaf cert
97-
openssl genrsa -out squid.key 2048
98-
openssl req -new -key squid.key \
99-
-subj "/C=US/ST=CA/L=SF/O=DB/OU=Test/CN=localhost" \
100-
-out squid.csr
101-
102-
openssl ca -batch -config ca.cnf -in squid.csr -out squid.crt
103-
openssl ca -batch -config ca.cnf -revoke squid.crt
104-
openssl ca -batch -gencrl -config ca.cnf -out intermediateCA.crl
75+
# Sign Squid certificate with Intermediate CA
76+
openssl x509 -req -in squid.csr -CA intermediateCA.crt -CAkey intermediateCA.key \
77+
-CAcreateserial -out squid.crt -days 365 -sha256 \
78+
-extfile squid_ext.cnf -extensions v3_req
10579
80+
# Create PEM file for Squid
10681
cat squid.crt squid.key > squid.pem
10782
chmod 400 squid.pem
83+
84+
# Copy to appropriate locations
10885
sudo cp squid.pem /etc/squid/
10986
sudo chown proxy:proxy /etc/squid/squid.pem
11087
111-
# Java trust‑store
88+
# Create Java Keystore from Root CA - with proper trust anchors
11289
rm -f test-truststore.jks
90+
91+
# Create a truststore with the root CA as a trusted certificate entry
11392
keytool -importcert -noprompt -trustcacerts -alias rootca -file rootCA.crt \
114-
-keystore test-truststore.jks -storepass changeit
93+
-keystore test-truststore.jks -storepass changeit
94+
95+
# Also add the intermediate CA to the trust store
11596
keytool -importcert -noprompt -trustcacerts -alias intermediateca -file intermediateCA.crt \
116-
-keystore test-truststore.jks -storepass changeit
97+
-keystore test-truststore.jks -storepass changeit
98+
11799
chmod 644 test-truststore.jks
118100
119-
- name: Configure Squid
101+
- name: Configure Squid with Standard SSL
120102
run: |
121103
sudo cp /etc/squid/squid.conf /etc/squid/squid.conf.orig
122-
sudo tee /etc/squid/squid.conf >/dev/null <<'SQ'
104+
105+
echo "
106+
# Basic Configuration
123107
http_port 3128
108+
109+
# Plain HTTPS port with certificate
124110
https_port 3129 tls-cert=/etc/squid/squid.pem
111+
112+
# Access Control - very permissive for testing
125113
http_access allow all
126114
always_direct allow all
115+
116+
# Avoid DNS issues in test environment
127117
dns_v4_first on
118+
119+
# Disable caching for testing
128120
cache deny all
121+
122+
# Logging
129123
debug_options ALL,1
130124
logfile_rotate 0
131125
cache_log /var/log/squid/cache.log
132126
access_log /var/log/squid/access.log squid
133-
SQ
127+
" | sudo tee /etc/squid/squid.conf
128+
134129
sudo mkdir -p /var/log/squid
135130
sudo chown -R proxy:proxy /var/log/squid
136-
sudo squid -k parse || true
131+
sudo chmod 755 /var/log/squid
132+
133+
sudo squid -k parse || echo "Configuration has issues but we'll try to run it anyway"
137134
138135
- name: Start Squid Proxy
139136
run: |
140137
sudo systemctl stop squid || true
141138
sudo pkill squid || true
139+
142140
sudo squid -N -d 3 -f /etc/squid/squid.conf &
141+
143142
sleep 5
143+
ps aux | grep squid
144144
145145
- name: Wait for Squid to be Ready
146146
run: |
147147
for i in {1..5}; do
148-
curl -s -x http://localhost:3128 http://example.com -m 10 -o /dev/null && exit 0
148+
if curl -v -x http://localhost:3128 http://example.com -m 10 -o /dev/null; then
149+
echo "HTTP proxy on 3128 is working!"
150+
break
151+
fi
152+
149153
sleep 3
150154
done
151-
exit 1
155+
156+
if ps aux | grep -v grep | grep squid > /dev/null; then
157+
echo "Squid is running"
158+
else
159+
echo "Squid is not running! Attempting restart..."
160+
sudo squid -N -d 3 -f /etc/squid/squid.conf &
161+
sleep 5
162+
fi
152163
153164
- name: Install Root CA in System Trust Store
154165
run: |
155-
sudo cp /tmp/ssl-certs/rootCA.crt /usr/local/share/ca-certificates/db-root.crt
166+
sudo cp /tmp/ssl-certs/rootCA.crt /usr/local/share/ca-certificates/databricks-test-rootca.crt
156167
sudo update-ca-certificates
157168
158169
- name: Maven Build
159-
run: mvn -q clean package -DskipTests
170+
run: |
171+
mvn clean package -DskipTests
160172
161173
- name: Set Environment Variables
162174
env:
163-
DATABRICKS_TOKEN: ${{ secrets.DATABRICKS_TOKEN }}
164-
DATABRICKS_HOST: ${{ secrets.DATABRICKS_HOST }}
165-
DATABRICKS_HTTP_PATH: ${{ secrets.DATABRICKS_HTTP_PATH }}
166-
HTTP_PROXY_URL: http://localhost:3128
167-
HTTPS_PROXY_URL: https://localhost:3129
168-
TRUSTSTORE_PATH: /tmp/ssl-certs/test-truststore.jks
169-
TRUSTSTORE_PASSWORD: changeit
170-
MAVEN_OPTS: "-Docsp.enable=true -Dcom.sun.security.enableCRLDP=true"
175+
DATABRICKS_TOKEN: ${{ secrets.DATABRICKS_TOKEN }}
176+
DATABRICKS_HOST: ${{ secrets.DATABRICKS_HOST }}
177+
DATABRICKS_HTTP_PATH: ${{ secrets.DATABRICKS_HTTP_PATH }}
178+
HTTP_PROXY_URL: "http://localhost:3128"
179+
HTTPS_PROXY_URL: "https://localhost:3129"
180+
TRUSTSTORE_PATH: "/tmp/ssl-certs/test-truststore.jks"
181+
TRUSTSTORE_PASSWORD: "changeit"
171182
run: |
172-
echo "DATABRICKS_TOKEN=${DATABRICKS_TOKEN}" >> $GITHUB_ENV
173-
echo "DATABRICKS_HOST=${DATABRICKS_HOST}" >> $GITHUB_ENV
183+
echo "DATABRICKS_TOKEN=${DATABRICKS_TOKEN}" >> $GITHUB_ENV
184+
echo "DATABRICKS_HOST=${DATABRICKS_HOST}" >> $GITHUB_ENV
174185
echo "DATABRICKS_HTTP_PATH=${DATABRICKS_HTTP_PATH}" >> $GITHUB_ENV
175-
echo "HTTP_PROXY_URL=${HTTP_PROXY_URL}" >> $GITHUB_ENV
176-
echo "HTTPS_PROXY_URL=${HTTPS_PROXY_URL}" >> $GITHUB_ENV
177-
echo "TRUSTSTORE_PATH=${TRUSTSTORE_PATH}" >> $GITHUB_ENV
186+
echo "HTTP_PROXY_URL=${HTTP_PROXY_URL}" >> $GITHUB_ENV
187+
echo "HTTPS_PROXY_URL=${HTTPS_PROXY_URL}" >> $GITHUB_ENV
188+
echo "TRUSTSTORE_PATH=${TRUSTSTORE_PATH}" >> $GITHUB_ENV
178189
echo "TRUSTSTORE_PASSWORD=${TRUSTSTORE_PASSWORD}" >> $GITHUB_ENV
179-
echo "MAVEN_OPTS=${MAVEN_OPTS}" >> $GITHUB_ENV
180190
181191
- name: Run SSL Tests
182-
run: mvn test -Dtest=**/SSLTest.java
192+
run: |
193+
mvn test -Dtest=**/SSLTest.java
183194
184195
- name: Cleanup
185196
if: always()
186197
run: |
187-
sudo pkill squid || true
188-
sudo rm -f /usr/local/share/ca-certificates/db-root.crt
189-
sudo update-ca-certificates --fresh
198+
sudo systemctl stop squid
199+
sudo systemctl disable squid
200+
sudo pkill squid
201+
sudo rm -f /usr/local/share/ca-certificates/databricks-test-rootca.crt
202+
sudo update-ca-certificates --fresh

src/test/java/com/databricks/client/jdbc/SSLTest.java

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -175,27 +175,64 @@ public void testWithSystemTrustStore() {
175175
}
176176
}
177177

178-
/**
179-
* Revocation checking ON + STRICT (undetermined status is rejected). Because none of the certs we
180-
* generate in the workflow have a CRL/OCSP endpoint, the status ends up “undetermined”, so the
181-
* driver **must fail**.
182-
*/
183178
@Test
184-
public void testRevocationCheckStrictFail() {
185-
System.out.println("Scenario: Revocation ON, undetermined NOT accepted – expect failure");
186-
for (boolean thrift : new boolean[] {true, false}) {
179+
public void testDirectConnectionSystemTrustStoreFallback() {
180+
System.out.println(
181+
"Scenario: UseSystemTrustStore=1 with no system property -> fallback to cacerts (direct)");
182+
183+
// ensure the property is *unset* for this test run
184+
String savedProp = System.getProperty("javax.net.ssl.trustStore");
185+
try {
186+
System.clearProperty("javax.net.ssl.trustStore");
187+
188+
for (boolean thrift : new boolean[] {true, false}) {
189+
String url = buildJdbcUrl(thrift, false, false, false, true, false);
190+
try {
191+
verifyConnect(url);
192+
} catch (Exception e) {
193+
fail(
194+
"Fallback‑to‑cacerts direct connect failed (thrift="
195+
+ thrift
196+
+ "): "
197+
+ e.getMessage());
198+
}
199+
}
200+
} finally {
201+
// restore original system state
202+
if (savedProp != null) {
203+
System.setProperty("javax.net.ssl.trustStore", savedProp);
204+
}
205+
}
206+
}
187207

188-
String url =
189-
buildJdbcUrl(thrift, true, false, false, true, false)
190-
+ "CheckCertificateRevocation=1;"
191-
+ "AcceptUndeterminedCertificateRevocation=0;";
192-
193-
assertThrows(
194-
Exception.class,
195-
() -> verifyConnect(url),
196-
"Strict revocation check should fail when revocation status is undetermined (thrift="
197-
+ thrift
198-
+ ")");
208+
@Test
209+
public void testIgnoreSystemPropertyWhenUseSystemTrustStoreDisabled() {
210+
System.out.println(
211+
"Scenario: bogus javax.net.ssl.trustStore present but UseSystemTrustStore=0 (driver must ignore)");
212+
213+
String savedProp = System.getProperty("javax.net.ssl.trustStore");
214+
try {
215+
System.setProperty("javax.net.ssl.trustStore", "/path/that/does/not/exist.jks");
216+
217+
for (boolean thrift : new boolean[] {true, false}) {
218+
String url = buildJdbcUrl(thrift, false, false, false, false, false);
219+
try {
220+
verifyConnect(url);
221+
} catch (Exception e) {
222+
fail(
223+
"Driver failed to ignore bogus system trust store (thrift="
224+
+ thrift
225+
+ "): "
226+
+ e.getMessage());
227+
}
228+
}
229+
} finally {
230+
// restore original value
231+
if (savedProp != null) {
232+
System.setProperty("javax.net.ssl.trustStore", savedProp);
233+
} else {
234+
System.clearProperty("javax.net.ssl.trustStore");
235+
}
199236
}
200237
}
201238
}

0 commit comments

Comments
 (0)