Skip to content

Commit 71c2d14

Browse files
authored
Merge pull request #18 from simota/feat/redshift-tls
feat(redshift): offer TLS on the SQL endpoint with a configured certificate
2 parents ea70cbb + ac4b407 commit 71c2d14

11 files changed

Lines changed: 625 additions & 4 deletions

File tree

‎Cargo.lock‎

Lines changed: 164 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,9 @@ Pub/Sub dashboard actions are available under `/dashboard/pubsub`:
446446
| --- | --- | --- |
447447
| PostgreSQL wire endpoint | Yes | Listens on `127.0.0.1:15439` by default for local Redshift-style SQL clients. |
448448
| PostgreSQL simple query protocol | Yes | Covers `psql` smoke workflows. |
449+
| TLS on the SQL endpoint | Yes | Off by default. Set `services.redshift.tls.certFile` and `services.redshift.tls.keyFile` (PEM; certificate chain leaf first, key in PKCS#8, PKCS#1, or SEC1; paths relative to where `devcloud up` runs) and clients that send an SSLRequest get TLS 1.2 or 1.3 with that certificate, so `sslmode=verify-full` works when the client trusts the issuing CA and the certificate names the host it connects to. devcloud does not issue certificates. Plain connections are still accepted unless `services.redshift.tls.require: true`. The standalone binary reads `DEVCLOUD_REDSHIFT_TLS_CERT_FILE`, `DEVCLOUD_REDSHIFT_TLS_KEY_FILE`, and `DEVCLOUD_REDSHIFT_TLS_REQUIRE`. |
449450
| PostgreSQL extended query protocol | Partial | Supports Parse, Bind, Describe, Execute, Sync, Close, text bind parameters, portal resume, and safe unsupported errors for binary formats. |
450-
| PostgreSQL execution backend | Yes | Default backend is managed local PostgreSQL; explicit memory fallback remains available for development continuity. Each SQL client connection gets its own PostgreSQL session, so temp tables, `SET`s, and transactions stay with that client and end when it disconnects. The SQL endpoint does not offer TLS (`sslmode=disable`/`prefer` clients only). |
451+
| PostgreSQL execution backend | Yes | Default backend is managed local PostgreSQL; explicit memory fallback remains available for development continuity. Each SQL client connection gets its own PostgreSQL session, so temp tables, `SET`s, and transactions stay with that client and end when it disconnects. See TLS below. |
451452
| Redshift SQL translation | Partial | Handles local subsets for DDL/DML, Redshift table attributes, CTAS/views/materialized-view metadata, function rewrites, COPY, and UNLOAD. |
452453
| COPY from local S3 | Partial | `COPY <table> FROM 's3://bucket/prefix'` loads every object under the prefix from the local S3 store into the PostgreSQL backend, on the client's own session (temp tables and open transactions work): default text format with `DELIMITER`, `CSV` / `FORMAT AS CSV`, `JSON 'auto'` (or `'auto ignorecase'`), `GZIP`, `IGNOREHEADER`, `NULL AS`, `EMPTYASNULL`, `BLANKSASNULL`; an empty field is NULL except in character columns, as on Redshift. `IAM_ROLE` / `CREDENTIALS` / `REGION` are accepted and ignored. Column lists, `MANIFEST`, JSONPaths, other compressions, and columnar formats are refused. The memory backend keeps its own CSV/JSON COPY. |
453454
| UNLOAD to local S3 | Partial | Memory backend only; the PostgreSQL backend does not run UNLOAD yet. |

‎orchestrator/src/config.rs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,16 @@ pub struct RedshiftServiceConfig {
272272
pub data_api: RedshiftDataApiConfig,
273273
pub sql: RedshiftSqlConfig,
274274
pub copy_unload: RedshiftCopyUnloadConfig,
275+
pub tls: RedshiftTlsConfig,
276+
}
277+
278+
/// TLS for the Redshift SQL endpoint: PEM files the user supplies.
279+
#[derive(Debug, Clone, PartialEq, Eq, Default)]
280+
pub struct RedshiftTlsConfig {
281+
pub cert_file: String,
282+
pub key_file: String,
283+
/// Refuse SQL clients that do not negotiate TLS.
284+
pub require: bool,
275285
}
276286

277287
#[derive(Debug, Clone, PartialEq, Eq, Default)]
@@ -581,6 +591,7 @@ pub fn default_config() -> Config {
581591
enable_local_s3: true,
582592
max_input_row_bytes: 4 * 1024 * 1024,
583593
},
594+
tls: RedshiftTlsConfig::default(),
584595
},
585596
redis: RedisServiceConfig {
586597
enabled: false,
@@ -1078,6 +1089,13 @@ pub fn apply_config_value(cfg: &mut Config, path: &[String], value: &str) -> io:
10781089
"services.redshift.sql.defaultSearchPath" => {
10791090
cfg.services.redshift.sql.default_search_path = value.to_string()
10801091
}
1092+
"services.redshift.tls.certFile" => {
1093+
cfg.services.redshift.tls.cert_file = trim_quotes(value)
1094+
}
1095+
"services.redshift.tls.keyFile" => cfg.services.redshift.tls.key_file = trim_quotes(value),
1096+
"services.redshift.tls.require" => {
1097+
cfg.services.redshift.tls.require = parse_bool("services.redshift.tls.require", value)?
1098+
}
10811099
"services.redshift.copyUnload.enableLocalS3" => {
10821100
cfg.services.redshift.copy_unload.enable_local_s3 =
10831101
parse_bool("services.redshift.copyUnload.enableLocalS3", value)?

‎orchestrator/src/services/redshift.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ pub async fn run(
100100
let sql_addr = format!("127.0.0.1:{}", cfg.server.redshift_port);
101101
let api_addr = format!("127.0.0.1:{}", cfg.server.redshift_api_port);
102102

103+
let tls = &cfg.services.redshift.tls;
104+
let sql_tls =
105+
devcloud_redshift::tls::sql_tls_from_files(&tls.cert_file, &tls.key_file, tls.require)
106+
.map_err(|e| format!("redshift: {e}"))?;
107+
103108
let server = Arc::new(Server::new(Config {
104109
sql_addr: sql_addr.clone(),
105110
api_addr: api_addr.clone(),
@@ -125,6 +130,7 @@ pub async fn run(
125130
sql_backend,
126131
translator,
127132
events_enabled: true,
133+
sql_tls,
128134
}));
129135

130136
let sql_listener = TcpListener::bind(&sql_addr)

‎services/redshift/Cargo.toml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ path = "src/main.rs"
1616
devcloud-s3 = { path = "../s3" }
1717
# gzip COPY sources (pure-Rust backend; miniz_oxide is already in the tree).
1818
flate2 = { version = "1", default-features = false, features = ["rust_backend"] }
19+
# TLS on the SQL endpoint (pure-Rust rustls with the ring provider; no
20+
# OpenSSL or CMake needed). Certificates come from files the user supplies.
21+
tokio-rustls = { version = "0.26", default-features = false, features = ["ring", "tls12"] }
22+
rustls-pki-types = { version = "1", features = ["std"] }
1923
md-5 = "0.10"
2024
sha2 = "0.10"
2125
hmac = "0.12"
@@ -25,3 +29,7 @@ serde = { version = "1", features = ["derive"] }
2529
# map marshaling. Do NOT enable preserve_order.
2630
serde_json = "1"
2731
tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros", "net", "io-util", "signal", "time", "sync"] }
32+
33+
[dev-dependencies]
34+
# Test-only: issues a throwaway CA and server certificate for the TLS tests.
35+
rcgen = { version = "0.13", default-features = false, features = ["ring", "pem"] }

‎services/redshift/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ pub mod snapshot;
5252
pub mod sql_parse;
5353
pub mod sql_predicates;
5454
pub mod storage;
55+
pub mod tls;
5556
pub mod translator;
5657

5758
pub use backend::{SqlBackend, SqlTransaction};

0 commit comments

Comments
 (0)