GCPCredentialsControllerService Controller Service
描述
为 Google Cloud Platform 处理器定义凭证。使用应用默认凭证
标签
属性
| 名称 | 默认值 | 可选值 | 描述 |
|---|---|---|---|
| Authentication Strategy | Application Default Credentials |
| 指定 Lynxus 如何向 Google Cloud 进行身份验证。 根据策略的不同,可能需要其他属性。 |
| Service Account JSON File | | 包含 JSON 格式的服务帐户密钥文件的文件的路径。 | |
| Service Account JSON | | 包含服务帐户密钥文件的原始 JSON。 敏感属性:是 支持表达式语言:是(仅使用环境/系统变量求值) | |
| Audience | | 与目标工作负载身份提供者对应的受众,通常是完整的资源名称。 | |
| Scope | https://www.googleapis.com/auth/cloud-platform | 请求交换的访问令牌的 OAuth2 范围。 多个范围可以用空格或逗号分隔。 | |
| STS Token Endpoint | https://sts.googleapis.com/v1/token | 用于令牌交换的 Google 安全令牌服务端点。 | |
| Subject Token Provider | | 控制器服务 API:OAuth2AccessTokenProvidercn.org.acal.lynxus-lynxus-standard-services-api-nar-2.11.8 | 检索外部工作负载身份令牌以进行交换的Controller Service。 |
| Subject Token Type | urn:ietf:params:oauth:token-type:jwt |
| 主题令牌提供者返回的令牌类型。 |
| Proxy Configuration Service | | 控制器服务 API:ProxyConfigurationServicecn.org.acal.lynxus-lynxus-standard-services-api-nar-2.11.8 | 指定代理配置 Controller Service 来代理网络请求。 |
| Delegation Strategy | Service Account |
| 委派策略决定使用 GCP 凭证进行调用时使用哪个帐户。 |
| Delegation User | | 此用户将被服务账户模拟以进行 API 调用。使用此凭证进行的 API 调用将显示为来自委托用户,具有委托用户的访问权限。从此凭证的处理器提供的任何范围都必须与服务账户设置域范围委派。 支持表达式语言:是(仅使用环境/系统变量求值) |
状态管理
该组件不存储状态。
受限 (Restricted)
该组件不受限。
提供的 Service API
GCPCredentialsService
详细说明
GCPCredentialsControllerService
GCPCredentialsControllerService 集中管理所有与 Google Cloud 交互的 Lynxus 组件所使用的认证策略。每种策略只暴露自己需要的属性,让管理员 无需改动下游 Processor 即可切换方式。本指南概述所有受支持的策略。
Application Default Credentials
Application Default Credentials(ADC)让 Lynxus 继承运行时环境提供的 凭据,包括:
- 引用服务账号密钥文件的
GOOGLE_APPLICATION_CREDENTIALS环境变量 - 开发机上的
gcloud auth application-default login - Cloud Shell 或其他自动注入 ADC 的 Google 托管环境
不需要额外属性。请确认提供 ADC 令牌的账号具备引用该 Controller Service 的 Processor 所需的 IAM 角色。
Service Account Credentials(JSON 文件)
当服务账号密钥材料存储在磁盘上时使用该策略。把 Service Account JSON File 属性配置为指向 JSON 密钥文件。Lynxus 在启用该 Controller Service 时读取文件并缓存 Google 凭据。
最佳实践
- 限制文件系统权限,确保只有 Lynxus 服务用户可以读取密钥。
- 定期轮换密钥,并在 Google Cloud Console 中删除未使用的密钥。
- 模拟(impersonate)域用户时,把 Delegation Strategy 设为 Delegated Account 并提供 Delegation User,让 Lynxus 代表 该用户调用 Google API。
Service Account Credentials(JSON 值)
该策略把整个服务账号 JSON 文档直接嵌入 Controller Service 属性。 该值被标记为敏感值,可以通过参数上下文(Parameter Context)注入, 把凭据与流程定义分离。
最佳实践
- 把 JSON 值存放在该属性引用的参数上下文中,以便按环境切换凭据。
- 使用
lynxus.properties中 Lynxus 的敏感属性加密功能,对磁盘上 存储的 JSON 加密。
Compute Engine Credentials
当 Lynxus 运行在 Google 托管的运行时(Compute Engine、GKE 等)上, 应使用实例绑定的服务账号时,选择 Compute Engine Credentials。 Google 会自动刷新 metadata 服务器令牌,因此不需要额外属性。
最佳实践
- 只给实例服务账号授予流程所需的角色。
- 如果多个 Lynxus 节点共享同一实例模板,请确认所有节点都拥有相同 的 IAM 权限,或配置 Workload Identity Federation 以实现更细的管控。
Workload Identity Federation
Workload Identity Federation(WIF)通过 Google 的 Security Token
Service(STS),把外部身份提供者的令牌交换为短期 Google Cloud
访问令牌。该 Controller Service 配置 Google 的
IdentityPoolCredentials,让 Google 客户端库自动刷新
Google Cloud 令牌。
1. 在 Google Cloud 中配置 Workload Identity Federation
# 创建 pool(每个环境只需一次)
gcloud iam workload-identity-pools create lynxus-pool \
--project=MY_PROJECT_ID \
--location=global \
--display-name="Lynxus Pool"
# 创建绑定你的 IdP 的 provider(以名为 myidp 的 OIDC 为例)
gcloud iam workload-identity-pools providers create-oidc myidp \
--project=MY_PROJECT_ID \
--location=global \
--workload-identity-pool=lynxus-pool \
--display-name="My Identity Provider" \
--issuer-uri="https://identity.myidp.com/oauth2/..." \
--allowed-audiences="//iam.googleapis.com/projects/<PROJECT_NUMBER>/locations/global/workloadIdentityPools/lynxus-pool/providers/myidp" \
--attribute-mapping="google.subject=assertion.sub"
记下命令打印的 audience 字符串,必须原样复制到 Lynxus 的 Audience 属性:
//iam.googleapis.com/projects/<PROJECT_NUMBER>/locations/global/workloadIdentityPools/lynxus-pool/providers/myidp
2. 为 workload identity 主体授权 Google Cloud 资源
STS 签发的访问令牌代表的是 workload identity 主体本身。在项目或 特定资源上为该身份授予 IAM 角色:
# 项目范围
gcloud projects add-iam-policy-binding MY_PROJECT_ID \
--member="principal://iam.googleapis.com/projects/<PROJECT_NUMBER>/locations/global/workloadIdentityPools/lynxus-pool/subject/IDENTITY_SUBJECT" \
--role="roles/storage.objectViewer"
# 桶范围(示例)
gcloud storage buckets add-iam-policy-binding gs://MY_BUCKET \
--member="principal://iam.googleapis.com/projects/<PROJECT_NUMBER>/locations/global/workloadIdentityPools/lynxus-pool/subject/IDENTITY_SUBJECT" \
--role="roles/storage.objectViewer"
IDENTITY_SUBJECT 必须与你在 provider 中映射的声明(例如
assertion.sub)一致。目前不支持服务账号模拟,因此请直接向
workload identity 主体授予角色。
3. 配置 Lynxus 属性(选择 Workload Identity 策略)
| 属性 | 说明 |
|---|---|
| Audience | 粘贴上面记录的 provider 资源名。 |
| Scope | 默认为 https://www.googleapis.com/auth/cloud-platform;如需更少权限,提供以空格或逗号分隔的 scope。 |
| STS Token Endpoint | 可选,覆盖 Google STS 端点;留空则使用 https://sts.googleapis.com/v1/token。 |
| Subject Token Provider | 获取上游工作负载身份令牌(JWT 或访问令牌)的 Controller Service。令牌必须包含属性映射所引用的声明。 |
| Subject Token Type | 默认为 urn:ietf:params:oauth:token-type:jwt。只有当上游提供者签发的是 OAuth 访问令牌而非 JWT 时,才选择另一种访问令牌类型。 |
| Proxy Configuration Service | 可选的 Controller Service,允许 Lynxus 通过 HTTP/SOCKS 代理访问 STS。 |
这些属性设置完成后,启用 GCPCredentialsControllerService。引用它的
Processor 会立即获得 IdentityPoolCredentials,Google 的库会使用
配置的 subject-token provider 自动刷新访问令牌。
验证流程
- 启用或刷新 Subject Token Provider Controller Service。
- 在 GCPCredentialsControllerService 上使用 Verify 操作。验证成功 表明 Lynxus 可以使用配置的代理、audience 和 scope 与 Google STS 交换 subject token。
- 启用依赖的 Processor。不需要其他 Controller Service。
故障排查
| 现象 | 说明 |
|---|---|
403 Caller does not have storage.objects.list |
确认 workload identity 主体拥有所需的 IAM 角色:gcloud projects get-iam-policy / gcloud storage buckets get-iam-policy。确保属性映射产生的 subject 与 IAM 中引用的一致。 |
| 验证时出现 STS 错误 | 仔细核对 Audience 字符串和 STS Token Endpoint。使用 DEBUG 日志或 Verify 对话框的输出来检查 STS 响应。确保 subject token 包含映射的声明。 |
| Google API 拒绝访问令牌 | 用联合令牌直接调用 API(例如 curl -H "Authorization: Bearer TOKEN" https://storage.googleapis.com/...)。如果仍失败,重新检查 IAM 绑定或 scope 选择。 |
| 需要轮换上游令牌 | Controller Service 会在到期前 60 秒请求新的 subject token。在 Subject Token Provider 上触发 Refresh 可立即使缓存的令牌失效。 |
所有策略都可以在单个 Controller Service 配置中切换,Lynxus 用户可以 在服务账号密钥、Compute Engine、Application Default Credentials 和 Workload Identity Federation 之间迁移,无需引入新的 Controller Service 或更新 Processor 属性。只需调整一次认证策略,所有依赖的 Processor 会自动使用新凭据。