Skip to content

Commit 6398240

Browse files
authored
Merge branch 'main' into get-field-filter-optimization
Signed-off-by: Craig Perkins <[email protected]>
2 parents 2a3965b + 46e5937 commit 6398240

File tree

19 files changed

+266
-195
lines changed

19 files changed

+266
-195
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55

66
## [Unreleased 3.x]
77
### Added
8+
- Add support for Basic Authentication in webhook audit log sink using `plugins.security.audit.config.username` and `plugins.security.audit.config.password` ([#5792](https://github.com/opensearch-project/security/pull/5792))
89

910
### Changed
1011
- Ensure all restHeaders from ActionPlugin.getRestHeaders are carried to threadContext for tracing ([#5396](https://github.com/opensearch-project/security/pull/5396))
@@ -23,7 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2324
- Add support for X509 v3 extensions (SAN) for authentication ([#5701](https://github.com/opensearch-project/security/pull/5701))
2425
- [Resource Sharing] Requires default_owner for resource/migrate API ([#5789](https://github.com/opensearch-project/security/pull/5789))
2526
- Optimize getFieldFilter to only return a predicate when index has FLS restrictions for user ([#5777](https://github.com/opensearch-project/security/pull/5777))
26-
27+
- Add --timeout (-to) as an option to securityadmin.sh ([#5787](https://github.com/opensearch-project/security/pull/5787))
2728

2829
### Bug Fixes
2930
- Create a WildcardMatcher.NONE when creating a WildcardMatcher with an empty string ([#5694](https://github.com/opensearch-project/security/pull/5694))

src/main/java/org/opensearch/security/OpenSearchSecurityPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,14 +1827,14 @@ public List<Setting<?>> getSettings() {
18271827
); // not filtered here
18281828
settings.add(
18291829
Setting.simpleString(
1830-
ConfigConstants.SECURITY_AUDIT_CONFIG_DEFAULT_PREFIX + ConfigConstants.SECURITY_AUDIT_EXTERNAL_OPENSEARCH_USERNAME,
1830+
ConfigConstants.SECURITY_AUDIT_CONFIG_DEFAULT_PREFIX + ConfigConstants.SECURITY_AUDIT_CONFIG_USERNAME,
18311831
Property.NodeScope,
18321832
Property.Filtered
18331833
)
18341834
);
18351835
settings.add(
18361836
Setting.simpleString(
1837-
ConfigConstants.SECURITY_AUDIT_CONFIG_DEFAULT_PREFIX + ConfigConstants.SECURITY_AUDIT_EXTERNAL_OPENSEARCH_PASSWORD,
1837+
ConfigConstants.SECURITY_AUDIT_CONFIG_DEFAULT_PREFIX + ConfigConstants.SECURITY_AUDIT_CONFIG_PASSWORD,
18381838
Property.NodeScope,
18391839
Property.Filtered
18401840
)

src/main/java/org/opensearch/security/auditlog/sink/ExternalOpenSearchSink.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ public ExternalOpenSearchSink(
8383
ConfigConstants.SECURITY_AUDIT_EXTERNAL_OPENSEARCH_ENABLE_SSL_CLIENT_AUTH,
8484
ConfigConstants.OPENDISTRO_SECURITY_AUDIT_SSL_ENABLE_SSL_CLIENT_AUTH_DEFAULT
8585
);
86-
final String user = sinkSettings.get(ConfigConstants.SECURITY_AUDIT_EXTERNAL_OPENSEARCH_USERNAME);
87-
final String password = sinkSettings.get(ConfigConstants.SECURITY_AUDIT_EXTERNAL_OPENSEARCH_PASSWORD);
86+
final String user = sinkSettings.get(ConfigConstants.SECURITY_AUDIT_CONFIG_USERNAME);
87+
final String password = sinkSettings.get(ConfigConstants.SECURITY_AUDIT_CONFIG_PASSWORD);
8888

8989
final HttpClientBuilder builder = HttpClient.builder(servers.toArray(new String[0]));
9090

src/main/java/org/opensearch/security/auditlog/sink/WebhookSink.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.nio.file.Path;
1919
import java.security.KeyStore;
2020
import java.security.cert.X509Certificate;
21+
import java.util.Base64;
2122
import java.util.concurrent.TimeUnit;
2223
import javax.net.ssl.SSLContext;
2324

@@ -60,6 +61,9 @@ public class WebhookSink extends AuditLogSink {
6061
WebhookFormat webhookFormat = null;
6162
final boolean verifySSL;
6263
final KeyStore effectiveTruststore;
64+
private final String username;
65+
private final String password;
66+
private final String basicAuthHeader;
6367

6468
public WebhookSink(
6569
final String name,
@@ -77,6 +81,19 @@ public WebhookSink(
7781
final String webhookUrl = sinkSettings.get(ConfigConstants.SECURITY_AUDIT_WEBHOOK_URL);
7882
final String format = sinkSettings.get(ConfigConstants.SECURITY_AUDIT_WEBHOOK_FORMAT);
7983

84+
// Read basic auth credentials
85+
this.username = sinkSettings.get(ConfigConstants.SECURITY_AUDIT_CONFIG_USERNAME);
86+
this.password = sinkSettings.get(ConfigConstants.SECURITY_AUDIT_CONFIG_PASSWORD);
87+
88+
// Generate Basic Auth header if credentials are provided
89+
if (this.username != null && this.password != null) {
90+
String credentials = this.username + ":" + this.password;
91+
String encodedCredentials = Base64.getEncoder().encodeToString(credentials.getBytes(StandardCharsets.UTF_8));
92+
this.basicAuthHeader = "Basic " + encodedCredentials;
93+
} else {
94+
this.basicAuthHeader = null;
95+
}
96+
8097
verifySSL = sinkSettings.getAsBoolean(ConfigConstants.SECURITY_AUDIT_WEBHOOK_SSL_VERIFY, true);
8198
httpClient = getHttpClient();
8299

@@ -225,6 +242,12 @@ boolean get(AuditMessage msg) {
225242

226243
protected boolean doGet(String url) {
227244
HttpGet httpGet = new HttpGet(url);
245+
246+
// Add Basic Auth header if credentials are configured
247+
if (basicAuthHeader != null) {
248+
httpGet.setHeader("Authorization", basicAuthHeader);
249+
}
250+
228251
CloseableHttpResponse serverResponse = null;
229252
try {
230253
serverResponse = httpClient.execute(httpGet);
@@ -280,6 +303,11 @@ protected boolean doPost(String url, String payload) {
280303

281304
HttpPost postRequest = new HttpPost(url);
282305

306+
// Add Basic Auth header if credentials are configured
307+
if (basicAuthHeader != null) {
308+
postRequest.setHeader("Authorization", basicAuthHeader);
309+
}
310+
283311
StringEntity input = new StringEntity(payload, webhookFormat.contentType.withCharset(StandardCharsets.UTF_8));
284312
postRequest.setEntity(input);
285313

src/main/java/org/opensearch/security/auth/http/saml/SamlFilesystemMetadataResolver.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,7 @@ public class SamlFilesystemMetadataResolver extends FilesystemMetadataResolver {
2929

3030
@Override
3131
protected byte[] fetchMetadata() throws ResolverException {
32-
try {
33-
return AccessController.doPrivilegedChecked(SamlFilesystemMetadataResolver.super::fetchMetadata);
34-
} catch (Exception e) {
35-
36-
if (e instanceof ResolverException) {
37-
throw (ResolverException) e;
38-
} else {
39-
throw new RuntimeException(e);
40-
}
41-
}
32+
return AccessController.doPrivilegedChecked(SamlFilesystemMetadataResolver.super::fetchMetadata);
4233
}
4334

4435
private static File getMetadataFile(String filePath, Settings settings, Path configPath) {

src/main/java/org/opensearch/security/auth/http/saml/SamlHTTPMetadataResolver.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,7 @@ public class SamlHTTPMetadataResolver extends HTTPMetadataResolver {
3737

3838
@Override
3939
protected byte[] fetchMetadata() throws ResolverException {
40-
try {
41-
return AccessController.doPrivilegedChecked(SamlHTTPMetadataResolver.super::fetchMetadata);
42-
} catch (Exception e) {
43-
if (e instanceof ResolverException) {
44-
throw (ResolverException) e;
45-
} else {
46-
throw new RuntimeException(e);
47-
}
48-
}
40+
return AccessController.doPrivilegedChecked(SamlHTTPMetadataResolver.super::fetchMetadata);
4941
}
5042

5143
private static SettingsBasedSSLConfiguratorV4.SSLConfig getSSLConfig(Settings settings, Path configPath) throws Exception {

src/main/java/org/opensearch/security/auth/ldap/util/LdapHelper.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,8 @@ public static List<LdapEntry> search(
6666

6767
return entries;
6868
});
69-
} catch (Exception e) {
70-
if (e instanceof LdapException) {
71-
throw (LdapException) e;
72-
} else if (e instanceof RuntimeException) {
73-
throw (RuntimeException) e;
74-
} else {
75-
throw new RuntimeException(e);
76-
}
69+
} catch (InvalidNameException e) {
70+
throw new RuntimeException(e);
7771
}
7872
}
7973

src/main/java/org/opensearch/security/auth/ldap2/LDAPAuthenticationBackend2.java

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,7 @@ public LDAPAuthenticationBackend2(final Settings settings, final Path configPath
8787

8888
@Override
8989
public User authenticate(AuthenticationContext context) throws OpenSearchSecurityException {
90-
try {
91-
return AccessController.doPrivilegedChecked(() -> authenticate0(context));
92-
} catch (Exception e) {
93-
if (e instanceof OpenSearchSecurityException) {
94-
throw (OpenSearchSecurityException) e;
95-
} else if (e instanceof RuntimeException) {
96-
throw (RuntimeException) e;
97-
} else {
98-
throw new RuntimeException(e);
99-
}
100-
}
90+
return AccessController.doPrivilegedChecked(() -> authenticate0(context));
10191
}
10292

10393
private User authenticate0(AuthenticationContext context) throws OpenSearchSecurityException {
@@ -217,19 +207,7 @@ public Optional<User> impersonate(User user) {
217207
}
218208

219209
private void authenticateByLdapServer(final Connection connection, final String dn, byte[] password) throws LdapException {
220-
try {
221-
AccessController.doPrivilegedChecked(
222-
() -> connection.getProviderConnection().bind(new BindRequest(dn, new Credential(password)))
223-
);
224-
} catch (Exception e) {
225-
if (e instanceof LdapException) {
226-
throw (LdapException) e;
227-
} else if (e instanceof RuntimeException) {
228-
throw (RuntimeException) e;
229-
} else {
230-
throw new RuntimeException(e);
231-
}
232-
}
210+
AccessController.doPrivilegedChecked(() -> connection.getProviderConnection().bind(new BindRequest(dn, new Credential(password))));
233211
}
234212

235213
private void authenticateByLdapServerWithSeparateConnection(final String dn, byte[] password) throws LdapException {

src/main/java/org/opensearch/security/auth/ldap2/LDAPAuthorizationBackend2.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,7 @@ private static List<Map.Entry<String, Settings>> convertOldStyleSettingsToNewSty
120120

121121
@Override
122122
public User addRoles(final User user, AuthenticationContext context) throws OpenSearchSecurityException {
123-
try {
124-
return AccessController.doPrivilegedChecked(() -> addRoles0(user, context));
125-
} catch (Exception e) {
126-
if (e instanceof OpenSearchSecurityException) {
127-
throw (OpenSearchSecurityException) e;
128-
} else if (e instanceof RuntimeException) {
129-
throw (RuntimeException) e;
130-
} else {
131-
throw new RuntimeException(e);
132-
}
133-
}
123+
return AccessController.doPrivilegedChecked(() -> addRoles0(user, context));
134124
}
135125

136126
private User addRoles0(final User user, AuthenticationContext context) throws OpenSearchSecurityException {

src/main/java/org/opensearch/security/auth/ldap2/MakeJava9Happy.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@ static ClassLoader getClassLoader() {
2727
}
2828

2929
if (classLoader == null) {
30-
31-
try {
32-
return AccessController.doPrivilegedChecked(() -> new Java9CL());
33-
} catch (Exception e) {
34-
throw new RuntimeException(e);
35-
}
30+
return AccessController.doPrivilegedChecked(() -> new Java9CL());
3631
}
3732

3833
return classLoader;

0 commit comments

Comments
 (0)