当应用程序(bin)具有“正常”权限时,它会很好地加载(服务帐户)凭据。这是运行脚本:
#!/bin/bash
export GOOGLE_APPLICATION_CREDENTIALS=/home/user/config/gcloud/key.json
./bin但是,当更改bin权限时:
chown root:root bin
chmod u+s bin我知道这个错误:
E1003 10:02:07.563899584 60263 credentials_generic.cc:35]不能得到家庭环境变量。{created_time:"2022-10-03T10:02:07.563943484+09:00"}:E1003 10:02:10.563621247 60263 google_default_credentials.cc:461]无法创建google默认凭据: UNKNOWN:creds_path unset google_default_credentials.cc:461
如有任何建议,将不胜感激。
谢谢。
发布于 2022-10-05 01:40:37
据我所知,这是gRPC的预期行为。gRPC使用secure_getenv()获取所有环境变量。在您的示例中,这意味着gRPC忽略了GOOGLE_APPLICATION_CREDENTIALS集。
您可能需要更改应用程序以使用显式服务帐户凭据。类似于:
auto is = std::ifstream(filename);
auto json_string =
std::string(std::istreambuf_iterator<char>(is.rdbuf()), {});
auto credentials =
google::cloud::MakeServiceAccountCredentials(json_string);
auto publisher = pubsub::Publisher(
pubsub::MakePublisherConnection(
pubsub::Topic(project_id, topic_id),
google::cloud::Options{}
.set<google::cloud::UnifiedCredentialsOption>(
credentials)));https://stackoverflow.com/questions/73941632
复制相似问题