[Storage] Easily generate signed URLs when using workload identity
Maintainer thường phản hồi trong vòng 1 ngày
@rajeevpodar đang làm issue này rồi.
Từ ngày 9/10/2026.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- google-cloud, ruby
- Lĩnh vực
- api, authentication, cloud
Hướng nghiên cứu
Bắt đầu với File#signed_url và đường dẫn signer_v2.rb được nêu trong lỗi, sau đó theo dõi cách các đối số issuer và signer được xử lý. So sánh luồng hiện có dựa trên khóa với các ví dụ về workload identity và IAM signBlob trong issue. Công việc được hoàn tất khi workload identity có thể tạo các URL đã ký thông qua một API được hỗ trợ và có tài liệu, mà không yêu cầu phía gọi tự tạo signer.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Hi, I am open to writing a PR to make code changes for this feature but wanted to start with an issue to get feedback.
When developing locally I can generate signed URL simply with:
require "google/cloud/storage"
storage = Google::Cloud::Storage.new(
project_id: "<project_id>",
credentials: ENV["GCP_CREDENTIALS_PATH"]
)
bucket = storage.bucket "<bucket_name>"
remote_file = bucket.file "foo/bar", skip_lookup: true
url = remote_file.signed_url method: "PUT", content_type: "application/json"
However, when running my code from within an eks pod with access grant via workload identitiy (https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity)
I get the error:
/usr/local/bundle/gems/google-cloud-storage-1.31.1/lib/google/cloud/storage/file/signer_v2.rb:88:in `determine_issuer': Service account credentials 'issuer (client_email)' is missing. To generate service account credentials see https://cloud.google.com/iam/docs/service-accounts (Google::Cloud::Storage::SignedUrlUnavailable)
Based on https://github.com/salrashid123/gcpsamples/blob/master/gcs_keyless_signedurl/main.py I was able to write some equivalent ruby code that works for generating a working signed URL (not the most well-factored code, just a proof-of-concept)
require "google/cloud/storage"
storage = Google::Cloud::Storage.new
bucket = storage.bucket "<bucket_name>"
remote_file = bucket.file "foo/bar", skip_lookup: true
path = "/#{bucket.name}/#{remote_file.name}"
url_manually = "https://storage.googleapis.com#{path}"
access_token = JSON.parse(`curl -s -H 'Metadata-Flavor: Google' http://metadata/computeMetadata/v1/instance/service-accounts/default/token`)["access_token"]
connection = Faraday.new(url: "https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/#{service_account_email}:signBlob") do |conn|
conn.request :json
end
expiration = 1.day.from_now.to_i
verb = "PUT"
content_md5 = ""
content_type = "application/json"
signature_string = "#{verb}\n#{content_md5}\n#{content_type}\n#{expiration}\n#{path}"
response = connection.post do |req|
req.headers["Authorization"] = "Bearer #{access_token}"
req.body = {delegates: [], payload: Base64.encode64(signature_string).gsub("\n","")}
end
signed_blob = JSON.parse(response.body)["signedBlob"]
signed_url = url_manually + "?" + URI.encode_www_form("GoogleAccessId": service_account_email, "Expires": expiration, "Signature": signed_blob)
So... I was thinking perhaps we could/should just change the implementation of signed_url to detect the conditions under which key-based signing will fail and automatically attempt this meta data service token + signBlob service method.
Or perhaps it's already exposed somewhere else within the depths of this ruby gem? (in which case in the very least the error message you see could be updated to point that out)
Thanks,
Jacob
Update based on https://googleapis.dev/ruby/google-cloud-storage/latest/Google/Cloud/Storage/File.html#signed_url-instance_method I have a better version
require "google/cloud/storage"
storage = Google::Cloud::Storage.new
bucket = storage.bucket "<bucket_name>"
remote_file = bucket.file "foo/bar", skip_lookup: true
issuer = "<service account email>"
signer = lambda do |string_to_sign|
IAMCredentials = Google::Apis::IamcredentialsV1
iam_client = IAMCredentials::IAMCredentialsService.new
scopes = ["https://www.googleapis.com/auth/iam"]
iam_client.authorization = Google::Auth.get_application_default scopes
request = Google::Apis::IamcredentialsV1::SignBlobRequest.new(
payload: string_to_sign
)
resource = "projects/-/serviceAccounts/#{issuer}"
response = iam_client.sign_service_account_blob resource, request
response.signed_blob
end
signed_url = remote_file.signed_url method: "PUT", content_type: "application/json", issuer: issuer, signer: signer
And the only things that are "custom" to my use case in this example end up being arguments into the signed_url method. so perhaps a simplification this gem could make would be to auto-generate the signer proc
Finally, I need a way to tell which version of the signed_url method args to use.
When running locally I have a credentials JSON file. so I need only call remote_file.signed_url method: "PUT", content_type: "application/json"
Whereas from my pod I have to call remote_file.signed_url method: "PUT", content_type: "application/json", issuer: issuer, signer: signer
If I do it backwards (specify an issue and signer when not on a pod) I get
/Users/jacob/.gem/ruby/3.0.1/gems/googleauth-0.16.2/lib/googleauth/application_default.rb:76:in `get_application_default': Could not load the default credentials. Browse to (RuntimeError)
https://developers.google.com/accounts/docs/application-default-credentials
for more information
Is there some simple call I could make to this gem to determine what context I'm in?
- Ngôn ngữ chính
- Ruby
- Star
- 1.4k
- Fork
- 581
- Merge trung bình
- 1 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 69
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của googleapis/google-cloud-ruby
-
eMudhra/emSign CA compromise (October 2026): what Cloud SDK Ruby Libraries developers need to doCó thể đã có người làm @viacheslav-rostovtsev đã nhận 13 ngày trước. Đang mởtype: process
googleapis/google-cloud-ruby#36690 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
chore(ci): remove temporary Windows grpc < 1.85.0 pin once x64-mingw-ucrt gem is publishedCó thể đã có người làm @viacheslav-rostovtsev đã nhận 21 ngày trước. Đang mởgrpc priority: p1 type: cleanup
googleapis/google-cloud-ruby#36677 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[google-cloud-datastore] timeout option has no effect: per-RPC defaults override it (same as #14050)Đang mởapi: datastore priority: p2 type: bug
googleapis/google-cloud-ruby#36632 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
storage/bigquery: google-apis-* dependency floors are lower than the wrappers actually requireCó thể làm lại được @kalragauri đã nhận 34 ngày trước và không có pull request nào đang mở. Đang mởapi: storage priority: p3 type: bug
googleapis/google-cloud-ruby#36610 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Support `STORAGE_EMULATOR_HOST` in the `google-cloud-storage` GemCó thể đã có người làm @rajeevpodar đã nhận 38 ngày trước. Đang mởapi: storage priority: p2 type: feature request
googleapis/google-cloud-ruby#34022 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của googleapis/google-cloud-ruby
Issue tương tự
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 66/100
philippe-nougaillon/coopcomm#543 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
we-promise/sure#5191 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
Supoort VXBilibili linksĐang mởSource Support
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
palkan/action_policy#316 ·