opensearch-project / opensearch-php

Official PHP Client for OpenSearch
Other
91 stars 54 forks source link

[FEATURE] STS authentication is not cached #173

Open arturkasperek opened 5 months ago

arturkasperek commented 5 months ago

Is your feature request related to a problem?

I noticed that each time when I make a request to OpenSearch with this client, it makes an additional request to sts for each OS request. Due to that behavior, each request is little bit slower

What solution would you like?

It should be possible to provide some caching store like a local filesystem - opensearch client should use that to store result of STS call. I think aws SDK PHP should support that already

What alternatives have you considered?

Don't know any alternative

shyim commented 5 months ago

I would like to implement that in OpenSearch, as I would like to make it more independent of aws-php SDK. We can require https://packagist.org/packages/psr/cache and allow as an optional parameter a caching

arturkasperek commented 5 months ago

At that moment workaround was to use custom credentialsProvider with caching enabled

dblock commented 5 months ago

@arturkasperek do you have code that shows how to do that? it would be helpful to add an auth guide like https://github.com/opensearch-project/opensearch-py/blob/main/guides/auth.md that includes it.

arturkasperek commented 5 months ago

@dblock:

            $provider = CredentialProvider::cache(CredentialProvider::defaultProvider(), $cache);

            $clientCreator = (new \OpenSearch\ClientBuilder())
                ->setHosts([$parsedUrl['scheme'] . '://' . $parsedUrl['host']])
                ->setSigV4Region(getenv('AWS_REGION') != false ? getenv('AWS_REGION') : 'us-east-1')
                ->setSigV4Service('es')
                ->setSigV4CredentialProvider($provider);