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

Ory based authorization #858

Draft
wants to merge 54 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
d3d7e54
Run tests on feature branches
Bdegraaf1234 Jun 11, 2024
ad6c73e
Update front end to use auth code login
mpgxvii Aug 5, 2024
8c9fec3
Add login endpoint to allow auth code grant login
mpgxvii Aug 5, 2024
c09291c
Add token validator updates to support hydra tokens
mpgxvii Aug 5, 2024
4820edc
Add auth server config to application properties
mpgxvii Aug 6, 2024
6beedc4
Fix access token converter
mpgxvii Aug 6, 2024
4bbb4e8
Add Ory components docker configurations
mpgxvii Aug 13, 2024
0590f33
Merge branch 'hydra-kratos-stack' of https://github.com/RADAR-base/Ma…
mpgxvii Aug 13, 2024
d0d61aa
Fix application properties
mpgxvii Aug 13, 2024
715ffaa
use single postgres instance for kratos and hydra
yatharthranjan Aug 14, 2024
7fa118c
Add MP authserve configs
mpgxvii Aug 14, 2024
75ee42e
Merge branch 'hydra-kratos-stack' of https://github.com/RADAR-base/Ma…
mpgxvii Aug 14, 2024
cda3c9d
Merge branch 'dev' of https://github.com/RADAR-base/ManagementPortal …
mpgxvii Aug 14, 2024
5234fd2
Remove unused KratosTokenVerifier and Oauth2LoginUiWebConfig
mpgxvii Aug 14, 2024
ea47775
Update setting of hydra token verifier loader
mpgxvii Aug 14, 2024
3d3eec0
use published dev docker image for UI
yatharthranjan Aug 14, 2024
1951b90
fix port mappings
yatharthranjan Aug 14, 2024
e1cdee9
Merge pull request #930 from RADAR-base/hydra-kratos-stack
yatharthranjan Aug 14, 2024
39b06b5
Merge remote-tracking branch 'origin/feature/ory-based-authorization'…
yatharthranjan Aug 14, 2024
85348d6
Update self-enrolment image and login redirect url
mpgxvii Aug 14, 2024
02e08a4
update login redirect url
mpgxvii Aug 14, 2024
d72ff43
Fix MP endpoint in kratos config
mpgxvii Aug 15, 2024
1a9daca
add separate login url for hydra
yatharthranjan Aug 19, 2024
bc2b2f6
Update ManagementPortal propreties with new loginUrl property
mpgxvii Aug 19, 2024
57eecfd
intermediate removal of unneeded components
yatharthranjan Aug 20, 2024
03c87ed
Fix ory stack configs
mpgxvii Aug 20, 2024
83087eb
Merge branch 'feat/hydra-token' of https://github.com/RADAR-base/Mana…
mpgxvii Aug 20, 2024
1882851
Remove OAuth2ServerConfiguration and use single SecurityConfig for auth
mpgxvii Aug 22, 2024
7600ae8
Refactor JwtAuthenticationFilter to accept jwt and session data
mpgxvii Aug 22, 2024
54aa7ff
Remove unused services
mpgxvii Aug 22, 2024
5e6f20d
Restore ory stack changes
mpgxvii Aug 22, 2024
eaa7d33
Update JwtAuthenticationFilter issues: make sure existing auth is che…
mpgxvii Aug 23, 2024
aa6b6f0
Merge branch 'feature/ory-based-authorization' of https://github.com/…
mpgxvii Aug 23, 2024
960a3b5
Restore deleted annotations
mpgxvii Aug 23, 2024
c11734e
Move access token fetching to AuthService
mpgxvii Aug 23, 2024
2988114
Invalidate session on logout
mpgxvii Aug 23, 2024
98110f7
Update kratos postgres
mpgxvii Aug 23, 2024
51b5fdd
Merge branch 'feature/ory-based-authorization' of https://github.com/…
mpgxvii Aug 23, 2024
2c4683c
Fix error component login url and remove unnecessary logs
mpgxvii Aug 23, 2024
12b7253
Update dependencies
mpgxvii Aug 23, 2024
393bcf9
Merge branch 'feature/ory-based-authorization' of https://github.com/…
mpgxvii Aug 23, 2024
afbe7b9
Fix jackson version
mpgxvii Aug 23, 2024
6a07d69
Fix jackson version
mpgxvii Aug 23, 2024
b4ec9b2
Merge branch 'feature/ory-based-authorization' of https://github.com/…
mpgxvii Aug 23, 2024
5741993
Remove unused TokenKeyEndpoint
mpgxvii Aug 23, 2024
8a4e061
Update verification webhook config
mpgxvii Sep 3, 2024
d52b9df
Update self-enrolment-ui tag
mpgxvii Sep 13, 2024
cb20142
Merge pull request #924 from RADAR-base/feat/hydra-token
mpgxvii Sep 13, 2024
1bac662
Merge branch 'dev' of https://github.com/RADAR-base/ManagementPortal …
mpgxvii Sep 16, 2024
93e18fb
Fix merge conflicts
mpgxvii Sep 16, 2024
96c2890
Add Ory config updates for jwt claims and ui env vars
mpgxvii Sep 25, 2024
f2af901
Check if subject is equal to clientId when grant type is not present
mpgxvii Sep 25, 2024
d5f0613
Merge branch 'dev' of https://github.com/RADAR-base/ManagementPortal …
mpgxvii Sep 26, 2024
dda9372
Add check for null subject before checking if equal to clientId
mpgxvii Sep 26, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Main
# Run in master and dev branches and in all pull requests to those branches
on:
push:
branches: [ master, dev ]
branches: [ master, dev, feature/* ]
pull_request: {}

env:
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ thymeleaf_version=3.1.2.RELEASE
spring_session_version=2021.2.0
gatling_version=3.8.4
mapstruct_version=1.5.5.Final
jackson_version=2.16.1
jackson_version=2.15.0
javax_xml_bind_version=2.3.3
javax_jaxb_core_version=2.3.0.1
javax_jaxb_runtime_version=2.3.8
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ interface RadarToken {
* @return true if the client credentials flow was certainly used, false otherwise.
*/
val isClientCredentials: Boolean
get() = grantType == CLIENT_CREDENTIALS
get() = grantType == CLIENT_CREDENTIALS || (subject != null && subject == clientId)

fun copyWithRoles(roles: Set<AuthorityReference>): RadarToken

Expand Down
46 changes: 16 additions & 30 deletions src/main/docker/etc/config/kratos/kratos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ dsn: memory

serve:
public:
base_url: http://127.0.0.1:4433/
base_url: http://localhost:4433/
admin:
base_url: http://kratos:4434/

selfservice:
default_browser_return_url: http://127.0.0.1:3000/
default_browser_return_url: http://localhost:3000/
allowed_return_urls:
- "http://127.0.0.1:3000/"
- "http://127.0.0.1:8080/"
Expand All @@ -19,23 +19,6 @@ selfservice:
methods:
password:
enabled: true
# oidc:
# config:
# providers:
# # social sign-in for google. This needs to be tied to a google account. values below were added by bastiaan
# - id: google_d292689d # this is `<provider-id>` in the Authorization callback URL. DO NOT CHANGE IT ONCE SET! current google callback: http://127.0.0.1:4433/self-service/methods/oidc/callback/google_d292689d
# provider: google
# client_id: 922854293804-r3fhl9tom6uutcq5c8fm4592l1t6s3mh.apps.googleusercontent.com # Replace this with the Client ID
# client_secret: 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 # Replace this with the Client secret
# issuer_url: https://accounts.google.com # Replace this with the providers issuer URL
# mapper_url: "base64://bG9jYWwgY2xhaW1zID0gewogIGVtYWlsX3ZlcmlmaWVkOiBmYWxzZSwKfSArIHN0ZC5leHRWYXIoJ2NsYWltcycpOwoKewogIGlkZW50aXR5OiB7CiAgICB0cmFpdHM6IHsKICAgICAgW2lmICdlbWFpbCcgaW4gY2xhaW1zICYmIGNsYWltcy5lbWFpbF92ZXJpZmllZCB0aGVuICdlbWFpbCcgZWxzZSBudWxsXTogY2xhaW1zLmVtYWlsLAogICAgfSwKICB9LAp9"
# # currently: GitHub example from: https://www.ory.sh/docs/kratos/social-signin/data-mapping
# # Alternatively, use an URL:
# # mapper_url: https://storage.googleapis.com/abc-cde-prd/9cac9717f007808bf17
# scope:
# - email
# # supported scopes can be found in your providers dev docs
# enabled: true
totp:
config:
issuer: Kratos
Expand All @@ -45,34 +28,34 @@ selfservice:

flows:
error:
ui_url: http://127.0.0.1:3000/error
ui_url: http://localhost:3000/error

settings:
ui_url: http://127.0.0.1:3000/settings

ui_url: http://localhost:3000/settings
recovery:
enabled: true
ui_url: http://127.0.0.1:3000/recovery
use: link
ui_url: http://localhost:3000/recovery
use: code

verification:
# our current flow necessitates that users reset their password after they activate an account in managementportal,
# this works as verification
ui_url: http://127.0.0.1:3000/verification
ui_url: http://localhost:3000/verification
enabled: true
use: link
use: code
after:
default_browser_return_url: http://127.0.0.1:3000
default_browser_return_url: http://localhost:3000/consent

logout:
after:
default_browser_return_url: http://127.0.0.1:3000/login
default_browser_return_url: http://localhost:3000/login

login:
ui_url: http://127.0.0.1:3000/login
ui_url: http://localhost:3000/login

registration:
ui_url: http://127.0.0.1:3000/registration
ui_url: http://localhost:3000/registration
after:
password:
hooks:
Expand Down Expand Up @@ -104,3 +87,6 @@ courier:
smtp:
connection_uri: smtps://test:test@mailslurper:1025/?skip_ssl_verify=true&disable_starttls=true
from_address: [email protected]

oauth2_provider:
url: http://hydra:4445
5 changes: 5 additions & 0 deletions src/main/docker/etc/config/kratos/webhook_body.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function(ctx) {
identity: if std.objectHas(ctx, "identity") then ctx.identity else null,
payload: if std.objectHas(ctx, "flow") && std.objectHas(ctx.flow, "transient_payload") then ctx.flow.transient_payload else null,
cookies: ctx.request_cookies
}
34 changes: 34 additions & 0 deletions src/main/docker/etc/postgres/init-user-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#! /bin/bash

set -e
set -u
export PGPASSWORD="$POSTGRES_PASSWORD"
export PGUSER="$POSTGRES_USER"

function create_user_and_database() {
export PGPASSWORD="$POSTGRES_PASSWORD"
export PGUSER="$POSTGRES_USER"
local database=$1
local database_exist=$(psql -U $PGUSER -tAc "SELECT 1 FROM pg_database WHERE datname='$database';")
if [[ "$database_exist" == 1 ]]; then
echo "Database $database already exists"
else
echo "Database $database does not exist"
echo " Creating database '$database' for user '$PGUSER'"

psql -U $PGUSER -v ON_ERROR_STOP=1 <<-EOSQL
CREATE DATABASE "$database";
GRANT ALL PRIVILEGES ON DATABASE $database TO $PGUSER;
EOSQL
fi
}

if [ -n "$POSTGRES_MULTIPLE_DATABASES" ]; then
echo "Multiple database creation requested: $POSTGRES_MULTIPLE_DATABASES"
#waiting for postgres
for db in $(echo $POSTGRES_MULTIPLE_DATABASES | tr ',' ' '); do
create_user_and_database $db
done
echo "Databases created"
fi

3 changes: 3 additions & 0 deletions src/main/docker/managementportal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ services:
- MANAGEMENTPORTAL_IDENTITYSERVER_SERVERURL=http://kratos:4433
- MANAGEMENTPORTAL_IDENTITYSERVER_LOGINURL=http://localhost:3000
- MANAGEMENTPORTAL_IDENTITYSERVER_SERVERADMINURL=http://kratos:4434
- MANAGEMENTPORTAL_AUTHSERVER_SERVERURL=http://hydra:4444
- MANAGEMENTPORTAL_AUTHSERVER_LOGINURL=http://localhost:4444
- MANAGEMENTPORTAL_AUTHSERVER_SERVERADMINURL=http://hydra:4445
- JHIPSTER_SLEEP=10 # gives time for the database to boot before the application
- JAVA_OPTS=-Xmx512m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 #enables remote debugging
ports:
Expand Down
27 changes: 23 additions & 4 deletions src/main/docker/non_managementportal/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ networks:
driver: bridge
internal: true

volumes:
pgdata:

services:
managementportal-postgresql:
extends:
Expand All @@ -22,10 +25,10 @@ services:
- db
- default

kratos-selfservice-ui-node:
radar-self-enrolment-ui:
extends:
file: ../ory_stack.yml
service: kratos-selfservice-ui-node
service: radar-self-enrolment-ui
networks:
- ory
- default
Expand All @@ -46,10 +49,10 @@ services:
networks:
- ory

postgresd-kratos:
postgresd-ory:
extends:
file: ../ory_stack.yml
service: postgresd-kratos
service: postgresd-ory
networks:
- ory

Expand All @@ -60,3 +63,19 @@ services:
networks:
- ory
- default

hydra-migrate:
extends:
file: ../ory_stack.yml
service: hydra-migrate
networks:
- ory

hydra:
extends:
file: ../ory_stack.yml
service: hydra
networks:
- ory
- default

81 changes: 65 additions & 16 deletions src/main/docker/ory_stack.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
version: '3.8'

volumes:
pgdata:

services:
kratos-selfservice-ui-node:
image:
oryd/kratos-selfservice-ui-node
radar-self-enrolment-ui:
image: ghcr.io/radar-base/radar-self-enrolment-ui:dev
environment:
- LOG_LEAK_SENSITIVE_VALUES=true
- KRATOS_PUBLIC_URL=http://kratos:4433
- KRATOS_ADMIN_URL=http://kratos:4434
- SECURITY_MODE=standalone
- KRATOS_BROWSER_URL=http://127.0.0.1:4433
- COOKIE_SECRET=unsafe_cookie_secret
- CSRF_COOKIE_NAME=radar
- CSRF_COOKIE_SECRET=unsafe_csrf_cookie_secret
- ORY_SDK_URL=http://kratos:4433
- HYDRA_ADMIN_URL=http://hydra:4445
- HYDRA_PUBLIC_URL=http://hydra:4444
ports:
- "3000:3000"
volumes:
Expand All @@ -27,7 +24,18 @@ services:
- "4434:4434" # admin, should be closed in production
restart: unless-stopped
environment:
- DSN=postgres://kratos:secret@postgresd-kratos/kratos?sslmode=disable&max_conns=20&max_idle_conns=4
- DSN=postgres://ory:secret@postgresd-ory/kratos?sslmode=disable&max_conns=20&max_idle_conns=4
- SELFSERVICE_FLOWS_REGISTRATION_AFTER_PASSWORD_HOOKS_0_HOOK=web_hook
- SELFSERVICE_FLOWS_REGISTRATION_AFTER_PASSWORD_HOOKS_0_CONFIG_METHOD=POST
- SELFSERVICE_FLOWS_REGISTRATION_AFTER_PASSWORD_HOOKS_0_CONFIG_URL=http://managementportal:8080/managementportal/api/kratos/subjects
- SELFSERVICE_FLOWS_REGISTRATION_AFTER_PASSWORD_HOOKS_0_CONFIG_BODY=/etc/config/kratos/webhook_body.jsonnet
- SELFSERVICE_FLOWS_REGISTRATION_AFTER_PASSWORD_HOOKS_0_CONFIG_RESPONSE_IGNORE=true
- SELFSERVICE_FLOWS_REGISTRATION_AFTER_PASSWORD_HOOKS_1_HOOK=session
- SELFSERVICE_FLOWS_VERIFICATION_AFTER_HOOKS_0_HOOK=web_hook
- SELFSERVICE_FLOWS_VERIFICATION_AFTER_HOOKS_0_CONFIG_METHOD=POST
- SELFSERVICE_FLOWS_VERIFICATION_AFTER_HOOKS_0_CONFIG_URL=http://managementportal:8080/managementportal/api/kratos/subjects/activate
- SELFSERVICE_FLOWS_VERIFICATION_AFTER_HOOKS_0_CONFIG_BODY=/etc/config/kratos/webhook_body.jsonnet
- SELFSERVICE_FLOWS_VERIFICATION_AFTER_HOOKS_0_CONFIG_RESPONSE_IGNORE=true
command: serve -c /etc/config/kratos/kratos.yml --dev --watch-courier
volumes:
- type: bind
Expand All @@ -38,23 +46,64 @@ services:
image:
oryd/kratos:v1.0.0
environment:
- DSN=postgres://kratos:secret@postgresd-kratos/kratos?sslmode=disable&max_conns=20&max_idle_conns=4
- DSN=postgres://ory:secret@postgresd-ory/kratos?sslmode=disable&max_conns=20&max_idle_conns=4
volumes:
- type: bind
source: ./etc/config/kratos
target: /etc/config/kratos
command: -c /etc/config/kratos/kratos.yml migrate sql -e --yes
restart: on-failure

postgresd-kratos:
postgresd-ory:
image: postgres:11.8
environment:
- POSTGRES_USER=kratos
- POSTGRES_USER=ory
- POSTGRES_PASSWORD=secret
- POSTGRES_DB=kratos
- POSTGRES_MULTIPLE_DATABASES=kratos,hydra
volumes:
- pgdata:/var/lib/postgresql/data
- ./etc/postgres/init-user-db.sh:/docker-entrypoint-initdb.d/init-user-db.sh

mailslurper:
image: oryd/mailslurper:latest-smtps
ports:
- "4436:4436"
- "4437:4437"

hydra-migrate:
image: oryd/hydra:v2.2.0
environment:
- DSN=postgres://ory:secret@postgresd-ory/hydra?sslmode=disable&max_conns=20&max_idle_conns=4
command: migrate sql -e --yes
restart: on-failure

hydra:
image: oryd/hydra:v2.2.0
depends_on:
- hydra-migrate
ports:
- "4444:4444" # Public port
- "4445:4445" # Admin port
- "5555:5555" # Port for hydra token user
command:
serve all --dev
restart: on-failure # TODO figure out why we need this (incorporate health check into hydra migrate command?)
environment:
- DSN=postgres://ory:secret@postgresd-ory/hydra?sslmode=disable&max_conns=20&max_idle_conns=4
- LOG_LEAK_SENSITIVE_VALUES=true
- URLS_SELF_ISSUER=http://localhost:4444
- URLS_SELF_PUBLIC=http://localhost:4444
- URLS_CONSENT=http://localhost:3000/consent
- URLS_LOGIN=http://localhost:3000/login
- URLS_LOGOUT=http://localhost:3000/logout
- URLS_IDENTITY_PROVIDER_PUBLICURL=http://localhost:4433
- URLS_IDENTITY_PROVIDER_URL=http://localhost:4434
- SECRETS_SYSTEM=youReallyNeedToChangeThis
- OIDC_SUBJECT_IDENTIFIERS_SUPPORTED_TYPES=public,pairwise
- OIDC_SUBJECT_IDENTIFIERS_PAIRWISE_SALT=youReallyNeedToChangeThis
- STRATEGIES_ACCESS_TOKEN=jwt
- STRATEGIES_JWT_SCOPE_CLAIM=both
- SERVE_PUBLIC_CORS_ENABLED=true
- SERVE_ADMIN_CORS_ENABLED=true
- OAUTH2_ALLOWED_TOP_LEVEL_CLAIMS=scope,roles,authorities,sources,user_name
- OAUTH2_MIRROR_TOP_LEVEL_CLAIMS=false
Loading
Loading