Kuzzle Plugin S3 #
S3 has a right system to limit who can upload files to buckets.
Presigned URLs are special disposable Urls generated by S3. It is possible to upload a file directly to one of these URLs so that it can be stored into the bucket.
These URLs must be generated on the server side, this plugin includes among other things the generation of these URLs so that developers can then send their files directly to S3 from a client application.
Installation #
npm install kuzzle-plugin-s3const s3Plugin = new S3Plugin();
app.plugin.use(s3Plugin);Plugin configuration #
In your kuzzlerc file, you can change the following configuration variable:
{
"plugins": {
"s3": {
"endpoints": {
"eu-west-3": {
"endpoint": "https://s3.eu-west-3.amazonaws.com",
"forcePathStyle": false,
"accessKeyIdPath": "foo.s3.eu-west-3.accessKeyId",
"secretAccessKeyPath": "foo.s3.eu-west-3.secretAccessKey",
"isMinio": false
},
"us-east-1": {
"endpoint": "https://s3.us-east-1.amazonaws.com",
"forcePathStyle": false,
"accessKeyIdPath": "foo.s3.us-east-1.accessKeyId",
"secretAccessKeyPath": "foo.s3.us-east-1.secretAccessKey",
"isMinio": false
},
"custom-minio": {
"endpoint": "https://minio.example.com",
"forcePathStyle": true,
"accessKeyIdPath": "foo.s3.minio.accessKeyId",
"secretAccessKeyPath": "foo.s3.minio.secretAccessKey",
"isMinio": true
}
},
"signedUrlTTL": "20min"
}
}
}Configuration Usage Documentation #
Overview #
The configuration defines S3-compatible endpoints, including AWS S3 and MinIO instances, and specifies credentials paths for secure access. It allows flexible integration with different storage backends.
Configuration Schema #
{
"plugins": {
"s3": {
"endpoints": {
"region-name": {
"endpoint": "string",
"forcePathStyle": "boolean",
"accessKeyIdPath": "string",
"secretAccessKeyPath": "string",
"isMinio": "boolean"
}
},
"signedUrlTTL": "string"
}
}
}Fields Explanation #
endpoints #
- A mapping of region names to their respective configurations.
region-name: A unique key for each endpoint configuration (e.g.,eu-west-3,us-east-1).
Endpoint Fields #
endpoint:- The URL of the S3-compatible storage service.
- Example:
https://s3.eu-west-3.amazonaws.comfor AWS S3 orhttps://minio.example.comfor MinIO.
forcePathStyle:- Indicates whether to use path-style addressing (e.g.,
https://endpoint/bucket/object) instead of virtual-hosted style. - Default:
falsefor AWS S3; set totruefor MinIO.
- Indicates whether to use path-style addressing (e.g.,
accessKeyIdPath:- Vault path where the
accessKeyIdis securely stored. - Example:
foo.s3.eu-west-3.accessKeyId.
- Vault path where the
secretAccessKeyPath:- Vault path for the
secretAccessKey. - Example:
foo.s3.eu-west-3.secretAccessKey.
- Vault path for the
isMinio:- Boolean flag indicating whether the endpoint is a MinIO instance.
- Example:
truefor MinIO;falsefor AWS S3.
signedUrlTTL #
- Specifies the time-to-live for signed URLs.
- Format: A human-readable duration string (e.g.,
20min,1h).
Usage Example #
Configuration File #
{
"plugins": {
"s3": {
"endpoints": {
"eu-west-3": {
"endpoint": "https://s3.eu-west-3.amazonaws.com",
"forcePathStyle": false,
"accessKeyIdPath": "foo.s3.eu-west-3.accessKeyId",
"secretAccessKeyPath": "foo.s3.eu-west-3.secretAccessKey",
"isMinio": false,
"s3ClientOptions": {
// any needed option from aws sdk https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#constructor-property
}
},
"minio-instance": {
"endpoint": "https://minio.example.com",
"forcePathStyle": true,
"accessKeyIdPath": "foo.s3.minio.accessKeyId",
"secretAccessKeyPath": "foo.s3.minio.secretAccessKey",
"isMinio": true
}
},
"signedUrlTTL": "30min"
}
}
}How the Configuration Is Used #
Endpoint Selection:
- The application determines the endpoint based on the
bucketRegionprovided in requests. - Example:
const bucketRegion = 'eu-west-3'; const endpointConfig = config.plugins.s3.endpoints[bucketRegion];
- The application determines the endpoint based on the
Credential Retrieval:
- The application fetches credentials from the vault using
accessKeyIdPathandsecretAccessKeyPath. That way, they can be shared for endpoints or not depending on S3 provider.
- The application fetches credentials from the vault using
Public Access Management:
- For AWS S3: Public access blocks are managed via
deletePublicAccessBlock. - For MinIO: Users are instructed to configure bucket policies or access rules directly.
- For AWS S3: Public access blocks are managed via
Signed URL Generation:
- The
signedUrlTTLfield specifies the expiration time for generated URLs. - Example:
const signedUrl = generateSignedUrl(bucketName, objectKey, endpointConfig, { expiresIn: config.plugins.s3.signedUrlTTL });
- The
Notes #
- Security: Always store sensitive credentials in a secure Do not hardcode them into the configuration.
- Compatibility: Set
forcePathStyletotruefor MinIO and similar storage backends. - Customization: Adjust
signedUrlTTLbased on your use case (e.g., temporary file access or downloads).