Skip to content

Commit 0e809c2

Browse files
NBorNeilBATB
andauthored
feat: Adding SSL options for Postgres (#2644)
* [feat] Allow SSL for Postgres Allow user to set SSL options in the feature_story.yml file for the offline, online, and registry sections Signed-off-by: Neil Borle <[email protected]> * [docs] SSL for Postgres Updated the reference docs for offline/online stores to describe the SSL options available Signed-off-by: Neil Borle <[email protected]> Co-authored-by: Neil Borle <[email protected]>
1 parent ffa33ad commit 0e809c2

File tree

5 files changed

+32
-0
lines changed

5 files changed

+32
-0
lines changed

docs/reference/offline-stores/postgres.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ The PostgreSQL offline store is an offline store that provides support for readi
1313
* `to_df` to retrieve the pandas dataframe.
1414
* `to_arrow` to retrieve the dataframe as a PyArrow table.
1515

16+
* sslmode, sslkey_path, sslcert_path, and sslrootcert_path are optional
17+
1618
## Example
1719

1820
{% code title="feature_store.yaml" %}
@@ -28,6 +30,10 @@ offline_store:
2830
db_schema: DB_SCHEMA
2931
user: DB_USERNAME
3032
password: DB_PASSWORD
33+
sslmode: verify-ca
34+
sslkey_path: /path/to/client-key.pem
35+
sslcert_path: /path/to/client-cert.pem
36+
sslrootcert_path: /path/to/server-ca.pem
3137
online_store:
3238
path: data/online_store.db
3339
```

docs/reference/online-stores/postgres.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ The PostgreSQL online store provides support for materializing feature values in
66

77
* Only the latest feature values are persisted
88

9+
* sslmode, sslkey_path, sslcert_path, and sslrootcert_path are optional
10+
911
## Example
1012

1113
{% code title="feature_store.yaml" %}
@@ -21,6 +23,10 @@ online_store:
2123
db_schema: DB_SCHEMA
2224
user: DB_USERNAME
2325
password: DB_PASSWORD
26+
sslmode: verify-ca
27+
sslkey_path: /path/to/client-key.pem
28+
sslcert_path: /path/to/client-cert.pem
29+
sslrootcert_path: /path/to/server-ca.pem
2430
```
2531
{% endcode %}
2632

sdk/python/feast/infra/registry_stores/contrib/postgres/registry_store.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
import psycopg2
24
from psycopg2 import sql
35

@@ -15,6 +17,10 @@ class PostgresRegistryConfig(RegistryConfig):
1517
db_schema: str
1618
user: str
1719
password: str
20+
sslmode: Optional[str]
21+
sslkey_path: Optional[str]
22+
sslcert_path: Optional[str]
23+
sslrootcert_path: Optional[str]
1824

1925

2026
class PostgreSQLRegistryStore(RegistryStore):
@@ -26,6 +32,10 @@ def __init__(self, config: PostgresRegistryConfig, registry_path: str):
2632
db_schema=config.db_schema,
2733
user=config.user,
2834
password=config.password,
35+
sslmode=getattr(config, "sslmode", None),
36+
sslkey_path=getattr(config, "sslkey_path", None),
37+
sslcert_path=getattr(config, "sslcert_path", None),
38+
sslrootcert_path=getattr(config, "sslrootcert_path", None),
2939
)
3040
self.table_name = config.path
3141
self.cache_ttl_seconds = config.cache_ttl_seconds

sdk/python/feast/infra/utils/postgres/connection_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ def _get_conn(config: PostgreSQLConfig):
1717
port=int(config.port),
1818
user=config.user,
1919
password=config.password,
20+
sslmode=config.sslmode,
21+
sslkey=config.sslkey_path,
22+
sslcert=config.sslcert_path,
23+
sslrootcert=config.sslrootcert_path,
2024
options="-c search_path={}".format(config.db_schema or config.user),
2125
)
2226
return conn

sdk/python/feast/infra/utils/postgres/postgres_config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
from pydantic import StrictStr
24

35
from feast.repo_config import FeastConfigBaseModel
@@ -10,3 +12,7 @@ class PostgreSQLConfig(FeastConfigBaseModel):
1012
db_schema: StrictStr = "public"
1113
user: StrictStr
1214
password: StrictStr
15+
sslmode: Optional[StrictStr] = None
16+
sslkey_path: Optional[StrictStr] = None
17+
sslcert_path: Optional[StrictStr] = None
18+
sslrootcert_path: Optional[StrictStr] = None

0 commit comments

Comments
 (0)