Skip to content

Updated ssl to true by default for core peer forwarder#1835

Merged
asifsmohammed merged 5 commits intoopensearch-project:mainfrom
asifsmohammed:cpf-ssl-default
Oct 4, 2022
Merged

Updated ssl to true by default for core peer forwarder#1835
asifsmohammed merged 5 commits intoopensearch-project:mainfrom
asifsmohammed:cpf-ssl-default

Conversation

@asifsmohammed
Copy link
Copy Markdown
Collaborator

@asifsmohammed asifsmohammed commented Sep 29, 2022

Signed-off-by: Asif Sohail Mohammed nsifmoh@amazon.com

Description

  • Server creation is moved from Spring configuration file to PeerForwarderServerProxy, so we don't need cert files for bean creation.
  • Now demo certificates added by this PR can be used while running Data Prepper with Peer Forwarder.
  • Peer forwarder can be started without configuring ssl, ssl_certificate_file, ssl_key_file and will use default certificates.
  • Manually tested it locally to verify if the default certificates are working.

Issues Resolved

resolves #1699

Check List

  • New functionality includes testing.
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed with a real name per the DCO

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@asifsmohammed asifsmohammed requested a review from a team as a code owner September 29, 2022 15:08
Copy link
Copy Markdown
Member

@dlvenable dlvenable left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can tell, this turns on SSL, but there is no configured certificate/key pair. So I expect Data Prepper will fail to start.

private Integer maxPendingRequests = 1024;
private boolean ssl = false;
private boolean ssl = true;
private String sslCertificateFile;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to set this default value to the sample certificate. I believe it would be config/sample-certificate.pem or something similar.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it fails if sample certificates in config directory are not used. I thought we just provide the sample certs and user has to configure it using them.
But I can update sslCertificateFile and sslKeyFile to default certs file paths.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be able to run by default. This is similar to how you can run OpenSearch by default with the default certificate.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @dlvenable, I tried adding the default paths to these configurations but it's challenging as we don't know the path at compile time. Because the system property DATA_PREPPER_HOME is not set.
If we hardcode the system property DATA_PREPPER_HOME then it can be changed at runtime using '-Ddata-prepper.dir=/app/data-prepper'.

Let me know if you have any suggestions? I think we can just leave it like this and ask the user to use the default certificates provided in /config directory but it's an additional step if ssl is enabled.

public static final String DEFAULT_CERTIFICATE_FILE_PATH = "config/default_certificate.pem";
public static final String DEFAULT_PRIVATE_KEY_FILE_PATH = "config/default_private_key.pem";
private static final String DATA_PREPPER_HOME = System.getProperty("data-prepper.dir");
    
private boolean ssl = true;
private String sslCertificateFile = Paths.get(DATA_PREPPER_HOME).resolve(DEFAULT_CERTIFICATE_FILE_PATH).toString();
private String sslKeyFile = Paths.get(DATA_PREPPER_HOME).resolve(DEFAULT_PRIVATE_KEY_FILE_PATH).toString();

One alternative is to pass in third argument to the ContextManager and make necessary changes in DataPrepperArgs. This approach is easier to implement if Data Prepper is run without arguments as we create the arguments in this approach.

final String dataPrepperPipelines = Paths.get(dataPrepperHome).resolve("pipelines/").toString();
final String dataPrepperConfig = Paths.get(dataPrepperHome).resolve("config/data-prepper-config.yaml").toString();
final String defaultSslCertificateFile = Paths.get(dataPrepperHome).resolve("config/default_certificate.pem").toString();
final String defaultSslPrivateKeyFile = Paths.get(dataPrepperHome).resolve("config/default_private_key.pem").toString();
contextManager = new ContextManager(dataPrepperPipelines, dataPrepperConfig, defaultSslCertificateFile, defaultSslPrivateKeyFile);

If user passes pipeline and Data Prepper config YAML files it would't be possible as arguments size can be dynamic.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we set the value to config/default-certificate would it not resolve correctly? It should resolve from the current directory which is the Data Prepper directory.

If this works for most scenarios, but not all, I'd be fine. We can improve it later.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try a POC for this and update here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried manual testing and config/defailt-cert-path works without configuring ssl, ssl_certificate_file, ssl_key_file.

private boolean ssl = false;
private boolean ssl = true;
private String sslCertificateFile;
private String sslKeyFile;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also be set to the default key file.

Signed-off-by: Asif Sohail Mohammed <nsifmoh@amazon.com>
Signed-off-by: Asif Sohail Mohammed <nsifmoh@amazon.com>
Signed-off-by: Asif Sohail Mohammed <nsifmoh@amazon.com>
TestDataProvider.INVALID_PEER_FORWARDER_WITH_THREAD_COUNT_CONFIG_FILE,
TestDataProvider.INVALID_PEER_FORWARDER_WITH_CONNECTION_CONFIG_FILE,
TestDataProvider.INVALID_PEER_FORWARDER_WITH_SSL_CONFIG_FILE,
// TestDataProvider.INVALID_PEER_FORWARDER_WITH_SSL_CONFIG_FILE
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this test still valid since the file doesn't exist? Or does the validation not yet happen?

TestDataProvider.INVALID_PEER_FORWARDER_WITH_CLOUD_MAP_WITHOUT_REGION_CONFIG_FILE,
TestDataProvider.INVALID_PEER_FORWARDER_WITH_DNS_WITHOUT_DOMAIN_NAME_CONFIG_FILE,
TestDataProvider.INVALID_PEER_FORWARDER_WITH_SSL,
// TestDataProvider.INVALID_PEER_FORWARDER_WITH_SSL
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be removed? If so, let's remove the line entirely.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests should be removed. They are invalid

Signed-off-by: Asif Sohail Mohammed <nsifmoh@amazon.com>
Signed-off-by: Asif Sohail Mohammed <nsifmoh@amazon.com>
@asifsmohammed asifsmohammed merged commit ae07d55 into opensearch-project:main Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make Peer Forwarding secure by default

3 participants