Skip to content

feat(pam): add NTLM and Kerberos auth support for MSSQL#6638

Merged
saifsmailbox98 merged 14 commits into
mainfrom
saif/pam-227-kerberos-auth-support-for-ms-sql
Jun 1, 2026
Merged

feat(pam): add NTLM and Kerberos auth support for MSSQL#6638
saifsmailbox98 merged 14 commits into
mainfrom
saif/pam-227-kerberos-auth-support-for-ms-sql

Conversation

@saifsmailbox98
Copy link
Copy Markdown
Contributor

@saifsmailbox98 saifsmailbox98 commented May 28, 2026

Context

Adds Windows Authentication (NTLM and Kerberos) to MSSQL PAM accounts, alongside the existing SQL Server Authentication. Auth method is selected per-account as a discriminated union on credentials — same pattern as SSH (Password/PublicKey/Certificate).

NTLM — challenge-response auth between gateway and SQL Server. Users provide a domain (e.g., CORP). Uses go-ntlmssp for the handshake. Two-party, no infrastructure beyond the SQL Server being domain-joined.

Kerberos — ticket-based auth via a KDC. Users provide realm, SPN, and optionally a KDC address (falls back to DNS SRV discovery when empty). Uses gokrb5/v8 for ticket acquisition and SPNEGO wrapping. Gateway contacts the KDC on port 88 to obtain service tickets.

Both methods use the same TDS SSPI field in LOGIN7 — the gateway builds the auth token and injects it on the server leg. The client-to-gateway leg is unchanged (dummy SQL auth).

Credential validation uses Tedious's native NTLM support for NTLM accounts. For Kerberos, it falls back to connectivity-only checks (Tedious doesn't support Kerberos) — same approach as SSH Certificate auth. Backend schemas include input validation on realm, KDC address, and SPN to prevent injection into the krb5.conf template.

Companion CLI PR: Infisical/cli#245

Screenshots

Steps to verify the change

Type

  • Fix
  • Feature
  • Improvement
  • Breaking
  • Docs
  • Chore

Checklist

  • Title follows the conventional commit format: type(scope): short description (scope is optional, e.g., fix: prevent crash on sync or fix(api): handle null response).
  • Tested locally
  • Updated docs (if needed)
  • Updated CLAUDE.md files (if needed)
  • Read the contributing guide

MSSQL PAM accounts now support Windows Authentication (NTLM) in
addition to SQL Server Authentication. The auth method is selected
per-account via a discriminated union on the credentials schema,
following the same pattern as SSH (password/publickey/certificate).

Backend: new MsSqlAuthMethod enum, discriminated union on account
credentials, NTLM branch in Tedious/Knex connection validation,
MSSQL added to session credentials response union.

Frontend: auth method selector on the MSSQL account form with
conditional domain field for NTLM.
…hema

Old MSSQL accounts without authMethod are handled via .default() in
account/sanitized schemas (scoped by parentType) and a service-level
backfill in getSessionCredentials. Session credentials schema uses a
strict variant without .default() to avoid cross-resource false matches
in the flat z.union.
MSSQL PAM accounts now support Kerberos (Windows Authentication via
KDC) alongside SQL auth and NTLM. Uses gokrb5/v8 for ticket
acquisition and SPNEGO token generation.
…rt-for-mssql-in-pam' into saif/pam-227-kerberos-auth-support-for-ms-sql
kdcAddress was missing from the sanitized credentials schema, causing
it to disappear when editing a Kerberos account. Also updated docs to
mention Kerberos auth and port 88 gateway requirement.
Regex used + (requires at least one char) which rejected empty strings
even though the field is optional. Changed to * and transform empty
string to undefined.
@linear
Copy link
Copy Markdown

linear Bot commented May 28, 2026

PAM-227

@infisical-review-police
Copy link
Copy Markdown

💬 Discussion in Slack: #pr-review-infisical-6638-feat-pam-add-kerberos-auth-support-for-mssql

Posted by Review Police — reviews, comments, new commits, and CI failures will stream into this channel.

@mintlify
Copy link
Copy Markdown

mintlify Bot commented May 28, 2026

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
infisical 🟢 Ready View Preview May 28, 2026, 4:13 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@gitguardian
Copy link
Copy Markdown

gitguardian Bot commented May 28, 2026

⚠️ GitGuardian has uncovered 3 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
9387833 Triggered Generic Password 4888b10 backend-go/docker-compose.test.yml View secret
29105343 Triggered Generic High Entropy Secret 4888b10 backend-go/internal/server/gen/http/secrets/client/encode_decode.go View secret
28944329 Triggered PostHog Project API Key 4888b10 backend-go/internal/config/config.go View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 28, 2026

Greptile Summary

