https://github.com/8gears/keycloak-auth-proxy
Reverse auth proxy container for OAuth/OpenID Connect
https://github.com/8gears/keycloak-auth-proxy
auth-proxy docker iam k8s keycloak keycloak-proxy oauth openid openid-connect openshift proxy proxy-service reverse-proxy
Last synced: about 1 month ago
JSON representation
Reverse auth proxy container for OAuth/OpenID Connect
- Host: GitHub
- URL: https://github.com/8gears/keycloak-auth-proxy
- Owner: 8gears
- License: apache-2.0
- Created: 2017-04-05T15:17:50.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-09-19T15:27:22.000Z (over 6 years ago)
- Last Synced: 2024-11-04T09:37:27.197Z (6 months ago)
- Topics: auth-proxy, docker, iam, k8s, keycloak, keycloak-proxy, oauth, openid, openid-connect, openshift, proxy, proxy-service, reverse-proxy
- Language: Shell
- Homepage:
- Size: 45.9 KB
- Stars: 40
- Watchers: 6
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-starred - 8gears/keycloak-auth-proxy - Reverse auth proxy container for OAuth/OpenID Connect (docker)
README
# Keycloak Auth Proxy
[](https://hub.docker.com/r/8gears/keycloak-auth-proxy/)
[](https://hub.docker.com/r/8gears/keycloak-auth-proxy/)
[](https://hub.docker.com/r/8gears/keycloak-auth-proxy/)
[](https://hub.docker.com/r/8gears/keycloak-auth-proxy/)The Reverse Auth Proxy in a Docker Container the provides OpenID Connect/OAuth authentication and authorization for HTTP services that that can't or won't do it themself.
This Auth Proxy Service uses [gambol99/keycloak-proxy](https://github.com/gambol99/keycloak-proxy), which is a Java/Undertow solution designed for Keycloak. However it should also work with any other OpenID Connect Provider.
What makes this project special is, that it can be configured with environment variables and can be easily deployed to Docker, Kubernetes or OpenShift.
## Mode of operation
![How reverse auth proxy works][prx_diag]
1. External traffic is directed to the auth proxy. The Auth proxy decides based on it configuration if the destination needs authentication.
2. The Auth Proxy work together with the IAM (Keycloak) and redirects the user to the IAM so the user can login.
3. After a successful login the proxy forwards the user to the protected content. According to proxy configuration setting the proxy checks if the user is allowed to access the path.## Typical Use cases
There are two very common use cases why one would use the Keycloak Auth Proxy in combination with an Identity & Access Management Service (IAM).
It is recommended that every service that needs authentication has a dedicated auth proxy in front of it.
- Protect static websites from unauthorized access, allowing only authenticated users to see the content.
This is useful in combination with static website generator or other generated documentation.
- Outsource the authentication/authorization step to Keycloak Auth Proxy and just relay on the forward HTTP headers with username/grants in the upstream application.
This approach can be handy if you have an application, where there are no OpenID Connect library or if you don't won't perform to many changes in the application.## Usage
There are three ways how the proxy can be configured.
The proxy configuration settings can be set with environment variables,environment variables plus config template or with the file `proxy.json` mounted as a volume to `/app/proxy.json`.The option that you choose depend on the use case. For simple static website auth the default proxy template is sufficient. For more complex scenarios the custom Proxy Config Template is able cover all possible options.
### Running with the default Proxy Config Template
In the simplest case the only thing you need to do is to set the mandatory environment variables. Prior the execution the variables merged with the default proxy config and then the proxy application is started.
```sh
docker run -ti \
-e TARGET_URL=asdf \
-e REALM="realm" \
-e REALM_PUBLIC_KEY='pub'
-e .... \
8gears/keycloak-auth-proxy
```With Docker Compose download the default docker-compose.yml
```sh
wget https://raw.githubusercontent.com/8gears/keycloak-auth-proxy/master/docker-compose.yml
```Adapt the mandatory env variables in `docker-compose.yml` and hit:
```sh
docker-compose - up
```### Running with custom Proxy Config Template
In order to combine the simplicity of the environment variables with the flexibility of the custom proxy config it is possible to provide your own template.
Take the existing `proxy.tmpl` from this repository and extended it to your need.
When you are done with the template minfy the content and set the variable ??`PROXY_TMPL` with the content.```sh
docker run -ti \
-e PROXY_TMPL={"target-url": "http://172.17.0.2:2015","bind-address": "0.0.0.0", ....
-e TARGET_URL=asdf \
-e REALM="realm" \
-e REALM_PUBLIC_KEY='pub'
-e .... \
8gears/keycloak-auth-proxy
```### Running with custom Proxy Config
Write your `proxy.json` file and mount it to `/app/proxy.json`. Prior start the Auth proxy startup script will check if the file exist and start the proxy with the provided file ignoring the template or any provided environment variables.
Instead of mapping you can provide the content via environment variable ?`PROXY_JSON` just like in the template example above.
```sh
docker run -v proxy.json:/app/proxy.json 8gears/keycloak-auth-proxy
```## Environment Variables
Can be used if you want to auth one service.
See the file [proxy.tmpl](proxy.tmpl)
Variables without default values are mandatory.
- `TARGET_URL` The URL to forward the traffic through
- `HTTP_PORT` (default `8080`) The port to bind the Auth Proxy too
- `BASE_PATH` (default `/` )
- `REALM` Adapter config realm
- `REALM_PUBLIC_KEY` Realm public key
- `AUTH_SERVER_URL` The auth server URL
- `RESOURCE` (default `account`) The resource to request aka client id
- `SECRET` Credential secret
- `CONSTRAINT_PATH` (default `/*`) You can define multiple path but they must be separated with an `;`
- `PROXY_TMPL` Instead of using the provided proxy config it is possible to provide a custom config.## OpenShift Deployment
In OpenShift you can create the service from the template `openshift_template.yml` by using the Web UI or CLI.
Copy the content of `openshift_template.yml` and paste it to the _Import YAML / JSON_ tab in the service catalog.
The OpenShift has a [detailed tutorial]([create_from_ui]) that covers the manual template instantiation.From the CLI execute the first command with the `--parameter` argument to get a list of all the possible parameters.
Next in the second command add all the needed parameters and pipe it to create.```sh
oc process --parameter -f https://raw.githubusercontent.com/8gears/keycloak-auth-proxy/master/openshift_template.ymloc process -f https://raw.githubusercontent.com/8gears/keycloak-auth-proxy/master/openshift_template.yml \
-p TARGET_URL=http://service-name:123 \
-p REALM=app42 \
| oc create -f -
```### OpenShift Service Catalog import
Import the template to the current namespace service catalog.
```sh
oc create -f https://raw.githubusercontent.com/8gears/keycloak-auth-proxy/master/openshift_template.yml
```Import template to global service catalog, so all users in all namespaces can use that template.
```sh
oc create -f https://raw.githubusercontent.com/8gears/keycloak-auth-proxy/master/openshift_template.yml -n openshift
```## Alternatives
Despite the uniqueness of _keycloak-auth-proxy_ there are other project that solve the similar problem differently.
- [OpenID / Keycloak Proxy service](https://github.com/gambol99/keycloak-proxy) This in Golang written proxy should work nicely with Keycloak and might be a value alternative to the current jvm proxy.
- [OAuth2 Proxy](https://github.com/bitly/oauth2_proxy)
- [Lua Resty OpenID/Connect](https://github.com/pingidentity/lua-resty-openidc) This library is designed for Nginx/OpenResty.[kcp]: https://github.com/keycloak/keycloak/tree/master/proxy
[prx_diag]: https://cdn.rawgit.com/8gears/keycloak-auth-proxy/master/docs/images/How_Keycloak_Auth_Proxy_works.svg
[create_from_ui]: https://docs.openshift.org/latest/dev_guide/templates.html#creating-from-templates-using-the-web-console