Skip to content

External indexing socket with SSL support#327

Merged
var77 merged 8 commits intomainfrom
varik/external-indexing-ssl
Aug 7, 2024
Merged

External indexing socket with SSL support#327
var77 merged 8 commits intomainfrom
varik/external-indexing-ssl

Conversation

@var77
Copy link
Copy Markdown
Collaborator

@var77 var77 commented Aug 2, 2024

No description provided.

Copy link
Copy Markdown

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

The pull request introduces SSL support for external indexing sockets, enhancing security for data transmission.

  • CMakeLists.txt: Added OpenSSL checks and conditional compile-time macros for SSL support.
  • ci/scripts/build-linux.sh: Updated to install lantern-cli from varik/external-indexing-server-ssl branch.
  • scripts/integration_tests.py: Added SSL setup for external indexing server tests.
  • src/hnsw/build.c: Replaced external_client_fd with external_socket for SSL support.
  • src/hnsw/external_index_socket.c: Added SSL initialization, read, send, and close functions.
  • src/hnsw/external_index_socket_ssl.c: New file for SSL support functions.
  • src/hnsw/options.c: Added ldb_external_index_secure option for enabling SSL connections.

11 file(s) reviewed, 34 comment(s)
Edit PR Review Bot Settings

@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.3)
include(CheckSymbolExists)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

info: Added include(CheckSymbolExists) to enable checking for the existence of specific symbols, which is necessary for the OpenSSL integration.

CMakeLists.txt Outdated
Comment on lines +253 to +257
check_symbol_exists(USE_OPENSSL ${PostgreSQL_INCLUDE_DIRS}/pg_config.h PG_USE_OPENSSL)

if(PG_USE_OPENSSL)
target_compile_definitions(lantern PRIVATE LANTERN_USE_OPENSSL)
endif()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

info: Added checks for OpenSSL symbols and conditionally defined LANTERN_USE_OPENSSL if OpenSSL is available. This is essential for enabling SSL support in the external indexing socket.

then
setup_rust
ORT_STRATEGY=system cargo install --git https://github.com/lanterndata/lantern_extras.git --branch main --debug --bin lantern-cli --root /tmp
ORT_STRATEGY=system cargo install --git https://github.com/lanterndata/lantern_extras.git --branch varik/external-indexing-server-ssl --debug --bin lantern-cli --root /tmp
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

info: Updated the branch for lantern-cli installation to varik/external-indexing-server-ssl.

@pytest.fixture
def external_index(request):
cli_path = os.getenv("LANTERN_CLI_PATH")
use_ssl = os.getenv("EXTERNAL_INDEX_SECURE")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

info: Added support for SSL by checking the EXTERNAL_INDEX_SECURE environment variable.

Comment on lines +664 to +665
subprocess.run(["openssl", "req", "-x509", "-nodes", "-days", "365", "-newkey", "rsa:2048", "-keyout", "/tmp/key.pem", "-out", "/tmp/cert.pem", "-subj", "/C=US/ST=California/L=San Francisco/O=Lantern/CN=lantern.dev"])
ssl_args = ["--cert", "/tmp/cert.pem", "--key", "/tmp/key.pem"]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

info: Generates SSL certificates and keys if EXTERNAL_INDEX_SECURE is set.

