Skip to content

unable to read private key from azure with az://{container}/{key} but /vsiaz/{container}/{key} works #2636

@hrodmn

Description

@hrodmn

Expected behavior and actual behavior.

I would like to be able to rely on the environment variables AZURE_STORAGE_ACCOUNT and AZURE_STORAGE_ACCESS_KEY to make it possible to read files that look like az://{container}/{key}, but rasterio does not seem to be pulling those environment variables the same way it can for S3 URIs.

This was working for me as recently as version 1.3a3, but in 1.3.3 I cannot get it to work! I have combed through rasterio/session.py and it appears that AZURE_STORAGE_ACCOUNT gets pulled from the environment, but AZURE_STORAGE_ACCESS_KEY does not. Is that intentional?

Steps to reproduce the problem.

I am not really sure how to provide a full reproducible examples for private storage container, but here is the pattern that I have observed.

This works:

AZURE_STORAGE_ACCOUNT={AZURE_STORAGE_ACCOUNT} AZURE_STORAGE_ACCESS_KEY={AZURE_STORAGE_ACCESS_KEY} rio info /vsiaz/{container}/{key}

This fails:

AZURE_STORAGE_ACCOUNT={AZURE_STORAGE_ACCOUNT} AZURE_STORAGE_ACCESS_KEY={AZURE_STORAGE_ACCESS_KEY} rio info az://{container}/{key}

I think this is happening because AzureSession will not pull AZURE_STORAGE_ACCESS_KEY from the environment.

$ AZURE_STORAGE_ACCOUNT=foo AZURE_STORAGE_ACCESS_KEY=bar python - <<EOF
> from rasterio.session import Session
> sesh = Session.from_path("az://lol/wut")
> print(sesh.credentials)
> EOF
{'azure_storage_account': 'foo', 'azure_storage_access_key': None}

As far as I can tell the only way to provide it is by calling AzureSession(azure_storage_access_key={AZURE_STORAGE_ACCESS_KEY}), but I don't know how to propagate that behavior through my entire environment.

Environment Information

$ rio --show-versions
rasterio info:
  rasterio: 1.3.3
      GDAL: 3.4.3
      PROJ: 8.2.1
      GEOS: 3.10.2
 PROJ DATA: /home/henry/.local/share/proj:/usr/share/proj
 GDAL DATA: None

System:
    python: 3.10.6 (main, Nov  2 2022, 18:53:38) [GCC 11.3.0]
executable: /home/henry/.virtualenvs/sequoia/bin/python
   machine: Linux-5.15.0-52-generic-x86_64-with-glibc2.35

Python deps:
    affine: 2.3.0
     attrs: 21.4.0
   certifi: 2021.10.08
     click: 8.0.3
     cligj: 0.7.2
    cython: 0.29.32
     numpy: 1.22.1
    snuggs: 1.4.7
click-plugins: None
setuptools: 59.8.0

Installation Method

pip install rasterio==1.3.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions