Search in sources :

Example 6 with CertificateProvider

use of com.amazon.dataprepper.plugins.certificate.CertificateProvider in project data-prepper by opensearch-project.

the class CertificateProviderFactoryTest method getCertificateProviderS3ProviderSuccess.

@Test
public void getCertificateProviderS3ProviderSuccess() {
    final Map<String, Object> settingsMap = new HashMap<>();
    settingsMap.put("ssl", true);
    settingsMap.put("awsRegion", "us-east-1");
    settingsMap.put("sslKeyCertChainFile", "s3://data/certificate/test_cert.crt");
    settingsMap.put("sslKeyFile", "s3://data/certificate/test_decrypted_key.key");
    final PluginSetting pluginSetting = new PluginSetting(null, settingsMap);
    pluginSetting.setPipelineName("pipeline");
    oTelTraceSourceConfig = OBJECT_MAPPER.convertValue(pluginSetting.getSettings(), OTelMetricsSourceConfig.class);
    oTelTraceSourceConfig.validateAndInitializeCertAndKeyFileInS3();
    certificateProviderFactory = new CertificateProviderFactory(oTelTraceSourceConfig);
    final CertificateProvider certificateProvider = certificateProviderFactory.getCertificateProvider();
    assertThat(certificateProvider, IsInstanceOf.instanceOf(S3CertificateProvider.class));
}
Also used : HashMap(java.util.HashMap) CertificateProvider(com.amazon.dataprepper.plugins.certificate.CertificateProvider) ACMCertificateProvider(com.amazon.dataprepper.plugins.certificate.acm.ACMCertificateProvider) FileCertificateProvider(com.amazon.dataprepper.plugins.certificate.file.FileCertificateProvider) S3CertificateProvider(com.amazon.dataprepper.plugins.certificate.s3.S3CertificateProvider) OTelMetricsSourceConfig(com.amazon.dataprepper.plugins.source.otelmetrics.OTelMetricsSourceConfig) S3CertificateProvider(com.amazon.dataprepper.plugins.certificate.s3.S3CertificateProvider) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Test(org.junit.jupiter.api.Test)

Example 7 with CertificateProvider

use of com.amazon.dataprepper.plugins.certificate.CertificateProvider in project data-prepper by opensearch-project.

the class HTTPSource method start.

@Override
public void start(final Buffer<Record<Log>> buffer) {
    if (buffer == null) {
        throw new IllegalStateException("Buffer provided is null");
    }
    if (server == null) {
        final ServerBuilder sb = Server.builder();
        sb.disableServerHeader();
        if (sourceConfig.isSsl()) {
            LOG.info("Creating http source with SSL/TLS enabled.");
            final CertificateProvider certificateProvider = certificateProviderFactory.getCertificateProvider();
            final Certificate certificate = certificateProvider.getCertificate();
            // TODO: enable encrypted key with password
            sb.https(sourceConfig.getPort()).tls(new ByteArrayInputStream(certificate.getCertificate().getBytes(StandardCharsets.UTF_8)), new ByteArrayInputStream(certificate.getPrivateKey().getBytes(StandardCharsets.UTF_8)));
        } else {
            LOG.warn("Creating http source without SSL/TLS. This is not secure.");
            LOG.warn("In order to set up TLS for the http source, go here: https://github.com/opensearch-project/data-prepper/tree/main/data-prepper-plugins/http-source#ssl");
            sb.http(sourceConfig.getPort());
        }
        authenticationProvider.addAuthenticationDecorator(sb);
        sb.maxNumConnections(sourceConfig.getMaxConnectionCount());
        final int requestTimeoutInMillis = sourceConfig.getRequestTimeoutInMillis();
        // Allow 2*requestTimeoutInMillis to accommodate non-blocking operations other than buffer writing.
        sb.requestTimeout(Duration.ofMillis(2 * requestTimeoutInMillis));
        final int threads = sourceConfig.getThreadCount();
        final ScheduledThreadPoolExecutor blockingTaskExecutor = new ScheduledThreadPoolExecutor(threads);
        sb.blockingTaskExecutor(blockingTaskExecutor, true);
        final int maxPendingRequests = sourceConfig.getMaxPendingRequests();
        final LogThrottlingStrategy logThrottlingStrategy = new LogThrottlingStrategy(maxPendingRequests, blockingTaskExecutor.getQueue());
        final LogThrottlingRejectHandler logThrottlingRejectHandler = new LogThrottlingRejectHandler(maxPendingRequests, pluginMetrics);
        // TODO: allow customization on URI path for log ingestion
        sb.decorator(HTTPSourceConfig.DEFAULT_LOG_INGEST_URI, ThrottlingService.newDecorator(logThrottlingStrategy, logThrottlingRejectHandler));
        final LogHTTPService logHTTPService = new LogHTTPService(requestTimeoutInMillis, buffer, pluginMetrics);
        sb.annotatedService(HTTPSourceConfig.DEFAULT_LOG_INGEST_URI, logHTTPService);
        if (sourceConfig.hasHealthCheckService()) {
            LOG.info("HTTP source health check is enabled");
            sb.service(HTTP_HEALTH_CHECK_PATH, HealthCheckService.of());
        }
        server = sb.build();
    }
    try {
        server.start().get();
    } catch (ExecutionException ex) {
        if (ex.getCause() != null && ex.getCause() instanceof RuntimeException) {
            throw (RuntimeException) ex.getCause();
        } else {
            throw new RuntimeException(ex);
        }
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
        throw new RuntimeException(ex);
    }
    LOG.info("Started http source on port " + sourceConfig.getPort() + "...");
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) CertificateProvider(com.amazon.dataprepper.plugins.certificate.CertificateProvider) ByteArrayInputStream(java.io.ByteArrayInputStream) ExecutionException(java.util.concurrent.ExecutionException) ServerBuilder(com.linecorp.armeria.server.ServerBuilder) Certificate(com.amazon.dataprepper.plugins.certificate.model.Certificate)

Example 8 with CertificateProvider

use of com.amazon.dataprepper.plugins.certificate.CertificateProvider in project data-prepper by opensearch-project.

the class CertificateProviderFactoryTest method getFileCertificateProviderSuccess.

@Test
public void getFileCertificateProviderSuccess() {
    final HTTPSourceConfig sourceConfig = mock(HTTPSourceConfig.class);
    when(sourceConfig.isSsl()).thenReturn(true);
    when(sourceConfig.getSslCertificateFile()).thenReturn(TEST_SSL_CERTIFICATE_FILE);
    when(sourceConfig.getSslKeyFile()).thenReturn(TEST_SSL_KEY_FILE);
    final CertificateProviderFactory certificateProviderFactory = new CertificateProviderFactory(sourceConfig);
    final CertificateProvider certificateProvider = certificateProviderFactory.getCertificateProvider();
    assertThat(certificateProvider, IsInstanceOf.instanceOf(FileCertificateProvider.class));
}
Also used : HTTPSourceConfig(com.amazon.dataprepper.plugins.source.loghttp.HTTPSourceConfig) FileCertificateProvider(com.amazon.dataprepper.plugins.certificate.file.FileCertificateProvider) FileCertificateProvider(com.amazon.dataprepper.plugins.certificate.file.FileCertificateProvider) CertificateProvider(com.amazon.dataprepper.plugins.certificate.CertificateProvider) Test(org.junit.jupiter.api.Test)

Example 9 with CertificateProvider

use of com.amazon.dataprepper.plugins.certificate.CertificateProvider in project data-prepper by opensearch-project.

the class CertificateProviderFactoryTest method getCertificateProviderAcmProviderSuccess.

@Test
public void getCertificateProviderAcmProviderSuccess() {
    final Map<String, Object> settingsMap = new HashMap<>();
    settingsMap.put("useAcmCertForSSL", true);
    settingsMap.put("awsRegion", "us-east-1");
    settingsMap.put("acmCertificateArn", "arn:aws:acm:us-east-1:account:certificate/1234-567-856456");
    settingsMap.put("sslKeyCertChainFile", "data/certificate/test_cert.crt");
    settingsMap.put("sslKeyFile", "data/certificate/test_decrypted_key.key");
    final PluginSetting pluginSetting = new PluginSetting(null, settingsMap);
    pluginSetting.setPipelineName("pipeline");
    oTelTraceSourceConfig = OBJECT_MAPPER.convertValue(pluginSetting.getSettings(), OTelMetricsSourceConfig.class);
    certificateProviderFactory = new CertificateProviderFactory(oTelTraceSourceConfig);
    final CertificateProvider certificateProvider = certificateProviderFactory.getCertificateProvider();
    assertThat(certificateProvider, IsInstanceOf.instanceOf(ACMCertificateProvider.class));
}
Also used : HashMap(java.util.HashMap) CertificateProvider(com.amazon.dataprepper.plugins.certificate.CertificateProvider) ACMCertificateProvider(com.amazon.dataprepper.plugins.certificate.acm.ACMCertificateProvider) FileCertificateProvider(com.amazon.dataprepper.plugins.certificate.file.FileCertificateProvider) S3CertificateProvider(com.amazon.dataprepper.plugins.certificate.s3.S3CertificateProvider) ACMCertificateProvider(com.amazon.dataprepper.plugins.certificate.acm.ACMCertificateProvider) OTelMetricsSourceConfig(com.amazon.dataprepper.plugins.source.otelmetrics.OTelMetricsSourceConfig) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Test(org.junit.jupiter.api.Test)

