@kosha-ai/integration-postgres 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Client } from 'pg';
|
|
2
|
-
import {
|
|
2
|
+
import { assertAllowedHost, basic as basicAuth, defineIntegration, packageDirs, } from '@kosha-ai/integration-sdk';
|
|
3
3
|
const { docsPath, migrationsPath } = packageDirs(import.meta.url);
|
|
4
4
|
export class PostgresConnectionError extends Error {
|
|
5
5
|
constructor(message) {
|
|
@@ -98,7 +98,7 @@ async function connectClient(target) {
|
|
|
98
98
|
* Read-only is enforced by Postgres itself (`BEGIN READ ONLY` rejects
|
|
99
99
|
* INSERT/UPDATE/DELETE/DDL/`SELECT ... FOR UPDATE` at the engine level), not
|
|
100
100
|
* by Kosha parsing the SQL text: the same trust-the-real-protocol stance
|
|
101
|
-
*
|
|
101
|
+
* Host validation is performed with DNS resolution rather than regexes.
|
|
102
102
|
*
|
|
103
103
|
* No connection pooling: every call opens and closes its own client, which
|
|
104
104
|
* is simplest and safest for a multi-tenant service where no two calls
|
|
@@ -110,7 +110,7 @@ async function withReadOnlyClient(fields, credential, fn) {
|
|
|
110
110
|
// Re-checked on every call, not only when the configuration was saved: a
|
|
111
111
|
// hostname that answered publicly yesterday can point inside the network
|
|
112
112
|
// today (DNS rebinding).
|
|
113
|
-
await
|
|
113
|
+
await assertAllowedHost(target.host);
|
|
114
114
|
let client;
|
|
115
115
|
try {
|
|
116
116
|
client = await connectClient(target);
|
|
@@ -150,7 +150,7 @@ export function postgres() {
|
|
|
150
150
|
label: 'URL',
|
|
151
151
|
type: 'host',
|
|
152
152
|
required: true,
|
|
153
|
-
help: 'The database host, optionally with :port (defaults to 5432), e.g. db.acme.test:5432.
|
|
153
|
+
help: 'The database host, optionally with :port (defaults to 5432), e.g. db.acme.test:5432. It must resolve from the Kosha server network.',
|
|
154
154
|
},
|
|
155
155
|
{
|
|
156
156
|
key: 'database',
|
package/docs/setup.md
CHANGED
|
@@ -9,10 +9,10 @@ each person who will end up running a query.
|
|
|
9
9
|
When you create the configuration, give Kosha:
|
|
10
10
|
|
|
11
11
|
- **URL** — the database host, optionally with `:port` (e.g. `db.acme.test`
|
|
12
|
-
or `db.acme.test:5432`; defaults to `5432`). It
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
or `db.acme.test:5432`; defaults to `5432`). It may be public or private,
|
|
13
|
+
such as an RDS instance in the same VPC, as long as it resolves from the
|
|
14
|
+
Kosha server network. A link-local address (`169.254.x.x`) is refused.
|
|
15
|
+
|
|
16
16
|
- **Database** — the database name.
|
|
17
17
|
|
|
18
18
|
Connections are always encrypted in transit (TLS), but the server's
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kosha-ai/integration-postgres",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Postgres integration for Kosha: read-only queries against a connected database",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kosha",
|
|
@@ -48,10 +48,10 @@
|
|
|
48
48
|
"key": "postgres"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@kosha-ai/integration-sdk": "0.
|
|
51
|
+
"@kosha-ai/integration-sdk": "0.5.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@types/pg": "^8.11.0",
|
|
55
|
-
"@kosha-ai/integration-sdk": "0.
|
|
55
|
+
"@kosha-ai/integration-sdk": "0.5.0"
|
|
56
56
|
}
|
|
57
57
|
}
|