Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using oauth and openapi #86

Merged
merged 11 commits into from
Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ help:
@echo " bump to update the package version."
@echo " dry to only display results (not applied) when combined with 'bump'."
@echo " dist to build source and wheel package."
@echo "\nSecurity targets:"
@echo " gensecret to generate a secret hash key."
@echo " gencert to generate a self-signed certificate."

.PHONY: debug
debug:
Expand Down Expand Up @@ -178,3 +181,16 @@ dist: clean
@-python setup.py sdist
@-python setup.py bdist_wheel
ls -l dist

## Security

.PHONY: gensecret
gensecret:
@echo "Generate a secret ..."
@-python -c 'import uuid; print(uuid.uuid4().hex)'

.PHONY: gencert
gencert:
@echo "Generate a self-signed certificate ..."
@-bash -c "openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout key.pem -out cert.pem"
@-bash -c "openssl x509 -pubkey -noout -in cert.pem > pubkey.pem"
27 changes: 19 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
=====================================
Twitcher: A simple OWS Security Proxy
=====================================
============================
Twitcher: OWS Security Proxy
============================

.. image:: https://img.shields.io/badge/docs-latest-brightgreen.svg
:target: http://twitcher.readthedocs.io/en/latest/?badge=latest
Expand All @@ -22,13 +22,12 @@ Twitcher: A simple OWS Security Proxy
Twitcher (the bird-watcher)
*a birdwatcher mainly interested in catching sight of rare birds.* (`Leo <https://dict.leo.org/ende/index_en.html>`_).

Twitcher is a security proxy for Web Processing Services (WPS). The execution of a WPS process is blocked by the proxy.
The proxy service uses access tokens (UUID) to run a WPS process.
The access tokens are valid only for a short period of time.
In addition one can also use X.509 certificates for WPS client authentication.
Twitcher is a security proxy for OWS services like Web Processing Services (WPS).
The proxy service uses OAuth2 access tokens to protect the OWS service access.
In addition one can also use X.509 certificates for client authentication.

The implementation is not restricted to WPS services.
It will be extended to more OWS services like WMS (Web Map Service) and CSW (Catalogue Service for the Web)
It will be extended to more OWS services like WMS (Web Map Service)
and might also be used for Thredds catalog services.

Twitcher extensions:
Expand All @@ -39,6 +38,18 @@ Twitcher extensions:

Twitcher is implemented with the Python `Pyramid`_ web framework.

You can try Twitcher online using Binder, or view the notebooks on NBViewer.

.. image:: https://mybinder.org/badge_logo.svg
:target: https://mybinder.org/v2/gh/bird-house/twitcher.git/dev-oauth?filepath=notebooks
:alt: Binder Launcher
:height: 20

.. image:: https://raw.githubusercontent.com/jupyter/design/master/logos/Badges/nbviewer_badge.png
:target: https://nbviewer.jupyter.org/github/bird-house/twitcher/tree/dev-oauth/notebooks/
:alt: NBViewer
:height: 20

Twitcher is part of the `Birdhouse`_ project. The documentation is on `ReadTheDocs`_.

Twitcher `Docker`_ images are also available for most recent tagged versions.
Expand Down
1 change: 1 addition & 0 deletions binder/environment.yml
1 change: 1 addition & 0 deletions binder/postBuild
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pip install -e .
20 changes: 13 additions & 7 deletions development.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@ retry.attempts = 3
# twitcher
twitcher.url = http://localhost:8000
twitcher.adapter = default
twitcher.rpcinterface = true
twitcher.username =
twitcher.password =
twitcher.ows_security = true
twitcher.username = demo
twitcher.password = demo
twitcher.ows_proxy = true
twitcher.ows_proxy_delegate = false
twitcher.ows_proxy_protected_path = /ows
# available types: default, random_token, signed_token, custom_token
twitcher.token.type = default
# run "make gencert"
twitcher.token.keyfile = key.pem
twitcher.token.certfile = pubkey.pem
twitcher.token.expires_in = 3600
twitcher.token.issuer = twitcher
# run "make gensecret"
twitcher.token.secret = 8dc7b9a238c54bde90f57e80b6ac8b34

###
# wsgi server configuration
Expand Down Expand Up @@ -67,8 +73,8 @@ handlers = console

