Skip to content

Commit 6a05de0

Browse files
author
Andrea Sessa
committed
Initial commit, supporting 6.3.2
0 parents  commit 6a05de0

File tree

20 files changed

+750
-0
lines changed

20 files changed

+750
-0
lines changed

.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.idea/*
2+
*.class
3+
*.zip
4+
/build/
5+
/bin/
6+
/target/
7+
*~
8+
deploy.sh
9+
.gradle
10+
.DS_Store
11+
.classpath
12+
.metadata/
13+
.project
14+
/.gradle/
15+
.settings/
16+
data/
17+
/.local-execution-hints.log
18+
/.local-*-execution-hints.log
19+
*.iml

.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
language: java
2+
script:
3+
- mvn clean verify
4+
- mvn package
5+
deploy:
6+
skip_cleanup: true
7+
provider: releases
8+
file: target/releases/elasticsearch-http-basic-plugin.zip
9+
api_key: b1f302f147825ef828d64a77cc5e37a9898f34a6
10+
on:
11+
repo: Sessa93/elasticsearch-http-basic
12+
tags: true
13+
branch: master

CHANGELOG.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this
4+
file. This file is structured according to http://keepachangelog.com/
5+
Use `date "+%Y-%m-%d"` to get the correct date formatting
6+
7+
- - -
8+
## [1.5.1][2015-08-30]
9+
### - Added
10+
- allow HEAD root url authentication #39
11+
- log http method on any request. #42
12+
- doc: 1.6.0, 1.7.0 support #52
13+
### - Fix
14+
- test: adapt to method signature change after 1.5.1 #55
15+
- test: run custom install and test commands in ci
16+
17+
## [1.5.0][2015-07-04]
18+
19+
### - Added
20+
- allow disabling ipwhitelist by setting its value to `false`
21+
- updated pom to depend on elasticsearch-parent project
22+
- travis test matrix for different ES versions
23+
24+
### Changed
25+
- restored default healthcheck for authenticated users
26+
- unauthenticated healthcheck for `/` returns `"{\"OK\":{}}"`
27+
- thanks @feaster83
28+
29+
## [1.4.0]
30+
## [1.0.3]
31+
32+
### - Added
33+
- Changelog
34+
- Disable Authentication for `/`, allowing it to be used for healtchecks.
35+
- thanks @archiloque

COPYING

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
elasticsearch-http-basic is Copyright (c) 2011, Florian and Felix Gilcher

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2011 Florian Gilcher <florian.gilcher@asquera.de>, Felix Gilcher <felix.gilcher@asquera.de>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
2+
[![Build Status](https://travis-ci.org/Asquera/elasticsearch-http-basic.svg?branch=master)](https://travis-ci.org/Asquera/elasticsearch-http-basic)
3+
4+
5+
# HTTP Basic / Ip auth for ElasticSearch
6+
7+
This plugin provides an extension of ElasticSearchs HTTP Transport module to enable **HTTP basic authentication** and/or
8+
**Ip based authentication**.
9+
10+
Requesting `/` does not request authentication to simplify health check configuration.
11+
12+
There is no way to configure this on a per index basis.
13+
14+
15+
## Version Mapping
16+
17+
| Http Basic Plugin | elasticsearch |
18+
|-----------------------------|------------------------------|
19+
| v1.0.0 | 6.3.2 |
20+
21+
22+
## Installation
23+
24+
Download the desired version from https://github.com/Cleafy/elasticsearch6-http-basic/releases and copy it to `plugins/http-basic`.
25+
26+
## Configuration
27+
28+
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.
29+
30+
| Setting key | Default value | Notes |
31+
|-----------------------------------|------------------------------|-------------------------------------------------------------------------|
32+
| `http.basic.enabled` | true | **true** disables the default ES HTTP Transport module |
33+
| `http.basic.user` | "admin" | |
34+
| `http.basic.password` | "admin_pw" |
35+
| `http.basic.log` | false | enables plugin logging to ES log. Unauthenticated requests are always logged. |
36+
37+
**Be aware that the password is stored in plain text.**
38+
39+
## Http basic authentication
40+
41+
see [this article](https://en.wikipedia.org/wiki/Basic_access_authentication)
42+
43+
## Configuration example
44+
45+
The following code enables plugin logging, sets user and password.
46+
47+
```
48+
http.basic.enable: true
49+
http.basic.log: true
50+
http.basic.user: "some_user"
51+
http.basic.password: "some_password"
52+
```
53+
54+
## Testing
55+
56+
**note:** localhost is a whitelisted ip as default.
57+
Considering a default configuration with **my_username** and **my_password** configured.
58+
59+
Correct credentials
60+
```
61+
$ curl -v --user my_username:my_password no_local_host:9200/foo # works (returns 200) (if credentials are set in configuration)
62+
```
63+
64+
Wrong credentials
65+
```
66+
$ curl -v --user my_username:wrong_password no_local_host:9200/ # health check, returns 200 with "{\"OK\":{}}" although Unauthorized
67+
$ curl -v --user my_username:password no_local_host:9200/foo # returns 401
68+
```
69+
70+
71+
## Issues
72+
73+
Please file your issue here:
74+
https://github.com/Cleafy/elasticsearch6-http-basic/issues

pom.xml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns: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.cleafy.elasticsearch6</groupId>
7+
<artifactId>elasticsearch6-http-basic</artifactId>
8+
<version>3.0.0</version>
9+
<packaging>jar</packaging>
10+
<name>Elasticsearch 6.x Http Basic plugin</name>
11+
<description>Adds HTTP Basic authentication (BA) to your Elasticsearch cluster</description>
12+
<url>https://github.com/Cleafy/elasticsearch-http-basic</url>
13+
<inceptionYear>2018</inceptionYear>
14+
15+
<properties>
16+
<tests.jvms>1</tests.jvms>
17+
<es.logger.level>INFO</es.logger.level>
18+
</properties>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>org.elasticsearch</groupId>
23+
<artifactId>elasticsearch</artifactId>
24+
<version>6.3.2</version>
25+
<scope>provided</scope>
26+
</dependency>
27+
28+
<dependency>
29+
<groupId>org.elasticsearch.test</groupId>
30+
<artifactId>framework</artifactId>
31+
<version>6.3.2</version>
32+
<scope>test</scope>
33+
</dependency>
34+
<dependency>
35+
<groupId>net.java.dev.jna</groupId>
36+
<artifactId>jna</artifactId>
37+
<version>4.1.0</version>
38+
<scope>test</scope>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.apache.logging.log4j</groupId>
42+
<artifactId>log4j-api</artifactId>
43+
<version>2.7</version>
44+
<scope>test</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.apache.logging.log4j</groupId>
48+
<artifactId>log4j-core</artifactId>
49+
<version>2.7</version>
50+
<scope>test</scope>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.apache.httpcomponents</groupId>
54+
<artifactId>httpclient</artifactId>
55+
<version>RELEASE</version>
56+
<scope>compile</scope>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.apache.logging.log4j</groupId>
60+
<artifactId>log4j-core</artifactId>
61+
<version>2.11.1</version>
62+
<scope>provided</scope>
63+
</dependency>
64+
<dependency>
65+
<groupId>org.apache.logging.log4j</groupId>
66+
<artifactId>log4j-api</artifactId>
67+
<version>2.11.1</version>
68+
<scope>compile</scope>
69+
</dependency>
70+
</dependencies>
71+
72+
<build>
73+
<finalName>elasticsearch6-http-basic-plugin</finalName>
74+
<resources>
75+
<resource>
76+
<directory>src/main/resources</directory>
77+
<filtering>false</filtering>
78+
</resource>
79+
</resources>
80+
81+
<plugins>
82+
<plugin>
83+
<groupId>org.apache.maven.plugins</groupId>
84+
<artifactId>maven-assembly-plugin</artifactId>
85+
<version>2.6</version>
86+
<configuration>
87+
<appendAssemblyId>false</appendAssemblyId>
88+
<outputDirectory>${project.build.directory}/releases/</outputDirectory>
89+
<descriptors>
90+
<descriptor>${basedir}/src/main/assemblies/plugin.xml</descriptor>
91+
</descriptors>
92+
</configuration>
93+
<executions>
94+
<execution>
95+
<phase>package</phase>
96+
<goals>
97+
<goal>single</goal>
98+
</goals>
99+
</execution>
100+
</executions>
101+
</plugin>
102+
103+
<plugin>
104+
<groupId>org.apache.maven.plugins</groupId>
105+
<artifactId>maven-compiler-plugin</artifactId>
106+
<version>3.3</version>
107+
<configuration>
108+
<source>1.8</source>
109+
<target>1.8</target>
110+
</configuration>
111+
</plugin>
112+
</plugins>
113+
</build>
114+
115+
</project>

reinstall.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ES=/usr/share/elasticsearch
2+
sudo $ES/bin/plugin remove http-basic
3+
mvn -DskipTests clean package
4+
FILE=`ls ./target/elasticsearch-*zip`
5+
sudo $ES/bin/plugin -url file:$FILE -install http-basic
6+
sudo service elasticsearch restart

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.cleafy.elasticsearch:elasticsearch6-http-basic</include>
23+
</includes>
24+
</dependencySet>
25+
</dependencySets>
26+
</assembly>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.cleafy.elasticsearch6.plugins.http;
2+
3+
import com.cleafy.elasticsearch6.plugins.http.auth.AuthCredentials;
4+
import com.cleafy.elasticsearch6.plugins.http.auth.HttpBasicAuthenticator;
5+
import com.cleafy.elasticsearch6.plugins.http.utils.Globals;
6+
import com.cleafy.elasticsearch6.plugins.http.utils.LoggerUtils;
7+
import org.elasticsearch.ElasticsearchException;
8+
import org.elasticsearch.client.node.NodeClient;
9+
import org.elasticsearch.common.settings.Settings;
10+
import org.elasticsearch.rest.*;
11+
import org.elasticsearch.transport.TransportException;
12+
13+
public class BasicRestFilter {
14+
private final HttpBasicAuthenticator httpBasicAuthenticator;
15+
private boolean isUnauthLogEnabled;
16+
17+
public BasicRestFilter(final Settings settings) {
18+
super();
19+
this.httpBasicAuthenticator = new HttpBasicAuthenticator(settings, new AuthCredentials(settings.get(Globals.SETTINGS_USERNAME, "pippo"), settings.get(Globals.SETTINGS_PASSWORD, "pluto").getBytes()));
20+
this.isUnauthLogEnabled = settings.getAsBoolean(Globals.SETTINGS_LOG, false);
21+
}
22+
23+
public RestHandler wrap(RestHandler original) {
24+
return (request, channel, client) -> {
25+
if (!checkAndAuthenticateRequest(request, channel, client)) {
26+
original.handleRequest(request, channel, client);
27+
}
28+
};
29+
}
30+
31+
private boolean checkAndAuthenticateRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
32+
ElasticsearchException forbiddenException = new TransportException("Forbidden");
33+
try {
34+
if (this.httpBasicAuthenticator.authenticate(request)) {
35+
LoggerUtils.logRequest(request, getClass());
36+
return false;
37+
}
38+
39+
if (this.isUnauthLogEnabled) { LoggerUtils.logUnAuthorizedRequest(request, getClass()); }
40+
channel.sendResponse(new BytesRestResponse(channel, RestStatus.FORBIDDEN, forbiddenException));
41+
} catch (Exception e) {
42+
if (this.isUnauthLogEnabled) { LoggerUtils.logUnAuthorizedRequest(request, getClass()); }
43+
channel.sendResponse(new BytesRestResponse(channel, RestStatus.FORBIDDEN, forbiddenException));
44+
return true;
45+
}
46+
return true;
47+
}
48+
}

0 commit comments

Comments
 (0)