Skip to content

Commit 0a0e7cf

Browse files
close #47 support connection with API key
1 parent a45c583 commit 0a0e7cf

File tree

6 files changed

+25
-10
lines changed

6 files changed

+25
-10
lines changed

.env.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ INSTALLATION_TYPE=source
3333
ELASTICSEARCH_URL=http://localhost:9200
3434
ELASTICSEARCH_USERNAME=
3535
ELASTICSEARCH_PASSWORD=
36+
ELASTICSEARCH_API_KEY=
3637
SSL_VERIFY_PEER=true
3738
SSL_VERIFY_HOST=true
3839
SECRET_REGISTER=

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ENV INSTALLATION_TYPE=docker
88
ENV ELASTICSEARCH_URL=$ELASTICSEARCH_URL
99
ENV ELASTICSEARCH_USERNAME=$ELASTICSEARCH_USERNAME
1010
ENV ELASTICSEARCH_PASSWORD=$ELASTICSEARCH_PASSWORD
11+
ENV ELASTICSEARCH_API_KEY=$ELASTICSEARCH_API_KEY
1112
ENV SSL_VERIFY_PEER=$SSL_VERIFY_PEER
1213
ENV SSL_VERIFY_HOST=$SSL_VERIFY_HOST
1314

config/services.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ services:
1717
$elasticsearchUrl: '%env(ELASTICSEARCH_URL)%'
1818
$elasticsearchUsername: '%env(ELASTICSEARCH_USERNAME)%'
1919
$elasticsearchPassword: '%env(ELASTICSEARCH_PASSWORD)%'
20+
$elasticsearchApiKey: '%env(ELASTICSEARCH_API_KEY)%'
2021
$sslVerifyPeer: '%env(bool:SSL_VERIFY_PEER)%'
2122
$sslVerifyHost: '%env(bool:SSL_VERIFY_HOST)%'
2223
$secretRegister: '%env(SECRET_REGISTER)%'

docs/docker-for-development.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,12 @@ echo 'path.repo: ["/usr/share/elasticsearch/fs"]' >> config/elasticsearch.yml
7777
docker pull stephanediondev/elasticsearch-admin
7878
docker stop elasticsearch-admin && docker rm elasticsearch-admin && docker rmi elasticsearch-admin
7979
docker run -e "ELASTICSEARCH_URL=http://x.x.x.x:9200" -e "SECRET_REGISTER=xxxxx" -p 80:8080 -d --name elasticsearch-admin stephanediondev/elasticsearch-admin
80-
81-
# Edit ELASTICSEARCH_URL and SECRET_REGISTER (random string to secure registration)
82-
# If Elasticsearch security features are enabled, add -e "ELASTICSEARCH_USERNAME=xxxxx" -e "ELASTICSEARCH_PASSWORD=xxxxx"
8380
```
8481

82+
Edit ```ELASTICSEARCH_URL``` and ```SECRET_REGISTER``` (random string to secure registration)
83+
84+
If Elasticsearch security features are enabled, add ```-e "ELASTICSEARCH_USERNAME=xxxxx" -e "ELASTICSEARCH_PASSWORD=xxxxx"``` or ```-e "ELASTICSEARCH_API_KEY=xxxxx"```
85+
8586
### Build and run elasticsearch-admin with source installation
8687

8788
````
@@ -90,11 +91,12 @@ docker stop elasticsearch-admin && docker rm elasticsearch-admin && docker rmi e
9091
docker build --force-rm --tag elasticsearch-admin .
9192
9293
docker run -e "ELASTICSEARCH_URL=http://x.x.x.x:9200" -e "SECRET_REGISTER=xxxxx" -p 80:8080 -d --name elasticsearch-admin elasticsearch-admin
93-
94-
# Edit ELASTICSEARCH_URL and SECRET_REGISTER (random string to secure registration)
95-
# If Elasticsearch security features are enabled, add -e "ELASTICSEARCH_USERNAME=xxxxx" -e "ELASTICSEARCH_PASSWORD=xxxxx"
9694
````
9795

96+
Edit ```ELASTICSEARCH_URL``` and ```SECRET_REGISTER``` (random string to secure registration)
97+
98+
If Elasticsearch security features are enabled, add ```-e "ELASTICSEARCH_USERNAME=xxxxx" -e "ELASTICSEARCH_PASSWORD=xxxxx"``` or ```-e "ELASTICSEARCH_API_KEY=xxxxx"```
99+
98100
### /etc/hosts
99101

100102
```
@@ -136,6 +138,7 @@ docker run -e "ELASTICSEARCH_URL=http://x.x.x.x:9200" -e "SECRET_REGISTER=xxxxx"
136138
SetEnv ELASTICSEARCH_URL http://x.x.x.x:500
137139
SetEnv ELASTICSEARCH_USERNAME elastic
138140
SetEnv ELASTICSEARCH_PASSWORD changeme
141+
SetEnv ELASTICSEARCH_API_KEY
139142
</VirtualHost>
140143
141144
<VirtualHost *:80>
@@ -147,6 +150,7 @@ docker run -e "ELASTICSEARCH_URL=http://x.x.x.x:9200" -e "SECRET_REGISTER=xxxxx"
147150
SetEnv ELASTICSEARCH_URL http://x.x.x.x:600
148151
SetEnv ELASTICSEARCH_USERNAME elastic
149152
SetEnv ELASTICSEARCH_PASSWORD changeme
153+
SetEnv ELASTICSEARCH_API_KEY
150154
</VirtualHost>
151155
152156
<VirtualHost *:80>
@@ -158,6 +162,7 @@ docker run -e "ELASTICSEARCH_URL=http://x.x.x.x:9200" -e "SECRET_REGISTER=xxxxx"
158162
SetEnv ELASTICSEARCH_URL http://x.x.x.x:700
159163
SetEnv ELASTICSEARCH_USERNAME elastic
160164
SetEnv ELASTICSEARCH_PASSWORD changeme
165+
SetEnv ELASTICSEARCH_API_KEY
161166
</VirtualHost>
162167
163168
<VirtualHost *:80>
@@ -169,5 +174,6 @@ docker run -e "ELASTICSEARCH_URL=http://x.x.x.x:9200" -e "SECRET_REGISTER=xxxxx"
169174
SetEnv ELASTICSEARCH_URL http://x.x.x.x:800
170175
SetEnv ELASTICSEARCH_USERNAME elastic
171176
SetEnv ELASTICSEARCH_PASSWORD changeme
177+
SetEnv ELASTICSEARCH_API_KEY
172178
</VirtualHost>
173179
```

docs/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Elasticsearch is a trademark of Elasticsearch BV, registered in the U.S. and in
3737
[(Back to table of contents)](#table-of-contents)
3838

3939
- Supported Elasticsearch versions: 2.x, 5.x, 6.x, 7.x, 8.x
40-
- Connection to Elasticsearch: server-side (no CORS issue), private or public, local or remote, http or https, credentials or not
40+
- Connection to Elasticsearch: server-side (no CORS issue), private or public, local or remote, http or https, authorization with user/password or API key
4141
- App users: register, login, logout, list, create, read, update, delete
4242
- App roles: list, create, read, update (permissions), delete
4343
- Notifications (Push API, Email, Slack Incoming Webhook, Microsoft Teams Incoming Webhook) about cluster health, node up, node down, disk threshold, license expiration, ES version
@@ -129,7 +129,7 @@ docker run -e "ELASTICSEARCH_URL=http://x.x.x.x:9200" -e "SECRET_REGISTER=xxxxx"
129129

130130
Edit ```ELASTICSEARCH_URL``` and ```SECRET_REGISTER``` (random string to secure registration)
131131

132-
If Elasticsearch security features are enabled, add ```-e "ELASTICSEARCH_USERNAME=xxxxx" -e "ELASTICSEARCH_PASSWORD=xxxxx"```
132+
If Elasticsearch security features are enabled, add ```-e "ELASTICSEARCH_USERNAME=xxxxx" -e "ELASTICSEARCH_PASSWORD=xxxxx"``` or ```-e "ELASTICSEARCH_API_KEY=xxxxx"```
133133

134134
If you have SSL certificates, add ```-v /path/privkey.pem:/etc/nginx/privkey.pem -v /path/fullchain.pem:/etc/nginx/fullchain.pem```
135135

@@ -263,7 +263,7 @@ cp .env.dist .env
263263

264264
In the ```.env``` file edit ```ELASTICSEARCH_URL``` and ```SECRET_REGISTER``` (random string to secure registration)
265265

266-
If Elasticsearch security features are enabled, edit ```ELASTICSEARCH_USERNAME``` and ```ELASTICSEARCH_PASSWORD```
266+
If Elasticsearch security features are enabled, edit ```ELASTICSEARCH_USERNAME``` and ```ELASTICSEARCH_PASSWORD``` or ```-e "ELASTICSEARCH_API_KEY=xxxxx"```
267267

268268
You can also edit ```VAPID_PUBLIC_KEY``` and ```VAPID_PRIVATE_KEY``` to use push notifications (only in HTTPS)
269269

src/Manager/CallManager.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class CallManager
8181

8282
protected string $elasticsearchPassword;
8383

84+
protected string $elasticsearchApiKey;
85+
8486
protected bool $sslVerifyPeer;
8587

8688
protected bool $sslVerifyHost;
@@ -91,6 +93,7 @@ public function __construct(
9193
string $elasticsearchUrl,
9294
string $elasticsearchUsername,
9395
string $elasticsearchPassword,
96+
string $elasticsearchApiKey,
9497
bool $sslVerifyPeer,
9598
bool $sslVerifyHost
9699
) {
@@ -99,6 +102,7 @@ public function __construct(
99102
$this->elasticsearchUrl = $elasticsearchUrl;
100103
$this->elasticsearchUsername = $elasticsearchUsername;
101104
$this->elasticsearchPassword = $elasticsearchPassword;
105+
$this->elasticsearchApiKey = $elasticsearchApiKey;
102106
$this->sslVerifyPeer = $sslVerifyPeer;
103107
$this->sslVerifyHost = $sslVerifyHost;
104108
}
@@ -123,7 +127,9 @@ public function call(CallRequestModel $callRequest): CallResponseModel
123127
$options['query']['format'] = 'json';
124128
}
125129

126-
if ($this->elasticsearchUsername && $this->elasticsearchPassword) {
130+
if ($this->elasticsearchApiKey) {
131+
$headers['Authorization'] = 'ApiKey '.$this->elasticsearchApiKey;
132+
} else if ($this->elasticsearchUsername && $this->elasticsearchPassword) {
127133
$headers['Authorization'] = 'Basic '.base64_encode($this->elasticsearchUsername.':'.$this->elasticsearchPassword);
128134
}
129135

0 commit comments

Comments
 (0)