Skip to content

Commit 7d58a95

Browse files
authored
Documentation intensifies.
1 parent fb120a2 commit 7d58a95

File tree

1 file changed

+80
-33
lines changed

1 file changed

+80
-33
lines changed

README.md

Lines changed: 80 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Bouncer [![bouncer](https://raw.githubusercontent.com/kaancfidan/bouncer/master/gopher.png)](https://gopherize.me/gopher/c9a63ec34e1f313f408fc4aa378666cead40a271)
2-
[![Go](https://github.com/kaancfidan/bouncer/workflows/Go/badge.svg)](https://github.com/kaancfidan/bouncer/actions?query=workflow%3AGo) [![Docker Pulls](https://img.shields.io/docker/pulls/kaancfidan/bouncer)](https://hub.docker.com/r/kaancfidan/bouncer) [![Go Report Card](https://goreportcard.com/badge/github.com/kaancfidan/bouncer)](https://goreportcard.com/report/github.com/kaancfidan/bouncer) [![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability/kaancfidan/bouncer)](https://codeclimate.com/github/kaancfidan/bouncer/maintainability) [![codecov](https://img.shields.io/codecov/c/github/kaancfidan/bouncer)](https://codecov.io/gh/kaancfidan/bouncer)
2+
[![Go](https://github.com/kaancfidan/bouncer/workflows/Go/badge.svg)](https://github.com/kaancfidan/bouncer/actions?query=workflow%3AGo) [![Docker Pulls](https://img.shields.io/docker/pulls/kaancfidan/bouncer)](https://hub.docker.com/r/kaancfidan/bouncer) [![Docker Image Size (latest semver)](https://img.shields.io/docker/image-size/kaancfidan/bouncer?sort=semver)](https://hub.docker.com/r/kaancfidan/bouncer) [![Go Report Card](https://goreportcard.com/badge/github.com/kaancfidan/bouncer)](https://goreportcard.com/report/github.com/kaancfidan/bouncer) [![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability/kaancfidan/bouncer)](https://codeclimate.com/github/kaancfidan/bouncer/maintainability) [![codecov](https://img.shields.io/codecov/c/github/kaancfidan/bouncer)](https://codecov.io/gh/kaancfidan/bouncer)
33
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fkaancfidan%2Fbouncer.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fkaancfidan%2Fbouncer?ref=badge_shield)
44

55
Bouncer is a [JWT]-based authentication and authorization service.
@@ -31,8 +31,8 @@ As an example, [this blog post](https://engineering.etermax.com/api-authorizatio
3131
- It aims to be out-of-the-box compatible with **nginx**, **traefik** and **envoy** without any development effort.
3232

3333
#### How it works
34-
- The **API gateway** receives an HTTP request from the client and it forwards the request (usually without including the body) to **Bouncer**.
35-
- **Bouncer** matches the request method and path to configured **route policies**.
34+
- The **API gateway** receives an HTTP request from the client and forwards it (usually without including the body) to **Bouncer**.
35+
- **Bouncer** matches the request method and path (i.e. GET /stuff/) to configured **route policies**.
3636
- If the most specific<sup>1</sup> **route policy** that matches the request explicitly allows anonymous requests, a response with status code **200(OK)** is returned.
3737
- **Bouncer** extracts the [Bearer] token and validates it for authentication. If authentication fails, a response with status code **401(Unauthorized)** is returned.
3838
- **Bouncer** extracts claims from the validated token and checks if all **claim policies** corresponding to the matched **route policies** are fulfilled. If not, a response with status code **403(Forbidden)** is returned.
@@ -54,37 +54,10 @@ When given an **upstream URL**, **Bouncer** performs the same checks as in the A
5454
- **Bouncer** is more flexible in route configuration, because it uses standard wildcard patterns to match paths.
5555
- **Bouncer** is less flexible in claim policy configuration, because claim requirements can only be expressed in equality comparisons (and "contains" checks in case of array claims).
5656

57-
#### Employee example
58-
The following configuration example is loosely based on the example provided in the above .NET Core documentation:
59-
60-
```yaml
61-
claimPolicies:
62-
EmployeeOnly:
63-
- claim: employee_number
64-
Founders:
65-
- claim: employee_number
66-
values: [1,2,3,4,5]
67-
HumanResources:
68-
- claim: department
69-
values: [HumanResources]
70-
71-
routePolicies:
72-
- path: /vacation/**
73-
policyName: EmployeeOnly
74-
- path: /vacation/policy
75-
allowAnonymous: true
76-
- path: /vacation/*/
77-
methods: [PUT, PATCH]
78-
policyName: Founders
79-
- path: /salary/**
80-
policyName: EmployeeOnly
81-
- path: /salary/*/
82-
methods: [PUT, PATCH]
83-
policyName: HumanResources
84-
```
85-
57+
### Examples
8658
#### Allow anonymous example
8759
The following configuration depicts a system in which all requests are allowed in without any authentication, except DELETEs and the ones with intentions to destroy the server.
60+
8861
```yaml
8962
claimPolicies: {}
9063

@@ -121,8 +94,82 @@ routePolicies:
12194
allowAnonymous: true
12295
```
12396

97+
#### Employee example
98+
The following configuration example is loosely based on the example provided in the [.NET Core docs](https://docs.microsoft.com/en-us/aspnet/core/security/authorization/claims?view=aspnetcore-3.1):
99+
100+
```yaml
101+
claimPolicies:
102+
EmployeeOnly:
103+
- claim: employee_number
104+
Founders:
105+
- claim: employee_number
106+
values: [1,2,3,4,5]
107+
HumanResources:
108+
- claim: department
109+
values: [HumanResources]
110+
111+
routePolicies:
112+
- path: /vacation/**
113+
policyName: EmployeeOnly
114+
- path: /vacation/policy
115+
allowAnonymous: true
116+
- path: /vacation/*/
117+
methods: [PUT, PATCH]
118+
policyName: Founders
119+
- path: /salary/**
120+
policyName: EmployeeOnly
121+
- path: /salary/*/
122+
methods: [PUT, PATCH]
123+
policyName: HumanResources
124+
```
125+
124126
## Current status
125-
The project is in its infancy, does not have MVP features yet and is far from being production-grade.
127+
First version has been released! 🎉 It's not battle-tested yet, but it's a start.
128+
129+
#### Current functionality in a nutshell:
130+
- Static signing key configuration w/ HMAC, RSA and EC support
131+
- Single valid issuer and audience configuration
132+
- Token expiration, "not before" and "issued at" checks with clock skew tolerance
133+
- Authorization policy config with YAML
134+
- Reverse proxy mode without TLS termination
135+
136+
## Usage
137+
### Docker image
138+
Create a volume directory:
139+
```zsh
140+
➜ ~ mkdir bouncer
141+
```
142+
Put a config YAML:
143+
```zsh
144+
➜ ~ echo "claimPolicies: {}\nroutePolicies: []\n" > bouncer/config.yaml
145+
```
146+
Run bouncer:
147+
```zsh
148+
➜ ~ docker run \
149+
--name bouncer \
150+
-d \
151+
--restart always \
152+
-e BOUNCER_SIGNING_METHOD=HMAC \
153+
-e BOUNCER_SIGNING_KEY=ThisIsSupposedToBeALongStringOfBytesLikeSixtyFourCharactersLong. \
154+
-v `pwd`/bouncer:/etc/bouncer \
155+
kaancfidan/bouncer:latest
156+
```
157+
158+
### Environment variables and command line flags
159+
Every startup setting has an environment variable and a CLI flag counterpart.
160+
161+
| Environment Variable | CLI Flag | Description |
162+
| -------------------- | -------- | ----------- |
163+
| BOUNCER_SIGNING_KEY | -k | Signing key to be used to validate tokens. Consider setting this variable through a file for multiline keys. e.g. `BOUNCER_SIGNING_KEY=$(cat rsa.pub)` |
164+
| BOUNCER_SIGNING_METHOD | -m | Signing method. Accepted values are **[HMAC, RSA, EC]**. |
165+
| BOUNCER_CONFIG_PATH | -p | Config YAML path. **default = /etc/bouncer/config.yaml** |
166+
| BOUNCER_LISTEN_ADDRESS | -l | TCP listen address. **default = :3512** |
167+
| BOUNCER_UPSTREAM_URL | --url | Upstream URL to be used in reverse proxy mode. If not set, Bouncer runs in pure auth server mode. |
168+
| BOUNCER_VALID_ISSUER | --iss | Valid issuer id. If set Bouncer validates **iss** claim. |
169+
| BOUNCER_VALID_AUDIENCE | --aud | Valid audience id. If set Bouncer validates **aud** claim. |
170+
| BOUNCER_REQUIRE_EXPIRATION | --exp | Require expiration (**exp**) timestamp on tokens. Unless explicitly set to **false**, **default = true** |
171+
| BOUNCER_REQUIRE_NOT_BEFORE | --nbf | Require "not before" (**nbf**) timestamp on tokens. Unless explicitly set to **false**, **default = true** |
172+
| BOUNCER_CLOCK_SKEW | --clk | Clock skew tolerance in seconds. When set **iat**, **exp**, **nbf** claims are checked with the given tolerance. |
126173

127174
## License
128175
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fkaancfidan%2Fbouncer.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fkaancfidan%2Fbouncer?ref=badge_large)

0 commit comments

Comments
 (0)