Skip to content

Commit a711360

Browse files
dlg99tiagomlalves
authored andcommitted
Added configs
1 parent 7355a5c commit a711360

File tree

2 files changed

+167
-7
lines changed

2 files changed

+167
-7
lines changed

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

Lines changed: 157 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,69 @@ public class AuthenticatorConfig extends AbstractConfig {
4141
public static final String PRINCIPAL_OPT = "auth.gssapi.principal";
4242
public static final String SERVICE_OPT = "auth.gssapi.service";
4343

44+
/*
45+
# oidc_options:
46+
# # OIDC Authentication server url (required when "oidc" authentication scheme is used).
47+
# issuer: https://auth.example.com/realms/my-realm
48+
#
49+
# # Array of accepted OIDC clients (by default all clients are accepted).
50+
# accepted_audience: []
51+
#
52+
# # Access token claim used to identify the user in the database (by default the "preferred_username"
53+
# # claim is used). When defined, the claim must exist at the top-level of the access token's JWT.
54+
# user_name_claim:
55+
#
56+
# # Array of claims used to identify the user roles in the database. For example, setting this
57+
# # configuration to "[ realm_roles.roles ]" will assume all OIDC realm roles. If the claim doesn't
58+
# # exist or does not identify an array of strings in the JWT, the setting will be ignored. Roles
59+
# # defined in these claims must be previously defined in the database such that any privilege grant
60+
# # is recognized and validated.
61+
# user_roles_claims: []
62+
#
63+
# # Set to true to initiate a TLS encrypted connections. Defaults to false. If case of
64+
# # truststore_path being set, it will default to true.
65+
# use_tls: false
66+
#
67+
# # Sets the keystore path with valid certificates to establish encrypted connections with the OIDC Server.
68+
# # When TLS is enabled, failure to set this option or an invalid path will result in an error.
69+
# truststore_path:
70+
# # Keystore password
71+
# truststore_password:
72+
# # Keystore type (JKS or PKCS12). By default, the trustore type is inferred from the keystore
73+
# # extension. For `.p12`, `.pkcs12`, or `.pfx` files, PKCS12 is used. For `.keystore` or
74+
# # `.jks` files, JKS is used. In case the keystore type cannot be inferred from the extension,
75+
# # this option must be set.
76+
# truststore_type: jks
77+
#
78+
# # Compatibility option, allowing older drivers to use OIDC authentication via password
79+
# # authentication, by using a pre-configurable username and passing an OIDC JWT access token as
80+
# # password. Defaults to false.
81+
# # allow_token_via_password_authentication: false
82+
# # When the above option is true, it allows configuring the username which will be used
83+
# # to detect that an OIDC JWT access token is being sent as password.
84+
# # token_username: oauth-bearer
85+
*/
86+
87+
public static final String OIDC_ISSUER = "auth.oidc.issuer";
88+
public static final String OIDC_ACCEPTED_AUDIENCE = "auth.oidc.accepted_audience";
89+
public static final String OIDC_USER_NAME_CLAIM = "auth.oidc.user_name_claim";
90+
public static final String OIDC_USER_ROLES_CLAIMS = "auth.oidc.user_roles_claims";
91+
public static final String OIDC_USE_TLS = "auth.oidc.use_tls";
92+
public static final String OIDC_TRUSTSTORE_PATH = "auth.oidc.truststore_path";
93+
public static final String OIDC_TRUSTSTORE_PASSWORD = "auth.oidc.truststore_password";
94+
public static final String OIDC_TRUSTSTORE_TYPE = "auth.oidc.truststore_type";
95+
public static final String OIDC_ALLOW_TOKEN_VIA_PASSWORD_AUTHENTICATION =
96+
"auth.oidc.allow_token_via_password_authentication";
97+
public static final String OIDC_TOKEN_USERNAME = "auth.oidc.token_username";
98+
4499
private static final Logger log = LoggerFactory.getLogger(AuthenticatorConfig.class);
45100
public static final ConfigDef CONFIG_DEF =
46101
new ConfigDef()
47102
.define(
48103
PROVIDER_OPT,
49104
ConfigDef.Type.STRING,
50105
"None",
51-
ConfigDef.ValidString.in("None", "PLAIN", "GSSAPI"),
106+
ConfigDef.ValidString.in("None", "PLAIN", "GSSAPI", "OIDC"),
52107
ConfigDef.Importance.HIGH,
53108
"Authentication provider")
54109
.define(
@@ -80,7 +135,74 @@ public class AuthenticatorConfig extends AbstractConfig {
80135
ConfigDef.Type.STRING,
81136
"dse",
82137
ConfigDef.Importance.HIGH,
83-
"SASL service name to use for GSSAPI provider authentication");
138+
"SASL service name to use for GSSAPI provider authentication")
139+
.define(
140+
OIDC_ISSUER,
141+
ConfigDef.Type.STRING,
142+
"",
143+
ConfigDef.Importance.HIGH,
144+
"OIDC Authentication server url")
145+
.define(
146+
OIDC_ACCEPTED_AUDIENCE,
147+
ConfigDef.Type.LIST,
148+
"",
149+
ConfigDef.Importance.HIGH,
150+
"Array of accepted OIDC clients")
151+
.define(
152+
OIDC_USER_NAME_CLAIM,
153+
ConfigDef.Type.STRING,
154+
"preferred_username",
155+
ConfigDef.Importance.HIGH,
156+
"Access token claim used to identify the user in the database")
157+
.define(
158+
OIDC_USER_ROLES_CLAIMS,
159+
ConfigDef.Type.LIST,
160+
"",
161+
ConfigDef.Importance.HIGH,
162+
"Array of claims used to identify the user roles in the database")
163+
.define(
164+
OIDC_USE_TLS,
165+
ConfigDef.Type.BOOLEAN,
166+
false,
167+
ConfigDef.Importance.HIGH,
168+
"Set to true to initiate a TLS encrypted connections. Defaults to false. If case of "
169+
+ "truststore_path being set, it will default to true.")
170+
.define(
171+
OIDC_TRUSTSTORE_PATH,
172+
ConfigDef.Type.STRING,
173+
"",
174+
ConfigDef.Importance.HIGH,
175+
"Sets the keystore path with valid certificates to establish encrypted connections with the OIDC Server.")
176+
.define(
177+
OIDC_TRUSTSTORE_PASSWORD,
178+
ConfigDef.Type.PASSWORD,
179+
"",
180+
ConfigDef.Importance.HIGH,
181+
"Keystore password")
182+
.define(
183+
OIDC_TRUSTSTORE_TYPE,
184+
ConfigDef.Type.STRING,
185+
"jks",
186+
ConfigDef.Importance.HIGH,
187+
"Keystore type (JKS or PKCS12). By default, the trustore type is inferred from the keystore "
188+
+ "extension. For `.p12`, `.pkcs12`, or `.pfx` files, PKCS12 is used. For `.keystore` or "
189+
+ "`.jks` files, JKS is used. In case the keystore type cannot be inferred from the extension, "
190+
+ "this option must be set.")
191+
.define(
192+
OIDC_ALLOW_TOKEN_VIA_PASSWORD_AUTHENTICATION,
193+
ConfigDef.Type.BOOLEAN,
194+
false,
195+
ConfigDef.Importance.HIGH,
196+
"Compatibility option, allowing older drivers to use OIDC authentication via password "
197+
+ "authentication, by using a pre-configurable username and passing an OIDC JWT access token as "
198+
+ "password.")
199+
.define(
200+
OIDC_TOKEN_USERNAME,
201+
ConfigDef.Type.STRING,
202+
"oauth-bearer",
203+
ConfigDef.Importance.HIGH,
204+
"When the above option is true, it allows configuring the username which will be used "
205+
+ "to detect that an OIDC JWT access token is being sent as password.");
84206

85207
@Nullable private final Path keyTabPath;
86208

@@ -101,9 +223,14 @@ public AuthenticatorConfig(Map<String, String> authSettings) {
101223
if (getService().isEmpty()) {
102224
throw new ConfigException(SERVICE_OPT, "<empty>", "is required");
103225
}
104-
105226
assertAccessibleFile(keyTabPath, KEYTAB_OPT);
106227
}
228+
229+
if (provider == Provider.OIDC) {
230+
if (getString(OIDC_ISSUER).isEmpty()) {
231+
throw new ConfigException(OIDC_ISSUER, "<empty>", "is required");
232+
}
233+
}
107234
}
108235

109236
/**
@@ -139,6 +266,19 @@ private static Map<String, String> sanitizeAuthSettings(Map<String, String> auth
139266
mutated.put(PRINCIPAL_OPT, getPrincipalFromKeyTab(keyTabPath.toString()));
140267
}
141268
}
269+
270+
if ("OIDC".equals(provider)) {
271+
// OIDC provider requires issuer to be set.
272+
if (!mutated.containsKey(OIDC_ISSUER) || mutated.get(OIDC_ISSUER).isEmpty()) {
273+
throw new ConfigException(OIDC_ISSUER, "<empty>", "is required for OIDC authentication");
274+
}
275+
// If truststore path is set, use TLS.
276+
if (mutated.containsKey(OIDC_TRUSTSTORE_PATH)
277+
&& !mutated.get(OIDC_TRUSTSTORE_PATH).isEmpty()) {
278+
mutated.put(OIDC_USE_TLS, "true");
279+
}
280+
}
281+
142282
return ImmutableMap.<String, String>builder().putAll(mutated).build();
143283
}
144284

@@ -191,7 +331,7 @@ public Provider getProvider() {
191331
return Provider.valueOf(providerString);
192332
} catch (IllegalArgumentException e) {
193333
throw new ConfigException(
194-
PROVIDER_OPT, providerString, "valid values are None, PLAIN, GSSAPI");
334+
PROVIDER_OPT, providerString, "valid values are None, PLAIN, GSSAPI, OIDC");
195335
}
196336
}
197337

@@ -226,12 +366,23 @@ public String toString() {
226366
PASSWORD_OPT,
227367
KEYTAB_OPT,
228368
PRINCIPAL_OPT,
229-
SERVICE_OPT);
369+
SERVICE_OPT,
370+
// OIDC opts
371+
OIDC_ISSUER,
372+
OIDC_ACCEPTED_AUDIENCE,
373+
OIDC_USER_NAME_CLAIM,
374+
OIDC_USE_TLS,
375+
OIDC_TRUSTSTORE_PATH,
376+
OIDC_TRUSTSTORE_PASSWORD,
377+
OIDC_TRUSTSTORE_TYPE,
378+
OIDC_ALLOW_TOKEN_VIA_PASSWORD_AUTHENTICATION,
379+
OIDC_TOKEN_USERNAME);
230380
}
231381

232382
public enum Provider {
233383
None,
234384
PLAIN,
235-
GSSAPI
385+
GSSAPI,
386+
OIDC
236387
}
237388
}

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)