Comment on lines +79 to +92
void close_ssl(external_index_socket_t *socket)
{
if(socket->ssl != NULL) {
SSL_free(socket->ssl);
socket->ssl = NULL;
}

if(socket->ssl_ctx != NULL) {
SSL_CTX_free(socket->ssl_ctx);
socket->ssl_ctx = NULL;
}

close(socket->fd);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

info: Implemented close_ssl function to properly free SSL resources and close the socket.

Comment on lines +1 to +12
#ifndef LDB_EXTERNAL_IDX_SOCKET_SSL_H
#define LDB_EXTERNAL_IDX_SOCKET_SSL_H

#ifdef LANTERN_USE_OPENSSL
#include <openssl/err.h>
#include <openssl/ssl.h>
#else
#define SSL_CTX void
#define SSL void
#endif

#endif // LDB_EXTERNAL_IDX_SOCKET_SSL_H
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

info: Introduced conditional inclusion of OpenSSL headers for SSL support in external indexing sockets.

int ldb_hnsw_ef_search;
int ldb_external_index_port;
char *ldb_external_index_host;
bool ldb_external_index_secure;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

info: Added a new boolean variable ldb_external_index_secure to store the SSL configuration for external indexing.

Comment on lines +404 to +413
DefineCustomBoolVariable("lantern.external_index_secure",
"Use SSL connection when connecting to external index socket",
"Set this to 0 to disable secure connection",
&ldb_external_index_secure,
true,
PGC_USERSET,
0,
NULL,
NULL,
NULL);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

info: Defined a new custom boolean variable lantern.external_index_secure to enable or disable SSL connections for the external index socket.

extern bool ldb_pgvector_compat;
extern int ldb_external_index_port;
extern char* ldb_external_index_host;
extern bool ldb_external_index_secure;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

info: Added extern bool ldb_external_index_secure; to support SSL for external indexing.

@var77 var77 force-pushed the varik/external-indexing-ssl branch 2 times, most recently from 481e62a to bc57b42 Compare August 2, 2024 14:44
@github-actions
Copy link
Copy Markdown

github-actions bot commented Aug 2, 2024

Benchmarks

metric old new pct change
recall (after create) 0.951 0.953 +0.21%
recall (after insert) 0.000 0.000 -
select tps 25374.002 25827.280 +1.79%
select bulk(100) tps 35.720 34.496 -3.43%
select latency (ms) 0.745 ± 1.560𝜎 0.726 ± 1.615𝜎 -2.55%
select bulk(100) latency (ms) 885.606 ± 99.034𝜎 884.818 ± 143.799𝜎 -0.09%
create latency (ms) 396793.805 393713.500 -0.78%
insert tps 431.859 447.078 +3.52%
insert bulk(100) tps 4.802 4.927 +2.60%
insert latency (ms) 73.505 ± 15.007𝜎 70.953 ± 15.966𝜎 -3.47%
insert bulk(100) latency (ms) 6513.105 ± 135.856𝜎 6365.889 ± 109.313𝜎 -2.26%
disk usage (bytes) 8192008192.000 8192008192.000 -

@var77 var77 force-pushed the varik/external-indexing-ssl branch 4 times, most recently from 73907d3 to 7968f95 Compare August 2, 2024 15:36
@var77 var77 force-pushed the varik/external-indexing-ssl branch from 7968f95 to a7c98f8 Compare August 2, 2024 15:59
@codecov
Copy link
Copy Markdown

codecov bot commented Aug 2, 2024

Codecov Report

Attention: Patch coverage is 73.39450% with 29 lines in your changes missing coverage. Please review.

Files Patch % Lines
src/hnsw/external_index_socket.c 72.72% 14 Missing and 4 partials ⚠️
src/hnsw/external_index_socket_ssl.c 68.57% 4 Missing and 7 partials ⚠️

📢 Thoughts on this report? Let us know!

mkdir build
cd build

if [ -n "$DISABLE_SSL" ]; then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

let's use DISABLE_SSL or USE_SSL, not both

@pytest.fixture
def external_index(request):
cli_path = os.getenv("LANTERN_CLI_PATH")
use_ssl = os.getenv("EXTERNAL_INDEX_SECURE") == "1"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can this variable be called USE_SSL or whatever we decide is the uniform name of the variable?

while(total < len) {
n = socket_con->send(socket_con, buf + total, bytesleft, flags);
if(n == -1 || n == 0) {
return n;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why is this silently returning the number and not closing the socket and erroring out?

it seems we would want to error out from all the callsites anyway. If so, the API is consuming since the caller might not realize they have to check for these values and deal with closing/erroring out since otherwise the function is quite high level (it handles partial sends and retires)

}

uint32 buf_size = read(client_fd, &init_response, EXTERNAL_INDEX_INIT_BUFFER_SIZE);
uint32 buf_size = socket_con->read(socket_con, (char *)&init_response, EXTERNAL_INDEX_INIT_BUFFER_SIZE);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

buf_size type must must int32 since it might report -1 an later error handling function below compares it against -1

@var77 var77 force-pushed the varik/external-indexing-ssl branch 4 times, most recently from be42e69 to c5e52d6 Compare August 6, 2024 16:44
@var77 var77 force-pushed the varik/external-indexing-ssl branch from c5e52d6 to d84c174 Compare August 6, 2024 16:46
@var77 var77 merged commit 3cd50df into main Aug 7, 2024
@var77 var77 deleted the varik/external-indexing-ssl branch August 7, 2024 08:46
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.

2 participants