外部密钥(External secrets)#
功能可用性
- 外部密钥可用于企业自建版和企业云版计划。
- n8n 支持 AWS Secrets Manager、Azure Key Vault、GCP Secrets Manager、Infisical 和 HashiCorp Vault。
- n8n 不支持 HashiCorp Vault Secrets。
Infisical 弃用
Infisical 已被弃用,不再推荐使用。请使用其他外部密钥提供者。
你可以使用外部秘密存储来管理 n8n 的凭据。
🌐 You can use an external secrets store to manage credentials for n8n.
n8n 将所有凭据加密存储在其数据库中,并默认限制对其的访问。通过外部机密功能,您可以将敏感凭据信息存储在外部保险库中,并在需要时让 n8n 加载它。这提供了额外的一层安全性,并允许您在一个集中位置管理跨多个 n8n 环境 使用的凭据。
🌐 n8n stores all credentials encrypted in its database, and restricts access to them by default. With the external secrets feature, you can store sensitive credential information in an external vault, and have n8n load it in when required. This provides an extra layer of security and allows you to manage credentials used across multiple n8n environments in one central place.
将 n8n 连接到你的密钥库(Connect n8n to your secrets store)#
秘密名字
您的秘密名称不能包含空格、连字符或其他特殊字符。n8n 支持包含字母数字字符(a-z、A-Z 和 0-9)及下划线的秘密名称。n8n 目前只支持秘密的明文值,不支持 JSON 对象或键值对。
- 在 n8n 中,前往 设置 > 外部密钥。
- 为你的商店提供商选择设置。
-
输入你的提供商凭据:
- Azure 密钥保管库:提供你的 保管库名称、租户 ID、客户端 ID 和 客户端密钥。请参考 Azure 文档来注册 Microsoft Entra ID 应用并创建服务主体。n8n 仅支持单行的密钥值。
-
AWS Secrets Manager:提供你的 访问密钥 ID、秘密访问密钥 和 区域。IAM 用户必须具有
secretsmanager:ListSecrets、secretsmanager:BatchGetSecretValue和secretsmanager:GetSecretValue权限。要授予 n8n 对 AWS Secrets Manager 中所有密钥的访问权限,你可以将以下策略附加到 IAM 用户:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AccessAllSecrets", "Effect": "Allow", "Action": [ "secretsmanager:ListSecrets", "secretsmanager:BatchGetSecretValue", "secretsmanager:GetResourcePolicy", "secretsmanager:GetSecretValue", "secretsmanager:DescribeSecret", "secretsmanager:ListSecretVersionIds", ], "Resource": "*" } ] }你也可以设置更严格的权限,只允许 n8n 访问特定的 AWS Secret Manager 密钥。你仍然需要允许
secretsmanager:ListSecrets和secretsmanager:BatchGetSecretValue权限才能访问所有资源。这些权限允许 n8n 获取 ARN 范围的密钥,但不会提供对密钥值的访问权限。接下来,你需要将
secretsmanager:GetSecretValue权限的范围设置为你希望与 n8n 共享的机密的特定 Amazon 资源名称(ARN)。确保在每个资源 ARN 中使用正确的区域和账户 ID。你可以在 AWS 仪表板中找到机密的 ARN 详细信息。例如,以下 IAM 策略仅允许访问你指定的 AWS 账户和区域中名称以
n8n开头的机密:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
{ "Version": "2012-10-17", "Statement": [ { "Sid": "ListingSecrets", "Effect": "Allow", "Action": [ "secretsmanager:ListSecrets", "secretsmanager:BatchGetSecretValue" ], "Resource": "*" }, { "Sid": "RetrievingSecrets", "Effect": "Allow", "Action": [ "secretsmanager:GetSecretValue", "secretsmanager:DescribeSecret" ], "Resource": [ "arn:aws:secretsmanager:us-west-2:123456789000:secret:n8n*" ] } ] }有关更多 IAM 权限策略示例,请查阅 AWS 文档。
-
HashiCorp Vault:提供你的 Vault 实例的 Vault URL,并选择你的 身份验证方法。输入你的身份验证信息。可选择提供命名空间。
- 请参阅 HashiCorp 文档了解你的认证方法: Token 认证方法 AppRole 认证方法 Userpass 认证方法
- 如果你使用 Vault 命名空间,你可以输入 n8n 应该连接的命名空间。有关 HashiCorp Vault 命名空间的更多信息,请参阅 Vault Enterprise 命名空间。
-
Infisical:提供一个 服务令牌。有关获取令牌的信息,请参阅 Infisical 的 服务令牌 文档。如果你自行托管 Infisical,请输入 站点 URL。
Infisical 环境
在创建令牌时,请确保选择正确的 Infisical 环境。n8n 会从该环境加载机密,并且无法访问其他 Infisical 环境中的机密。n8n 仅支持可以访问单个环境的服务令牌。
Infisical 文件夹
n8n 不支持 Infisical 文件夹。
-
Google Cloud Platform:为具有至少以下角色的服务账号提供 服务账号密钥(JSON):
Secret Manager Secret Accessor和Secret Manager Secret Viewer。有关更多信息,请参阅谷歌的服务账号文档。 1. 保存你的配置。 1. 使用 禁用 / 启用 切换来启用提供程序。
在 n8n 凭据中使用密钥(Use secrets in n8n credentials)#
要在 n8n 凭据中使用来自你存储的密钥:
🌐 To use a secret from your store in an n8n credential:
- 创建新的凭据,或打开现有凭据
- 在要使用密钥的字段中:
- 鼠标悬停在字段上。
- 选择 表达式。
-
在你想要使用秘密的字段中,输入引用该秘密名称的表达式:
1{{ $secrets.<vault-name>.<secret-name> }}<vault-name>is eithervault(for HashiCorp) orinfisicalorawsSecretsManager. Replace<secret-name>with the name as it appears in your vault.
在 n8n 环境中使用外部密钥(Using external secrets with n8n environments)#
n8n 的源代码控制和环境功能允许您创建不同的 n8n 环境,并由 Git 支持。该功能不支持在不同实例中使用不同的凭据。您可以使用外部秘密管理库来为不同环境提供不同的凭据,通过将每个 n8n 实例连接到不同的管理库或项目环境来实现。
🌐 n8n's Source control and environments feature allows you to create different n8n environments, backed by Git. The feature doesn't support using different credentials in different instances. You can use an external secrets vault to provide different credentials for different environments by connecting each n8n instance to a different vault or project environment.
例如,你有两个 n8n 实例,一个用于开发,一个用于生产。你使用 Infisical 作为你的密钥库。在 Infisical 中创建一个包含两个环境(开发和生产)的项目。为每个 Infisical 环境生成一个令牌。使用开发环境的令牌连接你的开发 n8n 实例,使用生产环境的令牌连接你的生产 n8n 实例。
🌐 For example, you have two n8n instances, one for development and one for production. You use Infisical for your vault. In Infisical, create a project with two environments, development and production. Generate a token for each Infisical environment. Use the token for the development environment to connect your development n8n instance, and the token for your production environment to connect your production n8n instance.
在项目中使用外部密钥(Using external secrets in projects)#
要在 RBAC 项目 中使用外部密钥,你必须在项目中拥有 实例所有者或实例管理员 的身份。
🌐 To use external secrets in an RBAC project, you must have an instance owner or instance admin as a member of the project.
故障排除(Troubleshooting)#
Infisical 版本变更(Infisical version changes)#
Infisical 的版本升级可能会导致与 n8n 的连接出现问题。如果你的 Infisical 连接停止工作,请检查是否最近有版本更改。如果有,请将问题报告给 help@n8n.io。
🌐 Infisical version upgrades can introduce problems connecting to n8n. If your Infisical connection stops working, check if there was a recent version change. If so, report the issue to help@n8n.io.
仅对实例所有者或管理员拥有的凭据设置外部密钥(Only set external secrets on credentials owned by an instance owner or admin)#
由于实例所有者和管理员拥有的权限,所有者和管理员可以使用机密表达式更新其他用户拥有的凭据。在预览模式下,实例所有者或管理员会看到操作似乎成功,但在生产环境中运行工作流时,机密将无法解析。
🌐 Due to the permissions that instance owners and admins have, it's possible for owners and admins to update credentials owned by another user with a secrets expression. This will appear to work in preview for an instance owner or admin, but the secret won't resolve when the workflow runs in production.
仅对由实例管理员或所有者拥有的凭据使用外部密钥。这可确保它们在生产环境中正确解析。
🌐 Only use external secrets for credentials that are owned by an instance admin or owner. This ensures they resolve correctly in production.