Example 10 with CertificateProvider

use of com.amazon.dataprepper.plugins.certificate.CertificateProvider in project data-prepper by opensearch-project.

the class CertificateProviderFactoryTest method getCertificateProviderFileProviderSuccess.

@Test
public void getCertificateProviderFileProviderSuccess() {
    final Map<String, Object> settingsMap = new HashMap<>();
    settingsMap.put("ssl", true);
    settingsMap.put("sslKeyCertChainFile", "data/certificate/test_cert.crt");
    settingsMap.put("sslKeyFile", "data/certificate/test_decrypted_key.key");
    final PluginSetting pluginSetting = new PluginSetting(null, settingsMap);
    pluginSetting.setPipelineName("pipeline");
    oTelTraceSourceConfig = OBJECT_MAPPER.convertValue(pluginSetting.getSettings(), OTelMetricsSourceConfig.class);
    certificateProviderFactory = new CertificateProviderFactory(oTelTraceSourceConfig);
    final CertificateProvider certificateProvider = certificateProviderFactory.getCertificateProvider();
    assertThat(certificateProvider, IsInstanceOf.instanceOf(FileCertificateProvider.class));
}
Also used : FileCertificateProvider(com.amazon.dataprepper.plugins.certificate.file.FileCertificateProvider) HashMap(java.util.HashMap) CertificateProvider(com.amazon.dataprepper.plugins.certificate.CertificateProvider) ACMCertificateProvider(com.amazon.dataprepper.plugins.certificate.acm.ACMCertificateProvider) FileCertificateProvider(com.amazon.dataprepper.plugins.certificate.file.FileCertificateProvider) S3CertificateProvider(com.amazon.dataprepper.plugins.certificate.s3.S3CertificateProvider) OTelMetricsSourceConfig(com.amazon.dataprepper.plugins.source.otelmetrics.OTelMetricsSourceConfig) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Test(org.junit.jupiter.api.Test)

Aggregations

CertificateProvider (com.amazon.dataprepper.plugins.certificate.CertificateProvider)11 FileCertificateProvider (com.amazon.dataprepper.plugins.certificate.file.FileCertificateProvider)7 Test (org.junit.jupiter.api.Test)7 PluginSetting (com.amazon.dataprepper.model.configuration.PluginSetting)6 ACMCertificateProvider (com.amazon.dataprepper.plugins.certificate.acm.ACMCertificateProvider)6 S3CertificateProvider (com.amazon.dataprepper.plugins.certificate.s3.S3CertificateProvider)6 HashMap (java.util.HashMap)6 Certificate (com.amazon.dataprepper.plugins.certificate.model.Certificate)4 ServerBuilder (com.linecorp.armeria.server.ServerBuilder)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ExecutionException (java.util.concurrent.ExecutionException)4 HealthGrpcService (com.amazon.dataprepper.plugins.health.HealthGrpcService)3 OTelMetricsSourceConfig (com.amazon.dataprepper.plugins.source.otelmetrics.OTelMetricsSourceConfig)3 OTelTraceSourceConfig (com.amazon.dataprepper.plugins.source.oteltrace.OTelTraceSourceConfig)3 GrpcServiceBuilder (com.linecorp.armeria.server.grpc.GrpcServiceBuilder)3 ServerInterceptor (io.grpc.ServerInterceptor)3 OTelProtoCodec (com.amazon.dataprepper.plugins.otel.codec.OTelProtoCodec)1 HTTPSourceConfig (com.amazon.dataprepper.plugins.source.loghttp.HTTPSourceConfig)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1