Skip to content

Commit bf7b100

Browse files
dlg99tiagomlalves
authored andcommitted
DSP-24890 Adds OIDC configuration options
Adds OIDC configuration options to connect to DSE/HCD.
1 parent 7355a5c commit bf7b100

File tree

2 files changed

+120
-8
lines changed

2 files changed

+120
-8
lines changed

common/src/main/java/com/datastax/oss/common/sink/config/AuthenticatorConfig.java

Lines changed: 110 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import edu.umd.cs.findbugs.annotations.Nullable;
2525
import java.lang.reflect.InvocationTargetException;
2626
import java.lang.reflect.Method;
27+
import java.net.URI;
28+
import java.net.URISyntaxException;
2729
import java.nio.file.Path;
2830
import java.util.HashMap;
2931
import java.util.Map;
@@ -39,7 +41,13 @@ public class AuthenticatorConfig extends AbstractConfig {
3941
public static final String PASSWORD_OPT = "auth.password";
4042
public static final String KEYTAB_OPT = "auth.gssapi.keyTab";
4143
public static final String PRINCIPAL_OPT = "auth.gssapi.principal";
42-
public static final String SERVICE_OPT = "auth.gssapi.service";
44+
public static final String SERVICE_OPT = "auth.gssapi.cservice";
45+
public static final String OIDC_ISSUER_OPT = "auth.oidc.issuer";
46+
public static final String OIDC_CLIENT_ID_OPT = "auth.oidc.client_id";
47+
public static final String OIDC_CLIENT_SECRET_OPT = "auth.oidc.client_secret";
48+
public static final String OIDC_USE_TLS_OPT = "auth.oidc.use_tls";
49+
public static final String OIDC_TRUSTSTORE_PATH_OPT = "auth.oidc.truststore_path";
50+
public static final String OIDC_TRUSTSTORE_PASSWORD_OPT = "auth.oidc.truststore_password";
4351

4452
private static final Logger log = LoggerFactory.getLogger(AuthenticatorConfig.class);
4553
public static final ConfigDef CONFIG_DEF =
@@ -48,7 +56,7 @@ public class AuthenticatorConfig extends AbstractConfig {
4856
PROVIDER_OPT,
4957
ConfigDef.Type.STRING,
5058
"None",
51-
ConfigDef.ValidString.in("None", "PLAIN", "GSSAPI"),
59+
ConfigDef.ValidString.in("None", "PLAIN", "GSSAPI", "OIDC"),
5260
ConfigDef.Importance.HIGH,
5361
"Authentication provider")
5462
.define(
@@ -80,7 +88,43 @@ public class AuthenticatorConfig extends AbstractConfig {
8088
ConfigDef.Type.STRING,
8189
"dse",
8290
ConfigDef.Importance.HIGH,
83-
"SASL service name to use for GSSAPI provider authentication");
91+
"SASL service name to use for GSSAPI provider authentication")
92+
.define(
93+
OIDC_ISSUER_OPT,
94+
ConfigDef.Type.STRING,
95+
"",
96+
ConfigDef.Importance.HIGH,
97+
"OIDC Authentication server url")
98+
.define(
99+
OIDC_CLIENT_ID_OPT,
100+
ConfigDef.Type.STRING,
101+
"",
102+
ConfigDef.Importance.HIGH,
103+
"OIDC Client Id to use for authentication")
104+
.define(
105+
OIDC_CLIENT_SECRET_OPT,
106+
ConfigDef.Type.PASSWORD,
107+
"",
108+
ConfigDef.Importance.HIGH,
109+
"OIDC Client Secret to use for authentication")
110+
.define(
111+
OIDC_USE_TLS_OPT,
112+
ConfigDef.Type.BOOLEAN,
113+
true,
114+
ConfigDef.Importance.HIGH,
115+
"Set to false to disable TLS encrypted connections. Defaults to true.")
116+
.define(
117+
OIDC_TRUSTSTORE_PATH_OPT,
118+
ConfigDef.Type.STRING,
119+
"",
120+
ConfigDef.Importance.HIGH,
121+
"Path to the truststore file containing the OIDC issuer's certificate.")
122+
.define(
123+
OIDC_TRUSTSTORE_PASSWORD_OPT,
124+
ConfigDef.Type.STRING,
125+
"",
126+
ConfigDef.Importance.HIGH,
127+
"Truststore file password containing the OIDC issuer's certificate.");
84128

85129
@Nullable private final Path keyTabPath;
86130

@@ -101,9 +145,28 @@ public AuthenticatorConfig(Map<String, String> authSettings) {
101145
if (getService().isEmpty()) {
102146
throw new ConfigException(SERVICE_OPT, "<empty>", "is required");
103147
}
104-
105148
assertAccessibleFile(keyTabPath, KEYTAB_OPT);
106149
}
150+
151+
if (provider == Provider.OIDC) {
152+
if (getString(OIDC_ISSUER_OPT).isEmpty()) {
153+
throw new ConfigException(OIDC_ISSUER_OPT, "<empty>", "is required");
154+
}
155+
156+
try {
157+
new URI(getString(OIDC_ISSUER_OPT));
158+
} catch (URISyntaxException e) {
159+
throw new ConfigException(
160+
OIDC_ISSUER_OPT, getString(OIDC_ISSUER_OPT), "is not a valid URI: " + e.getMessage());
161+
}
162+
163+
if (getString(OIDC_CLIENT_ID_OPT).isEmpty()) {
164+
throw new ConfigException(OIDC_CLIENT_ID_OPT, "<empty>", "is required");
165+
}
166+
if (getPassword(OIDC_CLIENT_SECRET_OPT).value().isEmpty()) {
167+
throw new ConfigException(OIDC_CLIENT_SECRET_OPT, "<empty>", "is required");
168+
}
169+
}
107170
}
108171

109172
/**
@@ -139,6 +202,13 @@ private static Map<String, String> sanitizeAuthSettings(Map<String, String> auth
139202
mutated.put(PRINCIPAL_OPT, getPrincipalFromKeyTab(keyTabPath.toString()));
140203
}
141204
}
205+
206+
if ("OIDC".equals(provider)) {
207+
if (!mutated.containsKey(OIDC_USE_TLS_OPT) || mutated.get(OIDC_USE_TLS_OPT).isEmpty()) {
208+
mutated.put(OIDC_USE_TLS_OPT, "true");
209+
}
210+
}
211+
142212
return ImmutableMap.<String, String>builder().putAll(mutated).build();
143213
}
144214

@@ -191,7 +261,7 @@ public Provider getProvider() {
191261
return Provider.valueOf(providerString);
192262
} catch (IllegalArgumentException e) {
193263
throw new ConfigException(
194-
PROVIDER_OPT, providerString, "valid values are None, PLAIN, GSSAPI");
264+
PROVIDER_OPT, providerString, "valid values are None, PLAIN, GSSAPI, OIDC");
195265
}
196266
}
197267

@@ -216,6 +286,35 @@ public String getService() {
216286
return getString(SERVICE_OPT);
217287
}
218288

289+
public URI getOIDCIssuer() {
290+
try {
291+
return new URI(getString(OIDC_ISSUER_OPT));
292+
} catch (URISyntaxException e) {
293+
// This should never happen because we validate the URI in the constructor.
294+
return null;
295+
}
296+
}
297+
298+
public String getOIDCClientId() {
299+
return getString(OIDC_CLIENT_ID_OPT);
300+
}
301+
302+
public String getOIDCClientSecret() {
303+
return getPassword(OIDC_CLIENT_SECRET_OPT).value();
304+
}
305+
306+
public boolean getOIDCUseTLS() {
307+
return getBoolean(OIDC_USE_TLS_OPT);
308+
}
309+
310+
public Path getOIDCTruststorePath() {
311+
return getFilePath(getString(OIDC_TRUSTSTORE_PATH_OPT));
312+
}
313+
314+
public String getOIDCTruststorePassword() {
315+
return getString(OIDC_TRUSTSTORE_PASSWORD_OPT);
316+
}
317+
219318
@Override
220319
public String toString() {
221320
return configToString(
@@ -226,12 +325,16 @@ public String toString() {
226325
PASSWORD_OPT,
227326
KEYTAB_OPT,
228327
PRINCIPAL_OPT,
229-
SERVICE_OPT);
328+
SERVICE_OPT,
329+
OIDC_ISSUER_OPT,
330+
OIDC_CLIENT_ID_OPT,
331+
OIDC_CLIENT_SECRET_OPT);
230332
}
231333

232334
public enum Provider {
233335
None,
234336
PLAIN,
235-
GSSAPI
337+
GSSAPI,
338+
OIDC
236339
}
237340
}

common/src/main/java/com/datastax/oss/common/sink/state/LifeCycleManager.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,11 +620,20 @@ private static void processAuthenticatorConfig(
620620
.withStringMap(
621621
AUTH_PROVIDER_SASL_PROPERTIES, ImmutableMap.of("javax.security.sasl.qop", "auth"))
622622
.withStringMap(DseDriverOption.AUTH_PROVIDER_LOGIN_CONFIGURATION, loginConfig);
623+
} else if (authConfig.getProvider() == AuthenticatorConfig.Provider.OIDC) {
624+
/*
625+
TODO: OidcApiAuthProvider.
626+
configLoaderBuilder
627+
.withClass(AUTH_PROVIDER_CLASS, OidcApiAuthProvider.class)
628+
.withString(AUTH_PROVIDER_SERVICE, authConfig.getService())
629+
....
630+
*/
631+
throw new RuntimeException("TODO: OIDC authentication is not supported yet.");
623632
}
624633
}
625634

626635
/**
627-
* Prepare insert or update (depending on whether or not the table is a COUNTER table), and delete
636+
* Prepare insert or update (depending on whether the table is a COUNTER table), and delete
628637
* statements asynchronously.
629638
*
630639
* @param session the session

0 commit comments

Comments
 (0)