Skip to content

Parse environment variables in the bucket setting - #204

Open
jmariklecr wants to merge 1 commit into
craftcms:3.xfrom
jmariklecr:bugfix/parse-env-bucket
Open

jmariklecr wants to merge 1 commit into
craftcms:3.xfrom
jmariklecr:bugfix/parse-env-bucket

Conversation

@jmariklecr

@jmariklecr jmariklecr commented Aug 12, 2026 •

Copy link
Copy Markdown

Description

On 3.x, the bucket setting isn't run through Env::parse() in getDiskConfig(), so an env var reference reaches the S3 client verbatim. With bucket: $S3_BUCKET in project config, every operation fails:

Error executing "HeadObject" on
"https://s3.amazonaws.com/%24S3_BUCKET/general-uploads/placeholders/100x100-1.jpg";
AWS HTTP error: 400 Bad Request

(%24S3_BUCKET being the URL-encoded literal $S3_BUCKET.)

A regression from the 6.x port. On 2.x, env parsing was declarative via EnvAttributeParserBehavior, covering seven attributes: keyId, secret, bucket, region, subfolder, cfDistributionId, cfPrefix. That behavior went away in the rewrite and each attribute became an explicit Env::parse() call. Six of seven were converted, bucket was missed.

This should be a safe change. The same Env::parse is used further down the same file:

$params = [
'Image' => [
'S3Object' => [
'Name' => $path,
'Bucket' => Env::parse($this->bucket),
],
],
];

Related issues

None. #181 is Craft 4 and unrelated. 2.x isn't affected (still uses the behavior).

Note on verification / CI

The 3.x branch's tooling doesn't appear to have been updated during the port, so
neither phpstan nor ECS run cleanly.

  • composer install fails: composer.lock still pins craftcms/cms 4.17.7 while composer.json requires ^6.0.0 (composer update resolves cleanly to 6.0.0-alpha.16. I did not include the resulting composer.lock in this PR)
  • composer phpstan fails: phpstan.neon includes craftcms/phpstan's shared config, which scans ../cms/src/Craft.php. That file doesn't exist in Craft 6. The legacy Craft class now lives in craftcms/yii2-adapter, which this plugin doesn't require, so PHPStan can't run on this branch at all.
  • composer check-cs exits 1 with 7 pre-existing violations across the branch, none related to this change. I decided not to fix them considering they are unrelated to the current work.
  • .github/workflows/ci.yml still specifies craft_version: '5' / php_version: '8.1'

The change itself was verified manually on Craft 6.0.0-alpha.16 / PHP 8.5: with bucket set via $S3_BUCKET, S3 operations return 400 before and succeed after. fileExists() true, correct size(), and the CP Assets index browses the volume.

Tooling issues probably belong in a separate PR.

Addendum

I used Claude Code to diagnose the issue and specifically checked whether it was isolated. bucket in getDiskConfig() appears to be the only one missing Env::parse().

@jmariklecr
jmariklecr force-pushed the bugfix/parse-env-bucket branch from ebc6c2f to 61ff4c8 Compare September 2, 2026 18:59
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