Skip to content

Commit 4844488

Browse files
committed
fix: SSL/TLS mode by default for postgres connection
Signed-off-by: ntkathole <nikhilkathole2683@gmail.com>
1 parent 088a802 commit 4844488

File tree

8 files changed

+27
-14
lines changed

8 files changed

+27
-14
lines changed

docs/reference/offline-stores/postgres.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ online_store:
3838
```
3939
{% endcode %}
4040
41-
Note that `sslmode`, `sslkey_path`, `sslcert_path`, and `sslrootcert_path` are optional parameters.
41+
Note that `sslmode` defaults to `require`, which encrypts the connection without certificate verification. To disable SSL (e.g. for local development), set `sslmode: disable`. For certificate verification, set `sslmode` to `verify-ca` or `verify-full` and provide the corresponding `sslrootcert_path` (and optionally `sslcert_path` and `sslkey_path` for mutual TLS).
4242
The full set of configuration options is available in [PostgreSQLOfflineStoreConfig](https://rtd.feast.dev/en/master/#feast.infra.offline_stores.contrib.postgres_offline_store.postgres.PostgreSQLOfflineStoreConfig).
4343

4444
Additionally, a new optional parameter `entity_select_mode` was added to tell how Postgres should load the entity data. By default(`temp_table`), a temporary table is created and the entity data frame or sql is loaded into that table. A new value of `embed_query` was added to allow directly loading the SQL query into a CTE, providing improved performance and skipping the need to CREATE and DROP the temporary table.

docs/reference/online-stores/postgres.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ 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
9+
* `sslmode` defaults to `require`, which encrypts the connection without certificate verification. To disable SSL (e.g. for local development), set `sslmode: disable`. For certificate verification, set `sslmode` to `verify-ca` or `verify-full` and provide the corresponding `sslrootcert_path` (and optionally `sslcert_path` and `sslkey_path` for mutual TLS)
1010

1111
## Getting started
1212
In order to use this online store, you'll need to run `pip install 'feast[postgres]'`. You can get started by then running `feast init -t postgres`.

go/internal/feast/onlinestore/postgresonlinestore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func buildPostgresConnString(config map[string]interface{}) string {
166166
if sslMode, ok := config["sslmode"].(string); ok && sslMode != "" {
167167
query.Set("sslmode", sslMode)
168168
} else {
169-
query.Set("sslmode", "disable")
169+
query.Set("sslmode", "require")
170170
}
171171

172172
if v, ok := config["sslcert_path"].(string); ok && v != "" {

go/internal/feast/onlinestore/postgresonlinestore_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestBuildPostgresConnStringDefaults(t *testing.T) {
3434
}
3535
connStr := buildPostgresConnString(config)
3636
assert.Contains(t, connStr, "localhost:5432")
37-
assert.Contains(t, connStr, "sslmode=disable")
37+
assert.Contains(t, connStr, "sslmode=require")
3838
}
3939

4040
func TestBuildPostgresConnStringWithSSL(t *testing.T) {

sdk/python/feast/infra/offline_stores/contrib/postgres_offline_store/tests/data_source.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def __init__(
8585
db_schema="public",
8686
user=self.container.env["POSTGRES_USER"],
8787
password=self.container.env["POSTGRES_PASSWORD"],
88+
sslmode="disable",
8889
)
8990

9091
def create_data_source(
@@ -124,6 +125,7 @@ def create_online_store(self) -> PostgreSQLOnlineStoreConfig: # type: ignore
124125
db_schema="feature_store",
125126
user=POSTGRES_USER,
126127
password=POSTGRES_PASSWORD,
128+
sslmode="disable",
127129
)
128130

129131
def create_saved_dataset_destination(self):

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class PostgreSQLConfig(FeastConfigBaseModel):
2121
db_schema: StrictStr = "public"
2222
user: StrictStr
2323
password: StrictStr
24-
sslmode: Optional[StrictStr] = None
24+
sslmode: Optional[StrictStr] = "require"
2525
sslkey_path: Optional[StrictStr] = None
2626
sslcert_path: Optional[StrictStr] = None
2727
sslrootcert_path: Optional[StrictStr] = None

sdk/python/feast/templates/postgres/bootstrap.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,25 @@ def bootstrap():
2929
postgres_schema = click.prompt("Postgres schema", default="public")
3030
postgres_user = click.prompt("Postgres user")
3131
postgres_password = click.prompt("Postgres password", hide_input=True)
32+
postgres_sslmode = click.prompt(
33+
"Postgres sslmode (disable, allow, prefer, require, verify-ca, verify-full)",
34+
default="require",
35+
)
3236

3337
if click.confirm(
3438
'Should I upload example data to Postgres (overwriting "feast_driver_hourly_stats" table)?',
3539
default=True,
3640
):
41+
config = PostgreSQLConfig(
42+
host=postgres_host,
43+
port=int(postgres_port),
44+
database=postgres_database,
45+
db_schema=postgres_schema,
46+
user=postgres_user,
47+
password=postgres_password,
48+
sslmode=postgres_sslmode,
49+
)
50+
3751
db_connection = psycopg.connect(
3852
conninfo=(
3953
f"postgresql://{postgres_user}"
@@ -42,21 +56,15 @@ def bootstrap():
4256
f":{int(postgres_port)}"
4357
f"/{postgres_database}"
4458
),
59+
sslmode=postgres_sslmode,
4560
options=f"-c search_path={postgres_schema}",
4661
)
4762

4863
with db_connection as conn, conn.cursor() as cur:
4964
cur.execute('DROP TABLE IF EXISTS "feast_driver_hourly_stats"')
5065

5166
df_to_postgres_table(
52-
config=PostgreSQLConfig(
53-
host=postgres_host,
54-
port=int(postgres_port),
55-
database=postgres_database,
56-
db_schema=postgres_schema,
57-
user=postgres_user,
58-
password=postgres_password,
59-
),
67+
config=config,
6068
df=driver_df,
6169
table_name="feast_driver_hourly_stats",
6270
)
@@ -67,6 +75,7 @@ def bootstrap():
6775
replace_str_in_file(config_file, "DB_SCHEMA", postgres_schema)
6876
replace_str_in_file(config_file, "DB_USERNAME", postgres_user)
6977
replace_str_in_file(config_file, "DB_PASSWORD", postgres_password)
78+
replace_str_in_file(config_file, "DB_SSLMODE", postgres_sslmode)
7079

7180

7281
if __name__ == "__main__":

sdk/python/feast/templates/postgres/feature_repo/feature_store.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ project: my_project
22
provider: local
33
registry:
44
registry_type: sql
5-
path: postgresql://DB_USERNAME:DB_PASSWORD@DB_HOST:DB_PORT/DB_NAME
5+
path: postgresql://DB_USERNAME:DB_PASSWORD@DB_HOST:DB_PORT/DB_NAME?sslmode=DB_SSLMODE
66
cache_ttl_seconds: 60
77
sqlalchemy_config_kwargs:
88
echo: false
@@ -15,6 +15,7 @@ online_store:
1515
db_schema: DB_SCHEMA
1616
user: DB_USERNAME
1717
password: DB_PASSWORD
18+
sslmode: DB_SSLMODE
1819
offline_store:
1920
type: postgres
2021
host: DB_HOST
@@ -23,4 +24,5 @@ offline_store:
2324
db_schema: DB_SCHEMA
2425
user: DB_USERNAME
2526
password: DB_PASSWORD
27+
sslmode: DB_SSLMODE
2628
entity_key_serialization_version: 3

0 commit comments

Comments
 (0)