Skip to content

files_external: Undefined array key "key" logged for S3 mounts without a static access key #63564

Description

@default50

Bug description

AmazonS3::__construct() computes the storage id with an unguarded
$this->params['key'] access:

// apps/files_external/lib/Lib/Storage/AmazonS3.php
// @todo: using `key` here may be problematic with different authentication methods and/or key rotation...
$this->id = 'amazon::external::' . md5($this->params['hostname'] . ':' . $this->params['bucket'] . ':' . $this->params['key']);

When an S3 external storage is mounted without a static access key — i.e. relying on
the AWS SDK default credential provider chain (environment, EC2 instance profile, ECS task
role, etc.) — the key param is absent. The credential layer already supports this:
S3ConnectionTrait::paramCredentialProvider() treats an empty/missing key as "no static
credentials" and rejects so the SDK falls through to its default provider chain:

// lib/private/Files/ObjectStore/S3ConnectionTrait.php
$key = empty($this->params['key']) ? null : $this->params['key'];
$secret = empty($this->params['secret']) ? null : $this->params['secret'];
...
if ($key && $secret) {
    return Create::promiseFor(new Credentials($key, $secret, $sessionToken));
}
$msg = 'Could not find parameters set for credentials in config file.';
return new RejectedPromise(new CredentialsException($msg));

But the id computation in the constructor accesses key unconditionally, so PHP emits
Undefined array key "key" on every storage construction, which is logged as a warning.
The result is continuous log noise for a fully supported, working configuration.

The maintainer @todo sitting directly above the line already anticipates this fragility.

Steps to reproduce

  1. Add an Amazon S3 external storage.
  2. Configure it to authenticate via the ambient AWS credential chain rather than a static
    access key (no key/secret provided).
  3. Browse the mount / let the storage be constructed.
  4. Check nextcloud.log.

Expected behaviour

A credential-less S3 mount that authenticates via the default AWS provider chain should work
without emitting Undefined array key "key" warnings.

Actual behaviour

Every construction of the storage logs:

Undefined array key "key" at apps/files_external/lib/Lib/Storage/AmazonS3.php

Suggested fix

Guard the access when building the id (the value only contributes to a hash):

$this->params['key'] ?? ''

This aligns the id computation with paramCredentialProvider(), which already treats key
as optional. Happy to open a PR.

Related

Server configuration

  • Nextcloud version: 34.0.3
  • files_external app version: 1.26.0
  • PHP version: 8.5.9

The offending line is present on master at the time of filing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    To triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions