跳至内容

外部密钥#

功能可用性

  • 外部密钥功能适用于企业自托管版和企业云版计划。
  • n8n支持AWS Secrets Manager、Azure Key Vault、GCP Secrets Manager、Infisical和HashiCorp Vault。
  • n8n不支持HashiCorp Vault Secrets

您可以使用外部密钥存储来管理n8n的凭证

n8n将所有凭证加密存储在其数据库中,默认情况下限制对其的访问。通过外部密钥功能,您可以将敏感凭证信息存储在外部保险库中,并在需要时由n8n加载。这提供了额外的安全层,并允许您在一个中心位置管理跨多个n8n环境使用的凭证。

将n8n连接到您的密钥存储库#

密钥名称

您的密钥名称不能包含空格、连字符或其他特殊字符。n8n支持的密钥名称可包含字母数字字符(a-zA-Z0-9)以及下划线。

  1. 在n8n中,前往设置 > 外部密钥
  2. 为您的店铺提供商选择设置
  3. 输入您的提供商凭据:

    • Azure Key Vault: 提供您的保管库名称租户ID客户端ID客户端密钥。请参考Azure文档注册Microsoft Entra ID应用并创建服务主体。n8n仅支持单行值的密钥。
    • AWS Secrets Manager: provide your access key ID, secret access key, and region. The IAM user must have the secretsmanager:ListSecrets, secretsmanager:BatchGetSecretValue, and secretsmanager:GetSecretValue permissions.

      To give n8n access to all secrets in your AWS Secrets Manager, you can attach the following policy to the IAM user:

       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": "*"
      		}
      	]
      }
      

      You can also be more restrictive and give n8n access to select specific AWS Secret Manager secrets. You still need to allow the secretsmanager:ListSecrets and secretsmanager:BatchGetSecretValue permissions to access all resources. These permissions allow n8n to retrieve ARN-scoped secrets, but don't provide access to the secret values.

      Next, you need set the scope for the secretsmanager:GetSecretValue permission to the specific Amazon Resource Names (ARNs) for the secrets you wish to share with n8n. Ensure you use the correct region and account ID in each resource ARNs. You can find the ARN details in the AWS dashboard for your secrets.

      For example, the following IAM policy only allows access to secrets with a name starting with n8n in your specified AWS account and region:

       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*"
      			]
      		}
      	]
      }
      

      For more IAM permission policy examples, consult the AWS documentation.

    • HashiCorp Vault: 提供您的保险库实例的Vault URL,并选择您的认证方式。输入您的认证详细信息。可选择性地提供一个命名空间。

    • Infisical: 提供一个服务令牌。关于如何获取令牌的信息,请参考Infisical的服务令牌文档。如果您自托管Infisical,请输入站点URL

      Infisical环境

      创建令牌时请确保选择正确的Infisical环境。n8n将从此环境加载密钥,无法访问其他Infisical环境中的密钥。n8n仅支持访问单一环境的服务令牌。

      Infisical文件夹

      n8n不支持Infisical文件夹

    • Google Cloud Platform: 提供一个服务账号密钥 (JSON格式),该服务账号至少需要拥有以下角色:Secret Manager Secret AccessorSecret Manager Secret Viewer。更多信息请参考Google的服务账号文档

  4. 保存您的配置。

  5. 使用禁用/启用开关来启用该提供程序。

在n8n凭证中使用密钥#

要在n8n凭证中使用存储的密钥:

  1. 创建新凭据,或打开现有凭据。
  2. On the field where you want to use a secret:
    1. 将鼠标悬停在字段上。
    2. 选择表达式
  3. 在需要使用密钥的字段中,输入引用密钥名称的表达式
    1
    {{ $secrets.<vault-name>.<secret-name> }}
    
    可以是vault(用于HashiCorp)或infisicalawsSecretsManager。将替换为您的密钥库中显示的密钥名称。

在n8n环境中使用外部密钥#

n8n的源代码控制和环境功能允许您创建不同的n8n环境,由Git支持。该功能不支持在不同实例中使用不同的凭据。您可以通过将每个n8n实例连接到不同的保险库或项目环境,使用外部密钥保险库为不同环境提供不同的凭据。

例如,您有两个n8n实例,一个用于开发环境,另一个用于生产环境。您使用Infisical作为密钥库。在Infisical中创建一个包含两个环境(开发和生产)的项目。为每个Infisical环境生成一个令牌。使用开发环境的令牌连接您的开发n8n实例,使用生产环境的令牌连接您的生产n8n实例。

在项目中使用外部密钥#

要在RBAC项目中使用外部密钥,您必须拥有实例所有者或实例管理员作为项目成员。

故障排除#

Infisical版本变更#

Infisical版本升级可能导致与n8n的连接问题。如果您的Infisical连接停止工作,请检查最近是否有版本变更。若有变更,请将问题报告至help@n8n.io。

仅对实例所有者或管理员拥有的凭据设置外部密钥#

由于实例所有者和管理员拥有的权限,所有者和管理员可以使用密钥表达式更新其他用户拥有的凭据。对于实例所有者或管理员来说,这在预览中看起来是可行的,但当工作流在生产环境中运行时,密钥将无法解析。

仅对实例管理员或所有者拥有的凭据使用外部密钥。这可以确保在生产环境中正确解析它们。

优云智算