Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Add unique constraints for ssh login user and login user mapping tables

Tuan Dang9e0fdb10b151
diff --git a/backend/src/db/migrations/20250405185753_ssh-mgmt-v2.ts b/backend/src/db/migrations/20250405185753_ssh-mgmt-v2.ts
index 3f7b4e2bf7..560fca9b11 100644
--- a/backend/src/db/migrations/20250405185753_ssh-mgmt-v2.ts
+++ b/backend/src/db/migrations/20250405185753_ssh-mgmt-v2.ts
@@ -29,6 +29,7 @@ export async function up(knex: Knex): Promise<void> {
t.uuid("sshHostId").notNullable();
t.foreign("sshHostId").references("id").inTable(TableName.SshHost).onDelete("CASCADE");
t.string("loginUser").notNullable(); // e.g. ubuntu, root, ec2-user, ...
+ t.unique(["sshHostId", "loginUser"]);
});
await createOnUpdateTrigger(knex, TableName.SshHostLoginUser);
}
@@ -41,6 +42,7 @@ export async function up(knex: Knex): Promise<void> {
t.foreign("sshHostLoginUserId").references("id").inTable(TableName.SshHostLoginUser).onDelete("CASCADE");
t.uuid("userId").nullable();
t.foreign("userId").references("id").inTable(TableName.Users).onDelete("CASCADE");
+ t.unique(["sshHostLoginUserId", "userId"]);
});
await createOnUpdateTrigger(knex, TableName.SshHostLoginUserMapping);
}
diff --git a/backend/src/ee/services/ssh-host/ssh-host-service.ts b/backend/src/ee/services/ssh-host/ssh-host-service.ts
index 20d3639573..69807431a7 100644
--- a/backend/src/ee/services/ssh-host/ssh-host-service.ts
+++ b/backend/src/ee/services/ssh-host/ssh-host-service.ts
@@ -188,20 +188,6 @@ export const sshHostServiceFactory = ({
});
const newSshHost = await sshHostDAL.transaction(async (tx) => {
- const existingHost = await sshHostDAL.findOne(
- {
- projectId,
- hostname
- },
- tx
- );
-
- if (existingHost) {
- throw new BadRequestError({
- message: `SSH host with hostname ${hostname} already exists`
- });
- }
-
const host = await sshHostDAL.create(
{
projectId,