LigaData-ltsentsiper opened a new issue, #55683:
URL: https://github.com/apache/arrow/issues/55683
### Describe the bug, including details regarding any error messages,
version, and platform., including details regarding any error messages,
version, and platform.
With a SAS token (`credential_kind` SASToken), `AzureFileSystem` decides
that a storage account **with** hierarchical
namespace has none. `Move()` then fails with "not implemented", and
`DeleteFile()` takes the flat-namespace path, which
fails on a hierarchical account. The same account works correctly with an
account key.
Versions: pyarrow 26.0.1 (Python 3.12, Linux x86_64) for the reproduction
below, and the C++ library built from the 26.0.1
source (Rocky Linux 9). I read the same code in the 26.0.0 tag and on
`main`; I did not run those versions.
The storage account is StorageV2 with hierarchical namespace enabled, blob
soft delete off.
**Reproduction** (account SAS with permissions `rwdlacyx`, services Blob,
resource types Service, Container and Object.
A container SAS gives the same result for the namespace detection and
`Move()`, but `create_dir` fails on it with a 403
for the container properties call, so the example uses the account SAS):
```python
import pyarrow.fs as pafs
sas = "?sv=...&ss=bf&srt=sco&sp=rwdlacyx&se=...&spr=https&sig=..." # note
the leading "?"
fs = pafs.AzureFileSystem(account_name="<account with hierarchical
namespace>", sas_token=sas)
fs.create_dir("<container>/probe", recursive=True)
with fs.open_output_stream("<container>/probe/a.txt") as f:
f.write(b"hello")
fs.move("<container>/probe/a.txt", "<container>/probe/b.txt")
```
Result with the SAS token:
```
OSError: FileSystem::Move() is not implemented for Azure Storage accounts
without Hierarchical Namespace support (see arrow/issues/40405).
```
Same account, same code, with `account_key=...` instead of `sas_token=...`:
the move succeeds.
A second symptom: because the account is believed to be flat, `DeleteFile`
first tries to create the parent's directory
marker blob (a blob whose name ends in `/`), which a hierarchical account
rejects, and the file is not deleted:
```
DeleteFile failed to ensure empty directory marker '<dir>' exists in
container: https://<account>.blob.core.windows.net/<container>?...
Azure Error: [InvalidUri] 400 The requested URI does not represent any
resource on the server.
```
(That message also contains the full request URL including the SAS
signature, which ends up in application logs. Might
be worth a separate look: the URL in these error messages is not redacted.)
### Cause
In `AzureOptions::MakeDataLakeServiceClient`
(`cpp/src/arrow/filesystem/azurefs.cc`, line 483 in 26.0.1):
```cpp
case CredentialKind::kSASToken:
return std::make_unique<DataLake::DataLakeServiceClient>(
AccountBlobUrl(account_name) + sas_token_, client_options);
```
Every other credential kind in that function (anonymous, token credentials,
shared key) passes `AccountDfsUrl(account_name)`.
Only the SAS case passes the **blob** URL. (The identical expression a few
lines above, in `MakeBlobServiceClient`, is
correct.)
`Azure::Storage::Files::DataLake::DataLakeServiceClient` keeps the URL it is
given as `m_serviceUrl`; it only converts it
to a blob URL for its internal blob client (`GetBlobUrlFromUrl`).
`GetFileSystemClient` / `GetDirectoryClient` / the path
client build their request URLs from `m_serviceUrl`, so all Data Lake REST
calls go to `<account>.blob.core.windows.net`.
`CheckIfHierarchicalNamespaceIsEnabled` calls
`GetDirectoryClient("").GetAccessControlList()` and treats HTTP 400 and 409
as "no hierarchical namespace". Sent to the blob host that request returns
`400 InvalidUri`, so the detector concludes
the account is flat. Evidence, same SAS, same request (`HEAD
/<container>/?action=getAccessControl`):
| Host | Result |
|---|---|
| `<account>.dfs.core.windows.net` | 200 |
| `<account>.blob.core.windows.net` | 400 `InvalidUri` |
(With a shared key, the DFS host also returns 200, which is why
`account_key` works.)
### Proposed fix
One line:
```diff
- AccountBlobUrl(account_name) + sas_token_, client_options);
+ AccountDfsUrl(account_name) + sas_token_, client_options);
```
in the `kSASToken` case of `MakeDataLakeServiceClient` only (not in
`MakeBlobServiceClient`).
I built Arrow 26.0.1 from source with this change and tested it against a
real hierarchical account in two ways.
1. A small C++ program calling `arrow::fs::AzureFileSystem` directly (the
equivalent of the pyarrow reproduction above),
linked once to stock 26.0.1 and once to the patched build, with an
account SAS and a container SAS:
| Call | Stock, SAS | Patched, account SAS | Patched, container SAS |
|---|---|---|---|
| `CreateDir` | fails (blob URL, `InvalidUri` 400) | OK | fails: 403 on
the container properties call (same as with stock Arrow, so unrelated to this
fix) |
| write + close | OK | OK | OK |
| `Move()` | `NotImplemented` ("without Hierarchical Namespace") | **OK**
| **OK** |
| `GetFileInfo` after the move | file not found (the move never happened)
| file, size 5 | file, size 5 |
| `DeleteFile` (file not moved before) | fails (`DeleteFile failed to
ensure empty directory marker`, `InvalidUri` 400) | OK | not run |
With the patch the SAS results are identical to the account key results
on every call I ran.
2. An application (C++, linked to the patched `libarrow`) that writes
Parquet files under a temporary name and renames
them: a 2,000,000 row run with 4 writers, with container SAS and account
SAS, produced correct output and left no
temporary files.
### Notes
- **Intent.** I looked at the history. The SAS PR (`GH-44308`, commit
`ba2b9e54e`) added a `kSASToken` case to both
`MakeBlobServiceClient` and `MakeDataLakeServiceClient`; in the Data Lake
one it uses `AccountBlobUrl(...) + sas_token_`,
while the cases right above it (and the code before the PR) use
`AccountDfsUrl(...)`. I found no review discussion of
that line, so it looks like the blob client's expression was copied. I
cannot rule out a reason I do not know about.
The Azurite based tests run against a flat namespace, so they would not
notice.
- **Versions checked (late 2026).** 26.0.1 (2026-11-03) is the latest
release; I tested it. There are no commits to
`azurefs.cc` after the 26.0.1 tag, `main` has the same line, and a search
of Arrow's issues and pull requests for this
problem found nothing (the nearest open issue, #49972, is about the
missing leading `?` in SAS tokens).
- **A separate observation, not part of this issue:** on a hierarchical
account `DeleteFile()` right after `Move()` fails
with `[LeaseIdMissing] 412`, also with an account key and stock Arrow, and
it succeeds about 20 s later. `Move()` takes a
15 s lease on the source (`MovePathWithDataLakeAPI`), renames with it, and
then `Forget()`s the guard, and the renamed
file seems to keep the lease until it runs out. I can file that separately
if it is of interest.
- Untested: user-delegation SAS; accounts without hierarchical namespace
with the patch (the DFS endpoint should answer 400/409 there as
it does for other credential types, so detection should still say "flat");
sovereign clouds / custom endpoints.
- A unit test looks feasible: `TestAzureOptions` in `azurefs_test.cc`
already has offline tests that call
`MakeDataLakeServiceClient()` (for example
`TestMakeDataLakeServiceClientInvalidAccountName`). A new one could build the
options with an account name
and `ConfigureSASCredential("?sig=x")` and check that
`MakeDataLakeServiceClient()->GetUrl()` uses the `dfs` host. I could not
compile it
here (Arrow's test build is not available), so treat it as an idea.
### Component(s)
C++, Python
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]