Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

address reviews

Andreyd48001c6e915
diff --git a/backend/src/ee/services/pam-web-access/clickhouse/pam-clickhouse-data-explorer-fns.test.ts b/backend/src/ee/services/pam-web-access/clickhouse/pam-clickhouse-data-explorer-fns.test.ts
index 84b6afde5a..dfa4c8f18f 100644
--- a/backend/src/ee/services/pam-web-access/clickhouse/pam-clickhouse-data-explorer-fns.test.ts
+++ b/backend/src/ee/services/pam-web-access/clickhouse/pam-clickhouse-data-explorer-fns.test.ts
@@ -5,6 +5,7 @@ import {
MAX_ROWS,
parseStatementBody,
splitClickhouseStatements,
+ toCellValue,
toRowObjects,
uniqueFieldNames
} from "./pam-clickhouse-data-explorer-fns";
@@ -99,6 +100,21 @@ describe("uniqueFieldNames", () => {
});
});
+describe("toCellValue", () => {
+ test("a Map, Array or Tuple becomes the text a client would print, not an object the grid cannot render", () => {
+ expect(toCellValue({ a: "b" })).toBe('{"a":"b"}');
+ expect(toCellValue([1, 2, 3])).toBe("[1,2,3]");
+ expect(toCellValue([1, "x"])).toBe('[1,"x"]');
+ });
+
+ test("scalars and nulls pass through untouched", () => {
+ expect(toCellValue("acme")).toBe("acme");
+ expect(toCellValue(7)).toBe(7);
+ expect(toCellValue(null)).toBeNull();
+ expect(toCellValue(undefined)).toBeNull();
+ });
+});
+
describe("toRowObjects", () => {
test("zips column names onto positional rows", () => {
expect(
@@ -182,6 +198,15 @@ describe("parseStatementBody", () => {
});
});
+ test("a composite column arrives as text rather than an object", () => {
+ const body = JSON.stringify({
+ meta: [{ name: "m", type: "Map(String, String)" }],
+ data: [[{ a: "b" }]],
+ rows: 1
+ });
+ expect(parseStatementBody(body).rows).toEqual([{ m: '{"a":"b"}' }]);
+ });
+
test("a repeated column name still reaches the grid", () => {
expect(parseStatementBody(compact(["a", "a"], [[1, 2]])).rows).toEqual([{ a: 1, a_1: 2 }]);
});
diff --git a/backend/src/ee/services/pam-web-access/clickhouse/pam-clickhouse-data-explorer-fns.ts b/backend/src/ee/services/pam-web-access/clickhouse/pam-clickhouse-data-explorer-fns.ts
index a8c0976474..78a7aa609d 100644
--- a/backend/src/ee/services/pam-web-access/clickhouse/pam-clickhouse-data-explorer-fns.ts
+++ b/backend/src/ee/services/pam-web-access/clickhouse/pam-clickhouse-data-explorer-fns.ts
@@ -130,8 +130,15 @@ export const uniqueFieldNames = (names: string[]): string[] => {
});
};
+// Map, Array and Tuple arrive as objects, which the grid cannot render, so they go over as text
+export const toCellValue = (value: unknown): unknown => {
+ if (value === null || value === undefined) return null;
+ if (typeof value === "object") return JSON.stringify(value);
+ return value;
+};
+
export const toRowObjects = (fieldNames: string[], data: unknown[][]): Record<string, unknown>[] =>
- data.map((values) => Object.fromEntries(fieldNames.map((name, index) => [name, values[index] ?? null])));
+ data.map((values) => Object.fromEntries(fieldNames.map((name, index) => [name, toCellValue(values[index])])));
// The explorer renders at most this many rows
export const MAX_ROWS = 1000;
@@ -175,7 +182,9 @@ export const parseStatementBody = (body: string, summary?: { written_rows: strin
const rows =
data.length > 0 && !Array.isArray(data[0])
- ? (data as Record<string, unknown>[])
+ ? (data as Record<string, unknown>[]).map((row) =>
+ Object.fromEntries(Object.entries(row).map(([key, value]) => [key, toCellValue(value)]))
+ )
: toRowObjects(fieldNames, data as unknown[][]);
return {
diff --git a/docs/documentation/platform/pam/accounts/clickhouse.mdx b/docs/documentation/platform/pam/accounts/clickhouse.mdx
index 412cfb9f89..a44b4e68bd 100644
--- a/docs/documentation/platform/pam/accounts/clickhouse.mdx
+++ b/docs/documentation/platform/pam/accounts/clickhouse.mdx
@@ -56,6 +56,8 @@ GRANT SELECT ON analytics.* TO pam_service;
Every session opens on the account's **Database**, whatever a client asks for. That is a starting point, not a limit: a session can still read any database the user has a grant on, and Web Access lists them all. Scope the grants, not the **Database** field.
+Sessions connect with the user's default roles. The gateway drops the `role` URL parameter, which would otherwise activate a role with no statement to record, so use `SET ROLE` instead and it's recorded like any other statement.
+
Command blocking matches the text of each statement, so a statement that builds SQL at runtime can run something a pattern would otherwise reject. Use ClickHouse grants for restrictions that have to hold.
## Connecting
diff --git a/frontend/src/pages/pam/PamDataExplorerPage/components/DataExplorerGrid.tsx b/frontend/src/pages/pam/PamDataExplorerPage/components/DataExplorerGrid.tsx
index a3d9d7872c..456080776e 100644
--- a/frontend/src/pages/pam/PamDataExplorerPage/components/DataExplorerGrid.tsx
+++ b/frontend/src/pages/pam/PamDataExplorerPage/components/DataExplorerGrid.tsx
@@ -49,10 +49,10 @@ type DataExplorerGridProps = {
const ROW_KEY_PREFIX = "__new_";
function readOnlyReason(dialect: SqlDialect, tableType?: string): string {
+ if (tableType === "view" || tableType === "materialized_view") return "This view is read-only.";
if (!supportsRowEditing(dialect)) {
- return "ClickHouse applies row changes as asynchronous mutations, so the grid is read-only. Edit from the SQL editor with ALTER TABLE ... UPDATE or DELETE FROM.";
+ return "This table is read-only. Edit it from the SQL editor.";
}
- if (tableType === "view" || tableType === "materialized_view") return "This view is read-only.";
return "This table has no primary key. Browsing is read-only — editing requires a primary key.";
}