Skip to content
This repository was archived by the owner on Sep 22, 2020. It is now read-only.

Commit 9520212

Browse files
Merge pull request #1 from comsysto/heroku-support
Heroku support
2 parents 834d61e + 8e06242 commit 9520212

13 files changed

Lines changed: 113 additions & 45 deletions

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ peewee.db
2424
*.pyc
2525
/dist/
2626
/*.egg-info
27-
build/
27+
build/
28+
29+
# heroku
30+
venv/

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: python heroku.py -e heroku -p $PORT --authType allGitHubUsers --owner comsysto --repository github-pages-basic-auth-proxy --obfuscator 086e41eb6ff7a50ad33ad742dbaa2e70b75740c4950fd5bbbdc71981e6fe88e3

README.md

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ Basic Auth checks against GitHub API. This little piece of software is brought t
88

99
**TOC**
1010
* [1. Introduction](#1-introduction)
11-
* [2. Installation](#2-installation)
12-
* [3. Roadmap](#3-roadmap)
13-
* [4. License](#4-license)
11+
* [2. Installation on Heroku](#2-installation-on-heroku)
12+
* [3. Installation on AWS](#3-installation-on-aws)
13+
* [4. Roadmap](#4-roadmap)
14+
* [5. License](#5-license)
1415

1516
## 1. Introduction
1617

@@ -54,7 +55,52 @@ Basic Auth checks against GitHub API. This little piece of software is brought t
5455
* If you create a directory in your `gh-pages` branch which is called e.g. `086e41eb6ff7a50ad33ad742dbaa2e70b75740c4950fd5bbbdc71981e6fe88e3` and proxy to this dir, it will be secure as long as no one knows **obfuscator** (you should keep it secret).
5556
* You proxy to https (TLS) so no man in the middle attack could get a hold of the obfuscator.
5657

57-
## 2. Installation
58+
## 2. Installation on Heroku
59+
60+
[![](./doc/heroku-logo.png)](https://dashboard.heroku.com/)
61+
62+
Create a heroku app and clone the git repo. ([Toolbelt is installed](https://toolbelt.heroku.com/) and you are logged in)
63+
64+
```
65+
$> cd ~/
66+
$> heroku create
67+
# Creating app... done, stack is cedar-14
68+
# https://protected-foo-21086.herokuapp.com/ | https://git.heroku.com/protected-foo-21086.git
69+
$> git clone https://git.heroku.com/protected-foo-21086.git heroku-gh-proxy
70+
```
71+
72+
You now have a folder `heroku-gh-proxy` in your homedir that contains the deployed app (currently empty).
73+
Next we clone the GitHub Pages Proxy and extract the latest snapshot into `heroku-gh-proxy` (absolute path needed)
74+
75+
```
76+
$> cd ~/
77+
$> git clone https://github.com/comsysto/github-pages-basic-auth-proxy.git
78+
$> cd github-pages-basic-auth-proxy
79+
$> git checkout-index -a -f --prefix=/Users/bg/heroku-gh-proxy/ # absolute path with trailing slash!
80+
```
81+
82+
Now change the `Procfile` to your repository and obfuscator settings and push.
83+
84+
```
85+
$> cd ~/heroku-gh-proxy
86+
vim Procfile # change your settings
87+
git add . -A
88+
git commit -m "init"
89+
git push
90+
```
91+
92+
Now your app should be up and running.
93+
94+
* You can access the health check `https://protected-foo-21086.herokuapp.com/health`
95+
* Or directly use the proxy and enter credentials `https://protected-foo-21086.herokuapp.com/`
96+
* A successfully deployed app log should look like this:
97+
* ![](./doc/heroku-logs.png)
98+
99+
100+
101+
## 3. Installation on AWS
102+
103+
[![](./doc/aws-logo.png)](https://aws.amazon.com/)
58104

59105
We will do demo setup for the following scenario:
60106

@@ -66,13 +112,13 @@ We will do demo setup for the following scenario:
66112
* https://my-secure-github-page.comsysto.com/
67113
* This is a `ec2.micro` Instance on AWS which is configured as described below.
68114

69-
### 2.1 Prerequisites
115+
### 3.1 Prerequisites
70116

71117
* You will need nginx, python 3 and git.
72118
* on Ubuntu: `apt-get install git nginx python3-setuptools build-essential python3-dev`
73119
* optional a ssl certificate
74120

75-
### 2.2 nginx setup
121+
### 3.2 nginx setup
76122

77123
We need some kind of vhost with SSL that proxies everything through to our python proxy.
78124

@@ -95,7 +141,7 @@ server {
95141
}
96142
```
97143

98-
### 2.3 python proxy setup
144+
### 3.3 python proxy setup
99145

100146
Install proxy
101147
```
@@ -126,7 +172,7 @@ $> cs-gh-proxy -e wsgi -p 8881 --authType allGitHubUsers --owner comsysto --repo
126172
* Now you can write some scripts to check for pidfile or port
127173
* lockfile ensures that there will only be a single instance
128174

129-
# 3. Roadmap
175+
# 4. Roadmap
130176

131177
* Provide oAuth instead of Basic Auth
132178
* Enable CORS
@@ -137,6 +183,6 @@ $> cs-gh-proxy -e wsgi -p 8881 --authType allGitHubUsers --owner comsysto --repo
137183
* Provide Heroku easy install
138184

139185

140-
# 4. License
186+
# 5. License
141187

142188
Licensed under [MIT License](./LICENSE.md)

app.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "GitHub Pages Auth Basic Proxy",
3+
"description": "GitHub Pages Auth Basic Proxy - Example Setup for Heroku",
4+
"image": "heroku/python",
5+
"repository": "https://github.com/comsysto/github-pages-basic-auth-proxy",
6+
"keywords": ["python", "gh-pages" ],
7+
"addons": [ ]
8+
}

cs_proxy/proxy.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import sys, os
2+
import argparse
3+
import colorama
24
from bottle import route, request, response, run, hook, abort, redirect, error, install, auth_basic
35
import simplejson as json
46
import random
@@ -10,6 +12,34 @@
1012
from jose.exceptions import JWSError
1113
import datetime
1214

15+
def main():
16+
#
17+
# CLI PARAMS
18+
#
19+
parser = argparse.ArgumentParser(description='comSysto GitHub Pages Auth Basic Proxy')
20+
21+
parser.add_argument("-e", "--environment", help='Which environment.', choices=['cgi', 'wsgi', 'heroku'])
22+
parser.add_argument("-gho", "--owner", help='the owner of the repository. Either organizationname or username.')
23+
parser.add_argument("-ghr", "--repository", help='the repository name.')
24+
parser.add_argument("-obf", "--obfuscator", help='the subfolder-name in gh-pages branch used as obfuscator')
25+
parser.add_argument("-p", "--port", help='the port to run proxy e.g. 8881')
26+
parser.add_argument("-a", "--authType", help='how should users auth.', choices=['allGitHubUsers', 'onlyGitHubOrgUsers'] )
27+
28+
29+
args = parser.parse_args()
30+
if not args.environment:
31+
print ('USAGE')
32+
print (' proxy that allows only members of the organization to access page: (owner must be an GitHub Organization)')
33+
print (' $> cs-gh-proxy -e wsgi -p 8881 --authType onlyGitHubOrgUsers --owner comsysto --repository github-pages-basic-auth-proxy --obfuscator 086e41eb6ff7a50ad33ad742dbaa2e70b75740c4950fd5bbbdc71981e6fe88e3')
34+
print ('')
35+
print (' proxy that allows all GitHub Users to access page: (owner can be GitHub Organization or normal user)')
36+
print (' $> cs-gh-proxy -e wsgi -p 8881 --authType allGitHubUsers --owner comsysto --repository github-pages-basic-auth-proxy --obfuscator 086e41eb6ff7a50ad33ad742dbaa2e70b75740c4950fd5bbbdc71981e6fe88e3')
37+
print ('')
38+
39+
sys.exit(1)
40+
41+
run_proxy(args)
42+
1343
#
1444
# global vars
1545
#
@@ -128,6 +158,8 @@ def proxy_trough_root_page():
128158
#
129159
if args.environment == 'wsgi':
130160
run(host='localhost', port=args.port, debug=True)
161+
if args.environment == 'heroku':
162+
run(host="0.0.0.0", port=int(os.environ.get("PORT", 5000)))
131163
else:
132164
run(server='cgi')
133165

cs_proxy/run_proxy.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

doc/aws-logo.png

18.2 KB
Loading

doc/heroku-logo.png

2.81 KB
Loading

doc/heroku-logs.png

177 KB
Loading

heroku.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import os
2+
from cs_proxy import proxy
3+
4+
proxy.main()

0 commit comments

Comments
 (0)