8000 v1.0.1 is set to master in verson mapping · fnet123/elasticsearch-http-basic@ffaa403 · GitHub
[go: up one dir, main page]

Skip to content

Commit ffaa403

Browse files
author
Ernesto
committed
v1.0.1 is set to master in verson mapping
fixed security problem in ip authentication. security problem introduced in commit 53d1cf8 changes: - remove usage of 'Host' header to identify client's ip - the request ip is used to ip authenticate direct connected clients - add usage of trusted proxy chain - the trusted proxy chain is used to ip authenticate indirect connected clients - added unit and integration tests - updated log messages remove uncompatible code
1 parent c2a6b01 commit ffaa403

17 files changed

+1663
-76
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@
66
*~
77
deploy.sh
88
.gradle
9+
.DS_Store
10+
.classpath
11+
.metadata/
12+
.project
13+
.settings/
14+
data/

README.md

Lines changed: 111 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,122 @@
1+
2+
**IMPORTANT NOTICE**: versions 1.0.4 is *insecure and should not be used*.
3+
They have a bug that allows an attacker to get ip authentication by setting
4+
its ip on the 'Host' header. A fix is provided for now for versions v1.1.1, v1.2.0 and
5+
v.1.3.0 of the plugin.
6+
17
# HTTP Basic auth for ElasticSearch
28

3-
This plugin provides an extension of ElasticSearchs HTTP Transport module to enable HTTP Basic authorization.
9+
This plugin provides an extension of ElasticSearchs HTTP Transport module to enable HTTP Basic authorization and
10+
Ip based authorization.
411

5-
Requesting / does not request authentication to simplify health heck configuration.
12+
Requesting `/` does not request authentication to simplify health check configuration.
613

714
There is no way to configure this on a per index basis.
815

16+
917
## Version Mapping
1018

1119
| Http Basic Plugin | elasticsearch |
1220
|-----------------------------|-----------------------|
13-
| 1.1.0 | 1.0.0 |
14-
| 1.0.4(master) | 0.90.7 |
21+
| 1.1.0(master) | 1.0.0 |
22+
| 1.0.4 | 0.90.7 |
1523

1624
## Installation
1725

1826
Download the current version from https://github.com/Asquera/elasticsearch-http-basic/releases and copy it to `plugins/http-basic`.
1927

2028
## Configuration
2129

22-
The plugin is disabled by default. Enabling basic authorization will disable the default HTTP Transport module.
30+
Once the plugin is installed it can be configured in the [elasticsearch modules configuration file](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/setup-configuration.html#settings). See the [elasticserach directory layout information](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/setup-dir-layout.html) for more information about the default paths of an ES installation.
31+
32+
| Setting key | Default value | Notes |
33+
|-----------------------------------|------------------------------|-------------------------------------------------------------------------|
34+
| `http.basic.enabled` | true | **true** disables the default ES HTTP Transport module |
35+
| `http.basic.user` | "admin" | |
36+
| `http.basic.password` | "admin_pw" | |
37+
| `http.basic.ipwhitelist` | ["localhost", "127.0.0.1"] | uses Host Name Resolution from [java.net.InetAddress](http://docs.oracle.com/javase/7/docs/api/java/net/InetAddress.html) |
38+
| `http.basic.trusted_proxy_chains` | [] | Set an array of trusted proxies ips chains |
39+
| `http.basic.log` | false | enables plugin logging to ES log. Unauthenticated requests are always logged. |
40+
| `http.basic.xforward` | "" | most common is [X-Forwarded-For](http://en.wikipedia.org/wiki/X-Forwarded-For) |
41+
42+
Be aware that the password is stored in plain text.
43+
44+
## Ip based authentication
45+
46+
A client is **authenticated iff** its **request** is **trusted** and its **ip is whitelisted**.
47+
A Request from a client connected *directly* (direct client) is **trusted**. Its ip is the request ip.
48+
A Request form a client connected *via proxies* (remote client) is **trusted iff** there is a tail
49+
subchain of the request chain that matches a tail subchain of the trusted proxy chains.
50+
51+
**A tail subchain** of a chain "*A,B,C*" is a subchain that matches it by the end.
52+
Example: the 3 tail subchains of the ip chain *A,B,C* are:
53+
54+
(pseudo code) tailSubchains("A,B,C") --> ["A,B,C", "B,C", "C"]
55+
56+
The request chain of a remote client is obtained following these steps:
57+
58+
- read the request's xforward configured header field.
59+
- remove the xforwarded defined client's ip (first listed ip as defined by X-F F438 orwarded-For) from it.
60+
- append the request ip to it.
61+
62+
The ip chain of a remote client is the ip previous to the longest trusted tail subchain .Is the ip used to check
63+
against the whitelist.
64+
65+
66+
### Request chain checks
67+
68+
Having the following configuration:
69+
70+
http.basic.xforward = 'X-Forwarded-For'
71+
http.basic.trusted_proxy_chains = ["B,C", "Z"]
72+
73+
#### Trusted cases:
74+
75+
- A remote client with ip *A* connects to [server] via proxies with ips *B* and *C*. *X-Forwarded-For* header has "*A,B*", removing the client's ip "*A*" and adding the request ip *C*, the resulting chain *B,C* matches a trusted tail subchain. Client's ip is A.
76+
77+
[A] --> B --> C --> [server]
78+
79+
- A remote client with ip *A* connects to [server] via proxies with ips *R*, *P*, *B* and *C*. *X-Forwarded-For* header has "*A,R,P,B*".
80+
Removing the client's ip "*A*" and adding the request ip *C* , the resulting chain ** matches a trusted tail subchain. **note**: in this case "*P*" is taken as the client's ip, and checked against the white list. Client's ip is P.
81+
82+
[A] --> R --> P --> B --> C --> [server]
83+
84+
- A remote client with ip *A* connects to [server] via *C*. *X-Forwarded-For* header has
85+
*A*, removing the client's ip *A* and adding the request ip *C*, the resulting chain *C* matches a trusted tail subchain. Client's ip is A.
86+
87+
[A] --> C --> [server]
88+
89+
- client *A* connects directly to [server]. *X-Forwarded-For* header is not set. Client's ip is A.
90+
91+
[A] --> [server]
92+
93+
#### Untrusted cases:
94+
95+
- A remote client with ip *A* connects to [server] via *D*. *X-Forwarded-For* header has
96+
"*A*", removing the client's ip "*A*" and adding the request ip *D*, the resulting chain *D* doesn't match any trusted sub ip chain.
97+
98+
[A] --> D --> [server]
99+
100+
- A remote client with ip *X* connects to proxy with ip *C* passing a faked *X-Forwarded-For* header "*R*". *C* will check the IP of the request and add it to the *X-Forwarded-For* field. the server will receive and *X-Forwarded-For* header
101+
as: "*R,X*", remove the client's ip "*R*", add the request ip "*C*" and finally drop the request, as "*X,C*" doesn't match the trusted ip.
102+
103+
[X] -- R --> C --> [server]
104+
105+
106+
### configuration example
107+
108+
The following code enables plugin logging, sets user and password, sets chain
109+
"1.1.1.1,2.2.2.2" as trusted , whitelists ip 3.3.3.3 and defines xforward
110+
header as the common 'X-Forwarded-For':
23111

24112
```
25-
http.basic.enabled: true
26-
http.basic.user: "my_username"
27-
http.basic.password: "my_password"
113+
http.basic.log: true
114+
http.basic.user: "some_user"
115+
http.basic.password: "some_password"
116+
http.basic.ipwhitelist: ["3.3.3.3"]
117+
http.basic.xforward: "X-Forwarded-For"
118+
http.basic.trusted_proxy_chains: ["1.1.1.1,2.2.2.2"]
119+
>>>>>>> 8f3012f... fixed security problem in ip authentication.
28120
```
29121

30122
Be aware that the password is stored in plain text.
@@ -34,12 +126,21 @@ Be aware that the password is stored in plain text.
34126
```
35127
$ curl -v localhost:9200 # works
36128
$ curl -v --user my_username:my_password localhost:9200/foo # works
129+
```
130+
131+
**note:** localhost is a whitelisted ip as default.
132+
```
37133
$ curl -v --user my_username:password localhost:9200/foo # sends 401
38134
```
39135

40-
## Problems
136+
## Development
137+
138+
### Testing
139+
Maven is configured to run the unit and integration tests. This plugin makes
140+
use of [ES Integration Tests](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/integration-tests.html)
41141

42-
This will not send WWW-Authorize headers - this is due to elasticsearch not allowing to add custom headers to responses.
142+
`mvn test` test runs all tests
143+
`mvn integration-test` test runs integration tests only
43144

44145
## Issues
45146

pom.xml

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,53 @@
1313
<properties>
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1515
<elasticsearch.version>1.0.0</elasticsearch.version>
16+
<lucene.version>4.6.1</lucene.version>
1617
</properties>
1718

1819
<dependencies>
20+
21+
<dependency>
22+
<groupId>org.apache.lucene</groupId>
23+
<artifactId>lucene-test-framework</artifactId>
24+
<version>${lucene.version}</version>
25+
<scope>test</scope>
26+
</dependency>
27+
28+
<dependency>
29+
<groupId>org.apache.httpcomponents</groupId>
30+
<artifactId>httpclient</artifactId>
31+
<version>4.3.5</version>
32+
<scope>test</scope>
33+
</dependency>
34+
1935
<dependency>
2036
<groupId>org.elasticsearch</groupId>
2137
<artifactId>elasticsearch</artifactId>
2238
<version>${elasticsearch.version}</version>
2339
</dependency>
2440

2541
<dependency>
26-
<groupId>org.testng</groupId>
27-
<artifactId>testng</artifactId>
28-
<version>6.8</version>
29-
<scope>test</scope>
30-
<exclusions>
31-
<exclusion>
32-
<groupId>org.hamcrest</groupId>
33-
<artifactId>hamcrest-core</artifactId>
34-
</exclusion>
35-
<exclusion>
36-
<groupId>junit</groupId>
37-
<artifactId>junit</artifactId>
38-
</exclusion>
39-
</exclusions>
42+
<groupId>org.elasticsearch</groupId>
43+
<artifactId>elasticsearch</artifactId>
44+
<version>${elasticsearch.version}</version>
45+
<type>test-jar</type>
46+
<scope>test</scope>
4047
</dependency>
48+
49+
<dependency>
50+
<groupId>org.hamcrest</groupId>
51+
<artifactId>hamcrest-all</artifactId>
52+
<version>1.3</version>
53+
<scope>test</scope>
54+
</dependency>
55+
56+
<dependency>
57+
<groupId>junit</groupId>
58+
<artifactId>junit</artifactId>
59+
<version>4.10</version>
60+
<scope>test</scope>
61+
</dependency>
62+
4163
</dependencies>
4264
<build>
4365
<!-- Create a zip file according to elasticsearch naming scheme -->

0 commit comments

Comments
 (0)
0