adonisjs / drive-s3

S3 driver for AdonisJS drive
MIT License
21 stars 9 forks source link

S3 Signed URL Expiration #5

Closed Drakmord2 closed 2 years ago

Drakmord2 commented 2 years ago

Following https://docs.adonisjs.com/guides/drive#getsignedurl to generate a pre-signed URL from S3 using the snippet below

const url = await Drive.getSignedUrl(
    file_location,
    {
      contentType: 'application/pdf',
      expiresIn: 120,
    }
)

yields an URL like this

https://redacted_s3_url?
        X-Amz-Algorithm=AWS4-HMAC-SHA256&
        X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&
        X-Amz-Credential=redacted_credential&
        X-Amz-Date=20220302T210925Z&
        X-Amz-Expires=900&
        X-Amz-Signature=redacted_signature&
        X-Amz-SignedHeaders=host&
        response-content-type=application%2Fpdf&
        x-id=GetObject

The issue is that expiresIn has no effect on the X-Amz-Expires header as it is always set to 900 seconds. It happens when using both string or integer values (i.e. '2mins' or 120). Am I missing something or is this feature not available for S3?


Configs

contracts/drive.ts

declare module '@ioc:Adonis/Core/Drive' {
  interface DisksList {
    s3: {
      config: S3DriverConfig
      implementation: S3DriverContract
    }
  }
}

config/drive.ts

const driveConfig: DriveConfig = {
  disk: Env.get('DRIVE_DISK'),
  disks: {
    s3: {
      driver: 's3',
      visibility: 'private',
      key: Env.get('AWS_ACCESS_KEY'),
      secret: Env.get('AWS_SECRET_KEY'),
      region: Env.get('S3_REGION'),
      bucket: Env.get('S3_BUCKET'),
      endpoint: Env.get('S3_ENDPOINT'),
    },
  },
}

Dependencies

"@adonisjs/core": "^5.4.1",
"@adonisjs/drive-s3": "^1.0.5",

Node

NodeJS - v14.18.3
NPM - 6.14.15