forked from opensearch-project/data-prepper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use an ObjectInputFilter to serialize allow deserialization of only c…
…ertain objects in peer-to-peer connections. Additionally, it refactors some application configurations to improve integration testing. Fixes opensearch-project#2310. (opensearch-project#2311) Signed-off-by: David Venable <[email protected]>
- Loading branch information
Showing
10 changed files
with
574 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...rc/main/java/org/opensearch/dataprepper/peerforwarder/codec/LoggingObjectInputFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.peerforwarder.codec; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.ObjectInputFilter; | ||
import java.util.Objects; | ||
|
||
/** | ||
* A decorator for {@link ObjectInputFilter} which logs information when the filter is rejected. | ||
*/ | ||
class LoggingObjectInputFilter implements ObjectInputFilter { | ||
private static final Logger LOG = LoggerFactory.getLogger(LoggingObjectInputFilter.class); | ||
private final ObjectInputFilter filter; | ||
|
||
public LoggingObjectInputFilter(final ObjectInputFilter filter) { | ||
this.filter = Objects.requireNonNull(filter); | ||
} | ||
|
||
@Override | ||
public Status checkInput(final FilterInfo filterInfo) { | ||
final Status status = filter.checkInput(filterInfo); | ||
|
||
if(status == Status.REJECTED) { | ||
LOG.warn("Unable to deserialize: {}", filterInfo.serialClass()); | ||
} | ||
|
||
return status; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...main/java/org/opensearch/dataprepper/peerforwarder/codec/PeerForwarderCodecAppConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.peerforwarder.codec; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
import org.opensearch.dataprepper.peerforwarder.PeerForwarderConfiguration; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.yaml.snakeyaml.LoaderOptions; | ||
|
||
import java.io.ObjectInputFilter; | ||
|
||
@Configuration | ||
public class PeerForwarderCodecAppConfig { | ||
@Bean | ||
public PeerForwarderCodec peerForwarderCodec( | ||
final PeerForwarderConfiguration peerForwarderConfiguration, | ||
final ObjectInputFilter objectInputFilter, | ||
@Qualifier("peerForwarderObjectMapper") final ObjectMapper objectMapper) { | ||
return peerForwarderConfiguration.getBinaryCodec() ? | ||
new JavaPeerForwarderCodec(objectInputFilter) : new JacksonPeerForwarderCodec(objectMapper); | ||
} | ||
|
||
@Bean(name = "peerForwarderObjectMapper") | ||
public ObjectMapper objectMapper() { | ||
final JavaTimeModule javaTimeModule = new JavaTimeModule(); | ||
final LoaderOptions loaderOptions = new LoaderOptions(); | ||
loaderOptions.setCodePointLimit(10 * 1024 * 1024); // 10MB | ||
final YAMLFactory yamlFactory = YAMLFactory.builder() | ||
.loaderOptions(loaderOptions) | ||
.build(); | ||
return new ObjectMapper(yamlFactory).registerModule(javaTimeModule); | ||
} | ||
|
||
@Bean | ||
public ObjectInputFilter objectInputFilter() { | ||
final String baseModelPackage = "org.opensearch.dataprepper.model"; | ||
|
||
final String pattern = | ||
"java.lang.Object;" + | ||
"java.util.*;" + | ||
"java.time.*;" + | ||
"com.fasterxml.jackson.databind.node.*;" + | ||
"org.opensearch.dataprepper.peerforwarder.model.*;" + | ||
baseModelPackage + ".event.*;" + | ||
baseModelPackage + ".trace.*;" + | ||
baseModelPackage + ".log.*;" + | ||
baseModelPackage + ".metric.*;" + | ||
baseModelPackage + ".document.*;" + | ||
"com.google.common.collect.ImmutableMap*;" + | ||
"com.google.common.collect.RegularImmutableMap*;" + | ||
"!*"; | ||
|
||
final ObjectInputFilter filter = ObjectInputFilter.Config.createFilter(pattern); | ||
|
||
return new LoggingObjectInputFilter(filter); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.