Giter VIP home page Giter VIP logo

postgres-auth-server's Introduction

postgres-auth-server

This is an authentication server, similar to htpasswd-auth-server or ldap-auth-server. All users are stored in a Postgresql table, and there's a web interface. Administrators can set user's passwords, and require a user to change their password on their next login. Users can change their own passwords.

Installation

Install OpenResty

I have a repo for automatically installing OpenResty + luarocks - https://github.com/jprjr/setup-openresty

git clone https://github.com/jprjr/setup-openresty /tmp/setup-openresty
/tmp/setup-openresty/setup-openresty --prefix=/opt/openresty

This will install openresty at /opt/openresty. You can then add /opt/openresty/bin to your PATH, or make make symlinks from /usr/local/bin to the binaries/scripts at /opt/openresty/bin, whichever you prefer.

In all my examples, I'll assume you've somehow added luarocks to your PATH.

Install other prerequisites, setup Postgres

You'll need libyaml-dev and postgresql installed

sudo apt-get install libyaml-dev postgresql

Then create a username, password, and database for postgres-auth-server. You should change the below example to have a better password.

sudo -u postgres psql -c "create user psql_auth with password 'psql_auth'"
sudo -u postgres psql -c "create database psql_auth with owner psql_auth"

Option 1: Install Globally with LuaRocks

sudo luarocks install postgres-auth-server

Assuming you used the setup-openresty script, then you'll find postgres-auth-server at /opt/openresty/bin/postgres-auth-server

Create a file at /etc/postgres-auth-server/config.yaml -- there's an example config.yaml file in this repo. Edit as needed.

Move on down to the Usage section

Option 2: Self-contained install

You can setup postgres-auth-server to use its own lua_modules folder:

git clone https://github.com/jprjr/postgres-auth-server.git
postgres-auth-server
luarocks-openresty --tree=lua_modules make rockspecs/postgres-auth-server-dev-1.rockspec

Then launch with

./bin/postgres-auth-server

By default, ./bin/postgres-auth-server will just try to use lua - you can specify a lua binary to run with -l (binary), ie:

./bin/postgres-auth-server -l /opt/openresty/bin/lua

Performing authentication

The authentication endpoint for apps/nginx is /auth, ie:

  • http://127.0.0.1:8080/auth
  • http://192.168.1.50:8080/auth
  • http://192.168.1.50:8080/users/auth -- if setup with http_prefix: '/users'

Please look at the etc/config.yaml.example file for details on how to configure this.

Usage

In any examples, substiute postgres-auth-server with ./bin/posgres-auth-server if you went for the self-contained installation.

postgres-auth-server help

Usage: postgres-auth-server [-c /path/to/config.yaml] <action>
Available actions:
  add username -- interactively add user
  admin username -- make user admin
  unadmin username -- make user admin
  change username -- require change for user
  list -- list users
  import /path/to/htpasswd -- import existing htpasswd file
  run   -- run server
  check -- check config file

postgres-auth-server add (username)

Prompts for a username, password, whether the user should be an admin, and if the user should be forced to change their password at next login.

postgres-auth-server admin (username)

Makes (username) flagged as an admin user.

postgres-auth-server unadmin (username)

Removes admin status from a user.

postgres-auth-server change (username)

Forces a password change at next login.

postgres-auth-server list

Lists usernames, admin status, password change required status

postgres-auth-server import /path/to/htpasswd

Imports an existing htpasswd file.

If a user already exists, postgres-auth-server prints a warning message indicating as such.

If the htpasswd file contains an encryption method not supported by postgres-auth-server, the user is not imported and a message is printed.

postgres-auth-server run

Launches postgres-auth-server

postgres-auth-server check

Attempts to parse the config file and checks for errors. Also tests that the postgres credentials are valid.

LICENSE

MIT (see LICENSE)

postgres-auth-server's People

Contributors

jprjr avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

postgres-auth-server's Issues

Error: No results matching query were found when installing postgres-auth-server

Hello,

I'm assuming that luarocks is some of package management for lua. Nevertheless, I'm having trouble installing postgres-auth-server globally, see below:

sudo luarocks-openresty install postgres-auth-server

Error: No results matching query were found.
sudo luarocks-openresty search postgres            

postgres - Search results for Lua 5.1:
======================================


Rockspecs and source rocks:
---------------------------

lua-resty-postgres
   1.0-0 (rockspec) - https://luarocks.org
   1.0-0 (src) - https://luarocks.org

luadbi-postgresql
   0.7-1 (rockspec) - https://luarocks.org
   0.6-2 (rockspec) - https://luarocks.org
   0.6-2 (src) - https://luarocks.org
   0.5-2 (rockspec) - https://luarocks.org
   0.5-2 (src) - https://luarocks.org
   0.5-1 (rockspec) - https://luarocks.org
   0.5-1 (src) - https://luarocks.org

luasql-postgres
   2.4.0-1 (rockspec) - https://luarocks.org
   2.4.0-1 (src) - https://luarocks.org
   2.3.5-2 (rockspec) - https://luarocks.org
   2.3.5-1 (rockspec) - https://luarocks.org
   2.3.4-1 (rockspec) - https://luarocks.org
   2.3.3-1 (rockspec) - https://luarocks.org
   2.3.2-1 (rockspec) - https://luarocks.org
   2.3.1-1 (rockspec) - https://luarocks.org
   2.3.0-1 (rockspec) - https://luarocks.org
   2.3.0-1 (src) - https://luarocks.org

Build failure due to luaposix

You've already commented on this issue here luaposix/luaposix#320 (comment), I was wondering if wanted my workaround patch? I could create a PR?

From f55e59bf7e61cc06e7f43daff98d80b0288d8cda Mon Sep 17 00:00:00 2001
From: lhorace <[email protected]>
Date: Sun, 6 Jan 2019 08:09:09 -0500
Subject: [PATCH] Downgrade luaposix to earlier version to fix building, see
 https://github.com/luaposix/luaposix/issues/320

---
 rockspecs/postgres-auth-server-dev-1.rockspec | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/rockspecs/postgres-auth-server-dev-1.rockspec b/rockspecs/postgres-auth-server-dev-1.rockspec
index 75de8f9..65aeb87 100644
--- a/rockspecs/postgres-auth-server-dev-1.rockspec
+++ b/rockspecs/postgres-auth-server-dev-1.rockspec
@@ -10,7 +10,9 @@ dependencies = {
   "lecho",
   "lapis",
   "lyaml",
-  "luaposix",
+  -- Latest luaposix fails to build, requires non-existent luke rock
+  -- Downgrade to a working version!
+  "luaposix == 34.0.1-1",
   "luacrypto",
   "lua-crypt",
 }
-- 
2.20.1

User Delete Typo

When attempting to delete a user from the /users page identified a typo in the button

should be a quick fix in line 9 in the following file "/opt/postgres-auth-server/lib/postgres-auth-server/views/deleteuser.etlua"
<button type="submit" class="pure-button pure-button-primary">Delte User</button>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.