Also pass HOME env var in access_env_vars (#8685)

Noticed this while debugging a test failure in #8673 which only occurs
with real S3 instead of mock S3: if you authenticate to S3 via
`AWS_PROFILE`, then it requires the `HOME` env var to be set so that it
can read inside the `~/.aws` directory.

The scrubber abstraction `StorageScrubber::scrubber_cli` in
`neon_fixtures.py` would otherwise not work. My earlier PR #6556 has
done similar things for the `neon_local` wrapper.

You can try:

```
aws sso login --profile dev
export ENABLE_REAL_S3_REMOTE_STORAGE=y REMOTE_STORAGE_S3_BUCKET=neon-github-ci-tests REMOTE_STORAGE_S3_REGION=eu-central-1 AWS_PROFILE=dev
RUST_BACKTRACE=1 BUILD_TYPE=debug DEFAULT_PG_VERSION=16 ./scripts/pytest -vv --tb=short -k test_scrubber_tenant_snapshot
```

before and after this patch: this patch fixes it.
This commit is contained in:
Arpad Müller
2024-08-10 14:04:47 +02:00
committed by GitHub
parent 401dcd3551
commit 507f1a5bdd

View File

@@ -177,9 +177,14 @@ class S3Storage:
def access_env_vars(self) -> Dict[str, str]:
if self.aws_profile is not None:
return {
env = {
"AWS_PROFILE": self.aws_profile,
}
# Pass through HOME env var because AWS_PROFILE needs it in order to work
home = os.getenv("HOME")
if home is not None:
env["HOME"] = home
return env
if self.access_key is not None and self.secret_key is not None:
return {
"AWS_ACCESS_KEY_ID": self.access_key,