Skip to content

Commit 6ce1deb

Browse files
committed
Intial commit
1 parent 2370261 commit 6ce1deb

File tree

6 files changed

+287
-0
lines changed

6 files changed

+287
-0
lines changed

defaults/main.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
3+
oaut2_proxy_http : "https://github.com/bitly/oauth2_proxy/releases/download/v2.0.1/oauth2_proxy-2.0.1.linux-amd64.go1.4.2.tar.gz"
4+
oaut2_proxy_http_sha256 : "c6d8f6d74e1958ce1688f3cf7d60648b9d0d6d4344d74c740c515a00b4e023ad"
5+
oauth2_user : "oauth2"
6+
oauth2_dir : "/var/oauth2_proxy"
7+
oauth2_dir_tmp : "/var/oauth2_proxy/tmp"
8+
oauth2_dir_log : "/var/log/oauth2-proxy/"
9+
oauth2_config_path : "/var/oauth2_proxy/oauth2_config.cfg"
10+
oauth2_compress_filename : "{{ oaut2_proxy_http | basename }}"
11+
oauth2_filename : "{{ oauth2_compress_filename |replace('.tar.gz', '') }}"
12+
13+
# See for all options https://raw.githubusercontent.com/bitly/oauth2_proxy/master/contrib/oauth2_proxy.cfg.example
14+
oauth2_proxy_config :
15+
http_address : "127.0.0.1:5000"
16+
upstreams : [ "127.0.0.1:6060" ]
17+
provider : "github"
18+
email-domain : "*"
19+
cookie-secure : false
20+
cookie-domain : "localhost:5000"
21+
cookie_secret : "COOK_SECRET"
22+
client_id : "YOUR_CLIENT_ID"
23+
client_secret : "CLIENT_SECERET"
24+
25+
oauth2_config_cmdline_args : "-github-org='MYCoolORg'"

handlers/main.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
3+
- name: oauth2-proxy restart
4+
service:
5+
name="oauth2-proxy"
6+
state=restarted

meta/main.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
galaxy_info:
3+
author: Adham Helal
4+
description:
5+
company: Hellofresh
6+
7+
license: license (MIT)
8+
min_ansible_version: 1.9
9+
platforms:
10+
- name: Ubuntu
11+
versions:
12+
- trusty
13+
categories:
14+
- networking
15+
16+
dependencies: []

tasks/main.yml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
3+
- name: Create the directories for site specific configurations
4+
user:
5+
name="{{ oauth2_user }}"
6+
shell="/bin/false"
7+
home="{{ oauth2_dir }}"
8+
9+
- name: Create the directories for site specific configurations
10+
file:
11+
path="{{ item }}"
12+
state=directory
13+
owner="{{ oauth2_user }}"
14+
group=root
15+
mode=0750
16+
with_items:
17+
- "{{ oauth2_dir }}"
18+
- "{{ oauth2_dir_tmp }}"
19+
- "{{ oauth2_dir_log }}"
20+
21+
- name: Download compressed oauth2 binary
22+
get_url:
23+
url="{{ oaut2_proxy_http }}"
24+
sha256sum="{{ oaut2_proxy_http_sha256 | default(omit) }}"
25+
dest="{{ oauth2_dir_tmp }}"
26+
owner="{{ oauth2_user }}"
27+
28+
- name: unarchive oauth2 binary
29+
unarchive:
30+
src="{{ oauth2_dir_tmp }}/{{ oauth2_compress_filename }}"
31+
dest="{{ oauth2_dir }}/"
32+
creates="{{ oauth2_dir }}/{{ oauth2_compress_filename }}"
33+
copy=no
34+
35+
- name: Create current symlink
36+
file:
37+
src="{{ oauth2_dir }}/{{ oauth2_filename }}"
38+
dest="{{ oauth2_dir }}/current"
39+
owner="{{ oauth2_user }}"
40+
mode="0755"
41+
state="link"
42+
notify:
43+
- oauth2-proxy restart
44+
45+
- name: Deploy init.d script
46+
template:
47+
src="init.d.sh.j2.sh"
48+
dest="/etc/init.d/oauth2-proxy"
49+
mode="0755"
50+
notify:
51+
- oauth2-proxy restart
52+
53+
- name: Deploy Config
54+
template:
55+
src="config.j2"
56+
dest="{{ oauth2_config_path }}"
57+
owner="{{ oauth2_user }}"
58+
mode="0600"
59+
notify:
60+
- oauth2-proxy restart
61+
62+
- name: Service start
63+
service:
64+
name="oauth2-proxy"
65+
state="started"
66+
enabled="True"

templates/config.j2

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## OAuth2 Proxy Config File
2+
## https://github.com/bitly/oauth2_proxy
3+
## https://github.com/bitly/oauth2_proxy/blob/master/contrib/oauth2_proxy.cfg.example
4+
5+
{% for k,v in oauth2_proxy_config.iteritems() %}
6+
{% if v is string %}
7+
{{ k }} = "{{ v }}"
8+
{% else %}
9+
{{ k }} = {{ v | to_json }}
10+
{% endif %}
11+
{% endfor %}

