Skip to content

Commit 131c04e

Browse files
authored
APISIX integration (#2061)
1 parent 6c9a8d2 commit 131c04e

33 files changed

+3015
-65
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ repos:
7272
- yarn.lock
7373
- --exclude-files
7474
- ".*/generated/"
75+
- --exclude-files
76+
- "config/keycloak/tls/*"
77+
- --exclude-files
78+
- "config/keycloak/realms/default-realm.json"
7579
additional_dependencies: ["gibberish-detector"]
7680
- repo: https://github.com/astral-sh/ruff-pre-commit
7781
rev: "v0.9.4"

.secrets.baseline

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@
100100
"test_.*.py",
101101
"poetry.lock",
102102
"yarn.lock",
103-
".*/generated/"
103+
".*/generated/",
104+
"config/keycloak/tls/*"
104105
]
105106
}
106107
],

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ RUN poetry install
5454
USER root
5555
COPY . /src
5656
WORKDIR /src
57-
RUN mkdir /src/staticfiles
57+
RUN mkdir -p /src/staticfiles
5858

5959
RUN apt-get clean && apt-get purge
6060

Dockerfile-litellm

Lines changed: 0 additions & 18 deletions
This file was deleted.

README-keycloak.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Keycloak and APISIX Integration
2+
3+
The "docker-compose.services.yml" file includes Keycloak and APISIX containers that you can use for authentication instead of spinning up separate ones or using the deployed instances. It's not enabled by default, but you can run it if you prefer not to run your own Keycloak/APISIX instances.
4+
5+
## Default Settings
6+
7+
There are some defaults that are part of this.
8+
9+
_SSL Certificate_: There's a self-signed cert that's in `config/keycloak/tls` - if you'd rather set up your own (or you have a real cert or something to use), you can drop the PEM files in there. See the README there for info.
10+
11+
_Realm_: There's a `default-realm.json` in `config/keycloak` that will get loaded by Keycloak when it starts up, and will set up a realm for you with some users and a client so you don't have to set it up yourself. The realm it creates is called `ol-local`.
12+
13+
The users it sets up are:
14+
15+
| User | Password |
16+
| ------------------- | --------- |
17+
| `[email protected]` | `student` |
18+
| `[email protected]` | `prof` |
19+
| `[email protected]` | `admin` |
20+
21+
The client it sets up is called `apisix`. You can change the passwords and get the secret in the admin.
22+
23+
## Making it Work
24+
25+
The Keycloak instance is part of the `keycloak` profile in the Composer file, so if you want to interact with it, you'll need to run `COMPOSE_PROFILES=backend,frontend,keycloak,apisix docker compose up`. (If you start the app without the profile, you can still start Keycloak later by specifying the profile.)
26+
27+
If you want to use the Keycloak and APISIX instances, follow these steps:
28+
29+
1. Change the value of `MITOL_API_BASE_URL` to `http://api.open.odl.local:8065` and `MITOL_API_LOGOUT_SUFFIX` to `logout/oidc` in your `shared.local.env` file.
30+
2. Add `MITOL_NEW_USER_LOGIN_URL=http://open.odl.local:8062/onboarding` to your `shared.local.env` file
31+
3. Copy all the env values under the "# APISIX/Keycloak " section of `backend.local.example.env` to your `backend.local.env` file. You can leave all the values as is.
32+
4. Keycloak needs to create its own database, which will only happen if you first destroy your current mit-learn database container: `docker compose down db`. If you prefer not to do this, you can manually create it by running the SQL in `config/postgres/init-keycloak.sql` in a postgres shell.
33+
5. Start containers with the command `COMPOSE_PROFILES=backend,frontend,keycloak,apisix docker compose up`
34+
35+
The Keycloak and APISIX containers should start up and stay running. APISIX is on port 8065, Keycloak on port 8066. Now you should be able to log in at `https://open.odl.local:8065/login` with one of the users mentioned above, or just click "Log in" from the home page at http://open.odl.local:8062. Try logging out and back in a couple times to make sure it works.

config/apisix/apisix.yaml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
upstreams:
2+
- id: 1
3+
nodes:
4+
"nginx:${{NGINX_PORT}}": 1
5+
type: roundrobin
6+
7+
routes:
8+
- id: 1
9+
name: "passauth"
10+
desc: "Wildcard route that can use auth but doesn't require it."
11+
priority: 0
12+
upstream_id: 1
13+
plugins:
14+
openid-connect:
15+
client_id: ${{KEYCLOAK_CLIENT_ID}}
16+
client_secret: ${{KEYCLOAK_CLIENT_SECRET}}
17+
discovery: ${{KEYCLOAK_DISCOVERY_URL}}
18+
realm: ${{KEYCLOAK_REALM_NAME}}
19+
scope: ${{KEYCLOAK_SCOPES}}
20+
bearer_only: false
21+
introspection_endpoint_auth_method: "client_secret_post"
22+
ssl_verify: false
23+
session:
24+
secret: ${{APISIX_SESSION_SECRET_KEY}}
25+
logout_path: "/logout/oidc"
26+
post_logout_redirect_uri: ${{APISIX_LOGOUT_URL}}
27+
unauth_action: "pass"
28+
cors:
29+
allow_origins: "**"
30+
allow_methods: "**"
31+
allow_headers: "**"
32+
allow_credential: true
33+
response-rewrite:
34+
headers:
35+
set:
36+
Referrer-Policy: "origin"
37+
uri: "*"
38+
- id: 2
39+
name: "logout-redirect"
40+
desc: "Strip trailing slash from logout redirect."
41+
priority: 10
42+
upstream_id: 1
43+
uri: "/logout/oidc/*"
44+
plugins:
45+
redirect:
46+
uri: "/logout/oidc"
47+
- id: 3
48+
name: "reqauth"
49+
desc: "Routes that require authentication."
50+
priority: 10
51+
upstream_id: 1
52+
plugins:
53+
openid-connect:
54+
client_id: ${{KEYCLOAK_CLIENT_ID}}
55+
client_secret: ${{KEYCLOAK_CLIENT_SECRET}}
56+
discovery: ${{KEYCLOAK_DISCOVERY_URL}}
57+
realm: ${{KEYCLOAK_REALM_NAME}}
58+
scope: ${{KEYCLOAK_SCOPES}}
59+
bearer_only: false
60+
introspection_endpoint_auth_method: "client_secret_post"
61+
ssl_verify: false
62+
session:
63+
secret: ${{APISIX_SESSION_SECRET_KEY}}
64+
logout_path: "/logout/oidc"
65+
post_logout_redirect_uri: ${{APISIX_LOGOUT_URL}}
66+
unauth_action: "auth"
67+
cors:
68+
allow_origins: "**"
69+
allow_methods: "**"
70+
allow_headers: "**"
71+
allow_credential: true
72+
response-rewrite:
73+
headers:
74+
set:
75+
Referrer-Policy: "origin"
76+
uris:
77+
- "/admin/login/*"
78+
- "/login/*"
79+
#END

config/apisix/config.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apisix:
2+
enable_admin: false
3+
enable_dev_mode: false
4+
node_listen:
5+
- port: ${{APISIX_PORT}}
6+
7+
deployment:
8+
role: data_plane
9+
role_data_plane:
10+
config_provider: yaml
11+
#END

config/apisix/debug.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
basic:
18+
enable: true # Enable the basic debug mode.
19+
http_filter:
20+
enable: false # Enable HTTP filter to dynamically apply advanced debug settings.
21+
enable_header_name: X-APISIX-Dynamic-Debug # If the header is present in a request, apply the advanced debug settings.
22+
hook_conf:
23+
enable: false # Enable hook debug trace to log the target module function's input arguments or returned values.
24+
name: hook_phase # Name of module and function list.
25+
log_level: warn # Severity level for input arguments and returned values in the error log.
26+
is_print_input_args: true # Print the input arguments.
27+
is_print_return_value: true # Print the return value.
28+
29+
hook_phase: # Name of module and function list.
30+
apisix: # Required module name.
31+
- http_access_phase # Required function names.
32+
- http_header_filter_phase
33+
- http_body_filter_phase
34+
- http_log_phase
35+
#END

config/keycloak/providers/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Place the SCIM plugin here if you intend to run it locally.

0 commit comments

Comments
 (0)