Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat(clickhouse): gate web access on an http port
bernie-g57b7e1a0224b
diff --git a/backend/src/ee/services/pam-account/pam-account-schemas.ts b/backend/src/ee/services/pam-account/pam-account-schemas.tsindex d5d456ebcf..37dfaa2d4b 100644--- a/backend/src/ee/services/pam-account/pam-account-schemas.ts+++ b/backend/src/ee/services/pam-account/pam-account-schemas.ts@@ -1164,6 +1164,17 @@ export const gatewaySupportsAccountType = (supportedTypes: string[] | undefined): boolean => !supportedTypes || supportedTypes.includes(resolveGatewayAccountType(accountType));+// Web Access speaks HTTP, so an account whose server has no HTTP interface cannot serve it. Returns the+// reason to show the user, or null when Web Access is fine.+export const webAccessUnavailableReason = (+ accountType: PamAccountType,+ connectionDetails: Record<string, unknown>+): string | null => {+ if (accountType !== PamAccountType.ClickHouse) return null;+ if ((connectionDetails as { port?: number }).port !== undefined) return null;+ return "Web access needs ClickHouse's HTTP interface. Set an HTTP port on this account, or connect with a native client through the CLI.";+};+// An absent flag means a gateway too old to report it, which is exactly the case this guards.export const gatewaySupportsClickHouseNative = (capabilities: { clickhouseNativeProtocol?: boolean } | null) =>Boolean(capabilities?.clickhouseNativeProtocol);diff --git a/backend/src/ee/services/pam-web-access/pam-web-access-service.ts b/backend/src/ee/services/pam-web-access/pam-web-access-service.tsindex 265e61c7ae..f915d95cae 100644--- a/backend/src/ee/services/pam-web-access/pam-web-access-service.ts+++ b/backend/src/ee/services/pam-web-access/pam-web-access-service.ts@@ -38,7 +38,8 @@ import {extractGatewayTarget,getAccountAccessibilityIssues,PamAccountAccessibilityIssue,- resolveSelectedHost+ resolveSelectedHost,+ webAccessUnavailableReason} from "../pam-account/pam-account-schemas";import { TPamSessionDALFactory } from "../pam-session/pam-session-dal";import { reportPamSessionEnded } from "../pam-session/pam-session-fns";@@ -185,6 +186,14 @@ export const pamWebAccessServiceFactory = ({throw new BadRequestError({ message: "Web access is not supported for this account type" });}+ const webAccessBlocked = webAccessUnavailableReason(+ account.accountType as PamAccountType,+ await decrypt(account.projectId, account.encryptedConnectionDetails)+ );+ if (webAccessBlocked) {+ throw new BadRequestError({ message: webAccessBlocked });+ }+const policy = resolveAccessControls(account.templatePolicies);const { requiresApproval } = policy;diff --git a/docs/documentation/platform/pam/accounts/clickhouse.mdx b/docs/documentation/platform/pam/accounts/clickhouse.mdxindex 6747ebc46c..cd0f0a71ca 100644--- a/docs/documentation/platform/pam/accounts/clickhouse.mdx+++ b/docs/documentation/platform/pam/accounts/clickhouse.mdx@@ -81,7 +81,7 @@ Command blocking matches the text of each statement, so a statement that buildsClickHouse has no schema layer inside a database, so the Data Explorer sidebar lists databases where it lists schemas for other account types.- Web Access works whichever interface the server has. It speaks HTTP, and for a server with HTTP turned off the gateway runs the statement over the native protocol and returns the result. The browser experience is the same, with the two limits described under [Servers with HTTP turned off](#servers-with-http-turned-off).+ Web Access speaks ClickHouse's HTTP interface, so it needs the account to have an **HTTP Port**. On an account with only a native port it is greyed out, and the CLI is the way in.</Tab><Tab title="CLI">@@ -129,17 +129,11 @@ The native protocol has no such limit. A statement arrives in its own packet, se## Servers with HTTP turned off-A server that serves only the native protocol works with native clients and with Web Access. Set the **Native Port** and leave **HTTP Port** empty.+A server that serves only the native protocol works with native clients. Set the **Native Port** and leave **HTTP Port** empty.-Native clients need nothing special: `clickhouse-client`, Python's `clickhouse-driver` and `clickhouse-go` speak to the session's port directly.+`clickhouse-client`, Python's `clickhouse-driver` and `clickhouse-go` speak to the session's port directly and need nothing special.-**HTTP clients need the server to have an HTTP port.** A ClickHouse account with no HTTP port is a native-only account, and JDBC tools such as DBeaver and DataGrip, along with `clickhouse-connect` and ODBC, can't reach it. They fail when they connect, with a message saying so. Give the account an HTTP port if you need them.--Web Access is the exception, because Infisical controls both ends of it. It speaks HTTP, so the gateway runs each statement over the native protocol and builds the result itself, with ClickHouse formatting the values so every column type keeps working. Three limits apply to Web Access on such an account, and none of them applies to a native client:--- Only a `SELECT`, `WITH` or `EXPLAIN` returns rows. A `SHOW` or `DESCRIBE` has to be run from a native client, or rewritten against `system.tables` and `system.columns`.-- A statement returning more than 100,000 rows, or more than 64 MB, is refused. Narrow the result, or use a native client.-- One statement at a time. A semicolon inside a statement is refused, because the native protocol runs a single statement per request.+**Everything that speaks HTTP needs the server to have an HTTP port.** That includes Web Access, JDBC tools such as DBeaver and DataGrip, `clickhouse-connect` and ODBC. Web Access is greyed out on such an account, and the other clients fail when they connect. Give the account an HTTP port if you need any of them.## Next stepsdiff --git a/frontend/src/pages/pam/components/LaunchSessionSheet.tsx b/frontend/src/pages/pam/components/LaunchSessionSheet.tsxindex 58ad32794e..b354a10cff 100644--- a/frontend/src/pages/pam/components/LaunchSessionSheet.tsx+++ b/frontend/src/pages/pam/components/LaunchSessionSheet.tsx@@ -41,14 +41,19 @@ type LaunchMethod = "browser" | "cli";const LaunchTab = ({account,supportsWebAccess,+ webAccessUnavailableReason,hosts}: {account: TAccessiblePamAccount;supportsWebAccess: boolean;+ webAccessUnavailableReason: string | null;hosts: string[];}) => {const { currentOrg } = useOrganization();- const [method, setMethod] = useState<LaunchMethod>(supportsWebAccess ? "browser" : "cli");+ const browserDisabled = Boolean(webAccessUnavailableReason);+ const [method, setMethod] = useState<LaunchMethod>(+ supportsWebAccess && !browserDisabled ? "browser" : "cli"+ );const needsHost = hosts.length > 1;const [selectedHost, setSelectedHost] = useState<string | undefined>(@@ -99,14 +104,25 @@ const LaunchTab = ({onValueChange={(value) => setMethod(value as LaunchMethod)}className="grid-cols-2 gap-3">- <FieldLabel htmlFor="launch-browser" variant="pam">+ <FieldLabel+ htmlFor="launch-browser"+ variant="pam"+ className={browserDisabled ? "cursor-not-allowed opacity-50" : undefined}+ ><Field orientation="horizontal" className="items-center gap-3"><Globe className="size-5 shrink-0 text-foreground" /><div className="flex-1 text-left"><p className="text-sm font-medium text-foreground">Browser</p>- <p className="text-xs text-muted">Connect directly from your browser.</p>+ <p className="text-xs text-muted">+ {webAccessUnavailableReason ?? "Connect directly from your browser."}+ </p></div>- <RadioGroupItem id="launch-browser" value="browser" className="sr-only" />+ <RadioGroupItem+ id="launch-browser"+ value="browser"+ disabled={browserDisabled}+ className="sr-only"+ /></Field></FieldLabel><FieldLabel htmlFor="launch-cli" variant="pam">@@ -178,7 +194,8 @@ const LaunchTab = ({};export const LaunchSessionSheet = ({ account, isOpen, onOpenChange }: Props) => {- const { typeMeta, typeName, subtitle, metadata, hosts } = useAccountSheetDetails(account, isOpen);+ const { typeMeta, typeName, subtitle, metadata, hosts, webAccessUnavailableReason } =+ useAccountSheetDetails(account, isOpen);if (!account) return null;@@ -199,7 +216,12 @@ export const LaunchSessionSheet = ({ account, isOpen, onOpenChange }: Props) =>label: "Launch",icon: <Rocket className="mr-1.5 size-4" />,content: (- <LaunchTab account={account} supportsWebAccess={supportsWebAccess} hosts={hosts} />+ <LaunchTab+ account={account}+ supportsWebAccess={supportsWebAccess}+ webAccessUnavailableReason={webAccessUnavailableReason}+ hosts={hosts}+ />)}]}diff --git a/frontend/src/pages/pam/components/accountSheetDetails.tsx b/frontend/src/pages/pam/components/accountSheetDetails.tsxindex f5d985613e..7edb49c96a 100644--- a/frontend/src/pages/pam/components/accountSheetDetails.tsx+++ b/frontend/src/pages/pam/components/accountSheetDetails.tsx@@ -50,7 +50,8 @@ export const useAccountSheetDetails = (account: TAccessiblePamAccount | null, istypeName: undefined,subtitle: undefined,metadata: [],- hosts: []+ hosts: [],+ webAccessUnavailableReason: null};}@@ -78,5 +79,12 @@ export const useAccountSheetDetails = (account: TAccessiblePamAccount | null, is...fieldRows(typeMeta?.credentialFields, credentials)];- return { typeMeta, typeName, subtitle, metadata, hosts };+ // Web Access speaks HTTP, so a ClickHouse account with no HTTP port cannot serve it. Left null while the+ // full account is still loading, so the option is not greyed out on missing data.+ const webAccessUnavailableReason =+ fullAccount && account.accountType === PamAccountType.ClickHouse && conn.port === undefined+ ? "Requires ClickHouse's HTTP interface. Set an HTTP port on this account, or use the CLI."+ : null;++ return { typeMeta, typeName, subtitle, metadata, hosts, webAccessUnavailableReason };};