mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-08 14:28:20 +00:00
Finish frame for LDAP auth
This commit is contained in:
Generated
+162
@@ -53,6 +53,7 @@
|
|||||||
"passport-github": "^1.1.0",
|
"passport-github": "^1.1.0",
|
||||||
"passport-gitlab2": "^5.0.0",
|
"passport-gitlab2": "^5.0.0",
|
||||||
"passport-google-oauth20": "^2.0.0",
|
"passport-google-oauth20": "^2.0.0",
|
||||||
|
"passport-ldapauth": "^3.0.1",
|
||||||
"pg": "^8.11.3",
|
"pg": "^8.11.3",
|
||||||
"picomatch": "^3.0.1",
|
"picomatch": "^3.0.1",
|
||||||
"pino": "^8.16.2",
|
"pino": "^8.16.2",
|
||||||
@@ -3957,6 +3958,14 @@
|
|||||||
"integrity": "sha512-2h3tFvkbHksiNcDiUdcJ08gXWG10fnahp30GJ2Tbt4vd4pfsbfkoKTaTbYykFoppaJ6DL3914nQ3PU1vVIlBRQ==",
|
"integrity": "sha512-2h3tFvkbHksiNcDiUdcJ08gXWG10fnahp30GJ2Tbt4vd4pfsbfkoKTaTbYykFoppaJ6DL3914nQ3PU1vVIlBRQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/ldapjs": {
|
||||||
|
"version": "2.2.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/ldapjs/-/ldapjs-2.2.5.tgz",
|
||||||
|
"integrity": "sha512-Lv/nD6QDCmcT+V1vaTRnEKE8UgOilVv5pHcQuzkU1LcRe4mbHHuUo/KHi0LKrpdHhQY8FJzryF38fcVdeUIrzg==",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@types/libsodium-wrappers": {
|
"node_modules/@types/libsodium-wrappers": {
|
||||||
"version": "0.7.13",
|
"version": "0.7.13",
|
||||||
"resolved": "https://registry.npmjs.org/@types/libsodium-wrappers/-/libsodium-wrappers-0.7.13.tgz",
|
"resolved": "https://registry.npmjs.org/@types/libsodium-wrappers/-/libsodium-wrappers-0.7.13.tgz",
|
||||||
@@ -5104,6 +5113,22 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/asn1": {
|
||||||
|
"version": "0.2.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.6.tgz",
|
||||||
|
"integrity": "sha512-ix/FxPn0MDjeyJ7i/yoHGFt/EX6LyNbxSEhPPXODPL+KB0VPk86UYfL0lMdy+KCnv+fmvIzySwaK5COwqVbWTQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"safer-buffer": "~2.1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/assert-plus": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-NfJ4UzBCcQGLDlQq7nHxH+tv3kyZ0hHQqF5BO6J7tNJeP5do1llPr8dZ8zHonfhAu0PHAdMkSo+8o0wxg9lZWw==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/assertion-error": {
|
"node_modules/assertion-error": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz",
|
||||||
@@ -5270,6 +5295,17 @@
|
|||||||
"axios": "0.x || 1.x"
|
"axios": "0.x || 1.x"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/backoff": {
|
||||||
|
"version": "2.5.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/backoff/-/backoff-2.5.0.tgz",
|
||||||
|
"integrity": "sha512-wC5ihrnUXmR2douXmXLCe5O3zg3GKIyvRi/hi58a/XyRxVI+3/yM0PYueQOZXPXQ9pxBislYkw+sF9b7C/RuMA==",
|
||||||
|
"dependencies": {
|
||||||
|
"precond": "0.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/balanced-match": {
|
"node_modules/balanced-match": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
|
||||||
@@ -5315,6 +5351,11 @@
|
|||||||
"node": ">= 10.0.0"
|
"node": ">= 10.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/bcryptjs": {
|
||||||
|
"version": "2.4.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-2.4.3.tgz",
|
||||||
|
"integrity": "sha512-V/Hy/X9Vt7f3BbPJEi8BdVFMByHi+jNXrYkW3huaybV/kQ0KJg0Y6PkEMbn+zeT+i+SiKZ/HMqJGIIt4LZDqNQ=="
|
||||||
|
},
|
||||||
"node_modules/before-after-hook": {
|
"node_modules/before-after-hook": {
|
||||||
"version": "2.2.3",
|
"version": "2.2.3",
|
||||||
"resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.3.tgz",
|
||||||
@@ -5785,6 +5826,11 @@
|
|||||||
"node": ">=6.6.0"
|
"node": ">=6.6.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/core-util-is": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
|
||||||
|
"integrity": "sha512-3lqz5YjWTYnW6dlDa5TLaTCcShfar1e40rmcJVwCBJC6mWlFuj0eCHIElmG1g5kyuJ/GD+8Wn4FFCcz4gJPfaQ=="
|
||||||
|
},
|
||||||
"node_modules/create-hash": {
|
"node_modules/create-hash": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz",
|
||||||
@@ -6855,6 +6901,14 @@
|
|||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||||
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
|
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
|
||||||
},
|
},
|
||||||
|
"node_modules/extsprintf": {
|
||||||
|
"version": "1.4.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.4.1.tgz",
|
||||||
|
"integrity": "sha512-Wrk35e8ydCKDj/ArClo1VrPVmN8zph5V4AtHwIuHhvMXsKf73UT3BOD+azBIW+3wOJ4FhEH7zyaJCFvChjYvMA==",
|
||||||
|
"engines": [
|
||||||
|
"node >=0.6.0"
|
||||||
|
]
|
||||||
|
},
|
||||||
"node_modules/fast-content-type-parse": {
|
"node_modules/fast-content-type-parse": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/fast-content-type-parse/-/fast-content-type-parse-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/fast-content-type-parse/-/fast-content-type-parse-1.1.0.tgz",
|
||||||
@@ -8584,6 +8638,57 @@
|
|||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/ldap-filter": {
|
||||||
|
"version": "0.3.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/ldap-filter/-/ldap-filter-0.3.3.tgz",
|
||||||
|
"integrity": "sha512-/tFkx5WIn4HuO+6w9lsfxq4FN3O+fDZeO9Mek8dCD8rTUpqzRa766BOBO7BcGkn3X86m5+cBm1/2S/Shzz7gMg==",
|
||||||
|
"dependencies": {
|
||||||
|
"assert-plus": "^1.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/ldapauth-fork": {
|
||||||
|
"version": "5.0.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/ldapauth-fork/-/ldapauth-fork-5.0.5.tgz",
|
||||||
|
"integrity": "sha512-LWUk76+V4AOZbny/3HIPQtGPWZyA3SW2tRhsWIBi9imP22WJktKLHV1ofd8Jo/wY7Ve6vAT7FCI5mEn3blZTjw==",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/ldapjs": "^2.2.2",
|
||||||
|
"bcryptjs": "^2.4.0",
|
||||||
|
"ldapjs": "^2.2.1",
|
||||||
|
"lru-cache": "^7.10.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.8.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/ldapauth-fork/node_modules/lru-cache": {
|
||||||
|
"version": "7.18.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz",
|
||||||
|
"integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/ldapjs": {
|
||||||
|
"version": "2.3.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/ldapjs/-/ldapjs-2.3.3.tgz",
|
||||||
|
"integrity": "sha512-75QiiLJV/PQqtpH+HGls44dXweviFwQ6SiIK27EqzKQ5jU/7UFrl2E5nLdQ3IYRBzJ/AVFJI66u0MZ0uofKYwg==",
|
||||||
|
"dependencies": {
|
||||||
|
"abstract-logging": "^2.0.0",
|
||||||
|
"asn1": "^0.2.4",
|
||||||
|
"assert-plus": "^1.0.0",
|
||||||
|
"backoff": "^2.5.0",
|
||||||
|
"ldap-filter": "^0.3.3",
|
||||||
|
"once": "^1.4.0",
|
||||||
|
"vasync": "^2.2.0",
|
||||||
|
"verror": "^1.8.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10.13.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/leven": {
|
"node_modules/leven": {
|
||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/leven/-/leven-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/leven/-/leven-2.1.0.tgz",
|
||||||
@@ -9730,6 +9835,18 @@
|
|||||||
"node": ">= 0.4.0"
|
"node": ">= 0.4.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/passport-ldapauth": {
|
||||||
|
"version": "3.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/passport-ldapauth/-/passport-ldapauth-3.0.1.tgz",
|
||||||
|
"integrity": "sha512-TRRx3BHi8GC8MfCT9wmghjde/EGeKjll7zqHRRfGRxXbLcaDce2OftbQrFG7/AWaeFhR6zpZHtBQ/IkINdLVjQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"ldapauth-fork": "^5.0.1",
|
||||||
|
"passport-strategy": "^1.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.8.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/passport-oauth2": {
|
"node_modules/passport-oauth2": {
|
||||||
"version": "1.7.0",
|
"version": "1.7.0",
|
||||||
"resolved": "https://registry.npmjs.org/passport-oauth2/-/passport-oauth2-1.7.0.tgz",
|
"resolved": "https://registry.npmjs.org/passport-oauth2/-/passport-oauth2-1.7.0.tgz",
|
||||||
@@ -10284,6 +10401,14 @@
|
|||||||
"node": ">=15.0.0"
|
"node": ">=15.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/precond": {
|
||||||
|
"version": "0.2.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/precond/-/precond-0.2.3.tgz",
|
||||||
|
"integrity": "sha512-QCYG84SgGyGzqJ/vlMsxeXd/pgL/I94ixdNFyh1PusWmTCyVfPJjZ1K1jvHtsbfnXQs2TSkEP2fR7QiMZAnKFQ==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/prelude-ls": {
|
"node_modules/prelude-ls": {
|
||||||
"version": "1.2.1",
|
"version": "1.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz",
|
||||||
@@ -12737,6 +12862,43 @@
|
|||||||
"node": ">= 0.8"
|
"node": ">= 0.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/vasync": {
|
||||||
|
"version": "2.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/vasync/-/vasync-2.2.1.tgz",
|
||||||
|
"integrity": "sha512-Hq72JaTpcTFdWiNA4Y22Amej2GH3BFmBaKPPlDZ4/oC8HNn2ISHLkFrJU4Ds8R3jcUi7oo5Y9jcMHKjES+N9wQ==",
|
||||||
|
"engines": [
|
||||||
|
"node >=0.6.0"
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"verror": "1.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/vasync/node_modules/verror": {
|
||||||
|
"version": "1.10.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz",
|
||||||
|
"integrity": "sha512-ZZKSmDAEFOijERBLkmYfJ+vmk3w+7hOLYDNkRCuRuMJGEmqYNCNLyBBFwWKVMhfwaEF3WOd0Zlw86U/WC/+nYw==",
|
||||||
|
"engines": [
|
||||||
|
"node >=0.6.0"
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"assert-plus": "^1.0.0",
|
||||||
|
"core-util-is": "1.0.2",
|
||||||
|
"extsprintf": "^1.2.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/verror": {
|
||||||
|
"version": "1.10.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/verror/-/verror-1.10.1.tgz",
|
||||||
|
"integrity": "sha512-veufcmxri4e3XSrT0xwfUR7kguIkaxBeosDg00yDWhk49wdwkSUrvvsm7nc75e1PUyvIeZj6nS8VQRYz2/S4Xg==",
|
||||||
|
"dependencies": {
|
||||||
|
"assert-plus": "^1.0.0",
|
||||||
|
"core-util-is": "1.0.2",
|
||||||
|
"extsprintf": "^1.2.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.6.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/vite": {
|
"node_modules/vite": {
|
||||||
"version": "5.0.12",
|
"version": "5.0.12",
|
||||||
"resolved": "https://registry.npmjs.org/vite/-/vite-5.0.12.tgz",
|
"resolved": "https://registry.npmjs.org/vite/-/vite-5.0.12.tgz",
|
||||||
|
|||||||
@@ -114,6 +114,7 @@
|
|||||||
"passport-github": "^1.1.0",
|
"passport-github": "^1.1.0",
|
||||||
"passport-gitlab2": "^5.0.0",
|
"passport-gitlab2": "^5.0.0",
|
||||||
"passport-google-oauth20": "^2.0.0",
|
"passport-google-oauth20": "^2.0.0",
|
||||||
|
"passport-ldapauth": "^3.0.1",
|
||||||
"pg": "^8.11.3",
|
"pg": "^8.11.3",
|
||||||
"picomatch": "^3.0.1",
|
"picomatch": "^3.0.1",
|
||||||
"pino": "^8.16.2",
|
"pino": "^8.16.2",
|
||||||
|
|||||||
Vendored
+3
@@ -3,6 +3,7 @@ import "fastify";
|
|||||||
import { TUsers } from "@app/db/schemas";
|
import { TUsers } from "@app/db/schemas";
|
||||||
import { TAuditLogServiceFactory } from "@app/ee/services/audit-log/audit-log-service";
|
import { TAuditLogServiceFactory } from "@app/ee/services/audit-log/audit-log-service";
|
||||||
import { TCreateAuditLogDTO } from "@app/ee/services/audit-log/audit-log-types";
|
import { TCreateAuditLogDTO } from "@app/ee/services/audit-log/audit-log-types";
|
||||||
|
import { TLdapConfigServiceFactory } from "@app/ee/services/ldap-config/ldap-config-service";
|
||||||
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
||||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";
|
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";
|
||||||
import { TSamlConfigServiceFactory } from "@app/ee/services/saml-config/saml-config-service";
|
import { TSamlConfigServiceFactory } from "@app/ee/services/saml-config/saml-config-service";
|
||||||
@@ -69,6 +70,7 @@ declare module "fastify" {
|
|||||||
};
|
};
|
||||||
auditLogInfo: Pick<TCreateAuditLogDTO, "userAgent" | "userAgentType" | "ipAddress" | "actor">;
|
auditLogInfo: Pick<TCreateAuditLogDTO, "userAgent" | "userAgentType" | "ipAddress" | "actor">;
|
||||||
ssoConfig: Awaited<ReturnType<TSamlConfigServiceFactory["getSaml"]>>;
|
ssoConfig: Awaited<ReturnType<TSamlConfigServiceFactory["getSaml"]>>;
|
||||||
|
ldapConfig: Awaited<ReturnType<TLdapConfigServiceFactory["getLdapCfg"]>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface FastifyInstance {
|
interface FastifyInstance {
|
||||||
@@ -107,6 +109,7 @@ declare module "fastify" {
|
|||||||
snapshot: TSecretSnapshotServiceFactory;
|
snapshot: TSecretSnapshotServiceFactory;
|
||||||
saml: TSamlConfigServiceFactory;
|
saml: TSamlConfigServiceFactory;
|
||||||
scim: TScimServiceFactory;
|
scim: TScimServiceFactory;
|
||||||
|
ldap: TLdapConfigServiceFactory;
|
||||||
auditLog: TAuditLogServiceFactory;
|
auditLog: TAuditLogServiceFactory;
|
||||||
secretScanning: TSecretScanningServiceFactory;
|
secretScanning: TSecretScanningServiceFactory;
|
||||||
license: TLicenseServiceFactory;
|
license: TLicenseServiceFactory;
|
||||||
|
|||||||
Vendored
+4
@@ -50,6 +50,9 @@ import {
|
|||||||
TIntegrations,
|
TIntegrations,
|
||||||
TIntegrationsInsert,
|
TIntegrationsInsert,
|
||||||
TIntegrationsUpdate,
|
TIntegrationsUpdate,
|
||||||
|
TLdapConfigs,
|
||||||
|
TLdapConfigsInsert,
|
||||||
|
TLdapConfigsUpdate,
|
||||||
TOrganizations,
|
TOrganizations,
|
||||||
TOrganizationsInsert,
|
TOrganizationsInsert,
|
||||||
TOrganizationsUpdate,
|
TOrganizationsUpdate,
|
||||||
@@ -318,6 +321,7 @@ declare module "knex/types/tables" {
|
|||||||
TSecretSnapshotFoldersUpdate
|
TSecretSnapshotFoldersUpdate
|
||||||
>;
|
>;
|
||||||
[TableName.SamlConfig]: Knex.CompositeTableType<TSamlConfigs, TSamlConfigsInsert, TSamlConfigsUpdate>;
|
[TableName.SamlConfig]: Knex.CompositeTableType<TSamlConfigs, TSamlConfigsInsert, TSamlConfigsUpdate>;
|
||||||
|
[TableName.LdapConfig]: Knex.CompositeTableType<TLdapConfigs, TLdapConfigsInsert, TLdapConfigsUpdate>;
|
||||||
[TableName.OrgBot]: Knex.CompositeTableType<TOrgBots, TOrgBotsInsert, TOrgBotsUpdate>;
|
[TableName.OrgBot]: Knex.CompositeTableType<TOrgBots, TOrgBotsInsert, TOrgBotsUpdate>;
|
||||||
[TableName.AuditLog]: Knex.CompositeTableType<TAuditLogs, TAuditLogsInsert, TAuditLogsUpdate>;
|
[TableName.AuditLog]: Knex.CompositeTableType<TAuditLogs, TAuditLogsInsert, TAuditLogsUpdate>;
|
||||||
[TableName.GitAppInstallSession]: Knex.CompositeTableType<
|
[TableName.GitAppInstallSession]: Knex.CompositeTableType<
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import { Knex } from "knex";
|
||||||
|
|
||||||
|
import { TableName } from "../schemas";
|
||||||
|
import { createOnUpdateTrigger, dropOnUpdateTrigger } from "../utils";
|
||||||
|
|
||||||
|
export async function up(knex: Knex): Promise<void> {
|
||||||
|
if (!(await knex.schema.hasTable(TableName.LdapConfig))) {
|
||||||
|
await knex.schema.createTable(TableName.LdapConfig, (t) => {
|
||||||
|
t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid());
|
||||||
|
t.uuid("orgId").notNullable().unique();
|
||||||
|
t.foreign("orgId").references("id").inTable(TableName.Organization);
|
||||||
|
t.boolean("isActive").notNullable();
|
||||||
|
t.string("url").notNullable();
|
||||||
|
t.string("encryptedBindDN");
|
||||||
|
t.string("bindDNIV");
|
||||||
|
t.string("bindDNTag");
|
||||||
|
t.string("encryptedBindPass");
|
||||||
|
t.string("bindPassIV");
|
||||||
|
t.string("bindPassTag");
|
||||||
|
t.text("searchBase").notNullable();
|
||||||
|
t.string("encryptedCACert");
|
||||||
|
t.string("caCertIV");
|
||||||
|
t.string("caCertTag");
|
||||||
|
t.timestamps(true, true, true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await knex.schema.alterTable(TableName.Users, (t) => {
|
||||||
|
t.string("username");
|
||||||
|
t.uuid("orgId");
|
||||||
|
t.string("email").nullable().alter();
|
||||||
|
});
|
||||||
|
|
||||||
|
await knex(TableName.Users).update("username", knex.ref("email"));
|
||||||
|
|
||||||
|
await createOnUpdateTrigger(knex, TableName.LdapConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(knex: Knex): Promise<void> {
|
||||||
|
await knex.schema.dropTableIfExists(TableName.LdapConfig);
|
||||||
|
await knex.schema.alterTable(TableName.Users, (t) => {
|
||||||
|
t.dropColumn("username");
|
||||||
|
t.dropColumn("orgId");
|
||||||
|
t.string("email").notNullable().alter();
|
||||||
|
});
|
||||||
|
await dropOnUpdateTrigger(knex, TableName.LdapConfig);
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ export * from "./identity-universal-auths";
|
|||||||
export * from "./incident-contacts";
|
export * from "./incident-contacts";
|
||||||
export * from "./integration-auths";
|
export * from "./integration-auths";
|
||||||
export * from "./integrations";
|
export * from "./integrations";
|
||||||
|
export * from "./ldap-configs";
|
||||||
export * from "./models";
|
export * from "./models";
|
||||||
export * from "./org-bots";
|
export * from "./org-bots";
|
||||||
export * from "./org-memberships";
|
export * from "./org-memberships";
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
// Code generated by automation script, DO NOT EDIT.
|
||||||
|
// Automated by pulling database and generating zod schema
|
||||||
|
// To update. Just run npm run generate:schema
|
||||||
|
// Written by akhilmhdh.
|
||||||
|
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
import { TImmutableDBKeys } from "./models";
|
||||||
|
|
||||||
|
export const LdapConfigsSchema = z.object({
|
||||||
|
id: z.string().uuid(),
|
||||||
|
orgId: z.string().uuid(),
|
||||||
|
isActive: z.boolean(),
|
||||||
|
url: z.string(),
|
||||||
|
encryptedBindDN: z.string().nullable().optional(),
|
||||||
|
bindDNIV: z.string().nullable().optional(),
|
||||||
|
bindDNTag: z.string().nullable().optional(),
|
||||||
|
encryptedBindPass: z.string().nullable().optional(),
|
||||||
|
bindPassIV: z.string().nullable().optional(),
|
||||||
|
bindPassTag: z.string().nullable().optional(),
|
||||||
|
searchBase: z.string(),
|
||||||
|
encryptedCACert: z.string().nullable().optional(),
|
||||||
|
caCertIV: z.string().nullable().optional(),
|
||||||
|
caCertTag: z.string().nullable().optional(),
|
||||||
|
createdAt: z.date(),
|
||||||
|
updatedAt: z.date()
|
||||||
|
});
|
||||||
|
|
||||||
|
export type TLdapConfigs = z.infer<typeof LdapConfigsSchema>;
|
||||||
|
export type TLdapConfigsInsert = Omit<TLdapConfigs, TImmutableDBKeys>;
|
||||||
|
export type TLdapConfigsUpdate = Partial<Omit<TLdapConfigs, TImmutableDBKeys>>;
|
||||||
@@ -50,6 +50,7 @@ export enum TableName {
|
|||||||
SecretRotation = "secret_rotations",
|
SecretRotation = "secret_rotations",
|
||||||
SecretRotationOutput = "secret_rotation_outputs",
|
SecretRotationOutput = "secret_rotation_outputs",
|
||||||
SamlConfig = "saml_configs",
|
SamlConfig = "saml_configs",
|
||||||
|
LdapConfig = "ldap_configs",
|
||||||
AuditLog = "audit_logs",
|
AuditLog = "audit_logs",
|
||||||
GitAppInstallSession = "git_app_install_sessions",
|
GitAppInstallSession = "git_app_install_sessions",
|
||||||
GitAppOrg = "git_app_org",
|
GitAppOrg = "git_app_org",
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { TImmutableDBKeys } from "./models";
|
|||||||
|
|
||||||
export const UsersSchema = z.object({
|
export const UsersSchema = z.object({
|
||||||
id: z.string().uuid(),
|
id: z.string().uuid(),
|
||||||
email: z.string(),
|
email: z.string().nullable().optional(),
|
||||||
authMethods: z.string().array().nullable().optional(),
|
authMethods: z.string().array().nullable().optional(),
|
||||||
superAdmin: z.boolean().default(false).nullable().optional(),
|
superAdmin: z.boolean().default(false).nullable().optional(),
|
||||||
firstName: z.string().nullable().optional(),
|
firstName: z.string().nullable().optional(),
|
||||||
@@ -20,7 +20,9 @@ export const UsersSchema = z.object({
|
|||||||
devices: z.unknown().nullable().optional(),
|
devices: z.unknown().nullable().optional(),
|
||||||
createdAt: z.date(),
|
createdAt: z.date(),
|
||||||
updatedAt: z.date(),
|
updatedAt: z.date(),
|
||||||
isGhost: z.boolean().default(false)
|
isGhost: z.boolean().default(false),
|
||||||
|
username: z.string().nullable().optional(),
|
||||||
|
orgId: z.string().uuid().nullable().optional()
|
||||||
});
|
});
|
||||||
|
|
||||||
export type TUsers = z.infer<typeof UsersSchema>;
|
export type TUsers = z.infer<typeof UsersSchema>;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { registerLdapRouter } from "./ldap-router";
|
||||||
import { registerLicenseRouter } from "./license-router";
|
import { registerLicenseRouter } from "./license-router";
|
||||||
import { registerOrgRoleRouter } from "./org-role-router";
|
import { registerOrgRoleRouter } from "./org-role-router";
|
||||||
import { registerProjectRoleRouter } from "./project-role-router";
|
import { registerProjectRoleRouter } from "./project-role-router";
|
||||||
@@ -35,6 +36,7 @@ export const registerV1EERoutes = async (server: FastifyZodProvider) => {
|
|||||||
});
|
});
|
||||||
await server.register(registerSamlRouter, { prefix: "/sso" });
|
await server.register(registerSamlRouter, { prefix: "/sso" });
|
||||||
await server.register(registerScimRouter, { prefix: "/scim" });
|
await server.register(registerScimRouter, { prefix: "/scim" });
|
||||||
|
await server.register(registerLdapRouter, { prefix: "/ldap" });
|
||||||
await server.register(registerSecretScanningRouter, { prefix: "/secret-scanning" });
|
await server.register(registerSecretScanningRouter, { prefix: "/secret-scanning" });
|
||||||
await server.register(registerSecretRotationRouter, { prefix: "/secret-rotations" });
|
await server.register(registerSecretRotationRouter, { prefix: "/secret-rotations" });
|
||||||
await server.register(registerSecretVersionRouter, { prefix: "/secret" });
|
await server.register(registerSecretVersionRouter, { prefix: "/secret" });
|
||||||
|
|||||||
@@ -0,0 +1,172 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
||||||
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||||
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||||
|
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||||
|
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
||||||
|
// All the any rules are disabled because passport typesense with fastify is really poor
|
||||||
|
|
||||||
|
import { Authenticator } from "@fastify/passport";
|
||||||
|
import fastifySession from "@fastify/session";
|
||||||
|
import { FastifyRequest } from "fastify";
|
||||||
|
import LdapStrategy from "passport-ldapauth";
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
import { LdapConfigsSchema } from "@app/db/schemas";
|
||||||
|
import { getConfig } from "@app/lib/config/env";
|
||||||
|
import { logger } from "@app/lib/logger";
|
||||||
|
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
||||||
|
import { AuthMode } from "@app/services/auth/auth-type";
|
||||||
|
|
||||||
|
export const registerLdapRouter = async (server: FastifyZodProvider) => {
|
||||||
|
const appCfg = getConfig();
|
||||||
|
const passport = new Authenticator({ key: "ldap", userProperty: "passportUser" });
|
||||||
|
await server.register(fastifySession, { secret: appCfg.COOKIE_SECRET_SIGN_KEY });
|
||||||
|
await server.register(passport.initialize());
|
||||||
|
await server.register(passport.secureSession());
|
||||||
|
|
||||||
|
passport.use(
|
||||||
|
new LdapStrategy(
|
||||||
|
server.services.ldap.getLDAPConfiguration,
|
||||||
|
// eslint-disable-next-line
|
||||||
|
async (req, user, cb) => {
|
||||||
|
try {
|
||||||
|
const { isUserCompleted, providerAuthToken } = await server.services.ldap.ldapLogin({
|
||||||
|
username: user.uid,
|
||||||
|
firstName: user.givenName,
|
||||||
|
lastName: user.sn,
|
||||||
|
relayState: (req.body as { RelayState?: string }).RelayState,
|
||||||
|
orgId: (req as unknown as FastifyRequest).ldapConfig.organization
|
||||||
|
});
|
||||||
|
|
||||||
|
return cb(null, { isUserCompleted, providerAuthToken });
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(err);
|
||||||
|
return cb(null, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
server.route({
|
||||||
|
url: "/login",
|
||||||
|
method: "POST",
|
||||||
|
schema: {
|
||||||
|
body: z.object({
|
||||||
|
organizationSlug: z.string().trim()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
preValidation: passport.authenticate("ldapauth", {
|
||||||
|
session: false,
|
||||||
|
failureFlash: true,
|
||||||
|
failureRedirect: "/login/provider/error"
|
||||||
|
// this is due to zod type difference
|
||||||
|
}) as any,
|
||||||
|
handler: (req, res) => {
|
||||||
|
let nextUrl;
|
||||||
|
if (req.passportUser.isUserCompleted) {
|
||||||
|
nextUrl = `${appCfg.SITE_URL}/login/sso?token=${encodeURIComponent(req.passportUser.providerAuthToken)}`;
|
||||||
|
} else {
|
||||||
|
nextUrl = `${appCfg.SITE_URL}/signup/sso?token=${encodeURIComponent(req.passportUser.providerAuthToken)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(200).send({
|
||||||
|
nextUrl
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
server.route({
|
||||||
|
url: "/config",
|
||||||
|
method: "GET",
|
||||||
|
onRequest: verifyAuth([AuthMode.JWT]),
|
||||||
|
schema: {
|
||||||
|
querystring: z.object({
|
||||||
|
organizationId: z.string().trim()
|
||||||
|
}),
|
||||||
|
response: {
|
||||||
|
200: z.object({
|
||||||
|
id: z.string(),
|
||||||
|
organization: z.string(),
|
||||||
|
isActive: z.boolean(),
|
||||||
|
url: z.string(),
|
||||||
|
bindDN: z.string(),
|
||||||
|
bindPass: z.string(),
|
||||||
|
searchBase: z.string(),
|
||||||
|
caCert: z.string()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
handler: async (req) => {
|
||||||
|
const ldap = await server.services.ldap.getLdapCfg({
|
||||||
|
actor: req.permission.type,
|
||||||
|
actorId: req.permission.id,
|
||||||
|
orgId: req.query.organizationId,
|
||||||
|
actorOrgId: req.permission.orgId
|
||||||
|
});
|
||||||
|
return ldap;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
server.route({
|
||||||
|
url: "/config",
|
||||||
|
method: "POST",
|
||||||
|
onRequest: verifyAuth([AuthMode.JWT]),
|
||||||
|
schema: {
|
||||||
|
body: z.object({
|
||||||
|
organizationId: z.string().trim(),
|
||||||
|
isActive: z.boolean(),
|
||||||
|
url: z.string().trim(),
|
||||||
|
bindDN: z.string().trim(),
|
||||||
|
bindPass: z.string().trim(),
|
||||||
|
searchBase: z.string().trim(),
|
||||||
|
caCert: z.string().trim().default("")
|
||||||
|
}),
|
||||||
|
response: {
|
||||||
|
200: LdapConfigsSchema
|
||||||
|
}
|
||||||
|
},
|
||||||
|
handler: async (req) => {
|
||||||
|
const ldap = await server.services.ldap.createLdapCfg({
|
||||||
|
actor: req.permission.type,
|
||||||
|
actorId: req.permission.id,
|
||||||
|
orgId: req.body.organizationId,
|
||||||
|
actorOrgId: req.permission.orgId,
|
||||||
|
...req.body
|
||||||
|
});
|
||||||
|
|
||||||
|
return ldap;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
server.route({
|
||||||
|
url: "/config",
|
||||||
|
method: "PATCH",
|
||||||
|
onRequest: verifyAuth([AuthMode.JWT]),
|
||||||
|
schema: {
|
||||||
|
body: z.object({
|
||||||
|
organizationId: z.string().trim(),
|
||||||
|
isActive: z.boolean().optional(),
|
||||||
|
url: z.string().trim().optional(),
|
||||||
|
bindDN: z.string().trim().optional(),
|
||||||
|
bindPass: z.string().trim().optional(),
|
||||||
|
searchBase: z.string().trim().optional(),
|
||||||
|
caCert: z.string().trim().optional()
|
||||||
|
}),
|
||||||
|
response: {
|
||||||
|
200: LdapConfigsSchema
|
||||||
|
}
|
||||||
|
},
|
||||||
|
handler: async (req) => {
|
||||||
|
const ldap = await server.services.ldap.updateLdapCfg({
|
||||||
|
actor: req.permission.type,
|
||||||
|
actorId: req.permission.id,
|
||||||
|
orgId: req.body.organizationId,
|
||||||
|
actorOrgId: req.permission.orgId,
|
||||||
|
...req.body
|
||||||
|
});
|
||||||
|
|
||||||
|
return ldap;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -92,7 +92,8 @@ export enum EventType {
|
|||||||
|
|
||||||
interface UserActorMetadata {
|
interface UserActorMetadata {
|
||||||
userId: string;
|
userId: string;
|
||||||
email: string;
|
email?: string;
|
||||||
|
username?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ServiceActorMetadata {
|
interface ServiceActorMetadata {
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { TDbClient } from "@app/db";
|
||||||
|
import { TableName } from "@app/db/schemas";
|
||||||
|
import { ormify } from "@app/lib/knex";
|
||||||
|
|
||||||
|
export type TLdapConfigDALFactory = ReturnType<typeof ldapConfigDALFactory>;
|
||||||
|
|
||||||
|
export const ldapConfigDALFactory = (db: TDbClient) => {
|
||||||
|
const ldapCfgOrm = ormify(db, TableName.LdapConfig);
|
||||||
|
|
||||||
|
return { ...ldapCfgOrm };
|
||||||
|
};
|
||||||
@@ -0,0 +1,427 @@
|
|||||||
|
import { ForbiddenError } from "@casl/ability";
|
||||||
|
import { FastifyRequest } from "fastify";
|
||||||
|
import jwt from "jsonwebtoken";
|
||||||
|
|
||||||
|
import { OrgMembershipRole, OrgMembershipStatus, SecretKeyEncoding, TLdapConfigsUpdate } from "@app/db/schemas";
|
||||||
|
import { getConfig } from "@app/lib/config/env";
|
||||||
|
import {
|
||||||
|
decryptSymmetric,
|
||||||
|
encryptSymmetric,
|
||||||
|
generateAsymmetricKeyPair,
|
||||||
|
generateSymmetricKey,
|
||||||
|
infisicalSymmetricDecrypt,
|
||||||
|
infisicalSymmetricEncypt
|
||||||
|
} from "@app/lib/crypto/encryption";
|
||||||
|
import { BadRequestError } from "@app/lib/errors";
|
||||||
|
import { TOrgPermission } from "@app/lib/types";
|
||||||
|
import { AuthMethod, AuthTokenType } from "@app/services/auth/auth-type";
|
||||||
|
import { TOrgBotDALFactory } from "@app/services/org/org-bot-dal";
|
||||||
|
import { TOrgDALFactory } from "@app/services/org/org-dal";
|
||||||
|
import { TUserDALFactory } from "@app/services/user/user-dal";
|
||||||
|
|
||||||
|
import { TLicenseServiceFactory } from "../license/license-service";
|
||||||
|
import { OrgPermissionActions, OrgPermissionSubjects } from "../permission/org-permission";
|
||||||
|
import { TPermissionServiceFactory } from "../permission/permission-service";
|
||||||
|
import { TLdapConfigDALFactory } from "./ldap-config-dal";
|
||||||
|
import { TCreateLdapCfgDTO, TLdapLoginDTO, TUpdateLdapCfgDTO } from "./ldap-config-types";
|
||||||
|
|
||||||
|
// TODO: check the Picks
|
||||||
|
type TLdapConfigServiceFactoryDep = {
|
||||||
|
ldapConfigDAL: TLdapConfigDALFactory;
|
||||||
|
orgDAL: Pick<
|
||||||
|
TOrgDALFactory,
|
||||||
|
"createMembership" | "updateMembershipById" | "findMembership" | "findOrgById" | "findOne" | "updateById"
|
||||||
|
>;
|
||||||
|
orgBotDAL: Pick<TOrgBotDALFactory, "findOne" | "create" | "transaction">;
|
||||||
|
userDAL: Pick<TUserDALFactory, "create" | "findOne" | "transaction" | "updateById">;
|
||||||
|
permissionService: Pick<TPermissionServiceFactory, "getOrgPermission">;
|
||||||
|
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type TLdapConfigServiceFactory = ReturnType<typeof ldapConfigServiceFactory>;
|
||||||
|
|
||||||
|
export const ldapConfigServiceFactory = ({
|
||||||
|
ldapConfigDAL,
|
||||||
|
orgDAL,
|
||||||
|
orgBotDAL,
|
||||||
|
userDAL,
|
||||||
|
permissionService,
|
||||||
|
licenseService
|
||||||
|
}: TLdapConfigServiceFactoryDep) => {
|
||||||
|
const createLdapCfg = async ({
|
||||||
|
actor,
|
||||||
|
actorId,
|
||||||
|
orgId,
|
||||||
|
actorOrgId,
|
||||||
|
isActive,
|
||||||
|
url,
|
||||||
|
bindDN,
|
||||||
|
bindPass,
|
||||||
|
searchBase,
|
||||||
|
caCert
|
||||||
|
}: TCreateLdapCfgDTO) => {
|
||||||
|
const { permission } = await permissionService.getOrgPermission(actor, actorId, orgId, actorOrgId);
|
||||||
|
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Create, OrgPermissionSubjects.Sso);
|
||||||
|
|
||||||
|
const plan = await licenseService.getPlan(orgId);
|
||||||
|
if (!plan.ldap)
|
||||||
|
throw new BadRequestError({
|
||||||
|
message:
|
||||||
|
"Failed to create LDAP configuration due to plan restriction. Upgrade plan to create LDAP configuration."
|
||||||
|
});
|
||||||
|
|
||||||
|
const orgBot = await orgBotDAL.transaction(async (tx) => {
|
||||||
|
const doc = await orgBotDAL.findOne({ orgId }, tx);
|
||||||
|
if (doc) return doc;
|
||||||
|
|
||||||
|
const { privateKey, publicKey } = generateAsymmetricKeyPair();
|
||||||
|
const key = generateSymmetricKey();
|
||||||
|
const {
|
||||||
|
ciphertext: encryptedPrivateKey,
|
||||||
|
iv: privateKeyIV,
|
||||||
|
tag: privateKeyTag,
|
||||||
|
encoding: privateKeyKeyEncoding,
|
||||||
|
algorithm: privateKeyAlgorithm
|
||||||
|
} = infisicalSymmetricEncypt(privateKey);
|
||||||
|
const {
|
||||||
|
ciphertext: encryptedSymmetricKey,
|
||||||
|
iv: symmetricKeyIV,
|
||||||
|
tag: symmetricKeyTag,
|
||||||
|
encoding: symmetricKeyKeyEncoding,
|
||||||
|
algorithm: symmetricKeyAlgorithm
|
||||||
|
} = infisicalSymmetricEncypt(key);
|
||||||
|
|
||||||
|
return orgBotDAL.create(
|
||||||
|
{
|
||||||
|
name: "Infisical org bot",
|
||||||
|
publicKey,
|
||||||
|
privateKeyIV,
|
||||||
|
encryptedPrivateKey,
|
||||||
|
symmetricKeyIV,
|
||||||
|
symmetricKeyTag,
|
||||||
|
encryptedSymmetricKey,
|
||||||
|
symmetricKeyAlgorithm,
|
||||||
|
orgId,
|
||||||
|
privateKeyTag,
|
||||||
|
privateKeyAlgorithm,
|
||||||
|
privateKeyKeyEncoding,
|
||||||
|
symmetricKeyKeyEncoding
|
||||||
|
},
|
||||||
|
tx
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
const key = infisicalSymmetricDecrypt({
|
||||||
|
ciphertext: orgBot.encryptedSymmetricKey,
|
||||||
|
iv: orgBot.symmetricKeyIV,
|
||||||
|
tag: orgBot.symmetricKeyTag,
|
||||||
|
keyEncoding: orgBot.symmetricKeyKeyEncoding as SecretKeyEncoding
|
||||||
|
});
|
||||||
|
|
||||||
|
const { ciphertext: encryptedBindDN, iv: bindDNIV, tag: bindDNTag } = encryptSymmetric(bindDN, key);
|
||||||
|
const { ciphertext: encryptedBindPass, iv: bindPassIV, tag: bindPassTag } = encryptSymmetric(bindPass, key);
|
||||||
|
const { ciphertext: encryptedCACert, iv: caCertIV, tag: caCertTag } = encryptSymmetric(caCert, key);
|
||||||
|
|
||||||
|
const ldapConfig = await ldapConfigDAL.create({
|
||||||
|
orgId,
|
||||||
|
isActive,
|
||||||
|
url,
|
||||||
|
encryptedBindDN,
|
||||||
|
bindDNIV,
|
||||||
|
bindDNTag,
|
||||||
|
encryptedBindPass,
|
||||||
|
bindPassIV,
|
||||||
|
bindPassTag,
|
||||||
|
searchBase,
|
||||||
|
encryptedCACert,
|
||||||
|
caCertIV,
|
||||||
|
caCertTag
|
||||||
|
});
|
||||||
|
|
||||||
|
return ldapConfig;
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateLdapCfg = async ({
|
||||||
|
actor,
|
||||||
|
actorId,
|
||||||
|
orgId,
|
||||||
|
actorOrgId,
|
||||||
|
isActive,
|
||||||
|
url,
|
||||||
|
bindDN,
|
||||||
|
bindPass,
|
||||||
|
searchBase,
|
||||||
|
caCert
|
||||||
|
}: TUpdateLdapCfgDTO) => {
|
||||||
|
const { permission } = await permissionService.getOrgPermission(actor, actorId, orgId, actorOrgId);
|
||||||
|
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Edit, OrgPermissionSubjects.Sso);
|
||||||
|
|
||||||
|
const plan = await licenseService.getPlan(orgId);
|
||||||
|
if (!plan.ldap)
|
||||||
|
throw new BadRequestError({
|
||||||
|
message:
|
||||||
|
"Failed to update LDAP configuration due to plan restriction. Upgrade plan to update LDAP configuration."
|
||||||
|
});
|
||||||
|
|
||||||
|
const updateQuery: TLdapConfigsUpdate = {
|
||||||
|
isActive,
|
||||||
|
url,
|
||||||
|
searchBase
|
||||||
|
};
|
||||||
|
|
||||||
|
const orgBot = await orgBotDAL.findOne({ orgId });
|
||||||
|
if (!orgBot) throw new BadRequestError({ message: "Org bot not found", name: "OrgBotNotFound" });
|
||||||
|
const key = infisicalSymmetricDecrypt({
|
||||||
|
ciphertext: orgBot.encryptedSymmetricKey,
|
||||||
|
iv: orgBot.symmetricKeyIV,
|
||||||
|
tag: orgBot.symmetricKeyTag,
|
||||||
|
keyEncoding: orgBot.symmetricKeyKeyEncoding as SecretKeyEncoding
|
||||||
|
});
|
||||||
|
|
||||||
|
if (bindDN) {
|
||||||
|
const { ciphertext: encryptedBindDN, iv: bindDNIV, tag: bindDNTag } = encryptSymmetric(bindDN, key);
|
||||||
|
updateQuery.encryptedBindDN = encryptedBindDN;
|
||||||
|
updateQuery.bindDNIV = bindDNIV;
|
||||||
|
updateQuery.bindDNTag = bindDNTag;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bindPass) {
|
||||||
|
const { ciphertext: encryptedBindPass, iv: bindPassIV, tag: bindPassTag } = encryptSymmetric(bindPass, key);
|
||||||
|
updateQuery.encryptedBindPass = encryptedBindPass;
|
||||||
|
updateQuery.bindPassIV = bindPassIV;
|
||||||
|
updateQuery.bindPassTag = bindPassTag;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (caCert) {
|
||||||
|
const { ciphertext: encryptedCACert, iv: caCertIV, tag: caCertTag } = encryptSymmetric(caCert, key);
|
||||||
|
updateQuery.encryptedCACert = encryptedCACert;
|
||||||
|
updateQuery.caCertIV = caCertIV;
|
||||||
|
updateQuery.caCertTag = caCertTag;
|
||||||
|
}
|
||||||
|
|
||||||
|
const [ldapConfig] = await ldapConfigDAL.update({ orgId }, updateQuery);
|
||||||
|
|
||||||
|
return ldapConfig;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getLdapCfg2 = async (orgId: string) => {
|
||||||
|
const ldapConfig = await ldapConfigDAL.findOne({ orgId });
|
||||||
|
if (!ldapConfig) throw new BadRequestError({ message: "Failed to find organization LDAP data" });
|
||||||
|
|
||||||
|
const orgBot = await orgBotDAL.findOne({ orgId: ldapConfig.orgId });
|
||||||
|
if (!orgBot) throw new BadRequestError({ message: "Org bot not found", name: "OrgBotNotFound" });
|
||||||
|
|
||||||
|
const key = infisicalSymmetricDecrypt({
|
||||||
|
ciphertext: orgBot.encryptedSymmetricKey,
|
||||||
|
iv: orgBot.symmetricKeyIV,
|
||||||
|
tag: orgBot.symmetricKeyTag,
|
||||||
|
keyEncoding: orgBot.symmetricKeyKeyEncoding as SecretKeyEncoding
|
||||||
|
});
|
||||||
|
|
||||||
|
const {
|
||||||
|
encryptedBindDN,
|
||||||
|
bindDNIV,
|
||||||
|
bindDNTag,
|
||||||
|
encryptedBindPass,
|
||||||
|
bindPassIV,
|
||||||
|
bindPassTag,
|
||||||
|
encryptedCACert,
|
||||||
|
caCertIV,
|
||||||
|
caCertTag
|
||||||
|
} = ldapConfig;
|
||||||
|
|
||||||
|
let bindDN = "";
|
||||||
|
if (encryptedBindDN && bindDNIV && bindDNTag) {
|
||||||
|
bindDN = decryptSymmetric({
|
||||||
|
ciphertext: encryptedBindDN,
|
||||||
|
key,
|
||||||
|
tag: bindDNTag,
|
||||||
|
iv: bindDNIV
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let bindPass = "";
|
||||||
|
if (encryptedBindPass && bindPassIV && bindPassTag) {
|
||||||
|
bindPass = decryptSymmetric({
|
||||||
|
ciphertext: encryptedBindPass,
|
||||||
|
key,
|
||||||
|
tag: bindPassTag,
|
||||||
|
iv: bindPassIV
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let caCert = "";
|
||||||
|
if (encryptedCACert && caCertIV && caCertTag) {
|
||||||
|
caCert = decryptSymmetric({
|
||||||
|
ciphertext: encryptedCACert,
|
||||||
|
key,
|
||||||
|
tag: caCertTag,
|
||||||
|
iv: caCertIV
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: ldapConfig.id,
|
||||||
|
organization: ldapConfig.orgId,
|
||||||
|
isActive: ldapConfig.isActive,
|
||||||
|
url: ldapConfig.url,
|
||||||
|
bindDN,
|
||||||
|
bindPass,
|
||||||
|
searchBase: ldapConfig.searchBase,
|
||||||
|
caCert
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const getLdapCfg = async ({ actor, actorId, orgId, actorOrgId }: TOrgPermission) => {
|
||||||
|
const { permission } = await permissionService.getOrgPermission(actor, actorId, orgId, actorOrgId);
|
||||||
|
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Read, OrgPermissionSubjects.Sso);
|
||||||
|
return getLdapCfg2(orgId);
|
||||||
|
};
|
||||||
|
|
||||||
|
// eslint-disable-next-line
|
||||||
|
const getLDAPConfiguration = (req: FastifyRequest, callback: any) => {
|
||||||
|
const { organizationSlug } = req.body as {
|
||||||
|
organizationSlug: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
// req.ldapConfig = getLdapCfg2(organization.id);
|
||||||
|
|
||||||
|
const boot = async () => {
|
||||||
|
const organization = await orgDAL.findOne({ slug: organizationSlug });
|
||||||
|
const ldapConfig = await getLdapCfg2(organization.id); // repeat?
|
||||||
|
req.ldapConfig = ldapConfig;
|
||||||
|
|
||||||
|
// example
|
||||||
|
// var opts = {
|
||||||
|
// server: {
|
||||||
|
// // url: 'ldaps://openldap:636', // connection over SSL/TLS
|
||||||
|
// url: 'ldap://openldap:389',
|
||||||
|
// bindDN: 'cn=admin,dc=acme,dc=com',
|
||||||
|
// bindCredentials: 'admin',
|
||||||
|
// searchBase: 'ou=people,dc=acme,dc=com',
|
||||||
|
// searchFilter: '(uid={{username}})',
|
||||||
|
// searchAttributes: ['uid', 'givenName', 'sn'], // optional, defaults to all (get username too)
|
||||||
|
// // tlsOptions: {
|
||||||
|
// // ca: [caCert]
|
||||||
|
// // }
|
||||||
|
// },
|
||||||
|
// passReqToCallback: true
|
||||||
|
// };
|
||||||
|
|
||||||
|
const opts = {
|
||||||
|
server: {
|
||||||
|
url: ldapConfig.url,
|
||||||
|
bindDN: ldapConfig.bindDN,
|
||||||
|
bindCredentials: ldapConfig.bindPass,
|
||||||
|
searchBase: ldapConfig.searchBase,
|
||||||
|
searchFilter: "(uid={{username}})",
|
||||||
|
searchAttributes: ["uid", "givenName", "sn"],
|
||||||
|
...(ldapConfig.caCert !== ""
|
||||||
|
? {
|
||||||
|
tlsOptions: {
|
||||||
|
ca: [ldapConfig.caCert]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
: {})
|
||||||
|
},
|
||||||
|
passReqToCallback: true
|
||||||
|
};
|
||||||
|
|
||||||
|
// eslint-disable-next-line
|
||||||
|
callback(null, opts);
|
||||||
|
};
|
||||||
|
|
||||||
|
process.nextTick(async () => {
|
||||||
|
await boot();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const ldapLogin = async ({ username, firstName, lastName, orgId, relayState }: TLdapLoginDTO) => {
|
||||||
|
const appCfg = getConfig();
|
||||||
|
let user = await userDAL.findOne({
|
||||||
|
username,
|
||||||
|
orgId
|
||||||
|
});
|
||||||
|
|
||||||
|
const organization = await orgDAL.findOrgById(orgId);
|
||||||
|
if (!organization) throw new BadRequestError({ message: "Org not found" });
|
||||||
|
|
||||||
|
if (user) {
|
||||||
|
await userDAL.transaction(async (tx) => {
|
||||||
|
const [orgMembership] = await orgDAL.findMembership({ userId: user.id, orgId }, { tx });
|
||||||
|
if (!orgMembership) {
|
||||||
|
await orgDAL.createMembership(
|
||||||
|
{
|
||||||
|
userId: user.id,
|
||||||
|
orgId,
|
||||||
|
role: OrgMembershipRole.Member,
|
||||||
|
status: OrgMembershipStatus.Accepted
|
||||||
|
},
|
||||||
|
tx
|
||||||
|
);
|
||||||
|
} else if (orgMembership.status === OrgMembershipStatus.Invited) {
|
||||||
|
await orgDAL.updateMembershipById(
|
||||||
|
orgMembership.id,
|
||||||
|
{
|
||||||
|
status: OrgMembershipStatus.Accepted
|
||||||
|
},
|
||||||
|
tx
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
user = await userDAL.transaction(async (tx) => {
|
||||||
|
const newUser = await userDAL.create(
|
||||||
|
{
|
||||||
|
username,
|
||||||
|
firstName,
|
||||||
|
lastName,
|
||||||
|
authMethods: [AuthMethod.EMAIL],
|
||||||
|
isGhost: false
|
||||||
|
},
|
||||||
|
tx
|
||||||
|
);
|
||||||
|
await orgDAL.createMembership({
|
||||||
|
orgId,
|
||||||
|
role: OrgMembershipRole.Member,
|
||||||
|
status: OrgMembershipStatus.Invited // should this be invited?
|
||||||
|
});
|
||||||
|
return newUser;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const isUserCompleted = Boolean(user.isAccepted);
|
||||||
|
|
||||||
|
const providerAuthToken = jwt.sign(
|
||||||
|
{
|
||||||
|
authTokenType: AuthTokenType.PROVIDER_TOKEN,
|
||||||
|
userId: user.id,
|
||||||
|
firstName,
|
||||||
|
lastName,
|
||||||
|
organizationName: organization.name,
|
||||||
|
organizationId: organization.id,
|
||||||
|
authMethod: AuthMethod.LDAP,
|
||||||
|
isUserCompleted,
|
||||||
|
...(relayState
|
||||||
|
? {
|
||||||
|
callbackPort: (JSON.parse(relayState) as { callbackPort: string }).callbackPort
|
||||||
|
}
|
||||||
|
: {})
|
||||||
|
},
|
||||||
|
appCfg.AUTH_SECRET,
|
||||||
|
{
|
||||||
|
expiresIn: appCfg.JWT_PROVIDER_AUTH_LIFETIME
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return { isUserCompleted, providerAuthToken };
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
createLdapCfg,
|
||||||
|
updateLdapCfg,
|
||||||
|
getLdapCfg,
|
||||||
|
getLDAPConfiguration,
|
||||||
|
ldapLogin
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { TOrgPermission } from "@app/lib/types";
|
||||||
|
|
||||||
|
export type TCreateLdapCfgDTO = {
|
||||||
|
isActive: boolean;
|
||||||
|
url: string;
|
||||||
|
bindDN: string;
|
||||||
|
bindPass: string;
|
||||||
|
searchBase: string;
|
||||||
|
caCert: string;
|
||||||
|
} & TOrgPermission;
|
||||||
|
|
||||||
|
export type TUpdateLdapCfgDTO = Partial<{
|
||||||
|
isActive: boolean;
|
||||||
|
url: string;
|
||||||
|
bindDN: string;
|
||||||
|
bindPass: string;
|
||||||
|
searchBase: string;
|
||||||
|
caCert: string;
|
||||||
|
}> &
|
||||||
|
TOrgPermission;
|
||||||
|
|
||||||
|
export type TLdapLoginDTO = {
|
||||||
|
username: string;
|
||||||
|
firstName: string;
|
||||||
|
lastName: string;
|
||||||
|
orgId: string;
|
||||||
|
relayState?: string;
|
||||||
|
};
|
||||||
@@ -25,6 +25,7 @@ export const getDefaultOnPremFeatures = (): TFeatureSet => ({
|
|||||||
auditLogsRetentionDays: 0,
|
auditLogsRetentionDays: 0,
|
||||||
samlSSO: false,
|
samlSSO: false,
|
||||||
scim: false,
|
scim: false,
|
||||||
|
ldap: true,
|
||||||
status: null,
|
status: null,
|
||||||
trial_end: null,
|
trial_end: null,
|
||||||
has_used_trial: true,
|
has_used_trial: true,
|
||||||
|
|||||||
@@ -135,14 +135,14 @@ export const licenseServiceFactory = ({ orgDAL, permissionService, licenseDAL }:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const generateOrgCustomerId = async (orgName: string, email: string) => {
|
const generateOrgCustomerId = async (orgName: string, email?: string | null) => {
|
||||||
if (instanceType === InstanceType.Cloud) {
|
if (instanceType === InstanceType.Cloud) {
|
||||||
const {
|
const {
|
||||||
data: { customerId }
|
data: { customerId }
|
||||||
} = await licenseServerCloudApi.request.post<{ customerId: string }>(
|
} = await licenseServerCloudApi.request.post<{ customerId: string }>(
|
||||||
"/api/license-server/v1/customers",
|
"/api/license-server/v1/customers",
|
||||||
{
|
{
|
||||||
email,
|
email: email ?? "",
|
||||||
name: orgName
|
name: orgName
|
||||||
},
|
},
|
||||||
{ timeout: 5000, signal: AbortSignal.timeout(5000) }
|
{ timeout: 5000, signal: AbortSignal.timeout(5000) }
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ export type TFeatureSet = {
|
|||||||
auditLogsRetentionDays: 0;
|
auditLogsRetentionDays: 0;
|
||||||
samlSSO: false;
|
samlSSO: false;
|
||||||
scim: false;
|
scim: false;
|
||||||
|
ldap: true;
|
||||||
status: null;
|
status: null;
|
||||||
trial_end: null;
|
trial_end: null;
|
||||||
has_used_trial: true;
|
has_used_trial: true;
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ export const samlConfigServiceFactory = ({
|
|||||||
if (!plan.samlSSO)
|
if (!plan.samlSSO)
|
||||||
throw new BadRequestError({
|
throw new BadRequestError({
|
||||||
message:
|
message:
|
||||||
"Failed to update SAML SSO configuration due to plan restriction. Upgrade plan to update SSO configuration."
|
"Failed to create SAML SSO configuration due to plan restriction. Upgrade plan to create SSO configuration."
|
||||||
});
|
});
|
||||||
|
|
||||||
const orgBot = await orgBotDAL.transaction(async (tx) => {
|
const orgBot = await orgBotDAL.transaction(async (tx) => {
|
||||||
@@ -122,7 +122,6 @@ export const samlConfigServiceFactory = ({
|
|||||||
|
|
||||||
const { ciphertext: encryptedEntryPoint, iv: entryPointIV, tag: entryPointTag } = encryptSymmetric(entryPoint, key);
|
const { ciphertext: encryptedEntryPoint, iv: entryPointIV, tag: entryPointTag } = encryptSymmetric(entryPoint, key);
|
||||||
const { ciphertext: encryptedIssuer, iv: issuerIV, tag: issuerTag } = encryptSymmetric(issuer, key);
|
const { ciphertext: encryptedIssuer, iv: issuerIV, tag: issuerTag } = encryptSymmetric(issuer, key);
|
||||||
|
|
||||||
const { ciphertext: encryptedCert, iv: certIV, tag: certTag } = encryptSymmetric(cert, key);
|
const { ciphertext: encryptedCert, iv: certIV, tag: certTag } = encryptSymmetric(cert, key);
|
||||||
const samlConfig = await samlConfigDAL.create({
|
const samlConfig = await samlConfigDAL.create({
|
||||||
orgId,
|
orgId,
|
||||||
|
|||||||
@@ -20,21 +20,23 @@ export const buildScimUserList = ({
|
|||||||
|
|
||||||
export const buildScimUser = ({
|
export const buildScimUser = ({
|
||||||
userId,
|
userId,
|
||||||
|
username,
|
||||||
|
email,
|
||||||
firstName,
|
firstName,
|
||||||
lastName,
|
lastName,
|
||||||
email,
|
|
||||||
active
|
active
|
||||||
}: {
|
}: {
|
||||||
userId: string;
|
userId: string;
|
||||||
|
username: string;
|
||||||
|
email: string;
|
||||||
firstName: string;
|
firstName: string;
|
||||||
lastName: string;
|
lastName: string;
|
||||||
email: string;
|
|
||||||
active: boolean;
|
active: boolean;
|
||||||
}): TScimUser => {
|
}): TScimUser => {
|
||||||
return {
|
return {
|
||||||
schemas: ["urn:ietf:params:scim:schemas:core:2.0:User"],
|
schemas: ["urn:ietf:params:scim:schemas:core:2.0:User"],
|
||||||
id: userId,
|
id: userId,
|
||||||
userName: email,
|
userName: username,
|
||||||
displayName: `${firstName} ${lastName}`,
|
displayName: `${firstName} ${lastName}`,
|
||||||
name: {
|
name: {
|
||||||
givenName: firstName,
|
givenName: firstName,
|
||||||
|
|||||||
@@ -152,12 +152,13 @@ export const scimServiceFactory = ({
|
|||||||
findOpts
|
findOpts
|
||||||
);
|
);
|
||||||
|
|
||||||
const scimUsers = users.map(({ userId, firstName, lastName, email }) =>
|
const scimUsers = users.map(({ userId, username, firstName, lastName, email }) =>
|
||||||
buildScimUser({
|
buildScimUser({
|
||||||
userId: userId ?? "",
|
userId: userId ?? "",
|
||||||
|
username: username ?? "",
|
||||||
firstName: firstName ?? "",
|
firstName: firstName ?? "",
|
||||||
lastName: lastName ?? "",
|
lastName: lastName ?? "",
|
||||||
email,
|
email: email ?? "",
|
||||||
active: true
|
active: true
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -196,9 +197,10 @@ export const scimServiceFactory = ({
|
|||||||
|
|
||||||
return buildScimUser({
|
return buildScimUser({
|
||||||
userId: membership.userId as string,
|
userId: membership.userId as string,
|
||||||
|
username: membership.username as string,
|
||||||
|
email: membership.email ?? "",
|
||||||
firstName: membership.firstName as string,
|
firstName: membership.firstName as string,
|
||||||
lastName: membership.lastName as string,
|
lastName: membership.lastName as string,
|
||||||
email: membership.email,
|
|
||||||
active: true
|
active: true
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -284,9 +286,10 @@ export const scimServiceFactory = ({
|
|||||||
|
|
||||||
return buildScimUser({
|
return buildScimUser({
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
|
username: user.username as string,
|
||||||
firstName: user.firstName as string,
|
firstName: user.firstName as string,
|
||||||
lastName: user.lastName as string,
|
lastName: user.lastName as string,
|
||||||
email: user.email,
|
email: user.email ?? "",
|
||||||
active: true
|
active: true
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -342,9 +345,10 @@ export const scimServiceFactory = ({
|
|||||||
|
|
||||||
return buildScimUser({
|
return buildScimUser({
|
||||||
userId: membership.userId as string,
|
userId: membership.userId as string,
|
||||||
|
username: membership.username as string,
|
||||||
|
email: membership.email ?? "",
|
||||||
firstName: membership.firstName as string,
|
firstName: membership.firstName as string,
|
||||||
lastName: membership.lastName as string,
|
lastName: membership.lastName as string,
|
||||||
email: membership.email,
|
|
||||||
active
|
active
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -387,9 +391,10 @@ export const scimServiceFactory = ({
|
|||||||
|
|
||||||
return buildScimUser({
|
return buildScimUser({
|
||||||
userId: membership.userId as string,
|
userId: membership.userId as string,
|
||||||
|
username: membership.username as string,
|
||||||
|
email: membership.email ?? "",
|
||||||
firstName: membership.firstName as string,
|
firstName: membership.firstName as string,
|
||||||
lastName: membership.lastName as string,
|
lastName: membership.lastName as string,
|
||||||
email: membership.email,
|
|
||||||
active
|
active
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
+2
-2
@@ -149,7 +149,7 @@ export const secretScanningQueueFactory = ({
|
|||||||
await smtpService.sendMail({
|
await smtpService.sendMail({
|
||||||
template: SmtpTemplates.SecretLeakIncident,
|
template: SmtpTemplates.SecretLeakIncident,
|
||||||
subjectLine: `Incident alert: leaked secrets found in Github repository ${repository.fullName}`,
|
subjectLine: `Incident alert: leaked secrets found in Github repository ${repository.fullName}`,
|
||||||
recipients: adminEmails,
|
recipients: adminEmails.filter((email) => email).map((email) => email as string),
|
||||||
substitutions: {
|
substitutions: {
|
||||||
numberOfSecrets: Object.keys(allFindingsByFingerprint).length,
|
numberOfSecrets: Object.keys(allFindingsByFingerprint).length,
|
||||||
pusher_email: pusher.email,
|
pusher_email: pusher.email,
|
||||||
@@ -221,7 +221,7 @@ export const secretScanningQueueFactory = ({
|
|||||||
await smtpService.sendMail({
|
await smtpService.sendMail({
|
||||||
template: SmtpTemplates.SecretLeakIncident,
|
template: SmtpTemplates.SecretLeakIncident,
|
||||||
subjectLine: `Incident alert: leaked secrets found in Github repository ${repository.fullName}`,
|
subjectLine: `Incident alert: leaked secrets found in Github repository ${repository.fullName}`,
|
||||||
recipients: adminEmails,
|
recipients: adminEmails.filter((email) => email).map((email) => email as string),
|
||||||
substitutions: {
|
substitutions: {
|
||||||
numberOfSecrets: findings.length
|
numberOfSecrets: findings.length
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ export const injectAuditLogInfo = fp(async (server: FastifyZodProvider) => {
|
|||||||
payload.actor = {
|
payload.actor = {
|
||||||
type: ActorType.USER,
|
type: ActorType.USER,
|
||||||
metadata: {
|
metadata: {
|
||||||
email: req.auth.user.email,
|
email: req.auth.user.email as string | undefined,
|
||||||
|
username: req.auth.user.username as string | undefined,
|
||||||
userId: req.permission.id
|
userId: req.permission.id
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import { registerV1EERoutes } from "@app/ee/routes/v1";
|
|||||||
import { auditLogDALFactory } from "@app/ee/services/audit-log/audit-log-dal";
|
import { auditLogDALFactory } from "@app/ee/services/audit-log/audit-log-dal";
|
||||||
import { auditLogQueueServiceFactory } from "@app/ee/services/audit-log/audit-log-queue";
|
import { auditLogQueueServiceFactory } from "@app/ee/services/audit-log/audit-log-queue";
|
||||||
import { auditLogServiceFactory } from "@app/ee/services/audit-log/audit-log-service";
|
import { auditLogServiceFactory } from "@app/ee/services/audit-log/audit-log-service";
|
||||||
|
import { ldapConfigDALFactory } from "@app/ee/services/ldap-config/ldap-config-dal";
|
||||||
|
import { ldapConfigServiceFactory } from "@app/ee/services/ldap-config/ldap-config-service";
|
||||||
import { licenseDALFactory } from "@app/ee/services/license/license-dal";
|
import { licenseDALFactory } from "@app/ee/services/license/license-dal";
|
||||||
import { licenseServiceFactory } from "@app/ee/services/license/license-service";
|
import { licenseServiceFactory } from "@app/ee/services/license/license-service";
|
||||||
import { permissionDALFactory } from "@app/ee/services/permission/permission-dal";
|
import { permissionDALFactory } from "@app/ee/services/permission/permission-dal";
|
||||||
@@ -158,11 +160,12 @@ export const registerRoutes = async (
|
|||||||
|
|
||||||
const auditLogDAL = auditLogDALFactory(db);
|
const auditLogDAL = auditLogDALFactory(db);
|
||||||
const trustedIpDAL = trustedIpDALFactory(db);
|
const trustedIpDAL = trustedIpDALFactory(db);
|
||||||
const scimDAL = scimDALFactory(db);
|
|
||||||
|
|
||||||
// ee db layer ops
|
// ee db layer ops
|
||||||
const permissionDAL = permissionDALFactory(db);
|
const permissionDAL = permissionDALFactory(db);
|
||||||
const samlConfigDAL = samlConfigDALFactory(db);
|
const samlConfigDAL = samlConfigDALFactory(db);
|
||||||
|
const scimDAL = scimDALFactory(db);
|
||||||
|
const ldapConfigDAL = ldapConfigDALFactory(db);
|
||||||
const sapApproverDAL = secretApprovalPolicyApproverDALFactory(db);
|
const sapApproverDAL = secretApprovalPolicyApproverDALFactory(db);
|
||||||
const secretApprovalPolicyDAL = secretApprovalPolicyDALFactory(db);
|
const secretApprovalPolicyDAL = secretApprovalPolicyDALFactory(db);
|
||||||
const secretApprovalRequestDAL = secretApprovalRequestDALFactory(db);
|
const secretApprovalRequestDAL = secretApprovalRequestDALFactory(db);
|
||||||
@@ -226,6 +229,15 @@ export const registerRoutes = async (
|
|||||||
smtpService
|
smtpService
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const ldapService = ldapConfigServiceFactory({
|
||||||
|
ldapConfigDAL,
|
||||||
|
orgDAL,
|
||||||
|
orgBotDAL,
|
||||||
|
userDAL,
|
||||||
|
permissionService,
|
||||||
|
licenseService
|
||||||
|
});
|
||||||
|
|
||||||
const telemetryService = telemetryServiceFactory();
|
const telemetryService = telemetryServiceFactory();
|
||||||
const tokenService = tokenServiceFactory({ tokenDAL: authTokenDAL, userDAL });
|
const tokenService = tokenServiceFactory({ tokenDAL: authTokenDAL, userDAL });
|
||||||
const userService = userServiceFactory({ userDAL });
|
const userService = userServiceFactory({ userDAL });
|
||||||
@@ -529,6 +541,7 @@ export const registerRoutes = async (
|
|||||||
secretRotation: secretRotationService,
|
secretRotation: secretRotationService,
|
||||||
snapshot: snapshotService,
|
snapshot: snapshotService,
|
||||||
saml: samlService,
|
saml: samlService,
|
||||||
|
ldap: ldapService,
|
||||||
auditLog: auditLogService,
|
auditLog: auditLogService,
|
||||||
secretScanning: secretScanningService,
|
secretScanning: secretScanningService,
|
||||||
license: licenseService,
|
license: licenseService,
|
||||||
|
|||||||
@@ -91,9 +91,9 @@ export const registerAdminRouter = async (server: FastifyZodProvider) => {
|
|||||||
|
|
||||||
server.services.telemetry.sendPostHogEvents({
|
server.services.telemetry.sendPostHogEvents({
|
||||||
event: PostHogEventTypes.AdminInit,
|
event: PostHogEventTypes.AdminInit,
|
||||||
distinctId: user.user.email,
|
distinctId: user.user.email ?? user.user.username ?? "",
|
||||||
properties: {
|
properties: {
|
||||||
email: user.user.email,
|
email: user.user.email ?? "",
|
||||||
lastName: user.user.lastName || "",
|
lastName: user.user.lastName || "",
|
||||||
firstName: user.user.firstName || ""
|
firstName: user.user.firstName || ""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,11 +179,12 @@ export const registerOrgRouter = async (server: FastifyZodProvider) => {
|
|||||||
handler: async (req) => {
|
handler: async (req) => {
|
||||||
if (req.auth.actor !== ActorType.USER) return;
|
if (req.auth.actor !== ActorType.USER) return;
|
||||||
|
|
||||||
const organization = await server.services.org.createOrganization(
|
const organization = await server.services.org.createOrganization({
|
||||||
req.permission.id,
|
userId: req.permission.id,
|
||||||
req.auth.user.email,
|
userEmail: req.auth.user.email,
|
||||||
req.body.name
|
orgName: req.body.name
|
||||||
);
|
});
|
||||||
|
|
||||||
return { organization };
|
return { organization };
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import { secretRawSchema } from "../sanitizedSchemas";
|
|||||||
|
|
||||||
const getDistinctId = (req: FastifyRequest) => {
|
const getDistinctId = (req: FastifyRequest) => {
|
||||||
if (req.auth.actor === ActorType.USER) {
|
if (req.auth.actor === ActorType.USER) {
|
||||||
return req.auth.user.email;
|
return req.auth.user.email ?? req.auth.user.username ?? "unknown-user";
|
||||||
}
|
}
|
||||||
if (req.auth.actor === ActorType.IDENTITY) {
|
if (req.auth.actor === ActorType.IDENTITY) {
|
||||||
return `identity-${req.auth.identityId}`;
|
return `identity-${req.auth.identityId}`;
|
||||||
|
|||||||
@@ -97,13 +97,15 @@ export const registerSignupRouter = async (server: FastifyZodProvider) => {
|
|||||||
authorization: req.headers.authorization as string
|
authorization: req.headers.authorization as string
|
||||||
});
|
});
|
||||||
|
|
||||||
void server.services.telemetry.sendLoopsEvent(user.email, user.firstName || "", user.lastName || "");
|
if (user.email) {
|
||||||
|
void server.services.telemetry.sendLoopsEvent(user.email, user.firstName || "", user.lastName || "");
|
||||||
|
}
|
||||||
|
|
||||||
void server.services.telemetry.sendPostHogEvents({
|
void server.services.telemetry.sendPostHogEvents({
|
||||||
event: PostHogEventTypes.UserSignedUp,
|
event: PostHogEventTypes.UserSignedUp,
|
||||||
distinctId: user.email,
|
distinctId: user.email ?? user.username ?? "",
|
||||||
properties: {
|
properties: {
|
||||||
email: user.email,
|
email: user.email ?? "",
|
||||||
attributionSource: req.body.attributionSource
|
attributionSource: req.body.attributionSource
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -160,13 +162,15 @@ export const registerSignupRouter = async (server: FastifyZodProvider) => {
|
|||||||
authorization: req.headers.authorization as string
|
authorization: req.headers.authorization as string
|
||||||
});
|
});
|
||||||
|
|
||||||
void server.services.telemetry.sendLoopsEvent(user.email, user.firstName || "", user.lastName || "");
|
if (user.email) {
|
||||||
|
void server.services.telemetry.sendLoopsEvent(user.email, user.firstName || "", user.lastName || "");
|
||||||
|
}
|
||||||
|
|
||||||
void server.services.telemetry.sendPostHogEvents({
|
void server.services.telemetry.sendPostHogEvents({
|
||||||
event: PostHogEventTypes.UserSignedUp,
|
event: PostHogEventTypes.UserSignedUp,
|
||||||
distinctId: user.email,
|
distinctId: user.email ?? user.username ?? "",
|
||||||
properties: {
|
properties: {
|
||||||
email: user.email,
|
email: user.email ?? "",
|
||||||
attributionSource: "Team Invite"
|
attributionSource: "Team Invite"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { BadRequestError, UnauthorizedError } from "@app/lib/errors";
|
|||||||
|
|
||||||
import { AuthModeProviderJwtTokenPayload, AuthModeProviderSignUpTokenPayload, AuthTokenType } from "./auth-type";
|
import { AuthModeProviderJwtTokenPayload, AuthModeProviderSignUpTokenPayload, AuthTokenType } from "./auth-type";
|
||||||
|
|
||||||
export const validateProviderAuthToken = (providerToken: string, email: string) => {
|
export const validateProviderAuthToken = (providerToken: string, email?: string) => {
|
||||||
if (!providerToken) throw new UnauthorizedError();
|
if (!providerToken) throw new UnauthorizedError();
|
||||||
const appCfg = getConfig();
|
const appCfg = getConfig();
|
||||||
const decodedToken = jwt.verify(providerToken, appCfg.AUTH_SECRET) as AuthModeProviderJwtTokenPayload;
|
const decodedToken = jwt.verify(providerToken, appCfg.AUTH_SECRET) as AuthModeProviderJwtTokenPayload;
|
||||||
|
|||||||
@@ -38,17 +38,19 @@ export const authLoginServiceFactory = ({ userDAL, tokenService, smtpService }:
|
|||||||
if (!isDeviceSeen) {
|
if (!isDeviceSeen) {
|
||||||
const newDeviceList = devices.concat([{ ip, userAgent }]);
|
const newDeviceList = devices.concat([{ ip, userAgent }]);
|
||||||
await userDAL.updateById(user.id, { devices: JSON.stringify(newDeviceList) });
|
await userDAL.updateById(user.id, { devices: JSON.stringify(newDeviceList) });
|
||||||
await smtpService.sendMail({
|
if (user.email) {
|
||||||
template: SmtpTemplates.NewDeviceJoin,
|
await smtpService.sendMail({
|
||||||
subjectLine: "Successful login from new device",
|
template: SmtpTemplates.NewDeviceJoin,
|
||||||
recipients: [user.email],
|
subjectLine: "Successful login from new device",
|
||||||
substitutions: {
|
recipients: [user.email],
|
||||||
email: user.email,
|
substitutions: {
|
||||||
timestamp: new Date().toString(),
|
email: user.email,
|
||||||
ip,
|
timestamp: new Date().toString(),
|
||||||
userAgent
|
ip,
|
||||||
}
|
userAgent
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -199,10 +201,12 @@ export const authLoginServiceFactory = ({ userDAL, tokenService, smtpService }:
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
await sendUserMfaCode({
|
if (userEnc.email) {
|
||||||
userId: userEnc.userId,
|
await sendUserMfaCode({
|
||||||
email: userEnc.email
|
userId: userEnc.userId,
|
||||||
});
|
email: userEnc.email
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return { isMfaEnabled: true, token: mfaToken } as const;
|
return { isMfaEnabled: true, token: mfaToken } as const;
|
||||||
}
|
}
|
||||||
@@ -226,7 +230,7 @@ export const authLoginServiceFactory = ({ userDAL, tokenService, smtpService }:
|
|||||||
*/
|
*/
|
||||||
const resendMfaToken = async (userId: string) => {
|
const resendMfaToken = async (userId: string) => {
|
||||||
const user = await userDAL.findById(userId);
|
const user = await userDAL.findById(userId);
|
||||||
if (!user) return;
|
if (!user || !user.email) return;
|
||||||
await sendUserMfaCode({
|
await sendUserMfaCode({
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
email: user.email
|
email: user.email
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ export const authSignupServiceFactory = ({
|
|||||||
|
|
||||||
let organizationId;
|
let organizationId;
|
||||||
if (providerAuthToken) {
|
if (providerAuthToken) {
|
||||||
const { orgId } = validateProviderAuthToken(providerAuthToken, user.email);
|
const { orgId } = validateProviderAuthToken(providerAuthToken, user.email as string);
|
||||||
organizationId = orgId;
|
organizationId = orgId;
|
||||||
} else {
|
} else {
|
||||||
validateSignUpAuthorization(authorization, user.id);
|
validateSignUpAuthorization(authorization, user.id);
|
||||||
@@ -150,7 +150,11 @@ export const authSignupServiceFactory = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!organizationId) {
|
if (!organizationId) {
|
||||||
await orgService.createOrganization(user.id, user.email, organizationName);
|
await orgService.createOrganization({
|
||||||
|
userId: user.id,
|
||||||
|
userEmail: user.email,
|
||||||
|
orgName: organizationName
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedMembersips = await orgDAL.updateMembership(
|
const updatedMembersips = await orgDAL.updateMembership(
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ export enum AuthMethod {
|
|||||||
GITLAB = "gitlab",
|
GITLAB = "gitlab",
|
||||||
OKTA_SAML = "okta-saml",
|
OKTA_SAML = "okta-saml",
|
||||||
AZURE_SAML = "azure-saml",
|
AZURE_SAML = "azure-saml",
|
||||||
JUMPCLOUD_SAML = "jumpcloud-saml"
|
JUMPCLOUD_SAML = "jumpcloud-saml",
|
||||||
|
LDAP = "ldap"
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum AuthTokenType {
|
export enum AuthTokenType {
|
||||||
|
|||||||
@@ -243,6 +243,7 @@ export const orgDALFactory = (db: TDbClient) => {
|
|||||||
.select(
|
.select(
|
||||||
selectAllTableCols(TableName.OrgMembership),
|
selectAllTableCols(TableName.OrgMembership),
|
||||||
db.ref("email").withSchema(TableName.Users),
|
db.ref("email").withSchema(TableName.Users),
|
||||||
|
db.ref("username").withSchema(TableName.Users),
|
||||||
db.ref("firstName").withSchema(TableName.Users),
|
db.ref("firstName").withSchema(TableName.Users),
|
||||||
db.ref("lastName").withSchema(TableName.Users),
|
db.ref("lastName").withSchema(TableName.Users),
|
||||||
db.ref("scimEnabled").withSchema(TableName.Organization)
|
db.ref("scimEnabled").withSchema(TableName.Organization)
|
||||||
|
|||||||
@@ -233,7 +233,15 @@ export const orgServiceFactory = ({
|
|||||||
/*
|
/*
|
||||||
* Create organization
|
* Create organization
|
||||||
* */
|
* */
|
||||||
const createOrganization = async (userId: string, userEmail: string, orgName: string) => {
|
const createOrganization = async ({
|
||||||
|
userId,
|
||||||
|
userEmail,
|
||||||
|
orgName
|
||||||
|
}: {
|
||||||
|
userId: string;
|
||||||
|
orgName: string;
|
||||||
|
userEmail?: string | null;
|
||||||
|
}) => {
|
||||||
const { privateKey, publicKey } = generateAsymmetricKeyPair();
|
const { privateKey, publicKey } = generateAsymmetricKeyPair();
|
||||||
const key = generateSymmetricKey();
|
const key = generateSymmetricKey();
|
||||||
const {
|
const {
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ export const projectMembershipServiceFactory = ({
|
|||||||
await smtpService.sendMail({
|
await smtpService.sendMail({
|
||||||
template: SmtpTemplates.WorkspaceInvite,
|
template: SmtpTemplates.WorkspaceInvite,
|
||||||
subjectLine: "Infisical workspace invitation",
|
subjectLine: "Infisical workspace invitation",
|
||||||
recipients: invitees.map((i) => i.email),
|
recipients: invitees.filter((i) => i.email).map((i) => i.email as string),
|
||||||
substitutions: {
|
substitutions: {
|
||||||
workspaceName: project.name,
|
workspaceName: project.name,
|
||||||
callback_url: `${appCfg.SITE_URL}/login`
|
callback_url: `${appCfg.SITE_URL}/login`
|
||||||
@@ -207,7 +207,9 @@ export const projectMembershipServiceFactory = ({
|
|||||||
await smtpService.sendMail({
|
await smtpService.sendMail({
|
||||||
template: SmtpTemplates.WorkspaceInvite,
|
template: SmtpTemplates.WorkspaceInvite,
|
||||||
subjectLine: "Infisical workspace invitation",
|
subjectLine: "Infisical workspace invitation",
|
||||||
recipients: orgMembers.map(({ email }) => email).filter(Boolean),
|
recipients: orgMembers
|
||||||
|
.map(({ email }) => email)
|
||||||
|
.filter((email): email is string => email !== null && email !== undefined),
|
||||||
substitutions: {
|
substitutions: {
|
||||||
workspaceName: project.name,
|
workspaceName: project.name,
|
||||||
callback_url: `${appCfg.SITE_URL}/login`
|
callback_url: `${appCfg.SITE_URL}/login`
|
||||||
@@ -317,7 +319,7 @@ export const projectMembershipServiceFactory = ({
|
|||||||
await smtpService.sendMail({
|
await smtpService.sendMail({
|
||||||
template: SmtpTemplates.WorkspaceInvite,
|
template: SmtpTemplates.WorkspaceInvite,
|
||||||
subjectLine: "Infisical workspace invitation",
|
subjectLine: "Infisical workspace invitation",
|
||||||
recipients: orgMembers.map(({ user }) => user.email).filter(Boolean),
|
recipients: orgMembers.filter(({ user }) => user.email).map(({ user }) => user.email as string),
|
||||||
substitutions: {
|
substitutions: {
|
||||||
workspaceName: project.name,
|
workspaceName: project.name,
|
||||||
callback_url: `${appCfg.SITE_URL}/login`
|
callback_url: `${appCfg.SITE_URL}/login`
|
||||||
|
|||||||
@@ -350,7 +350,7 @@ export const secretQueueFactory = ({
|
|||||||
await smtpService.sendMail({
|
await smtpService.sendMail({
|
||||||
template: SmtpTemplates.SecretReminder,
|
template: SmtpTemplates.SecretReminder,
|
||||||
subjectLine: "Infisical secret reminder",
|
subjectLine: "Infisical secret reminder",
|
||||||
recipients: [...projectMembers.map((m) => m.user.email)],
|
recipients: [...projectMembers.map((m) => m.user.email)].filter((email) => email).map((email) => email as string),
|
||||||
substitutions: {
|
substitutions: {
|
||||||
reminderNote: data.note, // May not be present.
|
reminderNote: data.note, // May not be present.
|
||||||
projectName: project.name,
|
projectName: project.name,
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ export const superAdminServiceFactory = ({
|
|||||||
{
|
{
|
||||||
firstName,
|
firstName,
|
||||||
lastName,
|
lastName,
|
||||||
|
username: email,
|
||||||
email,
|
email,
|
||||||
superAdmin: true,
|
superAdmin: true,
|
||||||
isGhost: false,
|
isGhost: false,
|
||||||
@@ -97,11 +98,11 @@ export const superAdminServiceFactory = ({
|
|||||||
|
|
||||||
const initialOrganizationName = appCfg.INITIAL_ORGANIZATION_NAME ?? "Admin Org";
|
const initialOrganizationName = appCfg.INITIAL_ORGANIZATION_NAME ?? "Admin Org";
|
||||||
|
|
||||||
const organization = await orgService.createOrganization(
|
const organization = await orgService.createOrganization({
|
||||||
userInfo.user.id,
|
userId: userInfo.user.id,
|
||||||
userInfo.user.email,
|
userEmail: userInfo.user.email,
|
||||||
initialOrganizationName
|
orgName: initialOrganizationName
|
||||||
);
|
});
|
||||||
|
|
||||||
await updateServerCfg({ initialized: true });
|
await updateServerCfg({ initialized: true });
|
||||||
const token = await authService.generateUserTokens({
|
const token = await authService.generateUserTokens({
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ export type TUserServiceFactory = ReturnType<typeof userServiceFactory>;
|
|||||||
|
|
||||||
export const userServiceFactory = ({ userDAL }: TUserServiceFactoryDep) => {
|
export const userServiceFactory = ({ userDAL }: TUserServiceFactoryDep) => {
|
||||||
const toggleUserMfa = async (userId: string, isMfaEnabled: boolean) => {
|
const toggleUserMfa = async (userId: string, isMfaEnabled: boolean) => {
|
||||||
|
const user = await userDAL.findById(userId);
|
||||||
|
|
||||||
|
if (!user || !user.email) throw new BadRequestError({ name: "Failed to toggle MFA" });
|
||||||
|
|
||||||
const updatedUser = await userDAL.updateById(userId, {
|
const updatedUser = await userDAL.updateById(userId, {
|
||||||
isMfaEnabled,
|
isMfaEnabled,
|
||||||
mfaMethods: isMfaEnabled ? ["email"] : []
|
mfaMethods: isMfaEnabled ? ["email"] : []
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import {
|
|||||||
Login1Res,
|
Login1Res,
|
||||||
Login2DTO,
|
Login2DTO,
|
||||||
Login2Res,
|
Login2Res,
|
||||||
|
LoginLDAPDTO,
|
||||||
|
LoginLDAPRes,
|
||||||
ResetPasswordDTO,
|
ResetPasswordDTO,
|
||||||
SendMfaTokenDTO,
|
SendMfaTokenDTO,
|
||||||
SRP1DTO,
|
SRP1DTO,
|
||||||
@@ -37,6 +39,11 @@ export const login2 = async (loginDetails: Login2DTO) => {
|
|||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const loginLDAPRedirect = async (loginLDAPDetails: LoginLDAPDTO) => {
|
||||||
|
const { data } = await apiRequest.post<LoginLDAPRes>("/api/v1/ldap/login", loginLDAPDetails); // return if account is complete or not + provider auth token
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
export const useLogin1 = () => {
|
export const useLogin1 = () => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: async (details: {
|
mutationFn: async (details: {
|
||||||
|
|||||||
@@ -53,6 +53,16 @@ export type Login2Res = {
|
|||||||
tag?: string;
|
tag?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type LoginLDAPDTO = {
|
||||||
|
organizationSlug: string;
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type LoginLDAPRes = {
|
||||||
|
nextUrl: string;
|
||||||
|
}
|
||||||
|
|
||||||
export type SRP1DTO = {
|
export type SRP1DTO = {
|
||||||
clientPublicKey: string;
|
clientPublicKey: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export * from "./incidentContacts";
|
|||||||
export * from "./integrationAuth";
|
export * from "./integrationAuth";
|
||||||
export * from "./integrations";
|
export * from "./integrations";
|
||||||
export * from "./keys";
|
export * from "./keys";
|
||||||
|
export * from "./ldapConfig";
|
||||||
export * from "./organization";
|
export * from "./organization";
|
||||||
export * from "./roles";
|
export * from "./roles";
|
||||||
export * from "./scim";
|
export * from "./scim";
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
export {
|
||||||
|
useCreateLDAPConfig,
|
||||||
|
useGetLDAPConfig,
|
||||||
|
useUpdateLDAPConfig
|
||||||
|
} from "./queries";
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
|
|
||||||
|
import { apiRequest } from "@app/config/request";
|
||||||
|
|
||||||
|
const ldapConfigKeys = {
|
||||||
|
getLDAPConfig: (orgId: string) => [{ orgId }, "organization-ldap"] as const,
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useGetLDAPConfig = (organizationId: string) => {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ldapConfigKeys.getLDAPConfig(organizationId),
|
||||||
|
queryFn: async () => {
|
||||||
|
const { data } = await apiRequest.get(
|
||||||
|
`/api/v1/ldap/config?organizationId=${organizationId}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
enabled: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useCreateLDAPConfig = () => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: async ({
|
||||||
|
organizationId,
|
||||||
|
isActive,
|
||||||
|
url,
|
||||||
|
bindDN,
|
||||||
|
bindPass,
|
||||||
|
searchBase,
|
||||||
|
caCert
|
||||||
|
}: {
|
||||||
|
organizationId: string;
|
||||||
|
isActive: boolean;
|
||||||
|
url: string;
|
||||||
|
bindDN: string;
|
||||||
|
bindPass: string;
|
||||||
|
searchBase: string;
|
||||||
|
caCert?: string;
|
||||||
|
}) => {
|
||||||
|
const { data } = await apiRequest.post(
|
||||||
|
"/api/v1/ldap/config",
|
||||||
|
{
|
||||||
|
organizationId,
|
||||||
|
isActive,
|
||||||
|
url,
|
||||||
|
bindDN,
|
||||||
|
bindPass,
|
||||||
|
searchBase,
|
||||||
|
caCert
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
onSuccess(_, dto) {
|
||||||
|
queryClient.invalidateQueries(ldapConfigKeys.getLDAPConfig(dto.organizationId));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useUpdateLDAPConfig = () => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: async ({
|
||||||
|
organizationId,
|
||||||
|
isActive,
|
||||||
|
url,
|
||||||
|
bindDN,
|
||||||
|
bindPass,
|
||||||
|
searchBase,
|
||||||
|
caCert
|
||||||
|
}: {
|
||||||
|
organizationId: string;
|
||||||
|
isActive?: boolean;
|
||||||
|
url?: string;
|
||||||
|
bindDN?: string;
|
||||||
|
bindPass?: string;
|
||||||
|
searchBase?: string;
|
||||||
|
caCert?: string;
|
||||||
|
}) => {
|
||||||
|
const { data } = await apiRequest.patch(
|
||||||
|
"/api/v1/ldap/config",
|
||||||
|
{
|
||||||
|
organizationId,
|
||||||
|
isActive,
|
||||||
|
url,
|
||||||
|
bindDN,
|
||||||
|
bindPass,
|
||||||
|
searchBase,
|
||||||
|
caCert
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
onSuccess(_, dto) {
|
||||||
|
queryClient.invalidateQueries(ldapConfigKeys.getLDAPConfig(dto.organizationId));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -7,9 +7,9 @@ import { getAuthToken, isLoggedIn } from "@app/reactQuery";
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
InitialStep,
|
InitialStep,
|
||||||
|
LDAPStep,
|
||||||
MFAStep,
|
MFAStep,
|
||||||
SAMLSSOStep
|
SAMLSSOStep} from "./components";
|
||||||
} from "./components";
|
|
||||||
import { navigateUserToOrg } from "./Login.utils";
|
import { navigateUserToOrg } from "./Login.utils";
|
||||||
|
|
||||||
export const Login = () => {
|
export const Login = () => {
|
||||||
@@ -72,7 +72,10 @@ export const Login = () => {
|
|||||||
return (
|
return (
|
||||||
<SAMLSSOStep setStep={setStep} />
|
<SAMLSSOStep setStep={setStep} />
|
||||||
);
|
);
|
||||||
|
case 3:
|
||||||
|
return (
|
||||||
|
<LDAPStep setStep={setStep} />
|
||||||
|
);
|
||||||
default:
|
default:
|
||||||
return <div />;
|
return <div />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,7 +180,20 @@ export const InitialStep = ({ setStep, email, setEmail, password, setPassword }:
|
|||||||
leftIcon={<FontAwesomeIcon icon={faLock} className="mr-2" />}
|
leftIcon={<FontAwesomeIcon icon={faLock} className="mr-2" />}
|
||||||
className="mx-0 h-10 w-full"
|
className="mx-0 h-10 w-full"
|
||||||
>
|
>
|
||||||
Continue with SAML SSO
|
Continue with SAML
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div className="mt-2 w-1/4 min-w-[21.2rem] rounded-md text-center md:min-w-[20.1rem] lg:w-1/6">
|
||||||
|
<Button
|
||||||
|
colorSchema="primary"
|
||||||
|
variant="outline_bg"
|
||||||
|
onClick={() => {
|
||||||
|
setStep(3);
|
||||||
|
}}
|
||||||
|
leftIcon={<FontAwesomeIcon icon={faLock} className="mr-2" />}
|
||||||
|
className="mx-0 h-10 w-full"
|
||||||
|
>
|
||||||
|
Continue with LDAP
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<div className="my-4 flex w-1/4 min-w-[20rem] flex-row items-center py-2 lg:w-1/6">
|
<div className="my-4 flex w-1/4 min-w-[20rem] flex-row items-center py-2 lg:w-1/6">
|
||||||
|
|||||||
@@ -0,0 +1,128 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
|
import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider";
|
||||||
|
import { Button, Input } from "@app/components/v2";
|
||||||
|
import { loginLDAPRedirect } from "@app/hooks/api/auth/queries";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
setStep: (step: number) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const LDAPStep = ({
|
||||||
|
setStep
|
||||||
|
}: Props) => {
|
||||||
|
const { createNotification } = useNotificationContext();
|
||||||
|
const [organizationSlug, setOrganizationSlug] = useState("");
|
||||||
|
const [username, setUsername] = useState("");
|
||||||
|
const [password, setPassword] = useState("");
|
||||||
|
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
// const queryParams = new URLSearchParams(window.location.search);
|
||||||
|
|
||||||
|
const handleSubmission = async (e:React.FormEvent) => {
|
||||||
|
e.preventDefault()
|
||||||
|
try {
|
||||||
|
const { nextUrl } = await loginLDAPRedirect({
|
||||||
|
organizationSlug,
|
||||||
|
username,
|
||||||
|
password
|
||||||
|
});
|
||||||
|
|
||||||
|
createNotification({
|
||||||
|
text: "Successfully logged in",
|
||||||
|
type: "success"
|
||||||
|
});
|
||||||
|
|
||||||
|
// redirects either to /login/sso or /signup/sso
|
||||||
|
window.open(nextUrl);
|
||||||
|
window.close();
|
||||||
|
} catch (err) {
|
||||||
|
createNotification({
|
||||||
|
text: "Login unsuccessful. Double-check your credentials and try again.",
|
||||||
|
type: "error"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: add callback port support
|
||||||
|
|
||||||
|
// const callbackPort = queryParams.get("callback_port");
|
||||||
|
// window.open(`/api/v1/ldap/redirect/saml2/${ssoIdentifier}${callbackPort ? `?callback_port=${callbackPort}` : ""}`);
|
||||||
|
// window.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="mx-auto w-full max-w-md md:px-6">
|
||||||
|
<p className="mx-auto mb-6 flex w-max justify-center text-xl font-medium text-transparent bg-clip-text bg-gradient-to-b from-white to-bunker-200 text-center mb-8">
|
||||||
|
What's your LDAP Login?
|
||||||
|
</p>
|
||||||
|
<form onSubmit={handleSubmission}>
|
||||||
|
<div className="relative flex items-center justify-center lg:w-1/6 w-1/4 min-w-[20rem] md:min-w-[22rem] mx-auto w-full rounded-lg max-h-24 md:max-h-28">
|
||||||
|
<div className="flex items-center justify-center w-full rounded-lg max-h-24 md:max-h-28">
|
||||||
|
<Input
|
||||||
|
value={organizationSlug}
|
||||||
|
onChange={(e) => setOrganizationSlug(e.target.value)}
|
||||||
|
type="text"
|
||||||
|
placeholder="Enter your organization slug..."
|
||||||
|
isRequired
|
||||||
|
autoComplete="email"
|
||||||
|
id="email"
|
||||||
|
className="h-12"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="mt-2 relative flex items-center justify-center lg:w-1/6 w-1/4 min-w-[20rem] md:min-w-[22rem] mx-auto w-full rounded-lg max-h-24 md:max-h-28">
|
||||||
|
<div className="flex items-center justify-center w-full rounded-lg max-h-24 md:max-h-28">
|
||||||
|
<Input
|
||||||
|
value={username}
|
||||||
|
onChange={(e) => setUsername(e.target.value)}
|
||||||
|
type="text"
|
||||||
|
placeholder="Enter your LDAP username..."
|
||||||
|
isRequired
|
||||||
|
autoComplete="email"
|
||||||
|
id="email"
|
||||||
|
className="h-12"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="mt-2 relative flex items-center justify-center lg:w-1/6 w-1/4 min-w-[20rem] md:min-w-[22rem] mx-auto w-full rounded-lg max-h-24 md:max-h-28">
|
||||||
|
<div className="flex items-center justify-center w-full rounded-lg max-h-24 md:max-h-28">
|
||||||
|
<Input
|
||||||
|
value={password}
|
||||||
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
|
type="password"
|
||||||
|
placeholder="Enter your LDAP password..."
|
||||||
|
isRequired
|
||||||
|
autoComplete="current-password"
|
||||||
|
id="current-password"
|
||||||
|
className="select:-webkit-autofill:focus h-10"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className='lg:w-1/6 w-1/4 w-full mx-auto flex items-center justify-center min-w-[20rem] md:min-w-[22rem] text-center rounded-md mt-4'>
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
colorSchema="primary"
|
||||||
|
variant="outline_bg"
|
||||||
|
isFullWidth
|
||||||
|
className="h-14"
|
||||||
|
>
|
||||||
|
{t("login.login")}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<div className="flex flex-row items-center justify-center mt-4">
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
setStep(0);
|
||||||
|
}}
|
||||||
|
type="button"
|
||||||
|
className="text-bunker-300 text-sm hover:underline mt-2 hover:underline-offset-4 hover:decoration-primary-700 hover:text-bunker-200 duration-200 cursor-pointer"
|
||||||
|
>
|
||||||
|
{t("login.other-option")}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export { LDAPStep } from "./LDAPStep";
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
export { InitialStep } from "./InitialStep";
|
export { InitialStep } from "./InitialStep";
|
||||||
|
export { LDAPStep } from "./LDAPStep";
|
||||||
export { MFAStep } from "./MFAStep";
|
export { MFAStep } from "./MFAStep";
|
||||||
export { SAMLSSOStep } from "./SAMLSSOStep";
|
export { SAMLSSOStep } from "./SAMLSSOStep";
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,228 @@
|
|||||||
|
import { useEffect } from "react";
|
||||||
|
import { Controller, useForm } from "react-hook-form";
|
||||||
|
import { yupResolver } from "@hookform/resolvers/yup";
|
||||||
|
import * as yup from "yup";
|
||||||
|
|
||||||
|
import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider";
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
FormControl,
|
||||||
|
Input,
|
||||||
|
Modal,
|
||||||
|
ModalContent,
|
||||||
|
TextArea
|
||||||
|
} from "@app/components/v2";
|
||||||
|
import { useOrganization } from "@app/context";
|
||||||
|
import {
|
||||||
|
useCreateLDAPConfig,
|
||||||
|
useGetLDAPConfig,
|
||||||
|
useUpdateLDAPConfig
|
||||||
|
} from "@app/hooks/api";
|
||||||
|
import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||||
|
|
||||||
|
const schema = yup.object({
|
||||||
|
url: yup.string().required("URL is required"),
|
||||||
|
bindDN: yup.string().required("Bind DN is required"),
|
||||||
|
bindPass: yup.string().required("Bind Pass is required"),
|
||||||
|
searchBase: yup.string().required("Search Base is required"),
|
||||||
|
caCert: yup.string()
|
||||||
|
}).required();
|
||||||
|
|
||||||
|
export type AddLDAPFormData = yup.InferType<typeof schema>;
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
popUp: UsePopUpState<["addLDAP"]>;
|
||||||
|
handlePopUpClose: (popUpName: keyof UsePopUpState<["addLDAP"]>) => void;
|
||||||
|
handlePopUpToggle: (popUpName: keyof UsePopUpState<["addLDAP"]>, state?: boolean) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const LDAPModal = ({
|
||||||
|
popUp,
|
||||||
|
handlePopUpClose,
|
||||||
|
handlePopUpToggle
|
||||||
|
}: Props) => {
|
||||||
|
const { currentOrg } = useOrganization();
|
||||||
|
const { createNotification } = useNotificationContext();
|
||||||
|
const { mutateAsync: createMutateAsync, isLoading: createIsLoading } = useCreateLDAPConfig();
|
||||||
|
const { mutateAsync: updateMutateAsync, isLoading: updateIsLoading } = useUpdateLDAPConfig();
|
||||||
|
const { data } = useGetLDAPConfig(currentOrg?.id?? "");
|
||||||
|
|
||||||
|
const {
|
||||||
|
control,
|
||||||
|
handleSubmit,
|
||||||
|
reset,
|
||||||
|
} = useForm<AddLDAPFormData>({
|
||||||
|
resolver: yupResolver(schema)
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (data) {
|
||||||
|
reset({
|
||||||
|
url: data?.url ?? "",
|
||||||
|
bindDN: data?.bindDN ?? "",
|
||||||
|
bindPass: data?.bindPass ?? "",
|
||||||
|
searchBase: data?.searchBase ?? "",
|
||||||
|
caCert: data?.caCert ?? ""
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [data]);
|
||||||
|
|
||||||
|
const onSSOModalSubmit = async ({
|
||||||
|
url,
|
||||||
|
bindDN,
|
||||||
|
bindPass,
|
||||||
|
searchBase,
|
||||||
|
caCert
|
||||||
|
}: AddLDAPFormData) => {
|
||||||
|
try {
|
||||||
|
if (!currentOrg) return;
|
||||||
|
|
||||||
|
if (!data) {
|
||||||
|
await createMutateAsync({
|
||||||
|
organizationId: currentOrg.id,
|
||||||
|
isActive: false,
|
||||||
|
url,
|
||||||
|
bindDN,
|
||||||
|
bindPass,
|
||||||
|
searchBase,
|
||||||
|
caCert
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await updateMutateAsync({
|
||||||
|
organizationId: currentOrg.id,
|
||||||
|
isActive: false,
|
||||||
|
url,
|
||||||
|
bindDN,
|
||||||
|
bindPass,
|
||||||
|
searchBase,
|
||||||
|
caCert
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
handlePopUpClose("addLDAP");
|
||||||
|
|
||||||
|
createNotification({
|
||||||
|
text: `Successfully ${!data ? "added" : "updated"} LDAP configuration`,
|
||||||
|
type: "success"
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
createNotification({
|
||||||
|
text: `Failed to ${!data ? "add" : "update"} LDAP configuration`,
|
||||||
|
type: "error"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
isOpen={popUp?.addLDAP?.isOpen}
|
||||||
|
onOpenChange={(isOpen) => {
|
||||||
|
handlePopUpToggle("addLDAP", isOpen);
|
||||||
|
reset();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ModalContent title="Add LDAP">
|
||||||
|
<form onSubmit={handleSubmit(onSSOModalSubmit)}>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="url"
|
||||||
|
render={({ field, fieldState: { error } }) => (
|
||||||
|
<FormControl
|
||||||
|
label="URL"
|
||||||
|
errorText={error?.message}
|
||||||
|
isError={Boolean(error)}
|
||||||
|
>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
placeholder="ldaps://ldap.myorg.com:636"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="bindDN"
|
||||||
|
render={({ field, fieldState: { error } }) => (
|
||||||
|
<FormControl
|
||||||
|
label="Bind DN"
|
||||||
|
errorText={error?.message}
|
||||||
|
isError={Boolean(error)}
|
||||||
|
>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
placeholder="cn=infisical,ou=Users,dc=example,dc=com"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="bindPass"
|
||||||
|
render={({ field, fieldState: { error } }) => (
|
||||||
|
<FormControl
|
||||||
|
label="Bind Pass"
|
||||||
|
errorText={error?.message}
|
||||||
|
isError={Boolean(error)}
|
||||||
|
>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
placeholder="********"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="searchBase"
|
||||||
|
render={({ field, fieldState: { error } }) => (
|
||||||
|
<FormControl
|
||||||
|
label="Search Base / User DN"
|
||||||
|
errorText={error?.message}
|
||||||
|
isError={Boolean(error)}
|
||||||
|
>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
placeholder="ou=people,dc=acme,dc=com"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="caCert"
|
||||||
|
render={({ field, fieldState: { error } }) => (
|
||||||
|
<FormControl
|
||||||
|
label="CA Certificate"
|
||||||
|
errorText={error?.message}
|
||||||
|
isError={Boolean(error)}
|
||||||
|
>
|
||||||
|
<TextArea
|
||||||
|
{...field}
|
||||||
|
placeholder="-----BEGIN CERTIFICATE----- ..."
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<div className="mt-8 flex items-center">
|
||||||
|
<Button
|
||||||
|
className="mr-4"
|
||||||
|
size="sm"
|
||||||
|
type="submit"
|
||||||
|
isLoading={createIsLoading || updateIsLoading}
|
||||||
|
>
|
||||||
|
{!data ? "Add" : "Update"}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
colorSchema="secondary"
|
||||||
|
variant="plain"
|
||||||
|
onClick={() => handlePopUpClose("addLDAP")}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</ModalContent>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ import { OrgPermissionActions, OrgPermissionSubjects } from "@app/context";
|
|||||||
import { withPermission } from "@app/hoc";
|
import { withPermission } from "@app/hoc";
|
||||||
|
|
||||||
import { OrgGeneralAuthSection } from "./OrgGeneralAuthSection";
|
import { OrgGeneralAuthSection } from "./OrgGeneralAuthSection";
|
||||||
|
import { OrgLDAPSection } from "./OrgLDAPSection";
|
||||||
import { OrgScimSection } from "./OrgSCIMSection";
|
import { OrgScimSection } from "./OrgSCIMSection";
|
||||||
import { OrgSSOSection } from "./OrgSSOSection";
|
import { OrgSSOSection } from "./OrgSSOSection";
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ export const OrgAuthTab = withPermission(
|
|||||||
<div>
|
<div>
|
||||||
<OrgGeneralAuthSection />
|
<OrgGeneralAuthSection />
|
||||||
<OrgSSOSection />
|
<OrgSSOSection />
|
||||||
|
<OrgLDAPSection />
|
||||||
<OrgScimSection />
|
<OrgScimSection />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,137 @@
|
|||||||
|
import { faPlus } from "@fortawesome/free-solid-svg-icons";
|
||||||
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
|
||||||
|
import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider";
|
||||||
|
import { OrgPermissionCan } from "@app/components/permissions";
|
||||||
|
import { Button, Switch } from "@app/components/v2";
|
||||||
|
import {
|
||||||
|
OrgPermissionActions,
|
||||||
|
OrgPermissionSubjects,
|
||||||
|
useOrganization,
|
||||||
|
} from "@app/context";
|
||||||
|
import {
|
||||||
|
useCreateLDAPConfig,
|
||||||
|
useGetLDAPConfig,
|
||||||
|
useUpdateLDAPConfig
|
||||||
|
} from "@app/hooks/api";
|
||||||
|
import { usePopUp } from "@app/hooks/usePopUp";
|
||||||
|
|
||||||
|
import { LDAPModal } from "./LDAPModal";
|
||||||
|
|
||||||
|
export const OrgLDAPSection = (): JSX.Element => {
|
||||||
|
const { currentOrg } = useOrganization();
|
||||||
|
const { createNotification } = useNotificationContext();
|
||||||
|
const { data, isLoading } = useGetLDAPConfig(currentOrg?.id ?? "");
|
||||||
|
const { mutateAsync } = useUpdateLDAPConfig();
|
||||||
|
const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([
|
||||||
|
"addLDAP"
|
||||||
|
] as const);
|
||||||
|
|
||||||
|
const { mutateAsync: createMutateAsync } = useCreateLDAPConfig();
|
||||||
|
|
||||||
|
const handleSamlSSOToggle = async (value: boolean) => { // TODO: rename to LDAP toggle
|
||||||
|
try {
|
||||||
|
if (!currentOrg?.id) return;
|
||||||
|
|
||||||
|
await mutateAsync({
|
||||||
|
organizationId: currentOrg?.id,
|
||||||
|
isActive: value
|
||||||
|
});
|
||||||
|
|
||||||
|
createNotification({
|
||||||
|
text: `Successfully ${value ? "enabled" : "disabled"} LDAP`,
|
||||||
|
type: "success"
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
createNotification({
|
||||||
|
text: `Failed to ${value ? "enable" : "disable"} LDAP`,
|
||||||
|
type: "error"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const addLDAPBtnClick = async () => {
|
||||||
|
try {
|
||||||
|
if (currentOrg) {
|
||||||
|
if (!data) {
|
||||||
|
// case: LDAP is not configured
|
||||||
|
// -> initialize empty LDAP configuration
|
||||||
|
await createMutateAsync({
|
||||||
|
organizationId: currentOrg.id,
|
||||||
|
isActive: false,
|
||||||
|
url: "",
|
||||||
|
bindDN: "",
|
||||||
|
bindPass: "",
|
||||||
|
searchBase: "",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
handlePopUpOpen("addLDAP");
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="p-4 bg-mineshaft-900 mb-6 rounded-lg border border-mineshaft-600">
|
||||||
|
<div className="flex items-center mb-8">
|
||||||
|
<h2 className="text-xl font-semibold flex-1 text-white">LDAP Configuration</h2>
|
||||||
|
{!isLoading && (
|
||||||
|
<OrgPermissionCan I={OrgPermissionActions.Create} a={OrgPermissionSubjects.Sso}>
|
||||||
|
{(isAllowed) => (
|
||||||
|
<Button
|
||||||
|
onClick={addLDAPBtnClick}
|
||||||
|
colorSchema="secondary"
|
||||||
|
isDisabled={!isAllowed}
|
||||||
|
leftIcon={<FontAwesomeIcon icon={faPlus} />}
|
||||||
|
>
|
||||||
|
{data ? "Update LDAP" : "Set up LDAP"}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</OrgPermissionCan>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{data && (
|
||||||
|
<div className="mb-4">
|
||||||
|
<OrgPermissionCan I={OrgPermissionActions.Edit} a={OrgPermissionSubjects.Sso}>
|
||||||
|
{(isAllowed) => (
|
||||||
|
<Switch
|
||||||
|
id="enable-saml-sso"
|
||||||
|
onCheckedChange={(value) => handleSamlSSOToggle(value)}
|
||||||
|
isChecked={data ? data.isActive : false}
|
||||||
|
isDisabled={!isAllowed}
|
||||||
|
>
|
||||||
|
Enable LDAP
|
||||||
|
</Switch>
|
||||||
|
)}
|
||||||
|
</OrgPermissionCan>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className="mb-4">
|
||||||
|
<h3 className="text-mineshaft-400 text-sm">URL</h3>
|
||||||
|
<p className="text-gray-400 text-md">{data && data.url !== "" ? data.url : "-"}</p>
|
||||||
|
</div>
|
||||||
|
<div className="mb-4">
|
||||||
|
<h3 className="text-mineshaft-400 text-sm">Bind DN</h3>
|
||||||
|
<p className="text-gray-400 text-md">{data && data.bindDN !== "" ? data.bindDN : "-"}</p>
|
||||||
|
</div>
|
||||||
|
<div className="mb-4">
|
||||||
|
<h3 className="text-mineshaft-400 text-sm">Bind Pass</h3>
|
||||||
|
<p className="text-gray-400 text-md">
|
||||||
|
{data && data.bindPass !== "" ? "*".repeat(data.bindPass.length) : "-"}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="mb-4">
|
||||||
|
<h3 className="text-mineshaft-400 text-sm">Search Base / User DN</h3>
|
||||||
|
<p className="text-gray-400 text-md">{data && data.searchBase !== "" ? data.searchBase : "-"}</p>
|
||||||
|
</div>
|
||||||
|
<LDAPModal
|
||||||
|
popUp={popUp}
|
||||||
|
handlePopUpClose={handlePopUpClose}
|
||||||
|
handlePopUpToggle={handlePopUpToggle}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user