Applying same patch we did in #21048 but for `repository-s3` plugin. Backport of #21058 in master branch