Skip to content

fix: added example defining websocket rules with oathkeeper. Closes #896 #768

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

Merged
merged 36 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ac987e6
fix: added example defining websocket rules with oathkeeper. Closes #896
gen1us2k Apr 19, 2022
0b4d373
Update docs/oathkeeper/guides/websockets.mdx
gen1us2k Apr 19, 2022
2761325
u
gen1us2k Apr 19, 2022
17c8c5a
fix: added example defining websocket rules with oathkeeper. Closes #896
gen1us2k Apr 19, 2022
38d900d
Update docs/oathkeeper/guides/websockets.mdx
gen1us2k Apr 19, 2022
49c5023
u
gen1us2k Apr 19, 2022
9d2e508
Merge branch 'master' into websockets
vinckr Apr 22, 2022
10077c8
Merge branch 'websockets' of github.com:ory/docs into websockets
gen1us2k Apr 22, 2022
cfbedc2
Fixed sidebar
gen1us2k Apr 22, 2022
bbfc986
fix oathkeeper name
gen1us2k Apr 27, 2022
dbeb7ff
fixed websockets
gen1us2k Apr 27, 2022
ed4442d
fixed ports
gen1us2k Apr 27, 2022
0f153f0
Update docs/oathkeeper/guides/websockets.mdx
gen1us2k Apr 27, 2022
62311f1
Update docs/oathkeeper/guides/websockets.mdx
gen1us2k Apr 27, 2022
827d73e
Update docs/oathkeeper/guides/websockets.mdx
gen1us2k Apr 27, 2022
d8ea998
Update docs/oathkeeper/guides/websockets.mdx
gen1us2k Apr 27, 2022
8100372
ordered list
gen1us2k Apr 27, 2022
dbfed53
use numbered lists
gen1us2k Apr 27, 2022
922111a
latest fixes
gen1us2k Apr 28, 2022
19cf757
Update docs/oathkeeper/guides/websockets.mdx
gen1us2k Apr 28, 2022
0343eac
grammar fixes
gen1us2k Apr 28, 2022
af6acee
Update docs/oathkeeper/guides/websockets.mdx
gen1us2k Apr 28, 2022
4625ad5
fixed build
gen1us2k Apr 28, 2022
1f22835
fix: moved code to code-examples directory
gen1us2k May 2, 2022
15001ac
moved examples to code-examples
gen1us2k May 3, 2022
7e64896
fix: edit websockets oathkeeper doc
vinckr May 6, 2022
45f0974
fix: websockets oathkeeper doc sidebar
vinckr May 6, 2022
af87ed4
Merge remote-tracking branch 'origin' into websockets
vinckr May 6, 2022
4a09653
fix: websockets oathkeeper doc shorter title
vinckr May 6, 2022
ad3b6eb
added tests
gen1us2k May 9, 2022
2c8d5c6
fixed example
gen1us2k May 9, 2022
7c233ae
fixed build
gen1us2k May 9, 2022
c663cbe
u
gen1us2k May 17, 2022
c2f9974
small fix
gen1us2k May 18, 2022
5a64a17
removed redundant code
gen1us2k May 18, 2022
a0ed068
Merge remote-tracking branch 'origin' into websockets
vinckr May 31, 2022
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
79 changes: 79 additions & 0 deletions code-examples/oathkeeper/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
version: "3.7"
services:
oathkeeper:
image: oryd/oathkeeper:v0.38.25-beta.1
depends_on:
- kratos
ports:
- 8080:4455
- 4456:4456
command:
serve proxy -c "/etc/config/oathkeeper/oathkeeper.yml"
environment:
- LOG_LEVEL=debug
restart: on-failure
networks:
- intranet
volumes:
- ./oathkeeper:/etc/config/oathkeeper
postgres-kratos:
image: postgres:9.6
environment:
- POSTGRES_USER=kratos
- POSTGRES_PASSWORD=secret
- POSTGRES_DB=kratos
networks:
- intranet
kratos-migrate:
image: oryd/kratos:v0.9.0-alpha.3
links:
- postgres-kratos:postgres-kratos
environment:
- DSN=postgres://kratos:secret@postgres-kratos:5432/kratos?sslmode=disable&max_conns=20&max_idle_conns=4
networks:
- intranet
volumes:
- type: bind
source: ./kratos
target: /etc/config/kratos
command: -c /etc/config/kratos/kratos.yml migrate sql -e --yes
kratos:
image: oryd/kratos:v0.9.0-alpha.3
links:
- postgres-kratos:postgres-kratos
environment:
- DSN=postgres://kratos:secret@postgres-kratos:5432/kratos?sslmode=disable&max_conns=20&max_idle_conns=4
ports:
- '4433:4433'
- '4434:4434'
volumes:
- type: bind
source: ./kratos
target: /etc/config/kratos
networks:
- intranet
command: serve -c /etc/config/kratos/kratos.yml --dev --watch-courier
kratos-selfservice-ui-node:
image: oryd/kratos-selfservice-ui-node:latest
environment:
- KRATOS_PUBLIC_URL=http://kratos:4433/
- KRATOS_BROWSER_URL=http://127.0.0.1:4433/
networks:
- intranet
ports:
- "4455:3000"
restart: on-failure
mailslurper:
image: oryd/mailslurper:latest-smtps
ports:
- '4436:4436'
- '4437:4437'
networks:
- intranet
ws:
build:
context: "ws"
networks:
- intranet
networks:
intranet:
49 changes: 49 additions & 0 deletions code-examples/oathkeeper/kratos/identity.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"$id": "https://schemas.ory.sh/presets/kratos/quickstart/email-password/identity.schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Person",
"type": "object",
"properties": {
"traits": {
"type": "object",
"properties": {
"email": {
"type": "string",
"format": "email",
"title": "E-Mail",
"minLength": 3,
"ory.sh/kratos": {
"credentials": {
"password": {
"identifier": true
}
},
"verification": {
"via": "email"
},
"recovery": {
"via": "email"
}
}
},
"name": {
"type": "object",
"properties": {
"first": {
"title": "First Name",
"type": "string"
},
"last": {
"title": "Last Name",
"type": "string"
}
}
}
},
"required": [
"email"
],
"additionalProperties": false
}
}
}
84 changes: 84 additions & 0 deletions code-examples/oathkeeper/kratos/kratos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
version: v0.7.1-alpha.1

dsn: memory

serve:
public:
base_url: http://127.0.0.1:4433/
cors:
enabled: true
admin:
base_url: http://kratos:4434/

selfservice:
default_browser_return_url: http://127.0.0.1:4455/
allowed_return_urls:
- http://127.0.0.1:4455

methods:
password:
enabled: true

flows:
error:
ui_url: http://127.0.0.1:4455/error

settings:
ui_url: http://127.0.0.1:4455/settings
privileged_session_max_age: 15m

recovery:
enabled: true
ui_url: http://127.0.0.1:4455/recovery

verification:
enabled: true
ui_url: http://127.0.0.1:4455/verification
after:
default_browser_return_url: http://127.0.0.1:4455/

logout:
after:
default_browser_return_url: http://127.0.0.1:4455/login

login:
ui_url: http://127.0.0.1:4455/login
lifespan: 10m

registration:
lifespan: 10m
ui_url: http://127.0.0.1:4455/registration
after:
password:
hooks:
-
hook: session

log:
level: debug
format: text
leak_sensitive_values: true

secrets:
cookie:
- PLEASE-CHANGE-ME-I-AM-VERY-INSECURE
cipher:
- 32-LONG-SECRET-NOT-SECURE-AT-ALL

ciphers:
algorithm: xchacha20-poly1305

hashers:
algorithm: bcrypt
bcrypt:
cost: 8

identity:
default_schema_id: default
schemas:
- id: default
url: file:///etc/config/kratos/identity.schema.json

courier:
smtp:
connection_uri: smtps://test:test@mailslurper:1025/?skip_ssl_verify=true
19 changes: 19 additions & 0 deletions code-examples/oathkeeper/oathkeeper/access-rules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- id: 'ws:protected'
upstream:
preserve_host: true
url: 'http://ws:8080'
match:
url: 'http://127.0.0.1:8080/<**>'
methods:
- GET
- POST
authenticators:
- handler: cookie_session
mutators:
- handler: noop
authorizer:
handler: allow
errors:
- handler: redirect
config:
to: http://127.0.0.1:4455/login
78 changes: 78 additions & 0 deletions code-examples/oathkeeper/oathkeeper/oathkeeper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
log:
level: debug
format: json

serve:
proxy:
cors:
enabled: true
allowed_origins:
- http://127.0.0.1:8080
allowed_methods:
- POST
- GET
- PUT
- PATCH
- DELETE
allowed_headers:
- Authorization
- Content-Type
exposed_headers:
- Content-Type
allow_credentials: true
debug: true

errors:
fallback:
- json

handlers:
redirect:
enabled: true
config:
to: http://127.0.0.1:4455/login
when:
- error:
- unauthorized
- forbidden
request:
header:
accept:
- text/html
json:
enabled: true
config:
verbose: true

access_rules:
matching_strategy: glob
repositories:
- file:///etc/config/oathkeeper/access-rules.yml

authenticators:
anonymous:
enabled: true
config:
subject: guest

cookie_session:
enabled: true
config:
check_session_url: http://kratos:4433/sessions/whoami
preserve_path: true
extra_from: '@this'
subject_from: 'identity.id'
only:
- ory_kratos_session

noop:
enabled: true

authorizers:
allow:
enabled: true

mutators:
noop:
enabled: true

15 changes: 15 additions & 0 deletions code-examples/oathkeeper/ws/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM golang as builder

RUN mkdir /build

ADD . /build

WORKDIR /build
RUN GOOS=linux GOARCH=amd64 go build -o ws main.go

FROM alpine
EXPOSE 8090

COPY --from=builder /build/ws /ws
COPY index.html /index.html
ENTRYPOINT ["/ws"]
28 changes: 28 additions & 0 deletions code-examples/oathkeeper/ws/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module websocket

go 1.17

require (
github.com/gin-gonic/gin v1.7.7
github.com/gorilla/websocket v1.5.0
github.com/stretchr/testify v1.4.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.13.0 // indirect
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/go-playground/validator/v10 v10.4.1 // indirect
github.com/golang/protobuf v1.3.3 // indirect
github.com/json-iterator/go v1.1.9 // indirect
github.com/leodido/go-urn v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/ugorji/go/codec v1.1.7 // indirect
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
)
Loading