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

Pull request #8

Merged
merged 44 commits into from
Apr 25, 2018
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
65ce970
refresh backend
Dec 7, 2017
905766a
adding upstream back
Dec 7, 2017
45cb52a
refresh updates
Dec 8, 2017
1d5aeb8
changing paths to forked project
Dec 8, 2017
50a2cb3
Refresh README documentation
Dec 8, 2017
18c51da
started tests for refresh backend
Dec 29, 2017
e604a78
refresh test suite
Jan 3, 2018
738c60c
updates to make more concurrency-friendly
Jan 7, 2018
4e52e16
caching by token instead of request
Jan 19, 2018
7d9475e
no longer keeping request in handler object
Jan 23, 2018
d3c3f91
switching to full functionality
Feb 1, 2018
220f8da
initializer security context map
Feb 1, 2018
5c6f2d3
removing map because of concurrent writes issue
Feb 2, 2018
9853f09
unit tests
Feb 6, 2018
9c9345c
token generation
Feb 8, 2018
3d0e6f8
refactor first pass after code review
Mar 7, 2018
56fc16c
switch to startsmartlabs
Mar 9, 2018
d77df76
updating to newer auth endpoints
Mar 14, 2018
9dc7777
added logs to different auth failures
Mar 14, 2018
d7e6021
cannot reuse caddy module imports
Mar 14, 2018
67215b6
found bug causing panic when cached tokens expire
Mar 21, 2018
fbd8852
removing caddy-cache
Mar 25, 2018
9e9caa4
security context stored in bigcache
Mar 26, 2018
4e8e700
generalizing flow
Mar 29, 2018
ba76405
iterating over endpoints
Mar 30, 2018
55547ac
set/get resultkey from secrets file
Mar 30, 2018
6a2a4af
fixed logic to get 401s back
Mar 30, 2018
084334f
Readme update
Mar 31, 2018
065f0e7
removed tabs
Mar 31, 2018
4023fe0
moved slicemap functions to secrets
Mar 31, 2018
a694415
updated README
Mar 31, 2018
808d1b1
updated README
Mar 31, 2018
845085e
updated unit tests after generalization refactor
Apr 2, 2018
ad3f2a8
additional tests
Apr 3, 2018
dbb568e
preparing for pull request
Apr 2, 2018
1e6ddc7
cleaning up before pull request
Apr 2, 2018
a94b72d
finished tests
Apr 6, 2018
3b3665c
code review updates
Apr 6, 2018
2bb06a7
endpoint.Failure auth flow fix
Apr 6, 2018
8db110d
path changes for local testing
Apr 6, 2018
7595160
moving initialization code to construction
Apr 9, 2018
b4a2f5a
moving auth result to initialization section
Apr 10, 2018
42c4aeb
pr review updates
Apr 17, 2018
a85ed25
linter refactor
Apr 17, 2018
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
Empty file added .gitignore
Empty file.
86 changes: 86 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The following backends are supported.

