Google Cloud Java SDK พร้อม Workload Identity?
Oct 08 2020
กำลังพยายามหาวิธีพิสูจน์ตัวตนด้วย Storage API จากภายในคลัสเตอร์ GKE
รหัส:
Storage storage = StorageOptions.newBuilder()
.setCredentials(ServiceAccountCredentials.getApplicationDefault())
.setProjectId(gcpProjectId)
.build().getService();
getApplicationDefault() ได้รับการจัดทำเป็นเอกสารเพื่อใช้วิธีการเหล่านี้ในการตรวจสอบสิทธิ์กับ API:
- ไฟล์ข้อมูลรับรองที่กำหนดโดยตัวแปรสภาพแวดล้อม {@code GOOGLE_APPLICATION_CREDENTIALS}
- ข้อมูลรับรองที่จัดเตรียมโดยคำสั่ง {@code gcloud auth application-default login} ของ Google Cloud SDK
- ข้อมูลรับรองในตัวของ Google App Engine
- ข้อมูลรับรองในตัวของ Google Cloud Shell
- ข้อมูลรับรองในตัวของ Google Compute Engine
แอปพลิเคชันกำลังใช้คุณลักษณะข้อมูลประจำตัวปริมาณงาน GCP ดังนั้นบัญชีบริการของแอปพลิเคชัน (ในคลัสเตอร์) จึงมีคำอธิบายประกอบดังนี้
serviceAccount.annotations.iam.gke.io/gcp-service-account: [email protected]
ตอนนี้การเรียกไปยังบัญชีจัดเก็บล้มเหลวโดยมีข้อผิดพลาดต่อไปนี้:
{
"code" : 403,
"errors" : [ {
"domain" : "global",
"message" : "Primary: /namespaces/my-project.svc.id.goog with additional claims does not have storage.objects.create access to the Google Cloud Storage object.",
"reason" : "forbidden"
} ],
"message" : "Primary: /namespaces/my-project.svc.id.goog with additional claims does not have storage.objects.create access to the Google Cloud Storage object."
}
สิ่งนี้ทำให้ฉันคิดว่าข้อมูลประจำตัวของเวิร์กโหลดทำงานไม่ถูกต้อง ฉันคาดหวังว่าจะได้รับข้อความแสดงข้อผิดพลาดสำหรับบัญชีบริการที่มีคำอธิบายประกอบของฉันไม่ใช่ข้อความเริ่มต้น
มีอะไรอีกไหมที่ฉันควรทำ?
คำตอบ
MoritzSchmitzv.Hülst Oct 09 2020 at 15:47
คำอธิบายประกอบไม่ถูกต้อง แทน:
serviceAccount.annotations.iam.gke.io/gcp-service-account: [email protected]
มันจะต้องเป็น
iam.gke.io/gcp-service-account: [email protected]
ตอนนี้ข้อความแสดงข้อผิดพลาดยังแสดงให้เห็นว่าแอปกำลังใช้ข้อมูลประจำตัวของเวิร์กโหลด:
java.io.IOException: Unexpected Error code 403 trying to get security access token from Compute Engine metadata for the default service account: Unable to generate access token; IAM returned 403 Forbidden: The caller does not have permission
This error could be caused by a missing IAM policy binding on the target IAM service account.
For more information, refer to the Workload Identity documentation:
https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity#creating_a_relationship_between_ksas_and_gsas