在 AKS 和 EKS 上使用边车身份验证进行工作负载身份联合

借助工作负载身份联合 (WIF),您的 Apigee 工作负载可以使用来自外部提供方的凭据来获取 Apigee API 的 Google 安全令牌。本页面介绍了如何使用边车容器为 Apigee Hybrid 配置 WIF。此方法是使用 Kubernetes Projected 服务账号令牌的替代方案,如在 AKS 和 EKS 上启用工作负载身份联合中所述。如果您必须使用外部或自定义身份提供方 (IDP) 来获取身份验证令牌,请使用 Sidecar 方法。

借助此方法,您可以在非 GKE 平台上将边车与工作负载身份联合搭配使用,以装载来自首选身份提供方 (IDP) 的安全令牌,用于服务账号身份验证。

准备工作

此过程假定您已为 Google Cloud 云项目配置了工作负载身份联合,包括创建身份池和提供方,以及向 Kubernetes 服务账号授予适当的 IAM 权限。如需了解详情,请参阅在 AKS 和 EKS 上启用工作负载身份联合。

配置 Apigee Hybrid

如需启用使用边车身份验证的工作负载身份联合,请在 overrides.yaml 文件中配置边车。指定边车容器以及在边车与 Apigee Hybrid 组件之间共享数据的任何卷。如果您使用 Vault,请添加边车从 IDP 获取令牌所需的注释。

您只需在 overrides.yaml 文件中为所有组件配置一次 gcp.federatedWorkloadIdentity.sidecarSpec 部分。应用配置后,Helm 图表会在遇到值 APIGEE_COMPONENT 的任何位置插入相应组件的名称。

将以下配置添加到 overrides.yaml 文件中。选择与您的使用情形、Kubernetes Secret、服务账号 JSON 密钥文件或 Vault 相符的示例:

Secret 或文件

gcp:
  federatedWorkloadIdentity:
    enabled: true
    type: "sidecar"
    sidecarSpec:
      volumes: source-creds
      - name:
        secret:
          secretName: apigee-hybrid-APIGEE_COMPONENT
      container:
      - name: apigee-fwi-sidecar
        env: APIGEE_COMPONENT
        image: your-custom-sidecar-image
        volumeMounts:
        - name: shared-mount
          mountPath: /shared
        - name: source-creds
          mountPath: /source-creds
          readonly: true

保险柜

gcp:
  federatedWorkloadIdentity:
    enabled: true
    type: "sidecar"
    sidecarSpec:
      annotations:
      - vault.hashicorp.com/agent-inject: 'true'
      - vault.hashicorp.com/agent-pre-populate-only: 'false'
      - vault.hashicorp.com/log-level: 'trace'
      - vault.hashicorp.com/ca-cert: VAULT_CA_CERT_PATH
      - vault.hashicorp.com/namespace: 'VAULT_NAMESPACE'
      - vault.hashicorp.com/agent-service-account-token-volume-name: VAULT_TOKEN # for example: 'vault-token'
      - vault.hashicorp.com/secret-volume-path: VAULT_SECRET_VOLUME_PATH # for example: '/var/vault-data'
      - vault.hashicorp.com/service: VAULT_SERVICE_URL:8200 # For example: '127.0.0.1:8200' or 'https://dev-hcvault.nam.nsroot.net:8200'
      volumes: source-creds
      - name:
        secret:
          secretName: apigee-hybrid-APIGEE_COMPONENT
      container:
      - name: apigee-fwi-sidecar
        env: APIGEE_COMPONENT
        image: your-custom-sidecar-image
        volumeMounts:
        - name: shared-mount
          mountPath: /shared
        - name: source-creds
          mountPath: /source-creds
          readonly: true

如果您的边车需要通过 Vault 注释注入 Secret,您可以将这些注释添加到需要边车的每个组件。例如:

mart:
  annotations:
    vault.hashicorp.com/agent-inject: "true"
    vault.hashicorp.com/role: "VAULT_ROLE"
    vault.hashicorp.com/agent-inject-secret-token: "VAULT_SECRET_PATH"
    vault.hashicorp.com/agent-inject-template-token: |
      }- with secret "VAULT_SECRET_PATH" -}}
      {{ .Data.data.token }}
      {{- end -}

runtime:
  annotations:
    vault.hashicorp.com/agent-inject: "true"
    vault.hashicorp.com/role: "VAULT_ROLE"
    vault.hashicorp.com/agent-inject-secret-token: "VAULT_SECRET_PATH"
    vault.hashicorp.com/agent-inject-template-token: |
      {{- with secret "secrets/my-secret-path" -}}
      {{ .Data.data.token }}
      {{- end -}}

... other components ...

其中:

  • gcp.federatedWorkloadIdentity.enabled:必须为 true。
  • gcp.federatedWorkloadIdentity.type:必须为 "sidecar"。这会指示 Apigee Hybrid 使用边车方法进行工作负载身份联合。
  • gcp.federatedWorkloadIdentity.sidecarSpec.container:自定义边车的 Kubernetes 容器规范。您必须指定可从 IdP 获取令牌的自定义 image。
  • gcp.federatedWorkloadIdentity.sidecarSpec.volumes:要在混合 Pod 中装载的其他卷的列表。这是装载令牌的卷。
  • gcp.federatedWorkloadIdentity.sidecarSpec.annotations:(仅限 Vault)要应用于混合 Pod 的注释的映射。
  • [component].annotations:(仅限 Vault,可选)如果您的配置需要,则为要应用于各个 Hybrid 组件的注解映射。

更新 overrides.yaml 文件后,将更改应用于集群。运行以下命令以更新每个 Hybrid 组件:

  1. 确保您位于 apigee-charts/ 目录中。
  2. 升级 Apigee Operator/Controller:
    helm upgrade operator apigee-operator/ \
      --install \
      --namespace APIGEE_NAMESPACE \
      -f OVERRIDES_FILE
    
  3. 升级 Apigee 数据存储区:
    helm upgrade datastore apigee-datastore/ \
      --install \
      --namespace APIGEE_NAMESPACE \
      -f OVERRIDES_FILE
    
  4. 升级 Apigee 遥测:
    helm upgrade telemetry apigee-telemetry/ \
      --install \
      --namespace APIGEE_NAMESPACE \
      -f OVERRIDES_FILE
    
  5. 升级 Apigee Redis:
    helm upgrade redis apigee-redis/ \
      --install \
      --namespace APIGEE_NAMESPACE \
      -f OVERRIDES_FILE
    
  6. 升级 Apigee 入站流量管理器:
    helm upgrade ingress-manager apigee-ingress-manager/ \
      --install \
      --namespace APIGEE_NAMESPACE \
      -f OVERRIDES_FILE
    
  7. 升级 Apigee 组织:
    helm upgrade ORG_NAME apigee-org/ \
      --install \
      --namespace APIGEE_NAMESPACE \
      -f OVERRIDES_FILE
    
  8. 升级环境。

    一次只能安装一个环境。使用 --set env=ENV_NAME 指定环境。

    helm upgrade ENV_RELEASE_NAME apigee-env/ \
      --install \
      --namespace APIGEE_NAMESPACE \
      --set env=ENV_NAME \
      -f OVERRIDES_FILE
    
  9. 升级环境组 (virtualhosts)。

    一次只能升级一个环境组 (virtualhost)。使用 --set envgroup=ENV_GROUP_NAME 指定环境组。对 override.yaml 文件中提到的每个环境组重复运行以下命令:

    helm upgrade ENV_GROUP_RELEASE_NAME apigee-virtualhost/ \
      --install \
      --namespace APIGEE_NAMESPACE \
      --set envgroup=ENV_GROUP_NAME \
      -f OVERRIDES_FILE
    

有关详情,请参阅: