Merge branch 'main' into ENG-3802

This commit is contained in:
x032205
2025-10-10 14:39:16 -04:00
923 changed files with 15911 additions and 12423 deletions
@@ -127,7 +127,8 @@ export async function down(knex: Knex): Promise<void> {
});
await knex.schema.alterTable(TableName.SecretApprovalPolicyApprover, (tb) => {
tb.dropColumn("approverUserId");
tb.uuid("approverId").notNullable().alter();
// akhilmhdh: i had to comment this out and is not possible as membership is now changed in structure
// tb.uuid("approverId").notNullable().alter();
});
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,19 @@
import { Knex } from "knex";
import { TableName } from "../schemas";
export async function up(knex: Knex): Promise<void> {
if (!(await knex.schema.hasColumn(TableName.KmsKey, "kmipMetadata"))) {
await knex.schema.alterTable(TableName.KmsKey, (t) => {
t.jsonb("kmipMetadata");
});
}
}
export async function down(knex: Knex): Promise<void> {
if (await knex.schema.hasColumn(TableName.KmsKey, "kmipMetadata")) {
await knex.schema.alterTable(TableName.KmsKey, (t) => {
t.dropColumn("kmipMetadata");
});
}
}
@@ -0,0 +1,30 @@
// 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 AdditionalPrivilegesSchema = z.object({
id: z.string().uuid(),
name: z.string(),
isTemporary: z.boolean().default(false),
temporaryMode: z.string().nullable().optional(),
temporaryRange: z.string().nullable().optional(),
temporaryAccessStartTime: z.date().nullable().optional(),
temporaryAccessEndTime: z.date().nullable().optional(),
permissions: z.unknown(),
actorUserId: z.string().uuid().nullable().optional(),
actorIdentityId: z.string().uuid().nullable().optional(),
orgId: z.string().uuid().nullable().optional(),
projectId: z.string().nullable().optional(),
namespaceId: z.string().uuid().nullable().optional(),
createdAt: z.date(),
updatedAt: z.date()
});
export type TAdditionalPrivileges = z.infer<typeof AdditionalPrivilegesSchema>;
export type TAdditionalPrivilegesInsert = Omit<z.input<typeof AdditionalPrivilegesSchema>, TImmutableDBKeys>;
export type TAdditionalPrivilegesUpdate = Partial<Omit<z.input<typeof AdditionalPrivilegesSchema>, TImmutableDBKeys>>;
+5
View File
@@ -3,6 +3,7 @@ export * from "./access-approval-policies-approvers";
export * from "./access-approval-policies-bypassers";
export * from "./access-approval-requests";
export * from "./access-approval-requests-reviewers";
export * from "./additional-privileges";
export * from "./api-keys";
export * from "./app-connections";
export * from "./audit-log-streams";
@@ -73,8 +74,11 @@ export * from "./kms-keys";
export * from "./kms-root-config";
export * from "./ldap-configs";
export * from "./ldap-group-maps";
export * from "./membership-roles";
export * from "./memberships";
export * from "./microsoft-teams-integrations";
export * from "./models";
export * from "./namespaces";
export * from "./oidc-configs";
export * from "./org-bots";
export * from "./org-gateway-config";
@@ -108,6 +112,7 @@ export * from "./projects";
export * from "./rate-limit";
export * from "./relays";
export * from "./resource-metadata";
export * from "./roles";
export * from "./saml-configs";
export * from "./scim-tokens";
export * from "./secret-approval-policies";
+2 -1
View File
@@ -17,7 +17,8 @@ export const KmsKeysSchema = z.object({
createdAt: z.date(),
updatedAt: z.date(),
projectId: z.string().nullable().optional(),
keyUsage: z.string().default("encrypt-decrypt")
keyUsage: z.string().default("encrypt-decrypt"),
kmipMetadata: z.unknown().nullable().optional()
});
export type TKmsKeys = z.infer<typeof KmsKeysSchema>;
@@ -0,0 +1,26 @@
// 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 MembershipRolesSchema = z.object({
id: z.string().uuid(),
role: z.string(),
isTemporary: z.boolean().default(false),
temporaryMode: z.string().nullable().optional(),
temporaryRange: z.string().nullable().optional(),
temporaryAccessStartTime: z.date().nullable().optional(),
temporaryAccessEndTime: z.date().nullable().optional(),
customRoleId: z.string().uuid().nullable().optional(),
membershipId: z.string().uuid(),
createdAt: z.date(),
updatedAt: z.date()
});
export type TMembershipRoles = z.infer<typeof MembershipRolesSchema>;
export type TMembershipRolesInsert = Omit<z.input<typeof MembershipRolesSchema>, TImmutableDBKeys>;
export type TMembershipRolesUpdate = Partial<Omit<z.input<typeof MembershipRolesSchema>, TImmutableDBKeys>>;
+32
View File
@@ -0,0 +1,32 @@
// 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 MembershipsSchema = z.object({
id: z.string().uuid(),
scope: z.string(),
actorUserId: z.string().uuid().nullable().optional(),
actorIdentityId: z.string().uuid().nullable().optional(),
actorGroupId: z.string().uuid().nullable().optional(),
scopeOrgId: z.string().uuid(),
scopeProjectId: z.string().nullable().optional(),
scopeNamespaceId: z.string().uuid().nullable().optional(),
isActive: z.boolean().default(true),
status: z.string().nullable().optional(),
inviteEmail: z.string().nullable().optional(),
lastInvitedAt: z.date().nullable().optional(),
lastLoginAuthMethod: z.string().nullable().optional(),
lastLoginTime: z.date().nullable().optional(),
projectFavorites: z.string().array().nullable().optional(),
createdAt: z.date(),
updatedAt: z.date()
});
export type TMemberships = z.infer<typeof MembershipsSchema>;
export type TMembershipsInsert = Omit<z.input<typeof MembershipsSchema>, TImmutableDBKeys>;
export type TMembershipsUpdate = Partial<Omit<z.input<typeof MembershipsSchema>, TImmutableDBKeys>>;
+40
View File
@@ -178,6 +178,14 @@ export enum TableName {
SecretScanningScan = "secret_scanning_scans",
SecretScanningFinding = "secret_scanning_findings",
SecretScanningConfig = "secret_scanning_configs",
Membership = "memberships",
MembershipRole = "membership_roles",
Role = "roles",
AdditionalPrivilege = "additional_privileges",
Namespace = "namespaces",
// reminders
Reminder = "reminders",
ReminderRecipient = "reminders_recipients",
@@ -302,7 +310,39 @@ export enum ActionProjectType {
Any = "any"
}
export enum TemporaryPermissionMode {
Relative = "relative"
}
export enum MembershipActors {
Group = "group",
User = "user",
Identity = "identity"
}
export enum SortDirection {
ASC = "asc",
DESC = "desc"
}
export enum AccessScope {
Organization = "organization",
Namespace = "namespace",
Project = "project"
}
export type AccessScopeData =
| {
scope: AccessScope.Organization;
orgId: string;
}
| {
scope: AccessScope.Namespace;
orgId: string;
namespaceId: string;
}
| {
scope: AccessScope.Project;
orgId: string;
projectId: string;
};
+21
View File
@@ -0,0 +1,21 @@
// 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 NamespacesSchema = z.object({
id: z.string().uuid(),
name: z.string(),
description: z.string().nullable().optional(),
orgId: z.string().uuid(),
createdAt: z.date(),
updatedAt: z.date()
});
export type TNamespaces = z.infer<typeof NamespacesSchema>;
export type TNamespacesInsert = Omit<z.input<typeof NamespacesSchema>, TImmutableDBKeys>;
export type TNamespacesUpdate = Partial<Omit<z.input<typeof NamespacesSchema>, TImmutableDBKeys>>;
+25
View File
@@ -0,0 +1,25 @@
// 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 RolesSchema = z.object({
id: z.string().uuid(),
name: z.string(),
description: z.string().nullable().optional(),
slug: z.string(),
permissions: z.unknown(),
orgId: z.string().uuid().nullable().optional(),
projectId: z.string().nullable().optional(),
namespaceId: z.string().uuid().nullable().optional(),
createdAt: z.date(),
updatedAt: z.date()
});
export type TRoles = z.infer<typeof RolesSchema>;
export type TRolesInsert = Omit<z.input<typeof RolesSchema>, TImmutableDBKeys>;
export type TRolesUpdate = Partial<Omit<z.input<typeof RolesSchema>, TImmutableDBKeys>>;
@@ -0,0 +1,27 @@
// 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 UserNotificationsDefaultSchema = z.object({
id: z.string().uuid(),
userId: z.string().uuid(),
orgId: z.string().uuid().nullable().optional(),
type: z.string(),
title: z.string(),
body: z.string().nullable().optional(),
link: z.string().nullable().optional(),
isRead: z.boolean().default(false),
createdAt: z.date(),
updatedAt: z.date()
});
export type TUserNotificationsDefault = z.infer<typeof UserNotificationsDefaultSchema>;
export type TUserNotificationsDefaultInsert = Omit<z.input<typeof UserNotificationsDefaultSchema>, TImmutableDBKeys>;
export type TUserNotificationsDefaultUpdate = Partial<
Omit<z.input<typeof UserNotificationsDefaultSchema>, TImmutableDBKeys>
>;
+16 -7
View File
@@ -1,6 +1,6 @@
import { Knex } from "knex";
import { OrgMembershipRole, OrgMembershipStatus, TableName } from "../schemas";
import { AccessScope, OrgMembershipRole, OrgMembershipStatus, TableName } from "../schemas";
import { seedData1 } from "../seed-data";
export async function seed(knex: Knex): Promise<void> {
@@ -24,13 +24,22 @@ export async function seed(knex: Knex): Promise<void> {
])
.returning("*");
await knex(TableName.OrgMembership).insert([
const [membership] = await knex(TableName.Membership)
.insert([
{
scope: AccessScope.Organization,
scopeOrgId: org.id,
actorUserId: user.id,
isActive: true,
status: OrgMembershipStatus.Accepted
}
])
.returning("*");
await knex(TableName.MembershipRole).insert([
{
role: OrgMembershipRole.Admin,
orgId: org.id,
status: OrgMembershipStatus.Accepted,
userId: user.id,
isActive: true
membershipId: membership.id,
role: OrgMembershipRole.Admin
}
]);
}
+35 -23
View File
@@ -6,14 +6,15 @@ import { generateUserSrpKeys } from "@app/lib/crypto/srp";
import { initLogger, logger } from "@app/lib/logger";
import { alphaNumericNanoId } from "@app/lib/nanoid";
import { AuthMethod } from "@app/services/auth/auth-type";
import { membershipRoleDALFactory } from "@app/services/membership/membership-role-dal";
import { membershipUserDALFactory } from "@app/services/membership-user/membership-user-dal";
import { assignWorkspaceKeysToMembers, createProjectKey } from "@app/services/project/project-fns";
import { projectKeyDALFactory } from "@app/services/project-key/project-key-dal";
import { projectMembershipDALFactory } from "@app/services/project-membership/project-membership-dal";
import { projectUserMembershipRoleDALFactory } from "@app/services/project-membership/project-user-membership-role-dal";
import { superAdminDALFactory } from "@app/services/super-admin/super-admin-dal";
import { userDALFactory } from "@app/services/user/user-dal";
import {
AccessScope,
OrgMembershipRole,
OrgMembershipStatus,
ProjectMembershipRole,
@@ -39,8 +40,8 @@ const createUserWithGhostUser = async (
) => {
const projectKeyDAL = projectKeyDALFactory(knex);
const userDAL = userDALFactory(knex);
const projectMembershipDAL = projectMembershipDALFactory(knex);
const projectUserMembershipRoleDAL = projectUserMembershipRoleDALFactory(knex);
const membershipDAL = membershipUserDALFactory(knex);
const membershipRoleDAL = membershipRoleDALFactory(knex);
const email = `sudo-${alphaNumericNanoId(16)}-${orgId}@infisical.com`; // We add a nanoid because the email is unique. And we have to create a new ghost user each time, so we can have access to the private key.
@@ -63,25 +64,36 @@ const createUserWithGhostUser = async (
.onConflict("userId")
.merge();
await knex(TableName.OrgMembership)
const [orgMembership] = await knex(TableName.Membership)
.insert({
orgId,
userId: ghostUser.id,
role: OrgMembershipRole.Admin,
scope: AccessScope.Organization,
scopeOrgId: orgId,
actorUserId: ghostUser.id,
status: OrgMembershipStatus.Accepted,
isActive: true
})
.returning("*");
const [projectMembership] = await knex(TableName.ProjectMembership)
await knex(TableName.MembershipRole).insert([
{
membershipId: orgMembership.id,
role: OrgMembershipRole.Admin
}
]);
const [projectMembership] = await knex(TableName.Membership)
.insert({
userId: ghostUser.id,
projectId
actorUserId: ghostUser.id,
scopeProjectId: projectId,
scope: AccessScope.Project,
scopeOrgId: orgId,
status: OrgMembershipStatus.Accepted,
isActive: true
})
.returning("*");
await knex(TableName.ProjectUserMembershipRole).insert({
projectMembershipId: projectMembership.id,
await knex(TableName.MembershipRole).insert({
membershipId: projectMembership.id,
role: ProjectMembershipRole.Admin
});
@@ -142,17 +154,16 @@ const createUserWithGhostUser = async (
});
// Create a membership for the user
const userProjectMembership = await projectMembershipDAL.create(
const userProjectMembership = await membershipDAL.create(
{
projectId,
userId: user.id
scopeProjectId: projectId,
scope: AccessScope.Project,
actorUserId: user.id,
scopeOrgId: orgId
},
knex
);
await projectUserMembershipRoleDAL.create(
{ projectMembershipId: userProjectMembership.id, role: ProjectMembershipRole.Admin },
knex
);
await membershipRoleDAL.create({ membershipId: userProjectMembership.id, role: ProjectMembershipRole.Admin }, knex);
// Create a project key for the user
await projectKeyDAL.create(
@@ -195,10 +206,11 @@ export async function seed(knex: Knex): Promise<void> {
})
.returning("*");
const userOrgMembership = await knex(TableName.OrgMembership)
const userOrgMembership = await knex(TableName.Membership)
.where({
orgId: seedData1.organization.id,
userId: seedData1.id
scopeOrgId: seedData1.organization.id,
actorUserId: seedData1.id,
scope: AccessScope.Organization
})
.first();
+8 -6
View File
@@ -1,6 +1,6 @@
import { Knex } from "knex";
import { ProjectMembershipRole, ProjectType, ProjectVersion, TableName } from "../schemas";
import { AccessScope, ProjectMembershipRole, ProjectType, ProjectVersion, TableName } from "../schemas";
import { seedData1 } from "../seed-data";
export const DEFAULT_PROJECT_ENVS = [
@@ -23,15 +23,17 @@ export async function seed(knex: Knex): Promise<void> {
})
.returning("*");
const projectMembershipV3 = await knex(TableName.ProjectMembership)
const projectMembershipV3 = await knex(TableName.Membership)
.insert({
projectId: projectV2.id,
userId: seedData1.id
scopeProjectId: projectV2.id,
actorUserId: seedData1.id,
scope: AccessScope.Project,
scopeOrgId: seedData1.organization.id
})
.returning("*");
await knex(TableName.ProjectUserMembershipRole).insert({
await knex(TableName.MembershipRole).insert({
role: ProjectMembershipRole.Admin,
projectMembershipId: projectMembershipV3[0].id
membershipId: projectMembershipV3[0].id
});
// create default environments and default folders
+27 -15
View File
@@ -5,13 +5,12 @@ import { crypto } from "@app/lib/crypto/cryptography";
import { initLogger, logger } from "@app/lib/logger";
import { superAdminDALFactory } from "@app/services/super-admin/super-admin-dal";
import { IdentityAuthMethod, OrgMembershipRole, ProjectMembershipRole, TableName } from "../schemas";
import { AccessScope, IdentityAuthMethod, OrgMembershipRole, ProjectMembershipRole, TableName } from "../schemas";
import { seedData1 } from "../seed-data";
export async function seed(knex: Knex): Promise<void> {
// Deletes ALL existing entries
await knex(TableName.Identity).del();
await knex(TableName.IdentityOrgMembership).del();
initLogger();
@@ -78,34 +77,47 @@ export async function seed(knex: Knex): Promise<void> {
isClientSecretRevoked: false
}
]);
await knex(TableName.IdentityOrgMembership).insert([
const [orgMembership] = await knex(TableName.Membership)
.insert([
{
actorIdentityId: seedData1.machineIdentity.id,
scopeOrgId: seedData1.organization.id,
scope: AccessScope.Organization
}
])
.returning("*");
await knex(TableName.MembershipRole).insert([
{
identityId: seedData1.machineIdentity.id,
orgId: seedData1.organization.id,
membershipId: orgMembership.id,
role: OrgMembershipRole.Admin
}
]);
const identityProjectMembership = await knex(TableName.IdentityProjectMembership)
const identityProjectMembership = await knex(TableName.Membership)
.insert({
identityId: seedData1.machineIdentity.id,
projectId: seedData1.project.id
actorIdentityId: seedData1.machineIdentity.id,
scopeOrgId: seedData1.organization.id,
scope: AccessScope.Project,
scopeProjectId: seedData1.project.id
})
.returning("*");
await knex(TableName.IdentityProjectMembershipRole).insert({
await knex(TableName.MembershipRole).insert({
role: ProjectMembershipRole.Admin,
projectMembershipId: identityProjectMembership[0].id
membershipId: identityProjectMembership[0].id
});
const identityProjectMembershipV3 = await knex(TableName.IdentityProjectMembership)
const identityProjectMembershipV3 = await knex(TableName.Membership)
.insert({
identityId: seedData1.machineIdentity.id,
projectId: seedData1.projectV3.id
actorIdentityId: seedData1.machineIdentity.id,
scopeOrgId: seedData1.organization.id,
scope: AccessScope.Project,
scopeProjectId: seedData1.projectV3.id
})
.returning("*");
await knex(TableName.IdentityProjectMembershipRole).insert({
await knex(TableName.MembershipRole).insert({
role: ProjectMembershipRole.Admin,
projectMembershipId: identityProjectMembershipV3[0].id
membershipId: identityProjectMembershipV3[0].id
});
}