templates/init.d.sh.j2.sh

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
#! /bin/sh
2+
### BEGIN INIT INFO
3+
# Provides: oauth2-proxy
4+
# Required-Start: $remote_fs $syslog
5+
# Required-Stop: $remote_fs $syslog
6+
# Default-Start: 2 3 4 5
7+
# Default-Stop: 0 1 6
8+
# Short-Description: Start oauth2-proxy at boot time.
9+
# Description: A reverse proxy that provides authentication with Google, Github or other provider.
10+
### END INIT INFO
11+
12+
# Author: Yves H. <[email protected]>
13+
14+
# Do NOT "set -e"
15+
16+
# PATH should only include /usr/* if it runs after the mountnfs.sh script
17+
PATH=/sbin:/usr/sbin:/bin:/usr/bin
18+
DESC="A reverse proxy that provides authentication with Google, Github or other provider"
19+
NAME=`basename $0`
20+
DAEMON={{ oauth2_dir }}/current/oauth2_proxy
21+
DAEMON_ARGS="-config={{ oauth2_config_path }} {{ oauth2_config_cmdline_args }}"
22+
PIDFILE=/var/run/$NAME.pid
23+
SCRIPTNAME=/etc/init.d/oauth2-proxy
24+
USER={{ oauth2_user }}
25+
GROUP=$USER
26+
27+
STDOUT_LOG="/var/log/oauth2-proxy/$NAME.log"
28+
STDERR_LOG="/var/log/oauth2-proxy/$NAME.error.log"
29+
30+
# Exit if the package is not installed
31+
[ -x "$DAEMON" ] || exit 0
32+
33+
# Read configuration variable file if it is present
34+
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
35+
36+
# Load the VERBOSE setting and other rcS variables
37+
. /lib/init/vars.sh
38+
39+
# Define LSB log_* functions.
40+
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
41+
# and status_of_proc is working.
42+
. /lib/lsb/init-functions
43+
44+
VERBOSE=true
45+
46+
get_pid() {
47+
cat "$PIDFILE"
48+
}
49+
50+
is_running() {
51+
[ -f "$PIDFILE" ] && ps `get_pid` > /dev/null 2>&1
52+
}
53+
54+
#
55+
# Function that starts the daemon/service
56+
#
57+
do_start()
58+
{
59+
# Return
60+
# 0 if daemon has been started
61+
# 1 if daemon was already running
62+
# 2 if daemon could not be started
63+
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
64+
|| return 1
65+
66+
start-stop-daemon --make-pidfile --pidfile $PIDFILE --chuid $USER:$GROUP \
67+
--background --no-close --exec $DAEMON --start -- $DAEMON_ARGS \
68+
>> $STDOUT_LOG 2>> $STDERR_LOG
69+
70+
sleep 2
71+
if ! is_running; then
72+
return 2
73+
fi
74+
}
75+
76+
#
77+
# Function that stops the daemon/service
78+
#
79+
do_stop()
80+
{
81+
# Return
82+
# 0 if daemon has been stopped
83+
# 1 if daemon was already stopped
84+
# 2 if daemon could not be stopped
85+
# other if a failure occurred
86+
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
87+
RETVAL="$?"
88+
[ "$RETVAL" = 2 ] && return 2
89+
# Wait for children to finish too if this is a daemon that forks
90+
# and if the daemon is only ever run from this initscript.
91+
# If the above conditions are not satisfied then add some other code
92+
# that waits for the process to drop all resources that could be
93+
# needed by services started subsequently. A last resort is to
94+
# sleep for some time.
95+
start-stop-daemon --stop --quiet --oknodo --retry=0/1/KILL/5 --exec $DAEMON
96+
[ "$?" = 2 ] && return 2
97+
# Many daemons don't delete their pidfiles when they exit.
98+
rm -f $PIDFILE
99+
return "$RETVAL"
100+
}
101+
102+
#
103+
# Function that sends a SIGHUP to the daemon/service
104+
#
105+
do_reload() {
106+
#
107+
# If the daemon can reload its configuration without
108+
# restarting (for example, when it is sent a SIGHUP),
109+
# then implement that here.
110+
#
111+
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
112+
return 0
113+
}
114+
115+
case "$1" in
116+
start)
117+
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
118+
do_start
119+
case "$?" in
120+
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
121+
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
122+
esac
123+
;;
124+
stop)
125+
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
126+
do_stop
127+
case "$?" in
128+
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
129+
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
130+
esac
131+
;;
132+
status)
133+
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
134+
;;
135+
restart|force-reload)
136+
#
137+
# If the "reload" option is implemented then remove the
138+
# 'force-reload' alias
139+
#
140+
log_daemon_msg "Restarting $DESC" "$NAME"
141+
do_stop
142+
case "$?" in
143+
0|1)
144+
do_start
145+
case "$?" in
146+
0) log_end_msg 0 ;;
147+
1) log_end_msg 1 ;; # Old process is still running
148+
*) log_end_msg 1 ;; # Failed to start
149+
esac
150+
;;
151+
*)
152+
# Failed to stop
153+
log_end_msg 1
154+
;;
155+
esac
156+
;;
157+
*)
158+
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
159+
exit 3
160+
;;
161+
esac
162+
163+
:

0 commit comments

Comments
 (0)