24
24
import edu .umd .cs .findbugs .annotations .Nullable ;
25
25
import java .lang .reflect .InvocationTargetException ;
26
26
import java .lang .reflect .Method ;
27
+ import java .net .URI ;
28
+ import java .net .URISyntaxException ;
27
29
import java .nio .file .Path ;
28
30
import java .util .HashMap ;
29
31
import java .util .Map ;
@@ -39,7 +41,13 @@ public class AuthenticatorConfig extends AbstractConfig {
39
41
public static final String PASSWORD_OPT = "auth.password" ;
40
42
public static final String KEYTAB_OPT = "auth.gssapi.keyTab" ;
41
43
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" ;
43
51
44
52
private static final Logger log = LoggerFactory .getLogger (AuthenticatorConfig .class );
45
53
public static final ConfigDef CONFIG_DEF =
@@ -48,7 +56,7 @@ public class AuthenticatorConfig extends AbstractConfig {
48
56
PROVIDER_OPT ,
49
57
ConfigDef .Type .STRING ,
50
58
"None" ,
51
- ConfigDef .ValidString .in ("None" , "PLAIN" , "GSSAPI" ),
59
+ ConfigDef .ValidString .in ("None" , "PLAIN" , "GSSAPI" , "OIDC" ),
52
60
ConfigDef .Importance .HIGH ,
53
61
"Authentication provider" )
54
62
.define (
@@ -80,7 +88,43 @@ public class AuthenticatorConfig extends AbstractConfig {
80
88
ConfigDef .Type .STRING ,
81
89
"dse" ,
82
90
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." );
84
128
85
129
@ Nullable private final Path keyTabPath ;
86
130
@@ -101,9 +145,28 @@ public AuthenticatorConfig(Map<String, String> authSettings) {
101
145
if (getService ().isEmpty ()) {
102
146
throw new ConfigException (SERVICE_OPT , "<empty>" , "is required" );
103
147
}
104
-
105
148
assertAccessibleFile (keyTabPath , KEYTAB_OPT );
106
149
}
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
+ }
107
170
}
108
171
109
172
/**
@@ -139,6 +202,13 @@ private static Map<String, String> sanitizeAuthSettings(Map<String, String> auth
139
202
mutated .put (PRINCIPAL_OPT , getPrincipalFromKeyTab (keyTabPath .toString ()));
140
203
}
141
204
}
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
+
142
212
return ImmutableMap .<String , String >builder ().putAll (mutated ).build ();
143
213
}
144
214
@@ -191,7 +261,7 @@ public Provider getProvider() {
191
261
return Provider .valueOf (providerString );
192
262
} catch (IllegalArgumentException e ) {
193
263
throw new ConfigException (
194
- PROVIDER_OPT , providerString , "valid values are None, PLAIN, GSSAPI" );
264
+ PROVIDER_OPT , providerString , "valid values are None, PLAIN, GSSAPI, OIDC " );
195
265
}
196
266
}
197
267
@@ -216,6 +286,35 @@ public String getService() {
216
286
return getString (SERVICE_OPT );
217
287
}
218
288
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
+
219
318
@ Override
220
319
public String toString () {
221
320
return configToString (
@@ -226,12 +325,16 @@ public String toString() {
226
325
PASSWORD_OPT ,
227
326
KEYTAB_OPT ,
228
327
PRINCIPAL_OPT ,
229
- SERVICE_OPT );
328
+ SERVICE_OPT ,
329
+ OIDC_ISSUER_OPT ,
330
+ OIDC_CLIENT_ID_OPT ,
331
+ OIDC_CLIENT_SECRET_OPT );
230
332
}
231
333
232
334
public enum Provider {
233
335
None ,
234
336
PLAIN ,
235
- GSSAPI
337
+ GSSAPI ,
338
+ OIDC
236
339
}
237
340
}
0 commit comments