Spero di utilizzare il server Elasticsearch di Amazon per alimentare una ricerca di campi longtext in un database Django. Tuttavia, non voglio nemmeno esporre questa ricerca a coloro che non hanno un accesso e non vogliono fare affidamento sulla sicurezza attraverso l'oscurità o qualche tattica di restrizione IP (a meno che non funzioni bene con un'app di heroku esistente, dove viene distribuita l'app Django).Django-Haystack utilizzando Amazon Elasticsearch hosting con credenziali IAM
Haystack sembra fare molto per questo, ma non sembra essere un modo semplice per configurarlo per utilizzare le credenziali IAM di Amazon per accedere al servizio Elasticsearch. Questa funzionalità esiste in elasticsearch-py, che usa.
https://elasticsearch-py.readthedocs.org/en/master/#running-with-aws-elasticsearch-service
from elasticsearch import Elasticsearch, RequestsHttpConnection
from requests_aws4auth import AWS4Auth
host = 'YOURHOST.us-east-1.es.amazonaws.com'
awsauth = AWS4Auth(YOUR_ACCESS_KEY, YOUR_SECRET_KEY, REGION, 'es')
es = Elasticsearch(
hosts=[{'host': host, 'port': 443}],
http_auth=awsauth,
use_ssl=True,
verify_certs=True,
connection_class=RequestsHttpConnection
)
print(es.info())
Per quanto riguarda utilizzando l'autorizzazione HTTP, ho trovato questo sotto questioni in https://github.com/django-haystack/django-haystack/issues/1046
from urlparse import urlparse
parsed = urlparse('https://user:[email protected]:port')
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': parsed.hostname,
'INDEX_NAME': 'haystack',
'KWARGS': {
'port': parsed.port,
'http_auth': (parsed.username, parsed.password),
'use_ssl': True,
}
}
}
Mi chiedo se c'è un modo per unire questi due, qualcosa di simile a quanto segue (che , come previsto, dà un errore poiché è più di un semplice nome utente e password):
from requests_aws4auth import AWS4Auth
awsauth = AWS4Auth([AACCESS_KEY],[SECRET_KEY],[REGION],'es')
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': [AWSHOST],
'INDEX_NAME': 'haystack',
'KWARGS': {
'port': 443,
'http_auth': awsauth,
'use_ssl': True,
'verify_certs': True
}
},
}
.210
L'errore qui:
TypeError at /admin/
must be convertible to a buffer, not AWS4Auth
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.7.7
Exception Type: TypeError
Exception Value:
must be convertible to a buffer, not AWS4Auth
Exception Location: /usr/lib/python2.7/base64.py in b64encode, line 53
Tutte le idee su come ottenere questo risultato?
Stai tentando di utilizzare le credenziali AWS per autenticare gli utenti contro l'implementazione privata di ElasticSearch? –
Ho creato un utente Amazon IAM per l'app. Voglio che solo coloro che possono accedere all'app possano utilizzarlo per inviare richieste al server Elasticsearch. Quindi è necessaria una sola credenziale AWS. – Serioushouse