CodexBloom - Programming Q&A Platform

GCP Cloud Storage Signed URLs Expiring Prematurely When Using Regional Buckets

πŸ‘€ Views: 0 πŸ’¬ Answers: 1 πŸ“… Created: 2025-06-15
google-cloud-storage signed-urls node.js JavaScript

I'm upgrading from an older version and I've tried everything I can think of but I'm having trouble with signed URLs for my GCP Cloud Storage bucket, which is configured as a regional bucket. I generate the signed URLs using the `google-cloud/storage` library in Node.js, but they seem to expire much sooner than the duration I set when creating them. I've tried various expiration durations, but the behavior remains inconsistent. Here's the code snippet I'm using to generate the signed URL: ```javascript const { Storage } = require('@google-cloud/storage'); const storage = new Storage(); const bucketName = 'my-bucket'; const filename = 'my-file.txt'; const options = { version: 'v4', action: 'read', expires: Date.now() + 15 * 60 * 1000, // 15 minutes }; async function generateSignedUrl() { const [url] = await storage.bucket(bucketName).file(filename).getSignedUrl(options); console.log(`The signed url for ${filename} is ${url}`); } generateSignedUrl(); ``` I expected the signed URL to remain valid for 15 minutes, but I've noticed that it becomes invalid after just 5 minutes or less. I've confirmed that the bucket region and IAM permissions are configured correctly and that the file exists in the bucket. I've also tested with both `v4` and `v2` signing methods, but the issue persists. Additionally, I've checked the system time on my server to ensure it’s synchronized correctly. Could there be any settings or configurations in GCP that might affect the expiration time of signed URLs for regional buckets? Any help or insights would be greatly appreciated! Could this be a known issue? For context: I'm using Javascript on Ubuntu 22.04. Thanks in advance!