diff --git a/common/etc/nginx/include/s3gateway.js b/common/etc/nginx/include/s3gateway.js index b1be836a..486db09b 100644 --- a/common/etc/nginx/include/s3gateway.js +++ b/common/etc/nginx/include/s3gateway.js @@ -69,6 +69,12 @@ const FOUR_O_FOUR_ON_EMPTY_BUCKET = utils.parseBoolean(process.env['FOUR_O_FOUR_ * @type {string} * */ const S3_STYLE = process.env['S3_STYLE']; +/** + * Prefix to be prepended to all object names, allowing the serving of a + * subset of a bucket. Default ''. + * @type {string} + */ +const S3_OBJECT_PREFIX = process.env['S3_OBJECT_PREFIX'] || ''; /** * Additional header prefixes to strip from the response before sending to the * client. This is useful for removing headers that may contain sensitive @@ -285,6 +291,10 @@ function s3uri(r) { const basePath = s3BaseUri(r); let path; + if (S3_OBJECT_PREFIX) { + uriPath = S3_OBJECT_PREFIX + uriPath + } + // Create query parameters only if directory listing is enabled. if (ALLOW_LISTING && !utils.parseBoolean(r.variables.forIndexPage)) { const queryParams = _s3DirQueryParams(uriPath, r.method); diff --git a/docs/getting_started.md b/docs/getting_started.md index 5e24732f..e04cb45e 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -21,6 +21,7 @@ running as a Container or as a Systemd service. | `AWS_SECRET_ACCESS_KEY` | Yes | | | Secret access key | | `AWS_SESSION_TOKEN` | No | | | Session token. | | `S3_BUCKET_NAME` | Yes | | | Name of S3 bucket to proxy requests to | +| `S3_OBJECT_PREFIX` | No | | | Prefix to prepend to all S3 object paths | | `S3_REGION` | Yes | | | Region associated with API | | `S3_SERVER_PORT` | Yes | | | SSL/TLS port to connect to | | `S3_SERVER_PROTO` | Yes | `http`, `https` | | Protocol to used connect to S3 server |