Skip to content

Commit

Permalink
feat(redis): add TLS support to Redis FDW (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
burmecia authored Nov 28, 2024
1 parent 25d6050 commit 156993d
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 11 deletions.
51 changes: 45 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions docs/catalog/redis.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ The connection URL format is:
redis://[<username>][:<password>@]<hostname>[:port][/<db>]
```

The connection URL also supports TLS:

```
rediss://[<username>][:<password>@]<hostname>[:port][/<db>]
```

To enable insecure mode, append `#insecure` at the end of the URL:

```
rediss://[<username>][:<password>@]<hostname>[:port]/[<db>]#insecure
```

!!! note

Client certificate and custom root certificates are not supported when using TLS.

## Creating Foreign Tables

The Redis Wrapper supports data reads from Redis.
Expand Down
2 changes: 1 addition & 1 deletion wrappers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ tiberius = { version = "0.12.2", features = [
num-traits = { version = "0.2.17", optional = true }

# for redis_fdw
redis = { version = "0.24.0", features = ["streams"], optional = true }
redis = { version = "0.27.5", features = ["streams", "tls-rustls", "tls-rustls-insecure"], optional = true }

# for wasm_fdw
wasmtime = { version = "26.0.1", features = [
Expand Down
2 changes: 1 addition & 1 deletion wrappers/src/fdw/redis_fdw/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ This is a foreign data wrapper for [Redis](https://redis.io/). It is developed u

| Version | Date | Notes |
| ------- | ---------- | ---------------------------------------------------- |
| 0.1.1 | 2024-11-28 | Added TLS support |
| 0.1.0 | 2023-12-29 | Initial version |

17 changes: 14 additions & 3 deletions wrappers/src/fdw/redis_fdw/redis_fdw.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::stats;
use pgrx::{JsonB, PgBuiltInOids};
use redis::{Client, Commands, Connection};
use redis::{Client, Commands, Connection, TlsCertificates};
use serde_json::json;
use serde_json::value::Value as JsonValue;
use std::collections::HashMap;
Expand Down Expand Up @@ -41,7 +41,7 @@ fn check_target_columns(
}

#[wrappers_fdw(
version = "0.1.0",
version = "0.1.1",
author = "Supabase",
website = "https://github.com/supabase/wrappers/tree/main/wrappers/src/fdw/redis_fdw",
error_type = "RedisFdwError"
Expand Down Expand Up @@ -248,7 +248,18 @@ impl ForeignDataWrapper<RedisFdwError> for RedisFdw {
get_vault_secret(conn_url_id).unwrap_or_default()
}
};
let client = Client::open(conn_url)?;

let client = if conn_url.starts_with("rediss://") {
Client::build_with_tls(
conn_url,
TlsCertificates {
client_tls: None,
root_cert: None,
},
)
} else {
Client::open(conn_url)
}?;

stats::inc_stats(Self::FDW_NAME, stats::Metric::CreateTimes, 1);

Expand Down

0 comments on commit 156993d

Please sign in to comment.