Skip to content

feat(core): expose S3_REGION env var for S3-compatible backends (Garage/MinIO/Ceph) - #483

Merged
ostefano merged 4 commits into
MISP:masterfrom
alesnav:feat/s3-region-envvar
Oct 27, 2026
Merged

ostefano merged 4 commits into
MISP:masterfrom
alesnav:feat/s3-region-envvar

Conversation

@alesnav

@alesnav alesnav commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Problem

misp-core exposes S3_BUCKET, S3_ENDPOINT, S3_ACCESS_KEY, S3_SECRET_KEY as environment variables (core/files/etc/misp-docker/s3.envars.json), but not the region. The region stays hardcoded to eu-west-1 in app/Lib/Tools/AWSS3Client.php and can only be changed via the Plugin.S3_region DB setting.

This breaks S3-compatible self-hosted backends (Garage, MinIO, Ceph) that require a specific region. AWS SigV4 embeds the region in the credential scope, so the server rejects requests:

AwsException / AuthorizationHeaderMalformed (client): Authorization header malformed,
unexpected scope: '20261026/eu-west-1/s3/aws4_request',
expected: '20261026/garage/s3/aws4_request'

Result: attachment downloads fail with "Something went wrong - could not load attachment" even though Plugin.S3_aws_compatible=true, the object exists and the key is correct.

Reproduced on misp-core 2.5.x with attachments stored in Garage (attachments_dir=s3://). Verified the backend error via the cake shell (getAttachmentFile → NotFoundException: Could not download object ... AuthorizationHeaderMalformed). Setting Plugin.S3_region to the backend's region fixes it immediately.

Fix

Add Plugin.S3_region → ${S3_REGION} to s3.envars.json, so the region can be set via env var alongside the other S3 settings:

"Plugin.S3_region": {
    "default_value": "${S3_REGION}"
},

One-line addition, no behaviour change for AWS users (if S3_REGION is unset, the existing eu-west-1 default in AWSS3Client.php still applies).

Follow-up (docs)

Please also add # S3_REGION= under the S3 block in template.env (I kept this PR to the functional change; happy to include the doc line here if preferred):

# Set up S3 based attachment storage
# S3_BUCKET=
# S3_REGION=
# S3_ENDPOINT=
# S3_ACCESS_KEY=
# S3_SECRET_KEY=

Add Plugin.S3_region mapped to ${S3_REGION} in s3.envars.json so the S3
region can be set via environment variable.

misp-core only exposed S3_BUCKET/S3_ENDPOINT/S3_ACCESS_KEY/S3_SECRET_KEY;
the region stayed hardcoded to 'eu-west-1' in AWSS3Client.php and could
only be changed through the Plugin.S3_region DB setting. This breaks
S3-compatible self-hosted backends (Garage, MinIO, Ceph) that require a
specific region: the AWS SigV4 signature embeds the region in the credential
scope, so the server rejects requests with:

  AuthorizationHeaderMalformed: unexpected scope '.../eu-west-1/s3/aws4_request',
  expected '.../garage/s3/aws4_request'

-> attachment download fails with 'could not load attachment' even though the
object exists and the key is correct. Reproduced on Garage with misp-core 2.5.x.

With this change, S3_REGION=garage (or minio/us-east-1/etc.) can be set in
.env alongside S3_ENDPOINT, keeping all S3 config consistent via env vars.

Note: also add '# S3_REGION=' to template.env under the S3 block (docs).

@ostefano ostefano left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this var initialized anywhere?

@ostefano

Copy link
Copy Markdown
Collaborator

LGTM

@ostefano ostefano added enhancement New feature or request scheduled Will merge at the next opportunity labels Oct 27, 2026
@ostefano
ostefano merged commit 7e55a0f into MISP:master Oct 27, 2026
6 checks passed
@alesnav
alesnav deleted the feat/s3-region-envvar branch October 27, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request scheduled Will merge at the next opportunity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants