Skip to content

BulkAsync() per-request authentication failsΒ #8740

@krzysztofsmigiel

Description

@krzysztofsmigiel

Elastic.Clients.Elasticsearch version:
9.1.2

Elasticsearch version:
9.1.2

.NET runtime version:
9.0.109

Operating system version:
macOS 15.5 (24F74)

Description of the problem including expected versus actual behavior:
In our multi-tenant environment, we need to pass authentication credentials (JWT tokens) per-request rather than per-client. We accomplish this using RequestDescriptors with the RequestConfiguration lambda method, specifically calling rc.Authentication() to set credentials.

This per-request authentication pattern works correctly for all other Elasticsearch methods
It fails specifically for Bulk* methods (including BulkAsync())
The issue occurs with both JWT and Basic authentication, indicating it's not token-type specific
This functionality worked in version 8.19.2 but is broken in 9.1.2

Steps to reproduce:

  1. Create instance of ElasticsearchClient.
  2. Run BulkAsync() with per-request credentials
    var response = await client.BulkAsync(b => b
            .Index(IndexName)
            .IndexMany(documents)
            .RequestConfiguration(rc => rc.Authentication(new BasicAuthentication(_username, _password)))
    );
    

Expected behavior
Per-request authentication via RequestConfiguration should work consistently across all methods, including bulk operations.

Observed behavior
{"error":{"root_cause":[{"type":"security_exception","reason":"missing authentication credentials for REST request [/someindex/_bulk]","header":{"WWW-Authenticate":["Basic realm=\"security\", charset=\"UTF-8\"","ApiKey"]}}],"type":"security_exception","reason":"missing authentication credentials for REST request [/someindex/_bulk]","header":{"WWW-Authenticate":["Basic realm=\"security\", charset=\"UTF-8\"","ApiKey"]}},"status":401}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions