Skip to content
This repository was archived by the owner on Mar 4, 2019. It is now read-only.

Commit a3c8c0b

Browse files
committed
Merge pull request #45 from emig/1.5-organize-assembly
ES 1.5.x compatiblity
2 parents b342803 + 1145f15 commit a3c8c0b

File tree

12 files changed

+170
-125
lines changed

12 files changed

+170
-125
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ deploy.sh
1212
.project
1313
.settings/
1414
data/
15+
/.local-execution-hints.log
16+
/.local-*-execution-hints.log

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1+
sudo: false
12
language: java
3+
script: ./script/ci/run_build.sh
4+
env:
5+
- ES_VERSION=1.5.0
6+
- ES_VERSION=1.5.1
7+
- ES_VERSION=1.5.2
8+
cache:
9+
directories:
10+
- $HOME/.m2

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ All notable changes to this project will be documented in this
44
file. This file is structured according to http://keepachangelog.com/
55

66
- - -
7-
8-
## [1.4.1-pre][unreleased]
7+
## [1.5.0][unreleased]
8+
### - Added
9+
- allow disabling ipwhitelist by setting its value to `false`
10+
- updated pom to depend on elasticsearch-parent project
11+
- better travis test for different ES versions
912

1013
### Changed
1114
- restored default healthcheck for authenticated users &&

README.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@ There is no way to configure this on a per index basis.
1818

1919
| Http Basic Plugin | elasticsearch |
2020
|-----------------------------|-----------------------|
21-
| v1.4.0(master) | 1.4.0 |
21+
| v1.5.0(master) | 1.5.x |
22+
| v1.4.0 | 1.4.0 |
2223
| v1.3.0 | 1.3.0 |
2324
| v1.2.0 | 1.2.0 |
2425
| 1.1.0 | 1.0.0 |
2526
| 1.0.4 | 0.90.7 |
2627

2728
## Installation
2829

29-
Download the current version from https://github.com/Asquera/elasticsearch-http-basic/releases and copy it to `plugins/http-basic`.
30+
Download the desired version from https://github.com/Asquera/elasticsearch-http-basic/releases and copy it to `plugins/http-basic`.
3031

3132
## Configuration
3233