This PR adds Kerberos as a third authentication method for MSSQL PAM accounts alongside the existing SQL login and NTLM methods, using a discriminated union schema pattern on the credentials object.

  • New schemas and types: Backend Zod schemas (MsSQLKerberosCredentialsSchema, MsSQLNtlmCredentialsSchema) with regex validation on realm and kdcAddress to prevent krb5.conf injection; frontend mirrors the same union with a MsSqlAuthMethod enum.
  • Factory changes: sql-resource-factory.ts routes NTLM connections through Tedious's native auth object; Kerberos validation skips credential testing (Tedious doesn't support it) and falls back to TCP-only connectivity check.
  • Backward compatibility: A migration shim in pam-account-service.ts defaults old MSSQL accounts (without authMethod) to sql-login at session-credential assembly time.

Confidence Score: 3/5

The core feature works, but two security gaps in the Kerberos schema need to be closed before merging: the spn field accepts arbitrary characters that could break the gateway's krb5.conf template, and the kdcAddress field bypasses the host-validation guard used for every other user-supplied address in this codebase.

The Kerberos spn field has no character-restriction regex despite the PR explicitly adding such restrictions to realm and kdcAddress to prevent krb5.conf injection. Additionally, kdcAddress goes through the gateway as a user-supplied connection target without passing through verifyHostInputValidity, the same function used to guard against SSRF on the MSSQL host itself. Both issues are on the Kerberos credential-intake path and should be fixed before the feature ships.

backend/src/ee/services/pam-resource/mssql/mssql-resource-schemas.ts — the kdcAddress and spn field validations need attention before merge.

Security Review

  • krb5.conf injection via spn field (mssql-resource-schemas.ts): The spn field accepts up to 500 characters with no character allowlist. A value containing or ] could inject additional directives into the krb5.conf template the gateway builds at runtime. The PR explicitly protects realm and kdcAddress with a safe-character regex but omits the same guard for spn.
  • SSRF via user-controlled kdcAddress (mssql-resource-schemas.ts): kdcAddress is validated for character safety but not checked against private/loopback IP ranges. The gateway will make outbound Kerberos (port 88) connections to this address without routing it through verifyHostInputValidity, allowing a platform user to direct gateway network probes at internal infrastructure.

Important Files Changed

Filename Overview
backend/src/ee/services/pam-resource/mssql/mssql-resource-schemas.ts Defines discriminated-union schemas for three MSSQL auth methods; spn field lacks the same injection-prevention regex applied to realm/kdcAddress, and kdcAddress allows private IPs without SSRF guards.
backend/src/ee/services/pam-resource/shared/sql/sql-resource-factory.ts Adds NTLM auth path to the Knex connection config and a Kerberos early-return that skips credential validation; runtime logic is correct but the no-op Kerberos validation path should be documented to users.
backend/src/ee/services/pam-account/pam-account-service.ts Adds a backward-compat migration shim that injects authMethod: sql-login into old MSSQL account credentials that predate the authMethod field; safe and well-scoped.
backend/src/ee/routes/v1/pam-session-router.ts Adds MsSQLSessionCredentialsSchema to the union and reorders schemas so more-specific variants are tested before the simpler sql-login fallback; ordering comment explains the Zod union matching rationale.
backend/src/ee/services/pam-resource/mssql/mssql-resource-enums.ts New enum file defining the three MSSQL auth method string values; straightforward and correct.
frontend/src/hooks/api/pam/types/mssql-resource.ts Mirrors the backend auth-method union in frontend types; replaces the single TBaseSqlCredentials with a proper discriminated union matching the three auth methods.
frontend/src/pages/pam/PamAccountsPage/components/PamAccountForm/MsSQLAccountForm.tsx New MsSQLAccountFields component with conditional field rendering per auth method; password sentinel handling is preserved correctly for the update path.
docs/documentation/platform/pam/getting-started/resources/mssql.mdx Documentation updated to describe all three auth methods and new credential fields; accurate and well-structured.

Reviews (1): Last reviewed commit: "fix(pam): allow empty kdcAddress for Ker..." | Re-trigger Greptile

Comment thread backend/src/ee/services/pam-resource/mssql/mssql-resource-schemas.ts Outdated
@veria-ai
Copy link
Copy Markdown

veria-ai Bot commented May 28, 2026

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Security review

No open security issues remain on this pull request.

Fixed/addressed: 2 · PR risk: 0/10

@saifsmailbox98 saifsmailbox98 requested a review from bernie-g May 29, 2026 00:52
@saifsmailbox98 saifsmailbox98 changed the title feat(pam): add Kerberos auth support for MSSQL feat(pam): add NTLM and Kerberos auth support for MSSQL May 29, 2026
Comment thread docs/documentation/platform/pam/getting-started/resources/mssql.mdx Outdated
Comment thread docs/documentation/platform/pam/getting-started/resources/mssql.mdx
@saifsmailbox98 saifsmailbox98 merged commit 2c50873 into main Jun 1, 2026
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants