Skip to content

Commit fd4623f

Browse files
jrgnsJurgens du Toit
authored andcommitted
chore: Initial port from original codebase
fix: Reference correct path for db.rb chore: Add omniauth support refac: Use the security app to handle Omniauth routes chore: Add up and down db migrations refac: Link users to identities chore: Clean up config and documents fix: Link to registration from sidebar fix: Logout functionality refac: Make the views easier to customize refac: Proper load order for DB and models refac: Use Base Roda app fix: Allow admin users to create users fix: Properly handle authentication failure
1 parent 6699783 commit fd4623f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+54382
-60
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
/pkg/
88
/spec/reports/
99
/tmp/
10+
*_secret
11+
/node_modules

.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.3.1

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ sudo: false
22
language: ruby
33
rvm:
44
- 2.3.1
5+
services:
6+
- elasticsearch
7+
before_script:
8+
- sleep 10
59
before_install: gem install bundler -v 1.12.5

LICENSE.txt

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
1-
The MIT License (MIT)
1+
Copyright (c) Jade IT cc
22

3-
Copyright (c) 2016 TODO: Write your name
3+
ProxES is an Open Source project licensed under the terms of
4+
the LGPLv3 license. Please see <http://www.gnu.org/licenses/lgpl-3.0.html>
5+
for license text.
46

5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
11-
12-
The above copyright notice and this permission notice shall be included in
13-
all copies or substantial portions of the Software.
14-
15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21-
THE SOFTWARE.
7+
A commercial-friendly license allowing private forks and modifications of
8+
ProxES is available. Please contact [email protected] more detail.

README.md

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
1-
# Proxes
1+
[![Build Status](https://travis-ci.org/EagerELK/proxes.svg?branch=master)](https://travis-ci.org/EagerELK/proxes)
22

3-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/proxes`. To experiment with that code, run `bin/console` for an interactive prompt.
3+
# ProxES
44

5-
TODO: Delete this and the text above, and describe your gem
5+
ProxES provides a couple of components to allow you to embed and wrap
6+
Elasticsearch within your Rack app.
7+
8+
## Components
9+
10+
ProxES has two main components that works together, but can be used separately
11+
as well:
12+
13+
### 1. Management Interface
14+
15+
This interface gives you the ability to manage your Elasticsearch users and get
16+
and overview of your Elasticsearch cluster.
17+
18+
### 2. Security Middleware
19+
20+
The Rack middleware checks all requests going to your Elasticsearch cluster
21+
against the users and permissions you've set up in the Management Interface. It
22+
uses a combination of [Pundit](https://github.com/elabs/pundit) and
23+
[OmniAuth](https://github.com/omniauth/omniauth) to secure your cluster.
624

725
## Installation
826

@@ -22,7 +40,15 @@ Or install it yourself as:
2240

2341
## Usage
2442

25-
TODO: Write usage instructions here
43+
Check the included [`config.ru`](https://github.com/EagerELK/proxes/blob/master/config.ru) file for an example setup.
44+
45+
At a minimum, you need to
46+
47+
* Set up Session Middleware
48+
* Set up OmniAuth to Authenticate the user
49+
* Mount the `ProxES::App`
50+
* Proxy all Elasticsearch requests after running it through the `ProxES::Security`
51+
middleware
2652

2753
## Development
2854

@@ -34,8 +60,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
3460

3561
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/proxes.
3662

37-
3863
## License
3964

40-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
65+
The gem is available as open source under the terms of the [LGPLv3 license](http://www.gnu.org/licenses/lgpl-3.0.html).
4166

Rakefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
require "bundler/gem_tasks"
2-
require "rspec/core/rake_task"
1+
require 'rubygems'
2+
require 'bundler/gem_tasks'
3+
require 'rspec/core/rake_task'
34

45
RSpec::Core::RakeTask.new(:spec)
56

Vagrantfile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
Vagrant.configure(2) do |config|
5+
config.vm.box = "ubuntu/trusty64"
6+
7+
config.vm.network :private_network, ip: '172.16.248.110'
8+
9+
config.vm.provider "virtualbox" do |vb|
10+
vb.memory = "2048"
11+
end
12+
13+
config.vm.provision "shell", privileged: false, inline: <<-SHELL
14+
# Dependencies / Utilities
15+
sudo apt-get update
16+
sudo apt-get install -y screen curl git build-essential libssl-dev
17+
18+
# Ruby
19+
sudo apt-get install ruby2.0
20+
# if [ ! -f /home/vagrant/.rvm/scripts/rvm ]
21+
# then
22+
# gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
23+
# \\curl -sSL https://get.rvm.io | bash
24+
# fi
25+
# source /home/vagrant/.rvm/scripts/rvm
26+
27+
# Ruby and it's Gems
28+
cd /vagrant
29+
# rvm use $(cat .ruby-version) --install
30+
gem install bundler --no-rdoc --no-ri
31+
bundle install
32+
33+
# Node
34+
# if [ ! -f /home/vagrant/.nvm/nvm.sh ]
35+
# then
36+
# \\curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash
37+
# fi
38+
# export NVM_DIR="/home/vagrant/.nvm"
39+
# [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
40+
41+
# # Node and it's packages
42+
# nvm install `cat .nvmrc`
43+
# npm install --no-bin-links
44+
SHELL
45+
end

config.ru

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#\-o 0.0.0.0 -p 9292
2+
libdir = File.expand_path(File.dirname(__FILE__) + '/lib')
3+
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
4+
5+
require 'proxes'
6+
require 'proxes/db'
7+
8+
use Rack::Session::Pool
9+
# use Rack::Session::Cookie,
10+
# :key => '_ProxES_session',
11+
# #:secure=>!TEST_MODE, # Uncomment if only allowing https:// access
12+
# :secret=>File.read('.session_secret')
13+
14+
require 'omniauth'
15+
require 'omniauth-identity'
16+
# OmniAuth.config.test_mode = true
17+
18+
use OmniAuth::Builder do
19+
# The identity provider is used by the App.
20+
provider :identity,
21+
fields: [:username],
22+
model: ProxES::Identity,
23+
on_login: ProxES::Security,
24+
on_registration: ProxES::Security,
25+
locate_conditions: lambda{|req| {username: req['username']} }
26+
end
27+
28+
OmniAuth.config.on_failure = Proc.new { |env|
29+
OmniAuth::FailureEndpoint.new(env).redirect_to_failure
30+
}
31+
32+
require 'warden'
33+
require 'proxes/strategies/jwt_token'
34+
use Warden::Manager do |manager|
35+
manager.default_strategies :jwt_token
36+
manager.scope_defaults :default, action: '_proxes/unauthenticated'
37+
manager.failure_app = ProxES::Security
38+
end
39+
40+
Warden::Manager.serialize_into_session { |user| user.id }
41+
Warden::Manager.serialize_from_session { |id| ProxES::User[id] }
42+
43+
# Proxy all Elasticsearch requests
44+
map '/' do
45+
# Security
46+
use ProxES::Security
47+
48+
# Forward requests to ES
49+
run Rack::Proxy.new(backend: ENV['ELASTICSEARCH_URL'])
50+
end
51+
52+
# Management App
53+
map '/_proxes' do
54+
run ProxES::App
55+
end

lib/proxes.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
require "proxes/version"
2-
3-
module Proxes
4-
# Your code goes here...
5-
end
1+
require 'proxes/version'
2+
require 'proxes/base'
3+
require 'proxes/app'
4+
require 'proxes/security'
5+
require 'proxes/es_request'

lib/proxes/app.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require 'proxes/base'
2+
require 'proxes/routes'
3+
4+
module ProxES
5+
# Manage your Elasticsearch cluster, user and user sessions
6+
class App < ProxES::Base
7+
plugin :multi_route
8+
9+
def logger
10+
require 'logger'
11+
@logger ||= Logger.new($stdout)
12+
end
13+
14+
def root_url
15+
@root_url = opts[:root_url] || '/_proxes'
16+
end
17+
18+
route do |r|
19+
r.multi_route
20+
21+
r.public
22+
23+
r.get do
24+
authenticate!
25+
26+
view 'index'
27+
end
28+
end
29+
end
30+
end

0 commit comments

Comments
 (0)