[logger_twitcher]
level = DEBUG
handlers =
qualname = twitcher
handlers = console
qualname = TWITCHER

[logger_sqlalchemy]
level = WARN
Expand Down
Binary file removed docs/diagrams/oauth-wps-data-access.png
Binary file not shown.
Binary file removed docs/diagrams/twitcher-new.png
Binary file not shown.
1 change: 0 additions & 1 deletion docs/diagrams/twitcher-new.xml

This file was deleted.

Binary file removed docs/diagrams/twitcher-overview.dia
Binary file not shown.
Binary file modified docs/diagrams/twitcher-overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/diagrams/twitcher-overview.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mxfile userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Atom/1.38.2 Chrome/61.0.3163.100 Electron/2.0.18 Safari/537.36" version="9.1.0" editor="www.draw.io" type="device"><diagram id="6b31b2c4-f107-957b-7422-773966168f4d" name="Page-1">7Zpdc9o4FIZ/DTO7N4xsYdlcAiXZzjYTpnSa7qWwha2NsRghAuyvX8mW8Yec1AkY0kmTi+AjWZbOc3T8HpEenKz2txyvozsWkLhng2Dfg596tm1ZtiP/KMshs3geygwhp4HuVBjm9D+ijUBbtzQgm0pHwVgs6Lpq9FmSEF9UbJhztqt2W7K4+tQ1DolhmPs4Nq0PNBCRXoXtFva/CA2j/MkWGmYtC+w/hpxtE/28ng2X6U/WvML5WHqhmwgHbFcywWkPTjhjIvu02k9IrHybuy277+aZ1uO8OUlEqxv0ip5wvCX5lNOJiUPujHQ5RN1g9eB4F1FB5mvsq9adxC9tkVjFuvm4IKAuBGePZMJixtOhYOAOF6BoyX0rlz1e0jgu9VwuCfJ9ZWeJ0AFiefIaxzRM5IUvV0hk57G5ZO2FJ8IF2ZdM2gW3hK2I4AfZ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mpoICJ7KXPV10V1AlIORx+RD6wLkwY+XSncfHP+roVPrYWvkLchrNfCMD9FeW0tDG2zFm73CpCuwYdSt7XqsHlh0uaT9KSLkM3GbPlakJfF//Zk3Yt/oILT/wE=</diagram></mxfile>
61 changes: 38 additions & 23 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
@@ -1,36 +1,51 @@
.. toctree::
:hidden:
#############
API Reference
#############

.. _api:
.. automodule:: twitcher

*************************
XML-RPC API Documentation
*************************
Twitcher Client
===============

.. contents::
:local:
:depth: 2
.. autoclass:: twitcher.client.TwitcherService
:members:
:undoc-members:

Twitcher CLI
============

To use the XML-RPC interface, connect to twitcher’s HTTP port with any XML-RPC client library and run commands against it.
An example of doing this using Python’s ``xmlrpclib`` client library is as follows.
.. automodule:: twitcher.scripts.twitcherctl
:members:

.. code-block:: python
Twitcher OpenAPI
----------------

import xmlrpc.client as xmlrpclib
server = xmlrpclib.Server('http://localhost:8000/RPC2')
.. autoclass:: twitcher.api.TwitcherAPI
:members:

.. warning::
OWS Security
============

When accessing the default HTTPS service you need to deactivate SSL verfication.
See ``twitcher/client.py`` how this can be done. You may also use the following code::
.. automodule:: twitcher.oauth2
:members:

>> from twitcher import client
>> server = client._create_server('https://localhost:8000/RPC2', verify_ssl=False)
.. autoclass:: twitcher.oauth2.RandomTokenValidator
:members:

The `XML-RPC <http://xmlrpc.scripting.com/>`_ interface can also be accessed from Java and other languages.
.. autoclass:: twitcher.oauth2.SignedTokenValidator
:members:

See the ``twitcher/rpcinterface.py`` module for the available xmlrpc methods:
.. autoclass:: twitcher.oauth2.CustomTokenValidator
:members:

.. autoclass:: twitcher.rpcinterface.RPCInterface
:members:
OWS Registry
============

.. autoclass:: twitcher.owsregistry.OWSRegistry
:members:

OWS Proxy
=========

.. automodule:: twitcher.owsproxy
:members:
79 changes: 79 additions & 0 deletions docs/source/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,82 @@ Configuration

