Skip to content

Allow the use of 'prefix' in S3 buckets#61585

Open
mbartsch wants to merge 2 commits into
nextcloud:masterfrom
mbartsch:feature/s3-external-prefix
Open

Allow the use of 'prefix' in S3 buckets#61585
mbartsch wants to merge 2 commits into
nextcloud:masterfrom
mbartsch:feature/s3-external-prefix

Conversation

@mbartsch

@mbartsch mbartsch commented Jun 25, 2026

Copy link
Copy Markdown
  • Resolves: #

Summary

Adds an optional Object key prefix parameter to the S3-Compatible Object Storage external storage backend.

This allows scoping a mount to a sub-path within a shared bucket rather than requiring exclusive use of the entire bucket. For example, setting the
prefix to nextcloud/$user/ will store each user's files under their own namespace within the bucket, with $user being substituted automatically at
mount time.

What changed:

  • Backend/AmazonS3.php: new optional prefix field exposed in the admin UI
  • Storage/AmazonS3.php: prefix is parsed and normalized in the constructor (leading slashes stripped, trailing slash enforced), then applied
    transparently to all S3 key operations (read, write, delete, list, copy, presigned URLs). Keys returned from S3 listing responses have the prefix
    stripped before being stored in the in-memory cache or yielded as directory entries. The storage ID includes the prefix so two mounts to the same
    bucket with different prefixes are treated as distinct storages.

Variable substitution: $user (and any other registered placeholder) works in the prefix field automatically, since all backend options pass through
the existing applyConfigHandlers() pipeline before the storage is constructed.

TODO

  • Add unit tests for addPrefix / stripPrefix helpers and constructor normalization
  • Add integration test covering mount with a prefix set

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

Signed-off-by: Marcelo H. Bartsch <marcelo@bartsch.cl>
@mbartsch mbartsch force-pushed the feature/s3-external-prefix branch from 6a2538d to 7e55e24 Compare June 25, 2026 08:27
Signed-off-by: Marcelo H. Bartsch <marcelo@bartsch.cl>
@mbartsch mbartsch marked this pull request as ready for review June 25, 2026 09:12
@mbartsch mbartsch requested a review from a team as a code owner June 25, 2026 09:12
@mbartsch mbartsch requested review from ArtificialOwl, come-nc, provokateurin and salmart-dev and removed request for a team June 25, 2026 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant