发送反馈
  
   
 
  
    
      为本地或其他云服务提供商设置 ADC 
  
      
     
  
  
  
   
  
    
  
  
    
    
    
    
  
  
 
 
 
 
 
 
 
 
 
 
 
 
如果您在 Google Cloud之外运行应用,则需要提供 Google Cloud 可识别的凭据才能使用 Google Cloud 服务。
工作负载身份联合 
使用外部 IdP 的凭据进行 Google Cloud 身份验证的首选方法是使用工作负载身份联合 ;您需要创建一个凭据配置文件并将 GOOGLE_APPLICATION_CREDENTIALS 环境变量设置为指向它。此方法比创建服务账号密钥更安全。
如需有关为 ADC 设置工作负载身份联合的帮助,请参阅与其他云服务的工作负载身份联合 。
服务账号密钥 
如果您无法配置工作负载身份联合,则必须创建一个服务账号,为其授予您的应用所需的 IAM 角色,并为该服务账号创建密钥。
如需创建服务账号密钥并将其提供给 ADC,请执行以下操作:
  
    按照创建服务账号密钥 中的说明,创建一个具有您的应用所需的角色的服务账号,并为该服务账号创建密钥。 
  
    
  
   
   
     
   
  
  
    Set the environment variable GOOGLE_APPLICATION_CREDENTIALS
    to the path of the JSON file that contains your credentials.
    This variable applies only to your current shell session, so if you open
    a new session, set the variable again.
  
  
    Example:  Linux or macOS
   
export   GOOGLE_APPLICATION_CREDENTIALS = "KEY_PATH "  
   Replace KEY_PATH  with the path of the JSON file that contains your credentials.
   For example:
   
export   GOOGLE_APPLICATION_CREDENTIALS = "/home/user/Downloads/service-account-file.json"  
  
  
    Example:  Windows
    For PowerShell:
    
$env :GOOGLE_APPLICATION_CREDENTIALS= "KEY_PATH "  
    Replace KEY_PATH  with the path of the JSON file that contains your credentials.
    For example:
    
$env :GOOGLE_APPLICATION_CREDENTIALS= "C:\Users\username\Downloads\service-account-file.json"  
    For command prompt:
    
set   GOOGLE_APPLICATION_CREDENTIALS = KEY_PATH  
    Replace KEY_PATH  with the path of the JSON file that contains your credentials.
     
   
  
    注意 :当您设置 GOOGLE_APPLICATION_CREDENTIALS 环境变量时,ADC 会先检查此位置,然后仅在必要时检查其他位置。 
 
后续步骤 
  
  
  
     
  
  
 
  
    
    
      
       
         
  
  
    
    发送反馈
  
   
 
       
    
    
  
  
 
  如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可 获得了许可,并且代码示例已根据 Apache 2.0 许可 获得了许可。有关详情,请参阅 Google 开发者网站政策 。Java 是 Oracle 和/或其关联公司的注册商标。
  最后更新时间 (UTC):2025-10-19。
 
 
  
  
    
    
    
      
  
  
    需要向我们提供更多信息?
  
   
 
     
  
  
    
      [[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-10-19。"],[],[]]