Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
Fix merge conflicts
Tuan Dang2b91ec5ae96b
diff --cc backend/src/@types/fastify.d.tsindex 064927dfeb,994b324f6d..4776e26dc6--- a/backend/src/@types/fastify.d.ts+++ b/backend/src/@types/fastify.d.ts@@@ -33,7 -33,7 +33,8 @@@ import { TGroupProjectServiceFactory }import { TIdentityServiceFactory } from "@app/services/identity/identity-service";import { TIdentityAccessTokenServiceFactory } from "@app/services/identity-access-token/identity-access-token-service";import { TIdentityAwsAuthServiceFactory } from "@app/services/identity-aws-auth/identity-aws-auth-service";+ import { TIdentityGcpAuthServiceFactory } from "@app/services/identity-gcp-auth/identity-gcp-auth-service";+import { TIdentityKubernetesAuthServiceFactory } from "@app/services/identity-kubernetes-auth/identity-kubernetes-auth-service";import { TIdentityProjectServiceFactory } from "@app/services/identity-project/identity-project-service";import { TIdentityUaServiceFactory } from "@app/services/identity-ua/identity-ua-service";import { TIntegrationServiceFactory } from "@app/services/integration/integration-service";@@@ -117,7 -117,7 +118,8 @@@ declare module "fastify"identityAccessToken: TIdentityAccessTokenServiceFactory;identityProject: TIdentityProjectServiceFactory;identityUa: TIdentityUaServiceFactory;+ identityKubernetesAuth: TIdentityKubernetesAuthServiceFactory;+ identityGcpAuth: TIdentityGcpAuthServiceFactory;identityAwsAuth: TIdentityAwsAuthServiceFactory;accessApprovalPolicy: TAccessApprovalPolicyServiceFactory;accessApprovalRequest: TAccessApprovalRequestServiceFactory;diff --cc backend/src/@types/knex.d.tsindex f86d22df56,3a6aa549dc..3453352fa8--- a/backend/src/@types/knex.d.ts+++ b/backend/src/@types/knex.d.ts@@@ -62,9 -62,9 +62,12 @@@ importTIdentityAwsAuths,TIdentityAwsAuthsInsert,TIdentityAwsAuthsUpdate,+ TIdentityGcpAuths,+ TIdentityGcpAuthsInsert,+ TIdentityGcpAuthsUpdate,+ TIdentityKubernetesAuths,+ TIdentityKubernetesAuthsInsert,+ TIdentityKubernetesAuthsUpdate,TIdentityOrgMemberships,TIdentityOrgMembershipsInsert,TIdentityOrgMembershipsUpdate,@@@ -332,11 -332,11 +335,16 @@@ declare module "knex/types/tables"TIdentityUniversalAuthsInsert,TIdentityUniversalAuthsUpdate>;+ [TableName.IdentityKubernetesAuth]: Knex.CompositeTableType<+ TIdentityKubernetesAuths,+ TIdentityKubernetesAuthsInsert,+ TIdentityKubernetesAuthsUpdate+ >;+ [TableName.IdentityGcpAuth]: Knex.CompositeTableType<+ TIdentityGcpAuths,+ TIdentityGcpAuthsInsert,+ TIdentityGcpAuthsUpdate+ >;[TableName.IdentityAwsAuth]: Knex.CompositeTableType<TIdentityAwsAuths,TIdentityAwsAuthsInsert,diff --cc backend/src/db/schemas/index.tsindex 145b24a4ba,4993003f94..cffa4f4921--- a/backend/src/db/schemas/index.ts+++ b/backend/src/db/schemas/index.ts@@@ -18,7 -18,7 +18,8 @@@ export * from "./groups"export * from "./identities";export * from "./identity-access-tokens";export * from "./identity-aws-auths";+ export * from "./identity-gcp-auths";+export * from "./identity-kubernetes-auths";export * from "./identity-org-memberships";export * from "./identity-project-additional-privilege";export * from "./identity-project-membership-role";diff --cc backend/src/db/schemas/models.tsindex f1d528c2fa,4951de99eb..863e0a7e6c--- a/backend/src/db/schemas/models.ts+++ b/backend/src/db/schemas/models.ts@@@ -44,7 -44,7 +44,8 @@@ export enum TableNameIdentity = "identities",IdentityAccessToken = "identity_access_tokens",IdentityUniversalAuth = "identity_universal_auths",+ IdentityKubernetesAuth = "identity_kubernetes_auths",+ IdentityGcpAuth = "identity_gcp_auths",IdentityUaClientSecret = "identity_ua_client_secrets",IdentityAwsAuth = "identity_aws_auths",IdentityOrgMembership = "identity_org_memberships",@@@ -145,6 -145,6 +146,7 @@@ export enum ProjectUpgradeStatusexport enum IdentityAuthMethod {Univeral = "universal-auth",- Kubernetes_Auth = "kubernetes-auth",++ KUBERNETES_AUTH = "kubernetes-auth",+ GCP_AUTH = "gcp-auth",AWS_AUTH = "aws-auth"}diff --cc backend/src/server/routes/index.tsindex c2eb231174,3b0758d687..013ace491a--- a/backend/src/server/routes/index.ts+++ b/backend/src/server/routes/index.ts@@@ -80,8 -80,8 +80,10 @@@ import { identityAccessTokenDALFactoryimport { identityAccessTokenServiceFactory } from "@app/services/identity-access-token/identity-access-token-service";import { identityAwsAuthDALFactory } from "@app/services/identity-aws-auth/identity-aws-auth-dal";import { identityAwsAuthServiceFactory } from "@app/services/identity-aws-auth/identity-aws-auth-service";+ import { identityGcpAuthDALFactory } from "@app/services/identity-gcp-auth/identity-gcp-auth-dal";+ import { identityGcpAuthServiceFactory } from "@app/services/identity-gcp-auth/identity-gcp-auth-service";+import { identityKubernetesAuthDALFactory } from "@app/services/identity-kubernetes-auth/identity-kubernetes-auth-dal";+import { identityKubernetesAuthServiceFactory } from "@app/services/identity-kubernetes-auth/identity-kubernetes-auth-service";import { identityProjectDALFactory } from "@app/services/identity-project/identity-project-dal";import { identityProjectMembershipRoleDALFactory } from "@app/services/identity-project/identity-project-membership-role-dal";import { identityProjectServiceFactory } from "@app/services/identity-project/identity-project-service";@@@ -707,15 -711,15 +714,24 @@@ export const registerRoutes = asyncidentityUaDAL,licenseService});+ const identityKubernetesAuthService = identityKubernetesAuthServiceFactory({+ identityKubernetesAuthDAL,+ identityOrgMembershipDAL,+ identityAccessTokenDAL,+ identityDAL,+ orgBotDAL,+ permissionService,+ licenseService+ });+ const identityGcpAuthService = identityGcpAuthServiceFactory({+ identityGcpAuthDAL,+ identityOrgMembershipDAL,+ identityAccessTokenDAL,+ identityDAL,+ permissionService,+ licenseService+ });+const identityAwsAuthService = identityAwsAuthServiceFactory({identityAccessTokenDAL,identityAwsAuthDAL,@@@ -793,7 -797,7 +809,8 @@@identityAccessToken: identityAccessTokenService,identityProject: identityProjectService,identityUa: identityUaService,+ identityKubernetesAuth: identityKubernetesAuthService,+ identityGcpAuth: identityGcpAuthService,identityAwsAuth: identityAwsAuthService,secretApprovalPolicy: sapService,accessApprovalPolicy: accessApprovalPolicyService,diff --cc backend/src/server/routes/v1/index.tsindex 795be96dcf,1a02a4cbf2..262e3cb201--- a/backend/src/server/routes/v1/index.ts+++ b/backend/src/server/routes/v1/index.ts@@@ -3,7 -3,7 +3,8 @@@ import { registerAuthRoutes } from "./aimport { registerProjectBotRouter } from "./bot-router";import { registerIdentityAccessTokenRouter } from "./identity-access-token-router";import { registerIdentityAwsAuthRouter } from "./identity-aws-iam-auth-router";+ import { registerIdentityGcpAuthRouter } from "./identity-gcp-auth-router";+import { registerIdentityKubernetesRouter } from "./identity-kubernetes-auth-router";import { registerIdentityRouter } from "./identity-router";import { registerIdentityUaRouter } from "./identity-ua";import { registerIntegrationAuthRouter } from "./integration-auth-router";@@@ -29,7 -29,7 +30,8 @@@ export const registerV1Routes = async (async (authRouter) => {await authRouter.register(registerAuthRoutes);await authRouter.register(registerIdentityUaRouter);+ await authRouter.register(registerIdentityKubernetesRouter);+ await authRouter.register(registerIdentityGcpAuthRouter);await authRouter.register(registerIdentityAccessTokenRouter);await authRouter.register(registerIdentityAwsAuthRouter);},diff --cc backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.tsindex cba7e87ae0,0000000000..6fb9f6c39bmode 100644,000000..100644--- a/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts+++ b/backend/src/services/identity-kubernetes-auth/identity-kubernetes-auth-service.ts@@@ -1,515 -1,0 +1,515 @@@+import { ForbiddenError } from "@casl/ability";+import axios from "axios";+import https from "https";+import jwt from "jsonwebtoken";++import { IdentityAuthMethod, SecretKeyEncoding, TIdentityKubernetesAuthsUpdate } from "@app/db/schemas";+import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";+import { OrgPermissionActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";+import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";+import { getConfig } from "@app/lib/config/env";+import {+ decryptSymmetric,+ encryptSymmetric,+ generateAsymmetricKeyPair,+ generateSymmetricKey,+ infisicalSymmetricDecrypt,+ infisicalSymmetricEncypt+} from "@app/lib/crypto/encryption";+import { BadRequestError, UnauthorizedError } from "@app/lib/errors";+import { extractIPDetails, isValidIpOrCidr } from "@app/lib/ip";+import { TOrgBotDALFactory } from "@app/services/org/org-bot-dal";++import { AuthTokenType } from "../auth/auth-type";+import { TIdentityDALFactory } from "../identity/identity-dal";+import { TIdentityOrgDALFactory } from "../identity/identity-org-dal";+import { TIdentityAccessTokenDALFactory } from "../identity-access-token/identity-access-token-dal";+import { TIdentityAccessTokenJwtPayload } from "../identity-access-token/identity-access-token-types";+import { TIdentityKubernetesAuthDALFactory } from "./identity-kubernetes-auth-dal";+import { extractK8sUsername } from "./identity-kubernetes-auth-fns";+import {+ TAttachKubernetesAuthDTO,+ TCreateTokenReviewResponse,+ TGetKubernetesAuthDTO,+ TLoginKubernetesAuthDTO,+ TUpdateKubernetesAuthDTO+} from "./identity-kubernetes-auth-types";++type TIdentityKubernetesAuthServiceFactoryDep = {+ identityKubernetesAuthDAL: Pick<+ TIdentityKubernetesAuthDALFactory,+ "create" | "findOne" | "transaction" | "updateById"+ >;+ identityAccessTokenDAL: Pick<TIdentityAccessTokenDALFactory, "create">;+ identityOrgMembershipDAL: Pick<TIdentityOrgDALFactory, "findOne" | "findById">;+ identityDAL: Pick<TIdentityDALFactory, "updateById">;+ orgBotDAL: Pick<TOrgBotDALFactory, "findOne" | "transaction" | "create">;+ permissionService: Pick<TPermissionServiceFactory, "getOrgPermission">;+ licenseService: Pick<TLicenseServiceFactory, "getPlan">;+};++export type TIdentityKubernetesAuthServiceFactory = ReturnType<typeof identityKubernetesAuthServiceFactory>;++export const identityKubernetesAuthServiceFactory = ({+ identityKubernetesAuthDAL,+ identityOrgMembershipDAL,+ identityAccessTokenDAL,+ identityDAL,+ orgBotDAL,+ permissionService,+ licenseService+}: TIdentityKubernetesAuthServiceFactoryDep) => {+ const login = async ({ identityId, jwt: serviceAccountJwt }: TLoginKubernetesAuthDTO) => {+ const identityKubernetesAuth = await identityKubernetesAuthDAL.findOne({ identityId });+ if (!identityKubernetesAuth) throw new UnauthorizedError();++ const identityMembershipOrg = await identityOrgMembershipDAL.findOne({+ identityId: identityKubernetesAuth.identityId+ });+ if (!identityMembershipOrg) throw new BadRequestError({ message: "Failed to find identity" });++ const orgBot = await orgBotDAL.findOne({ orgId: identityMembershipOrg.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 { encryptedCaCert, caCertIV, caCertTag, encryptedTokenReviewerJwt, tokenReviewerJwtIV, tokenReviewerJwtTag } =+ identityKubernetesAuth;++ let caCert = "";+ if (encryptedCaCert && caCertIV && caCertTag) {+ caCert = decryptSymmetric({+ ciphertext: encryptedCaCert,+ iv: caCertIV,+ tag: caCertTag,+ key+ });+ }++ let tokenReviewerJwt = "";+ if (encryptedTokenReviewerJwt && tokenReviewerJwtIV && tokenReviewerJwtTag) {+ tokenReviewerJwt = decryptSymmetric({+ ciphertext: encryptedTokenReviewerJwt,+ iv: tokenReviewerJwtIV,+ tag: tokenReviewerJwtTag,+ key+ });+ }++ const { data }: { data: TCreateTokenReviewResponse } = await axios.post(+ `${identityKubernetesAuth.kubernetesHost}/apis/authentication.k8s.io/v1/tokenreviews`,+ {+ apiVersion: "authentication.k8s.io/v1",+ kind: "TokenReview",+ spec: {+ token: serviceAccountJwt+ }+ },+ {+ headers: {+ "Content-Type": "application/json",+ Authorization: `Bearer ${tokenReviewerJwt}`+ },+ httpsAgent: new https.Agent({+ ca: caCert,+ rejectUnauthorized: false // TODO: change to [true]+ })+ }+ );++ if ("error" in data.status) throw new UnauthorizedError({ message: data.status.error });++ // check the response to determine if the token is valid+ if (!(data.status && data.status.authenticated)) throw new UnauthorizedError();++ const { namespace: targetNamespace, name: targetName } = extractK8sUsername(data.status.user.username);++ if (identityKubernetesAuth.allowedNamespaces) {+ // validate if [targetNamespace] is in the list of allowed namespaces++ const isNamespaceAllowed = identityKubernetesAuth.allowedNamespaces+ .split(",")+ .map((namespace) => namespace.trim())+ .some((namespace) => namespace === targetNamespace);++ if (!isNamespaceAllowed) throw new UnauthorizedError();+ }++ if (identityKubernetesAuth.allowedNames) {+ // validate if [targetName] is in the list of allowed names++ const isNameAllowed = identityKubernetesAuth.allowedNames+ .split(",")+ .map((name) => name.trim())+ .some((name) => name === targetName);++ if (!isNameAllowed) throw new UnauthorizedError();+ }++ if (identityKubernetesAuth.allowedAudience) {+ // validate if [audience] is in the list of allowed audiences+ const isAudienceAllowed = data.status.audiences.some(+ (audience) => audience === identityKubernetesAuth.allowedAudience+ );++ if (!isAudienceAllowed) throw new UnauthorizedError();+ }++ const identityAccessToken = await identityKubernetesAuthDAL.transaction(async (tx) => {+ const newToken = await identityAccessTokenDAL.create(+ {+ identityId: identityKubernetesAuth.identityId,+ isAccessTokenRevoked: false,+ accessTokenTTL: identityKubernetesAuth.accessTokenTTL,+ accessTokenMaxTTL: identityKubernetesAuth.accessTokenMaxTTL,+ accessTokenNumUses: 0,+ accessTokenNumUsesLimit: identityKubernetesAuth.accessTokenNumUsesLimit+ },+ tx+ );+ return newToken;+ });++ const appCfg = getConfig();+ const accessToken = jwt.sign(+ {+ identityId: identityKubernetesAuth.identityId,+ identityAccessTokenId: identityAccessToken.id,+ authTokenType: AuthTokenType.IDENTITY_ACCESS_TOKEN+ } as TIdentityAccessTokenJwtPayload,+ appCfg.AUTH_SECRET,+ {+ expiresIn:+ Number(identityAccessToken.accessTokenMaxTTL) === 0+ ? undefined+ : Number(identityAccessToken.accessTokenMaxTTL)+ }+ );++ return { accessToken, identityKubernetesAuth, identityAccessToken, identityMembershipOrg };+ };++ const attachKubernetesAuth = async ({+ identityId,+ kubernetesHost,+ caCert,+ tokenReviewerJwt,+ allowedNamespaces,+ allowedNames,+ allowedAudience,+ accessTokenTTL,+ accessTokenMaxTTL,+ accessTokenNumUsesLimit,+ accessTokenTrustedIps,+ actorId,+ actorAuthMethod,+ actor,+ actorOrgId+ }: TAttachKubernetesAuthDTO) => {+ const identityMembershipOrg = await identityOrgMembershipDAL.findOne({ identityId });+ if (!identityMembershipOrg) throw new BadRequestError({ message: "Failed to find identity" });+ if (identityMembershipOrg.identity.authMethod)+ throw new BadRequestError({+ message: "Failed to add Kubernetes Auth to already configured identity"+ });++ if (accessTokenMaxTTL > 0 && accessTokenTTL > accessTokenMaxTTL) {+ throw new BadRequestError({ message: "Access token TTL cannot be greater than max TTL" });+ }++ const { permission } = await permissionService.getOrgPermission(+ actor,+ actorId,+ identityMembershipOrg.orgId,+ actorAuthMethod,+ actorOrgId+ );+ ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Create, OrgPermissionSubjects.Identity);++ const plan = await licenseService.getPlan(identityMembershipOrg.orgId);+ const reformattedAccessTokenTrustedIps = accessTokenTrustedIps.map((accessTokenTrustedIp) => {+ if (+ !plan.ipAllowlisting &&+ accessTokenTrustedIp.ipAddress !== "0.0.0.0/0" &&+ accessTokenTrustedIp.ipAddress !== "::/0"+ )+ throw new BadRequestError({+ message:+ "Failed to add IP access range to access token due to plan restriction. Upgrade plan to add IP access range."+ });+ if (!isValidIpOrCidr(accessTokenTrustedIp.ipAddress))+ throw new BadRequestError({+ message: "The IP is not a valid IPv4, IPv6, or CIDR block"+ });+ return extractIPDetails(accessTokenTrustedIp.ipAddress);+ });++ const orgBot = await orgBotDAL.transaction(async (tx) => {+ const doc = await orgBotDAL.findOne({ orgId: identityMembershipOrg.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: identityMembershipOrg.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: encryptedCaCert, iv: caCertIV, tag: caCertTag } = encryptSymmetric(caCert, key);+ const {+ ciphertext: encryptedTokenReviewerJwt,+ iv: tokenReviewerJwtIV,+ tag: tokenReviewerJwtTag+ } = encryptSymmetric(tokenReviewerJwt, key);++ const identityKubernetesAuth = await identityKubernetesAuthDAL.transaction(async (tx) => {+ const doc = await identityKubernetesAuthDAL.create(+ {+ identityId: identityMembershipOrg.identityId,+ kubernetesHost,+ encryptedCaCert,+ caCertIV,+ caCertTag,+ encryptedTokenReviewerJwt,+ tokenReviewerJwtIV,+ tokenReviewerJwtTag,+ allowedNamespaces,+ allowedNames,+ allowedAudience,+ accessTokenMaxTTL,+ accessTokenTTL,+ accessTokenNumUsesLimit,+ accessTokenTrustedIps: JSON.stringify(reformattedAccessTokenTrustedIps)+ },+ tx+ );+ await identityDAL.updateById(+ identityMembershipOrg.identityId,+ {- authMethod: IdentityAuthMethod.Kubernetes_Auth++ authMethod: IdentityAuthMethod.KUBERNETES_AUTH+ },+ tx+ );+ return doc;+ });++ return { ...identityKubernetesAuth, caCert, tokenReviewerJwt, orgId: identityMembershipOrg.orgId };+ };++ const updateKubernetesAuth = async ({+ identityId,+ kubernetesHost,+ caCert,+ tokenReviewerJwt,+ allowedNamespaces,+ allowedNames,+ allowedAudience,+ accessTokenTTL,+ accessTokenMaxTTL,+ accessTokenNumUsesLimit,+ accessTokenTrustedIps,+ actorId,+ actorAuthMethod,+ actor,+ actorOrgId+ }: TUpdateKubernetesAuthDTO) => {+ const identityMembershipOrg = await identityOrgMembershipDAL.findOne({ identityId });+ if (!identityMembershipOrg) throw new BadRequestError({ message: "Failed to find identity" });- if (identityMembershipOrg.identity?.authMethod !== IdentityAuthMethod.Kubernetes_Auth)++ if (identityMembershipOrg.identity?.authMethod !== IdentityAuthMethod.KUBERNETES_AUTH)+ throw new BadRequestError({+ message: "Failed to update Kubernetes Auth"+ });++ const identityKubernetesAuth = await identityKubernetesAuthDAL.findOne({ identityId });++ if (+ (accessTokenMaxTTL || identityKubernetesAuth.accessTokenMaxTTL) > 0 &&+ (accessTokenTTL || identityKubernetesAuth.accessTokenMaxTTL) >+ (accessTokenMaxTTL || identityKubernetesAuth.accessTokenMaxTTL)+ ) {+ throw new BadRequestError({ message: "Access token TTL cannot be greater than max TTL" });+ }++ const { permission } = await permissionService.getOrgPermission(+ actor,+ actorId,+ identityMembershipOrg.orgId,+ actorAuthMethod,+ actorOrgId+ );+ ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Edit, OrgPermissionSubjects.Identity);++ const plan = await licenseService.getPlan(identityMembershipOrg.orgId);+ const reformattedAccessTokenTrustedIps = accessTokenTrustedIps?.map((accessTokenTrustedIp) => {+ if (+ !plan.ipAllowlisting &&+ accessTokenTrustedIp.ipAddress !== "0.0.0.0/0" &&+ accessTokenTrustedIp.ipAddress !== "::/0"+ )+ throw new BadRequestError({+ message:+ "Failed to add IP access range to access token due to plan restriction. Upgrade plan to add IP access range."+ });+ if (!isValidIpOrCidr(accessTokenTrustedIp.ipAddress))+ throw new BadRequestError({+ message: "The IP is not a valid IPv4, IPv6, or CIDR block"+ });+ return extractIPDetails(accessTokenTrustedIp.ipAddress);+ });++ const updateQuery: TIdentityKubernetesAuthsUpdate = {+ kubernetesHost,+ allowedNamespaces,+ allowedNames,+ allowedAudience,+ accessTokenMaxTTL,+ accessTokenTTL,+ accessTokenNumUsesLimit,+ accessTokenTrustedIps: reformattedAccessTokenTrustedIps+ ? JSON.stringify(reformattedAccessTokenTrustedIps)+ : undefined+ };++ const orgBot = await orgBotDAL.findOne({ orgId: identityMembershipOrg.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 (caCert !== undefined) {+ const { ciphertext: encryptedCACert, iv: caCertIV, tag: caCertTag } = encryptSymmetric(caCert, key);+ updateQuery.encryptedCaCert = encryptedCACert;+ updateQuery.caCertIV = caCertIV;+ updateQuery.caCertTag = caCertTag;+ }++ if (tokenReviewerJwt !== undefined) {+ const {+ ciphertext: encryptedTokenReviewerJwt,+ iv: tokenReviewerJwtIV,+ tag: tokenReviewerJwtTag+ } = encryptSymmetric(tokenReviewerJwt, key);+ updateQuery.encryptedTokenReviewerJwt = encryptedTokenReviewerJwt;+ updateQuery.tokenReviewerJwtIV = tokenReviewerJwtIV;+ updateQuery.tokenReviewerJwtTag = tokenReviewerJwtTag;+ }++ const updatedKubernetesAuth = await identityKubernetesAuthDAL.updateById(identityKubernetesAuth.id, updateQuery);++ return { ...updatedKubernetesAuth, orgId: identityMembershipOrg.orgId };+ };++ const getKubernetesAuth = async ({+ identityId,+ actorId,+ actor,+ actorAuthMethod,+ actorOrgId+ }: TGetKubernetesAuthDTO) => {+ const identityMembershipOrg = await identityOrgMembershipDAL.findOne({ identityId });+ if (!identityMembershipOrg) throw new BadRequestError({ message: "Failed to find identity" });- if (identityMembershipOrg.identity?.authMethod !== IdentityAuthMethod.Kubernetes_Auth)++ if (identityMembershipOrg.identity?.authMethod !== IdentityAuthMethod.KUBERNETES_AUTH)+ throw new BadRequestError({+ message: "The identity does not have Kubernetes Auth attached"+ });++ const identityKubernetesAuth = await identityKubernetesAuthDAL.findOne({ identityId });++ const { permission } = await permissionService.getOrgPermission(+ actor,+ actorId,+ identityMembershipOrg.orgId,+ actorAuthMethod,+ actorOrgId+ );+ ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Read, OrgPermissionSubjects.Identity);++ const orgBot = await orgBotDAL.findOne({ orgId: identityMembershipOrg.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 { encryptedCaCert, caCertIV, caCertTag, encryptedTokenReviewerJwt, tokenReviewerJwtIV, tokenReviewerJwtTag } =+ identityKubernetesAuth;++ let caCert = "";+ if (encryptedCaCert && caCertIV && caCertTag) {+ caCert = decryptSymmetric({+ ciphertext: encryptedCaCert,+ iv: caCertIV,+ tag: caCertTag,+ key+ });+ }++ let tokenReviewerJwt = "";+ if (encryptedTokenReviewerJwt && tokenReviewerJwtIV && tokenReviewerJwtTag) {+ tokenReviewerJwt = decryptSymmetric({+ ciphertext: encryptedTokenReviewerJwt,+ iv: tokenReviewerJwtIV,+ tag: tokenReviewerJwtTag,+ key+ });+ }++ return { ...identityKubernetesAuth, caCert, tokenReviewerJwt, orgId: identityMembershipOrg.orgId };+ };++ return {+ login,+ attachKubernetesAuth,+ updateKubernetesAuth,+ getKubernetesAuth+ };+};diff --cc frontend/src/hooks/api/identities/constants.tsxindex d06fbc776c,d2669a308b..8ae22b30c6--- a/frontend/src/hooks/api/identities/constants.tsx+++ b/frontend/src/hooks/api/identities/constants.tsx@@@ -2,6 -2,6 +2,7 @@@ import { IdentityAuthMethod } from "./eexport const identityAuthToNameMap: { [I in IdentityAuthMethod]: string } = {[IdentityAuthMethod.UNIVERSAL_AUTH]: "Universal Auth",- [IdentityAuthMethod.AWS_AUTH]: "AWS Auth",- [IdentityAuthMethod.KUBERNETES_AUTH]: "Kubernetes Auth"++ [IdentityAuthMethod.KUBERNETES_AUTH]: "Kubernetes Auth",+ [IdentityAuthMethod.GCP_AUTH]: "GCP Auth",+ [IdentityAuthMethod.AWS_AUTH]: "AWS Auth"};diff --cc frontend/src/hooks/api/identities/enums.tsxindex 716504ae87,a67776c877..dc9d48cbd1--- a/frontend/src/hooks/api/identities/enums.tsx+++ b/frontend/src/hooks/api/identities/enums.tsx@@@ -1,5 -1,5 +1,6 @@@export enum IdentityAuthMethod {UNIVERSAL_AUTH = "universal-auth",- AWS_AUTH = "aws-auth",- KUBERNETES_AUTH = "kubernetes-auth"++ KUBERNETES_AUTH = "kubernetes-auth",+ GCP_AUTH = "gcp-auth",+ AWS_AUTH = "aws-auth"}diff --cc frontend/src/hooks/api/identities/index.tsxindex 6b2175543f,d59e096c09..be640572bc--- a/frontend/src/hooks/api/identities/index.tsx+++ b/frontend/src/hooks/api/identities/index.tsx@@@ -2,7 -2,7 +2,8 @@@ export { identityAuthToNameMap } from "export { IdentityAuthMethod } from "./enums";export {useAddIdentityAwsAuth,+ useAddIdentityGcpAuth,+ useAddIdentityKubernetesAuth,useAddIdentityUniversalAuth,useCreateIdentity,useCreateIdentityUniversalAuthClientSecret,@@@ -10,11 -10,11 +11,13 @@@useRevokeIdentityUniversalAuthClientSecret,useUpdateIdentity,useUpdateIdentityAwsAuth,+ useUpdateIdentityGcpAuth,+ useUpdateIdentityKubernetesAuth,useUpdateIdentityUniversalAuth} from "./mutations";export {useGetIdentityAwsAuth,+ useGetIdentityGcpAuth,+ useGetIdentityKubernetesAuth,useGetIdentityUniversalAuth,useGetIdentityUniversalAuthClientSecrets} from "./queries";diff --cc frontend/src/hooks/api/identities/mutations.tsxindex 6abf035898,5c2e20ff0f..d6c93044a3--- a/frontend/src/hooks/api/identities/mutations.tsx+++ b/frontend/src/hooks/api/identities/mutations.tsx@@@ -6,7 -6,7 +6,8 @@@ import { organizationKeys } from "../orimport { identitiesKeys } from "./queries";import {AddIdentityAwsAuthDTO,+ AddIdentityGcpAuthDTO,+ AddIdentityKubernetesAuthDTO,AddIdentityUniversalAuthDTO,ClientSecretData,CreateIdentityDTO,@@@ -16,12 -16,13 +17,14 @@@DeleteIdentityUniversalAuthClientSecretDTO,Identity,IdentityAwsAuth,+ IdentityGcpAuth,+ IdentityKubernetesAuth,IdentityUniversalAuth,UpdateIdentityAwsAuthDTO,UpdateIdentityDTO,+ UpdateIdentityGcpAuthDTO,- UpdateIdentityUniversalAuthDTO-} from "./types";+ UpdateIdentityKubernetesAuthDTO,+ UpdateIdentityUniversalAuthDTO} from "./types";export const useCreateIdentity = () => {const queryClient = useQueryClient();diff --cc frontend/src/hooks/api/identities/queries.tsxindex e7497b4de6,2996f275f0..270827b52a--- a/frontend/src/hooks/api/identities/queries.tsx+++ b/frontend/src/hooks/api/identities/queries.tsx@@@ -2,20 -2,15 +2,23 @@@ import { useQuery } from "@tanstack/reaimport { apiRequest } from "@app/config/request";-import { ClientSecretData, IdentityAwsAuth, IdentityGcpAuth, IdentityUniversalAuth } from "./types";+import {+ ClientSecretData,+ IdentityAwsAuth,++ IdentityGcpAuth,+ IdentityKubernetesAuth,- IdentityUniversalAuth} from "./types";++ IdentityUniversalAuth++} from "./types";export const identitiesKeys = {getIdentityUniversalAuth: (identityId: string) =>[{ identityId }, "identity-universal-auth"] as const,getIdentityUniversalAuthClientSecrets: (identityId: string) =>[{ identityId }, "identity-universal-auth-client-secrets"] as const,- getIdentityAwsAuth: (identityId: string) => [{ identityId }, "identity-aws-auth"] as const,+ getIdentityKubernetesAuth: (identityId: string) =>- [{ identityId }, "identity-kubernetes-auth"] as const++ [{ identityId }, "identity-kubernetes-auth"] as const,+ getIdentityGcpAuth: (identityId: string) => [{ identityId }, "identity-gcp-auth"] as const,+ getIdentityAwsAuth: (identityId: string) => [{ identityId }, "identity-aws-auth"] as const};export const useGetIdentityUniversalAuth = (identityId: string) => {diff --cc frontend/src/views/Org/MembersPage/components/OrgIdentityTab/components/IdentitySection/IdentityAuthMethodModal.tsxindex e3ecd9414c,74c4c7f6de..b088770502--- a/frontend/src/views/Org/MembersPage/components/OrgIdentityTab/components/IdentitySection/IdentityAuthMethodModal.tsx+++ b/frontend/src/views/Org/MembersPage/components/OrgIdentityTab/components/IdentitySection/IdentityAuthMethodModal.tsx@@@ -15,7 -15,7 +15,8 @@@ import { IdentityAuthMethod } from "@apimport { UsePopUpState } from "@app/hooks/usePopUp";import { IdentityAwsAuthForm } from "./IdentityAwsAuthForm";+ import { IdentityGcpAuthForm } from "./IdentityGcpAuthForm";+import { IdentityKubernetesAuthForm } from "./IdentityKubernetesAuthForm";import { IdentityUniversalAuthForm } from "./IdentityUniversalAuthForm";type Props = {@@@ -29,8 -29,8 +30,9 @@@const identityAuthMethods = [{ label: "Universal Auth", value: IdentityAuthMethod.UNIVERSAL_AUTH },- { label: "AWS Auth", value: IdentityAuthMethod.AWS_AUTH },- { label: "Kubernetes Auth", value: IdentityAuthMethod.KUBERNETES_AUTH }++ { label: "Kubernetes Auth", value: IdentityAuthMethod.KUBERNETES_AUTH },+ { label: "GCP Auth", value: IdentityAuthMethod.GCP_AUTH },+ { label: "AWS Auth", value: IdentityAuthMethod.AWS_AUTH }];const schema = yup@@@ -77,11 -77,11 +79,20 @@@ export const IdentityAuthMethodModal =/>);}+ case IdentityAuthMethod.KUBERNETES_AUTH: {+ return (+ <IdentityKubernetesAuthForm+ handlePopUpOpen={handlePopUpOpen}+ handlePopUpToggle={handlePopUpToggle}++ identityAuthMethodData={identityAuthMethodData}++ />++ );++ }+ case IdentityAuthMethod.GCP_AUTH: {+ return (+ <IdentityGcpAuthForm+ handlePopUpOpen={handlePopUpOpen}+ handlePopUpToggle={handlePopUpToggle}identityAuthMethodData={identityAuthMethodData}/>);