From 42aa3c3d466d322b2f7f45807763a81d78722e53 Mon Sep 17 00:00:00 2001 From: Tuan Dang Date: Fri, 18 Apr 2025 11:06:59 -0700 Subject: [PATCH] Remove extra tx in ssh nullable ca defaults migration, update ssh docs --- ...20250418003930_ssh-nullable-ca-defaults.ts | 30 +++---- docs/documentation/platform/ssh.mdx | 89 ++++++++++--------- 2 files changed, 57 insertions(+), 62 deletions(-) diff --git a/backend/src/db/migrations/20250418003930_ssh-nullable-ca-defaults.ts b/backend/src/db/migrations/20250418003930_ssh-nullable-ca-defaults.ts index 0711f8c18..2a0b85e1c 100644 --- a/backend/src/db/migrations/20250418003930_ssh-nullable-ca-defaults.ts +++ b/backend/src/db/migrations/20250418003930_ssh-nullable-ca-defaults.ts @@ -7,25 +7,17 @@ export async function up(knex: Knex): Promise { const hasDefaultHostCaCol = await knex.schema.hasColumn(TableName.ProjectSshConfig, "defaultHostSshCaId"); if (hasDefaultUserCaCol && hasDefaultHostCaCol) { - await knex.transaction(async (trx) => { - await trx.schema.alterTable(TableName.ProjectSshConfig, (t) => { - t.dropForeign(["defaultUserSshCaId"]); - t.dropForeign(["defaultHostSshCaId"]); - }); - await trx.schema.alterTable(TableName.ProjectSshConfig, (t) => { - // allow nullable (does not wipe existing values) - t.uuid("defaultUserSshCaId").nullable().alter(); - t.uuid("defaultHostSshCaId").nullable().alter(); - // re-add with SET NULL behavior (previously CASCADE) - t.foreign("defaultUserSshCaId") - .references("id") - .inTable(TableName.SshCertificateAuthority) - .onDelete("SET NULL"); - t.foreign("defaultHostSshCaId") - .references("id") - .inTable(TableName.SshCertificateAuthority) - .onDelete("SET NULL"); - }); + await knex.schema.alterTable(TableName.ProjectSshConfig, (t) => { + t.dropForeign(["defaultUserSshCaId"]); + t.dropForeign(["defaultHostSshCaId"]); + }); + await knex.schema.alterTable(TableName.ProjectSshConfig, (t) => { + // allow nullable (does not wipe existing values) + t.uuid("defaultUserSshCaId").nullable().alter(); + t.uuid("defaultHostSshCaId").nullable().alter(); + // re-add with SET NULL behavior (previously CASCADE) + t.foreign("defaultUserSshCaId").references("id").inTable(TableName.SshCertificateAuthority).onDelete("SET NULL"); + t.foreign("defaultHostSshCaId").references("id").inTable(TableName.SshCertificateAuthority).onDelete("SET NULL"); }); } diff --git a/docs/documentation/platform/ssh.mdx b/docs/documentation/platform/ssh.mdx index 8b04552e7..036968930 100644 --- a/docs/documentation/platform/ssh.mdx +++ b/docs/documentation/platform/ssh.mdx @@ -139,60 +139,63 @@ Once Infisical SSH is configured by an administrator, users can SSH to the remot The `infisical ssh connect` command can be used in either interactive or non-interactive mode to connect to a remote host. - ### Interactive Mode - In interactive mode, you'll first need to authenticate with Infisical by running: + + + In interactive mode, you'll first need to authenticate with Infisical by running: - ```bash - infisical login - ``` + ```bash + infisical login + ``` - Then simply run: + Then simply run: - ```bash - infisical ssh connect - ``` + ```bash + infisical ssh connect + ``` - You'll be prompted to select an SSH Host from a list of accessible hosts; this is based on project membership and login mappings configured on hosts by - the administrator. + You'll be prompted to select an SSH Host from a list of accessible hosts; this is based on project membership and login mappings configured on hosts by + the administrator. - ```bash - Use the arrow keys to navigate: ↓ ↑ → ← - ? Select an SSH Host: - ▸ ec2-12-345-678-910.ap-northeast-1.compute.amazonaws.com - ``` + ```bash + Use the arrow keys to navigate: ↓ ↑ → ← + ? Select an SSH Host: + ▸ ec2-12-345-678-910.ap-northeast-1.compute.amazonaws.com + ``` - After selecting a host, you'll be prompted to select a login user from a list of allowed login users: + After selecting a host, you'll be prompted to select a login user from a list of allowed login users: - ```bash - ? Select Login User: - ▸ ec2-user - ``` + ```bash + ? Select Login User: + ▸ ec2-user + ``` - If successful, you should be able to SSH to the remote host. + If successful, you should be able to SSH to the remote host. - ```bash - ✔ ec2-54-199-104-116.ap-northeast-1.compute.amazonaws.com - ✔ ec2-user - ✔ SSH credentials successfully added to agent - Connecting to ec2-user@ec2-12-345-678-910.ap-northeast-1.compute.amazonaws.com... - ``` + ```bash + ✔ ec2-54-199-104-116.ap-northeast-1.compute.amazonaws.com + ✔ ec2-user + ✔ SSH credentials successfully added to agent + Connecting to ec2-user@ec2-12-345-678-910.ap-northeast-1.compute.amazonaws.com... + ``` + + + For CI/CD pipelines or automation scenarios, you can use the non-interactive mode with an Infisical token: - ### Non-Interactive Mode - For CI/CD pipelines or automation scenarios, you can use the non-interactive mode with an Infisical token: + ```bash + infisical ssh connect \ + --hostname ec2-12-345-678-910.ap-northeast-1.compute.amazonaws.com \ + --loginUser ec2-user \ + --outFilePath ~/.ssh/id_rsa-cert.pub \ + --token + ``` - ```bash - infisical ssh connect \ - --hostname ec2-12-345-678-910.ap-northeast-1.compute.amazonaws.com \ - --loginUser ec2-user \ - --outFilePath ~/.ssh/id_rsa-cert.pub \ - --token - ``` - - This will: - - Connect to the specified hostname - - Use the specified login user - - Write the SSH credentials to the specified path instead of adding them to the SSH agent - - Authenticate using the provided Infisical token + This will: + - Connect to the specified hostname + - Use the specified login user + - Write the SSH credentials to the specified path instead of adding them to the SSH agent + - Authenticate using the provided Infisical token + +