@@ -36,8 +37,8 @@ Once the plugin is installed it can be configured in the [elasticsearch modules
3637
|-----------------------------------|------------------------------|-------------------------------------------------------------------------|
3738
| `http.basic.enabled` | true | **true** disables the default ES HTTP Transport module |
3839
| `http.basic.user` | "admin" | |
39-
| `http.basic.password` | "admin_pw" | |
40-
| `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) |
40+
| `http.basic.password` | "admin_pw" | |
41+
| `http.basic.ipwhitelist` | ["localhost", "127.0.0.1"] | If set to `false` no ip will be whitelisted. Uses Host Name Resolution from [java.net.InetAddress](http://docs.oracle.com/javase/7/docs/api/java/net/InetAddress.html) |
4142
| `http.basic.trusted_proxy_chains` | [] | Set an array of trusted proxies ips chains |
4243
| `http.basic.log` | false | enables plugin logging to ES log. Unauthenticated requests are always logged. |
4344
| `http.basic.xforward` | "" | most common is [X-Forwarded-For](http://en.wikipedia.org/wiki/X-Forwarded-For) |
@@ -123,14 +124,19 @@ http.basic.trusted_proxy_chains: ["1.1.1.1,2.2.2.2"]
123124

124125
## Testing
125126

127+
**note:** localhost is a whitelisted ip as default.
128+
Considering a default configuration with **my_username** and **my_password** configured.
129+
130+
Correct credentials
126131
```
127-
$ curl -v localhost:9200 # works
128-
$ curl -v --user my_username:my_password localhost:9200/foo # works
132+
$ curl -v localhost:9200 # works (returns 200) (by default localhost is configured as whitelisted ip)
133+
$ curl -v --user my_username:my_password no_local_host:9200/foo # works (returns 200) (if credentials are set in configuration)
129134
```
130135

131-
**note:** localhost is a whitelisted ip as default.
136+
Wrong credentials
132137
```
133-
$ curl -v --user my_username:password localhost:9200/foo # sends 401
138+
$ curl -v --user my_username:wrong_password no_local_host:9200/ # health check, returns 200 with "{\"OK\":{}}" although Unauthorized
139+
$ curl -v --user my_username:password no_local_host:9200/foo # returns 401
134140
```
135141

136142
## Development
@@ -139,8 +145,8 @@ $ curl -v --user my_username:password localhost:9200/foo # sends 401
139145
Maven is configured to run the unit and integration tests. This plugin makes
140146
use of [ES Integration Tests](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/integration-tests.html)
141147

142-
`mvn test` test runs all tests
143-
`mvn integration-test` test runs integration tests only
148+
`mvn test -Dtests.security.manager=false` test runs all tests
149+
`mvn integration-test -Dtests.security.manager=false` test runs integration tests only
144150

145151
## Issues
146152

pom.xml

Lines changed: 89 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,98 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3-
<modelVersion>4.0.0</modelVersion>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
exmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<groupId>com.asquera.elasticsearch</groupId>
7+
<artifactId>elasticsearch-http-basic</artifactId>
8+
<version>1.5.0</version>
9+
<packaging>jar</packaging>
10+
<name>Elasticsearch Http Basic plugin</name>
11+
<description>Adds HTTP Basic authentication (BA) to your Elasticsearch cluster</description>
12+
<url>https://github.com/Asquera/elasticsearch-http-basic/</url>
13+
<inceptionYear>2011</inceptionYear>
414

5-
<groupId>com.asquera.elasticsearch</groupId>
6-
<artifactId>elasticsearch-http-basic</artifactId>
7-
<version>1.4.1-pre</version>
8-
<packaging>jar</packaging>
15+
<parent>
16+
<groupId>org.elasticsearch</groupId>
17+
<artifactId>elasticsearch-parent</artifactId>
18+
<version>1.5.0</version>
19+
</parent>
920

10-
<name>Basic Authentication Plugin</name>
11-
<url>http://maven.apache.org</url>
21+
<properties>
22+
<tests.jvms>1</tests.jvms>
23+
<es.logger.level>INFO</es.logger.level>
24+
</properties>
1225

13-
<properties>
14-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15-
<elasticsearch.version>1.4.0</elasticsearch.version>
16-
<lucene.version>4.10.2</lucene.version>
17-
<lucene.maven.version>4.10.2</lucene.maven.version>
18-
</properties>
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.apache.httpcomponents</groupId>
29+
<artifactId>httpclient</artifactId>
30+
<version>4.3.5</version>
31+
<scope>test</scope>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.hamcrest</groupId>
35+
<artifactId>hamcrest-all</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>com.carrotsearch.randomizedtesting</groupId>
39+
<artifactId>randomizedtesting-runner</artifactId>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.apache.lucene</groupId>
43+
<artifactId>lucene-test-framework</artifactId>
44+
</dependency>
1945

20-
<dependencies>
46+
<dependency>
47+
<groupId>org.elasticsearch</groupId>
48+
<artifactId>elasticsearch</artifactId>
49+
<scope>provided</scope>
50+
</dependency>
2151

22-
<dependency>
23-
<groupId>org.apache.lucene</groupId>
24-
<artifactId>lucene-test-framework</artifactId>
25-
<version>${lucene.maven.version}</version>
26-
<scope>test</scope>
27-
</dependency>
52+
<dependency>
53+
<groupId>org.elasticsearch</groupId>
54+
<artifactId>elasticsearch</artifactId>
55+
<type>test-jar</type>
56+
</dependency>
2857

29-
<dependency>
30-
<groupId>org.apache.httpcomponents</groupId>
31-
<artifactId>httpclient</artifactId>
32-
<version>4.3.5</version>
33-
<scope>test</scope>
34-
</dependency>
58+
</dependencies>
3559

36-
<dependency>
37-
<groupId>com.carrotsearch.randomizedtesting</groupId>
38-
<artifactId>randomizedtesting-runner</artifactId>
39-
<version>2.1.10</version>
40-
<scope>test</scope>
41-
</dependency>
42-
<dependency>
43-
<groupId>org.elasticsearch</groupId>
44-
<artifactId>elasticsearch</artifactId>
45-
<version>${elasticsearch.version}</version>
46-
</dependency>
60+
<build>
61+
<resources>
62+
<resource>
63+
<directory>src/main/resources</directory>
64+
<filtering>true</filtering>
65+
</resource>
66+
</resources>
67+
<plugins>
68+
<plugin>
69+
<groupId>org.apache.maven.plugins</groupId>
70+
<artifactId>maven-compiler-plugin</artifactId>
71+
</plugin>
72+
<plugin>
73+
<groupId>com.carrotsearch.randomizedtesting</groupId>
74+
<artifactId>junit4-maven-plugin</artifactId>
75+
</plugin>
76+
<plugin>
77+
<groupId>org.apache.maven.plugins</groupId>
78+
<artifactId>maven-surefire-plugin</artifactId>
79+
</plugin>
80+
<plugin>
81+
<groupId>org.apache.maven.plugins</groupId>
82+
<artifactId>maven-source-plugin</artifactId>
83+
</plugin>
84+
<plugin>
85+
<groupId>org.apache.maven.plugins</groupId>
86+
<artifactId>maven-assembly-plugin</artifactId>
87+
</plugin>
88+
</plugins>
89+
</build>
4790

48-
<dependency>
49-
<groupId>org.elasticsearch</groupId>
50-
<artifactId>elasticsearch</artifactId>
51-
<version>${elasticsearch.version}</version>
52-
<type>test-jar</type>
53-
<scope>test</scope>
54-
</dependency>
55-
56-
<dependency>
57-
<groupId>org.hamcrest</groupId>
58-
<artifactId>hamcrest-all</artifactId>
59-
<version>1.3</version>
60-
<scope>test</scope>
61-
</dependency>
62-
63-
<dependency>
64-
<groupId>junit</groupId>
65-
<artifactId>junit</artifactId>
66-
<version>4.10</version>
67-
<scope>test</scope>
68-
</dependency>
69-
70-
</dependencies>
71-
<build>
72-
<!-- Create a zip file according to elasticsearch naming scheme -->
73-
<plugins>
74-
<plugin>
75-
<groupId>org.apache.maven.plugins</groupId>
76-
<artifactId>maven-antrun-plugin</artifactId>
77-
<version>1.6</version>
78-
<executions>
79-
<execution>
80-
<id>zip</id>
81-
<phase>package</phase>
82-
<configuration>
83-
<target>
84-
<zip basedir="${project.build.directory}"
85-
includes="${project.build.finalName}.jar"
86-
destfile="${project.build.directory}/${project.artifactId}-${project.version}.zip" />
87-
</target>
88-
</configuration>
89-
<goals>
90-
<goal>run</goal>
91-
</goals>
92-
</execution>
93-
</executions>
94-
</plugin>
95-
</plugins>
96-
97-
<pluginManagement>
98-
<plugins>
99-
<plugin>
100-
<groupId>org.apache.maven.plugins</groupId>
101-
<artifactId>maven-compiler-plugin</artifactId>
102-
<configuration>
103-
<source>1.7</source>
104-
<target>1.7</target>
105-
</configuration>
106-
</plugin>
107-
</plugins>
108-
</pluginManagement>
109-
</build>
91+
<repositories>
92+
<repository>
93+
<id>oss-snapshots</id>
94+
<name>Sonatype OSS Snapshots</name>
95+
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
96+
</repository>
97+
</repositories>
11098
</project>

script/ci/run_build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#! /usr/bin/env sh
2+
mvn -Delasticsearch.version=$ES_VERSION -Dtests.security.manager=false test

src/main/assemblies/plugin.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0"?>
2+
<assembly>
3+
<id>plugin</id>
4+
<formats>
5+
<format>zip</format>
6+
</formats>
7+
<includeBaseDirectory>false</includeBaseDirectory>
8+
<dependencySets>
9+
<dependencySet>
10+
<outputDirectory>/</outputDirectory>
11+
<useProjectArtifact>true</useProjectArtifact>
12+
<useTransitiveFiltering>true</useTransitiveFiltering>
13+
<excludes>
14+
<exclude>org.elasticsearch:elasticsearch</exclude>
15+
</excludes>
16+
</dependencySet>
17+
<dependencySet>
18+
<outputDirectory>/</outputDirectory>
19+
<useProjectArtifact>true</useProjectArtifact>
20+
<useTransitiveFiltering>true</useTransitiveFiltering>
21+
<includes>
22+
<include>com.asquera.elasticsearch:elasticsearch-http-basic</include>
23+
</includes>
24+
</dependencySet>
25+
</dependencySets>
26+
</assembly>

src/main/java/com/asquera/elasticsearch/plugins/http/HttpBasicServer.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ public class HttpBasicServer extends HttpServer {
5656

5757
this.user = settings.get("http.basic.user", "admin");
5858
this.password = settings.get("http.basic.password", "admin_pw");
59-
this.whitelist = new InetAddressWhitelist(
60-
settings.getAsArray("http.basic.ipwhitelist",
61-
new String[]{"localhost", "127.0.0.1"}));
59+
final boolean whitelistEnabled = settings.getAsBoolean("http.basic.ipwhitelist", true);
60+
String [] whitelisted = new String[0];
61+
if (whitelistEnabled) {
62+
whitelisted = settings.getAsArray("http.basic.ipwhitelist", new String[]{"localhost", "127.0.0.1"});
63+
}
64+
this.whitelist = new InetAddressWhitelist(whitelisted);
6265
this.proxyChains = new ProxyChains(
6366
settings.getAsArray(
6467
"http.basic.trusted_proxy_chains", new String[]{""}));
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
* Test a rest action that sets special response headers
3434
*/
3535
@ClusterScope(transportClientRatio = 0.0, scope = Scope.SUITE, numDataNodes = 1)
36-
public class EmptyWhitelistIntegrationTest extends HttpBasicServerPluginIntegrationTest {
36+
public class DisabledWhitelistIntegrationTest extends HttpBasicServerPluginIntegrationTest {
3737

3838
@Override
3939
protected Settings nodeSettings(int nodeOrdinal) {
4040
return builderWithPlugin().
41-
putArray("http.basic.ipwhitelist", "unkown")
41+
put("http.basic.ipwhitelist", false)
4242
.build();
4343
}
4444

@@ -62,4 +62,11 @@ public void clientBadCredentialsBasicAuthenticationFails() throws Exception {
6262
assertThat(response.getStatusCode()
6363
, equalTo(RestStatus.UNAUTHORIZED.getStatus()));
6464
}
65+
66+
@Test
67+
public void clientBadCredentialsSanityCheckOk() throws Exception {
68+
HttpResponse response = requestWithCredentials("admin:wrong").path("/").execute();
69+
assertThat(response.getStatusCode()
70+
, equalTo(RestStatus.OK.getStatus()));
71+
}
6572
}

src/test/java/com/asquera/elasticsearch/plugins/http/auth/integration/HttpBasicServerPluginIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @author Ernesto Miguez ([email protected])
2020
*/
2121

22-
public abstract class HttpBasicServerPluginIntegrationTest extends
22+
public class HttpBasicServerPluginIntegrationTest extends
2323
ElasticsearchIntegrationTest {
2424

2525
protected final String localhost = "127.0.0.1";

src/test/java/com/asquera/elasticsearch/plugins/http/auth/integration/IpAuthenticationIntegrationTest.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,4 @@ public void proxyViaLocalhostIpUnauthenticatesNonWhitelistedClients() throws Exc
102102
assertThat(response.getStatusCode(), equalTo(RestStatus.UNAUTHORIZED.getStatus()));
103103
}
104104
}
105-
106-
protected HttpRequestBuilder requestWithCredentials(String credentials) throws Exception {
107-
return httpClient().path("/_status")
108-
.addHeader("Authorization", "Basic " + Base64.encodeBytes(credentials.getBytes()));
109-
}
110-
111105
}

src/test/resources/log4j.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
log4j.rootLogger=INFO, out
2+
3+
log4j.appender.out=org.apache.log4j.ConsoleAppender
4+
log4j.appender.out.layout=org.apache.log4j.PatternLayout
5+
log4j.appender.out.layout.conversionPattern=[%d{ISO8601}][%-5p][%-25c] %m%n

0 commit comments

Comments
 (0)