Skip to content

Commit 93053a6

Browse files
committed
* 'main' of https://github.com/flipt-io/flipt-client-sdks: feat: add TLS configuration support to Ruby SDK (#1136) feat: add TLS configuration support to Java SDK (#1135)
2 parents eb13463 + 143e715 commit 93053a6

File tree

14 files changed

+639
-19
lines changed

14 files changed

+639
-19
lines changed

flipt-client-java/README.md

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,9 @@ The `FliptClient.builder()` method returns a `FliptClient.Builder` object that a
139139
- `authentication`: The authentication strategy to use when communicating with the upstream Flipt instance. If not provided, the client will default to no authentication. See the [Authentication](#authentication) section for more information.
140140
- `reference`: The [reference](https://docs.flipt.io/guides/user/using-references) to use when fetching flag state. If not provided, reference will not be used.
141141
- `fetchMode`: The fetch mode to use when fetching flag state. If not provided, the client will default to polling.
142-
- `errorStrategy`: The error strategy to use when fetching flag state. If not provide, the client will be default to fail. See the [Error Strategies](#error-strategies) section for more information.
142+
- `errorStrategy`: The error strategy to use when fetching flag state. If not provided, the client will default to fail. See the [Error Strategies](#error-strategies) section for more information.
143143
- `snapshot`: The initial snapshot to use when instantiating the client. See the [Snapshotting](#snapshotting) section for more information.
144+
- `tlsConfig`: The TLS configuration to use when connecting to the upstream Flipt instance. See the [TLS Configuration](#tls-configuration) section for more information.
144145

145146
### Authentication
146147

@@ -150,6 +151,111 @@ The `FliptClient` supports the following authentication strategies:
150151
- [Client Token Authentication](https://docs.flipt.io/authentication/using-tokens)
151152
- [JWT Authentication](https://docs.flipt.io/authentication/using-jwts)
152153

154+
### TLS Configuration
155+
156+
The `FliptClient` supports configuring TLS settings for secure connections to Flipt servers. This is useful when:
157+
158+
- Connecting to Flipt servers with self-signed certificates
159+
- Using custom Certificate Authorities (CAs)
160+
- Implementing mutual TLS authentication
161+
- Testing with insecure connections (development only)
162+
163+
#### Basic TLS with Custom CA Certificate
164+
165+
```java
166+
// Using a CA certificate file
167+
TlsConfig tlsConfig = TlsConfig.withCaCertFile("/path/to/ca.pem");
168+
169+
FliptClient client = FliptClient.builder()
170+
.url("https://flipt.example.com")
171+
.tlsConfig(tlsConfig)
172+
.build();
173+
```
174+
175+
```java
176+
// Using CA certificate data directly
177+
String caCertData = Files.readString(Paths.get("/path/to/ca.pem"));
178+
TlsConfig tlsConfig = TlsConfig.withCaCertData(caCertData);
179+
180+
FliptClient client = FliptClient.builder()
181+
.url("https://flipt.example.com")
182+
.tlsConfig(tlsConfig)
183+
.build();
184+
```
185+
186+
#### Mutual TLS Authentication
187+
188+
```java
189+
// Using certificate and key files
190+
TlsConfig tlsConfig = TlsConfig.withMutualTls(
191+
"/path/to/client.pem",
192+
"/path/to/client.key"
193+
);
194+
195+
FliptClient client = FliptClient.builder()
196+
.url("https://flipt.example.com")
197+
.tlsConfig(tlsConfig)
198+
.build();
199+
```
200+
201+
```java
202+
// Using certificate and key data directly
203+
String clientCertData = Files.readString(Paths.get("/path/to/client.pem"));
204+
String clientKeyData = Files.readString(Paths.get("/path/to/client.key"));
205+
206+
TlsConfig tlsConfig = TlsConfig.withMutualTlsData(clientCertData, clientKeyData);
207+
208+
FliptClient client = FliptClient.builder()
209+
.url("https://flipt.example.com")
210+
.tlsConfig(tlsConfig)
211+
.build();
212+
```
213+
214+
#### Advanced TLS Configuration
215+
216+
```java
217+
// Full TLS configuration with all options
218+
TlsConfig tlsConfig = TlsConfig.builder()
219+
.caCertFile(Optional.of("/path/to/ca.pem"))
220+
.clientCertFile(Optional.of("/path/to/client.pem"))
221+
.clientKeyFile(Optional.of("/path/to/client.key"))
222+
.insecureSkipVerify(Optional.of(false))
223+
.build();
224+
225+
FliptClient client = FliptClient.builder()
226+
.url("https://flipt.example.com")
227+
.tlsConfig(tlsConfig)
228+
.build();
229+
```
230+
231+
#### Development Mode (Insecure)
232+
233+
**⚠️ WARNING: Only use this in development environments!**
234+
235+
```java
236+
// Skip certificate verification (NOT for production)
237+
TlsConfig tlsConfig = TlsConfig.insecure();
238+
239+
FliptClient client = FliptClient.builder()
240+
.url("https://localhost:8443")
241+
.tlsConfig(tlsConfig)
242+
.build();
243+
```
244+
245+
#### TLS Configuration Options
246+
247+
The `TlsConfig` class supports the following options:
248+
249+
- `caCertFile`: Path to custom CA certificate file (PEM format)
250+
- `caCertData`: Raw CA certificate content (PEM format) - takes precedence over `caCertFile`
251+
- `insecureSkipVerify`: Skip certificate verification (development only)
252+
- `clientCertFile`: Client certificate file for mutual TLS (PEM format)
253+
- `clientKeyFile`: Client private key file for mutual TLS (PEM format)
254+
- `clientCertData`: Raw client certificate content (PEM format) - takes precedence over `clientCertFile`
255+
- `clientKeyData`: Raw client private key content (PEM format) - takes precedence over `clientKeyFile`
256+
257+
> **Note**: When both file paths and data are provided, the data fields take precedence. For example, if both `caCertFile` and `caCertData` are set, `caCertData` will be used.
258+
153259
### Error Strategies
154260

155261
The client `errorStrategy` method supports the following error strategies:

flipt-client-java/src/main/java/io/flipt/client/FliptClient.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
* var client = FliptClient.builder()
2828
* .url("http://localhost:8080")
2929
* .build();
30+
*
31+
* // With TLS configuration
32+
* var tlsClient = FliptClient.builder()
33+
* .url("https://flipt.example.com")
34+
* .tlsConfig(TlsConfig.withCaCertFile("/path/to/ca.pem"))
35+
* .build();
3036
* }</pre>
3137
*
3238
* @since 1.0.0
@@ -44,6 +50,7 @@ public class FliptClient implements AutoCloseable {
4450
private FetchMode fetchMode;
4551
private ErrorStrategy errorStrategy;
4652
private String snapshot;
53+
private TlsConfig tlsConfig;
4754

4855
private final Pointer engine;
4956
private final ObjectMapper objectMapper;
@@ -79,17 +86,19 @@ private FliptClient(
7986
Duration updateInterval,
8087
FetchMode fetchMode,
8188
ErrorStrategy errorStrategy,
82-
String snapshot) {
89+
String snapshot,
90+
TlsConfig tlsConfig) {
8391
this.environment = environment != null ? environment : "default";
8492
this.namespace = namespace != null ? namespace : "default";
8593
this.url = url != null ? url : "http://localhost:8080";
8694
this.authentication = authentication;
8795
this.reference = reference;
8896
this.requestTimeout = requestTimeout != null ? requestTimeout : Duration.ZERO;
89-
this.updateInterval = updateInterval != null ? updateInterval : Duration.ZERO;
97+
this.updateInterval = updateInterval != null ? updateInterval : Duration.ofSeconds(120);
9098
this.fetchMode = fetchMode != null ? fetchMode : FetchMode.POLLING;
9199
this.errorStrategy = errorStrategy != null ? errorStrategy : ErrorStrategy.FAIL;
92100
this.snapshot = snapshot;
101+
this.tlsConfig = tlsConfig;
93102

94103
this.objectMapper = new ObjectMapper();
95104
this.objectMapper.registerModule(new Jdk8Module());
@@ -105,7 +114,8 @@ private FliptClient(
105114
Optional.ofNullable(this.reference),
106115
Optional.ofNullable(this.fetchMode),
107116
Optional.ofNullable(this.errorStrategy),
108-
Optional.ofNullable(this.snapshot));
117+
Optional.ofNullable(this.snapshot),
118+
Optional.ofNullable(this.tlsConfig));
109119

110120
String clientOptionsSerialized;
111121

flipt-client-java/src/main/java/io/flipt/client/models/ClientOptions.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class ClientOptions {
1717
private final Optional<FetchMode> fetchMode;
1818
private final Optional<ErrorStrategy> errorStrategy;
1919
private final Optional<String> snapshot;
20+
private final Optional<TlsConfig> tlsConfig;
2021

2122
public ClientOptions(
2223
Optional<String> environment,
@@ -28,7 +29,8 @@ public ClientOptions(
2829
Optional<String> reference,
2930
Optional<FetchMode> fetchMode,
3031
Optional<ErrorStrategy> errorStrategy,
31-
Optional<String> snapshot) {
32+
Optional<String> snapshot,
33+
Optional<TlsConfig> tlsConfig) {
3234
this.environment = environment;
3335
this.namespace = namespace;
3436
this.url = url;
@@ -50,6 +52,7 @@ public ClientOptions(
5052
this.fetchMode = fetchMode;
5153
this.errorStrategy = errorStrategy;
5254
this.snapshot = snapshot;
55+
this.tlsConfig = tlsConfig;
5356
}
5457

5558
@JsonProperty("environment")
@@ -101,4 +104,9 @@ public Optional<ErrorStrategy> getErrorStrategy() {
101104
public Optional<String> getSnapshot() {
102105
return snapshot;
103106
}
107+
108+
@JsonProperty("tls_config")
109+
public Optional<TlsConfig> getTlsConfig() {
110+
return tlsConfig;
111+
}
104112
}

0 commit comments

Comments
 (0)