* [Simple](#simple)
* [Upstream](#upstream)
* [Refresh](#refresh)
* [GitlabCI](#gitlabci)
* [LDAP](#ldap)

Expand Down Expand Up @@ -77,6 +78,91 @@ Example
upstream url=https://google.com,skipverify=true,timeout=5s
```

### Refresh

Authentication with Refresh Token against configurable endpoints with response caching and cache entry expiration times. If failure conditions in the configuration file are met a 401 is returned otherwise result will be successful.
This module is designed to be used with the [caddy-secrets](https://github.com/startsmartlabs/caddy-secrets) plugin, a yaml file with a `reauth` object with an `endpoints` array will hold configurations for endpoints and how they work together for auth service.

Parameters for this backend:

| Parameter-Name | Description |
| ------------------|------------------------------------------------------------------------------------------|
| url | http/https url to call |
| skipverify | true to ignore TLS errors (optional, false by default) |
| timeout | request timeout (optional 1m by default, go duration syntax is supported) |
| follow | follow redirects (disabled by default as redirecting to a login page might cause a 200) |
| cookies | true to pass cookies to the upstream server |
| limit | int to set response size limit for endpoint requests (default 1000) |
| lifetime | time interval that a file cached by this module will remain valid (default 3 hours) |
| cleaninterval | time interval to clean cache of expired entries (default 1 second) |

Examples

- Caddyfile
```
refresh url=https://example.com,skipverify=true,timeout=5s,lifetime=3h,cleaninterval=1s,limit=1000
```

- Secrets file
```
reauth:
authorization: true # authorization bool (required) - whether to check for Authorization header,
Authorization access token stored in 'ResultsMap' under 'client_token' key
endpoints # endpoints array (required)
- name: refresh # endpoint of name 'refresh' (required)
url: null
path: "/access_token"
method: POST # auth request method (required) - at the moment only POST and GET are handled (value must be in caps)
data: # data array (required)
- key: grant_type
value: refresh_token
- key: refresh_token # object with 'refresh_token' key (required)
value: <refresh token to get access token> # value (required) - holds actual refresh token to request access token with
cachekey: refresh_token
headers:
- key: Content-Type
value: "application/x-www-form-urlencoded"
skipverify: true
cookies: true
responsekey: jwt_token
failures:
- validation: equality # there are 3 types of validation, 'equality' will have auth fail if
key: message # response body value under failure object key equality failure object value
value: Forbidden
valuemessage: false
message: "Refresh access token failed"
# access token is stored in 'ResultsMap' under 'refresh' key

- name: security_context # endpoint responses get stored in 'ResultsMap' under the name of the endpoint
url: https://different.example.com # url value should be set if endpoint uses different url than one in Caddyfile
path: "/security_context" # path is concatenated after url for request
method: GET # request method, GET will put data params in query, POST will encode form
data: # data needed for request
- key: access_token
value: "{client_token}" # surrounding keys with {}'s will have them replaced by values in 'ResultsMap'
cachekey: client_token # cache entry key
headers: # keys and values to set on endpoint request headers
- key: Authorization
value: "Bearer {refresh}" # surrounding keys with {}'s will have them replaced by values in 'ResultsMap'
skipverify: true # whether endpoint request should use Caddyfile skipverify configuration
cookies: true # whether endpoint request should use Caddyfile cookies configuration
responsekey: null # if set, the key will be used to pull value from endpoint response
failures:
- validation: presence # 'presence' validation will have auth fail if response body has failure object key
key: error
value: ~
valuemessage: true # if valuemessage bool is true, response object value under failure object key
message: "Security context error: " is concatenated to failure message
- validataion: status # 'status' validation will have auth fail if endpoint response status
key: ~ matches failure object value
value: 401
valuemessage: false
message: "Security context unauthorized"
resultkey: security_context # last endpoint response stored in 'ResultsMap' is passed down caddy filter chain
in a query param with the key named after 'resultkey' value
```


### GitlabCI

Authenticate against Gitlab as the gitlab-ci-user for the purposes of letting the gitlab-ci access otherwise protected resources without storing credentials in gitlab or gitlab-ci.yml. Works basically like the [Upstream]#upstream backend except the username you provide is the project path
Expand Down
8 changes: 4 additions & 4 deletions backends/backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
package backends

import (
_ "github.com/freman/caddy-reauth/backends/gitlabci"
_ "github.com/freman/caddy-reauth/backends/ldap"
_ "github.com/freman/caddy-reauth/backends/simple"
_ "github.com/freman/caddy-reauth/backends/upstream"
_ "github.com/fellou89/caddy-reauth/backends/gitlabci"
_ "github.com/fellou89/caddy-reauth/backends/refresh"
_ "github.com/fellou89/caddy-reauth/backends/simple"
_ "github.com/fellou89/caddy-reauth/backends/upstream"
)

// This page intentionally left blank ;)
2 changes: 1 addition & 1 deletion backends/gitlabci/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"strings"
"time"

"github.com/freman/caddy-reauth/backend"
"github.com/fellou89/caddy-reauth/backend"
)

// Backend name
Expand Down
2 changes: 1 addition & 1 deletion backends/ldap/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"sync"
"time"

"github.com/freman/caddy-reauth/backend"
"github.com/fellou89/caddy-reauth/backend"

ldp "gopkg.in/ldap.v2"
)
Expand Down
Loading