Twitcher has a configuration file `development.ini` for local development.
Copy and edit this configuration to adapt to your settings.

Service
-------

Edit the configuration to change the service parameters.

The URL of the Twitcher service endpoint:

.. code-block:: ini

twitcher.url = http://localhost:8000


Basic Authentication
--------------------

Twitcher uses basic authentication for client application registration.
Edit username in password in the configuration:

.. code-block:: ini

twitcher.username = demo
twitcher.password = demo


OAuth2 Token Generator
----------------------

Twitcher uses `OAuth2 tokens`_ to control access to the service registration and the OWS service access.
You can use three types of tokens.

Random Token
++++++++++++

Tokens with UUID strings stored in the local twitcher database.

Edit the configuration file:

.. code-block:: ini

twitcher.token.type = random_token # default
cehbrecht marked this conversation as resolved.
Show resolved Hide resolved


Signed Token
++++++++++++

`JWT tokens`_ signed with a certificate. You can generate a self-signed certificate
for testing with the Makefile:

.. code-block:: console

$ make gencert

Edit the configuration file:

.. code-block:: ini

twitcher.token.type = signed_token
twitcher.token.keyfile = key.pem # private key
twitcher.token.certfile = pubkey.pem # public key

Custom Token
++++++++++++

JWT tokens using a shared secret. You can generate a UUID secret with:

.. code-block:: console

$ make gensecret

Edit the configuration file:

.. code-block:: ini

twitcher.token.type = custom_token
twitcher.token.secret = secret

.. _OAuth2 tokens: https://oauthlib.readthedocs.io/en/latest/oauth2/tokens/bearer.html
.. _JWT tokens: https://pyjwt.readthedocs.io/en/latest/usage.html
34 changes: 34 additions & 0 deletions docs/source/dev_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,39 @@ Do the same as above using the ``Makefile``.
$ make lint
$ make coverage

Upgrade Database
----------------
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe database migration should be done automatically, otherwise chances are Twitcher's schemas in the code vs the retrieved ones from the db will mismatch and just cause the app to crash.
Expected behaviour should be that the db and its schemas are migrated up/down on boot time to match the installed Twitcher version.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know ... I thought it would be safer to run make migrate intentionally. Though it might not harm when run each time before make start.


Initialize and upgrade the database using Alembic_.

Generate your first revision:

.. code-block:: console

$ conda activate twitcher
$ alembic -c development.ini revision --autogenerate -m "init"

.. warning::

This first step is only needed in development to generate a new database schema version.

Upgrade to that revision:

.. code-block:: console

$ alembic -c development.ini upgrade head

Load default data into the database using a script.

.. code-block:: console

$ initialize_twitcher_db development.ini

.. note::

You can use `make migrate` as a shortcut to upgrade or init the twitcher database (last two steps).


Building the docs
-----------------

Expand Down Expand Up @@ -84,3 +117,4 @@ See the bumpversion_ documentation for details.

.. _bumpversion: https://pypi.org/project/bumpversion/
.. _pytest: https://docs.pytest.org/en/latest/
.. _Alembic: https://alembic.sqlalchemy.org/en/latest/
1 change: 0 additions & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
installation
configuration
dev_guide
running
tutorial
api
changes
29 changes: 4 additions & 25 deletions docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,11 @@ For development you can use this command:
Initialize Database
===================

Initialize and upgrade the database using Alembic_.

Generate your first revision:

.. code-block:: console

$ conda activate twitcher
$ alembic -c development.ini revision --autogenerate -m "init"

.. warning::

This first step is only needed in development to generate a new database schema version.

Upgrade to that revision:
Before you can start the service you need to initialize or upgrade the database:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see previous note


.. code-block:: console

$ alembic -c development.ini upgrade head

Load default data into the database using a script.

.. code-block:: console

$ initialize_twitcher_db development.ini

.. note::

You can use `make migrate` as a shortcut to upgrade or init the twitcher database (last two steps).
$ make migrate

Starting Twitcher Service
=========================
Expand All @@ -94,6 +71,8 @@ Start the twitcher service using the `development.ini` configuration:
.. code-block:: console

$ pserve development.ini --reload
OR
$ make start

.. _waitress: https://docs.pylonsproject.org/projects/waitress/en/latest/
.. _Conda: https://conda.io/en/latest/
Expand Down
Loading