@kumori.systems/components-apisix 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/kumori.systems/components/apisix/@0.0.1/README.adoc +130 -0
- package/kumori.systems/components/apisix/@0.0.1/assets/images/routing_diagram.png +0 -0
- package/kumori.systems/components/apisix/@0.0.1/componentref.cue +26 -0
- package/kumori.systems/components/apisix/@0.0.1/cue.mod/module.cue +1 -0
- package/kumori.systems/components/apisix/@0.0.1/kmodule.cue +30 -0
- package/kumori.systems/components/apisix/@0.0.1/manifest.cue +159 -0
- package/kumori.systems/components/apisix/@0.0.1/openid-connect.cue +587 -0
- package/kumori.systems/components/apisix/@0.0.1/serviceref.cue +26 -0
- package/kumori.systems/components/apisix/@0.0.1/settings/apisix_settings.cue +33 -0
- package/kumori.systems/components/apisix/@0.0.1/settings/entrypoint.cue +38 -0
- package/kumori.systems/components/apisix/@0.0.1/settings/types/connections.cue +131 -0
- package/kumori.systems/components/apisix/@0.0.1/settings/types/consumer.cue +6 -0
- package/kumori.systems/components/apisix/@0.0.1/settings/types/globalrule.cue +6 -0
- package/kumori.systems/components/apisix/@0.0.1/settings/types/healthcheck.cue +39 -0
- package/kumori.systems/components/apisix/@0.0.1/settings/types/plugin.cue +20 -0
- package/kumori.systems/components/apisix/@0.0.1/settings/types/pluginmetadata.cue +6 -0
- package/kumori.systems/components/apisix/@0.0.1/settings/types/route.cue +34 -0
- package/kumori.systems/components/apisix/@0.0.1/settings/types/service.cue +6 -0
- package/kumori.systems/components/apisix/@0.0.1/settings/types/ssl.cue +11 -0
- package/kumori.systems/components/apisix/@0.0.1/settings/types/streamroute.cue +6 -0
- package/kumori.systems/components/apisix/@0.0.1/settings/types/upstream.cue +35 -0
- package/kumori.systems/components/apisix/@0.0.1/settings/types/utils.cue +11 -0
- package/package.json +1 -0
@@ -0,0 +1,130 @@
|
|
1
|
+
= APISIX Component
|
2
|
+
:note-number: 0.0.1
|
3
|
+
:revnumber: {note-number}
|
4
|
+
:api-version: 1.0-rc1
|
5
|
+
:icons: font
|
6
|
+
:toclevels: 4
|
7
|
+
:icons: font
|
8
|
+
:sectanchors:
|
9
|
+
:sectlinks:
|
10
|
+
:sectnums:
|
11
|
+
:imagesdir: ./assets/images
|
12
|
+
:toc-title: Contents
|
13
|
+
:toc:
|
14
|
+
|
15
|
+
== Overview
|
16
|
+
This component configures and manages the Apache APISIX API gateway, including integration with OpenID Connect (OIDC) for authentication, and various other custom routes, services, and plugins. It provides an API gateway solution that handles routing, authentication, and session management for the CMC services.
|
17
|
+
|
18
|
+
== Usage
|
19
|
+
|
20
|
+
=== Configuration
|
21
|
+
The configuration of the compontent itself is pretty minimal. It publishes a single server channel and N client channels where services can be connected.
|
22
|
+
|
23
|
+
This component expects three input parameters two of them being optional:
|
24
|
+
|
25
|
+
* `channelsCount`: Sets the number of client channels that must be generated. Defaults to 10.
|
26
|
+
* `apisixSettings`: This is the base configuration of APISIX where by default we tell it to run in standlone mode (does not need any etcd) and that the configuration of the routes/services/plugins will be done by configuration file.
|
27
|
+
* `apisixStandalone`: This is the configuration file that defines how requests are handled. Currently it expects a CUE structure that then will be converted into a yaml file. Below there is a summary of the configuration file used in the CMC service.
|
28
|
+
** Example configuration in CUE:
|
29
|
+
```
|
30
|
+
apisix_config: {
|
31
|
+
routes: [
|
32
|
+
{
|
33
|
+
uri: "/my_route/*"
|
34
|
+
upstream: {
|
35
|
+
nodes: {
|
36
|
+
"0.service_0:80": 1
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
]
|
41
|
+
}
|
42
|
+
```
|
43
|
+
|
44
|
+
To understand how routing/plugins works it's better to read the documentation from APISIX itself:
|
45
|
+
|
46
|
+
* https://apisix.apache.org/docs/apisix/deployment-modes/#standalone
|
47
|
+
* https://apisix.apache.org/docs/apisix/plugins/openid-connect/
|
48
|
+
* https://apisix.apache.org/docs/apisix/plugins/serverless/
|
49
|
+
|
50
|
+
==== Routes
|
51
|
+
|
52
|
+
Here are the configured routes for the APISIX component in the context of the CMC service:
|
53
|
+
|
54
|
+
. **/idp/**:
|
55
|
+
* **Description**: Public route. Routes traffic to Dex for identity management.
|
56
|
+
* **Upstream**: Dex service at `0.dex_channel_name:80`.
|
57
|
+
|
58
|
+
. **/platform, /platformdeprecated, /docs***:
|
59
|
+
* **Description**: Public routes. Routes traffic to the KSDS server, handling platform and documentation requests.
|
60
|
+
* **Upstream**: KSDS server at `0.cmc_channel_name:80`.
|
61
|
+
|
62
|
+
. **/api/**:
|
63
|
+
* **Description**: Protected route. Main API route, secured by OpenID Connect for authentication.
|
64
|
+
* **Upstream**: KSDS server at `0.cmc_channel_name:80`.
|
65
|
+
* **Plugins**:
|
66
|
+
** `openid-connect`: Handles authentication with OpenID Connect.
|
67
|
+
*** **Action for unauthenticated requests: `deny`**.
|
68
|
+
|
69
|
+
. **/api/**:
|
70
|
+
* **Description**: Protected route. Main API route, secured by Client Certificate authentication. It expects to receive the `X-FORWARDED-CLIENT-CERT` header set by the inbound of the cluster when a client presents its certifcate. Then a custom plugin transforms the certificate in the header into a JWT token that KSDS is able to understand.
|
71
|
+
* **Upstream**: KSDS server at `0.cmc_channel_name:80`.
|
72
|
+
* **Plugins**:
|
73
|
+
** `serverless-post-function`: Transforms the content of `X-FORWARDED-CLIENT-CERT` header into a JWT that KSDS can understand.
|
74
|
+
|
75
|
+
. [.line-through]#**/api/**:# (Might be added in the near future)
|
76
|
+
* [.line-through]#**Description**: Protected route. Main API route, secured by deployment tokens generated by the KSDS server. It expects to receive a token in the `X-API-TOKEN` header.#
|
77
|
+
* [.line-through]#**Plugins**:#
|
78
|
+
** [.line-through]#`serverless-post-function`: Validates the token presented in the requests, it must be signed with the same secret as the signing secret in the KSDS and not expired. If the validation succeeds then the token is rewriten in the `Authorization` header son the KSDS server can perform further authorization.#
|
79
|
+
|
80
|
+
. **/tokens**:
|
81
|
+
* **Description**: Protected route. Show the current user token.
|
82
|
+
* **Upstream**: N/A.
|
83
|
+
* **Plugins**:
|
84
|
+
** `openid-connect`: Handles authentication.
|
85
|
+
** `serverless-post-function`: Executes token extraction.
|
86
|
+
|
87
|
+
. **/tokens**:
|
88
|
+
* **Description**: Protected route. Show the current user token.
|
89
|
+
* **Upstream**: N/A.
|
90
|
+
* **Plugins**:
|
91
|
+
** `serverless-post-function`: Transforms the content of `X-FORWARDED-CLIENT-CERT` header into a JWT that KSDS can understand.
|
92
|
+
** `serverless-post-function`: Executes token extraction.
|
93
|
+
|
94
|
+
. **/* (WUI Route)**:
|
95
|
+
* **Description**: Protected route. Handles general traffic routed to the Web User Interface (WUI).
|
96
|
+
* **Upstream**: WUI service at `0.wui_channel_name:80`.
|
97
|
+
* **Plugins**:
|
98
|
+
** `openid-connect`: Ensures authentication via OIDC.
|
99
|
+
*** **Action for unauthenticated requests: `auth` (redirect the user to the login page)**.
|
100
|
+
|
101
|
+
. **/* (WUI Route)**:
|
102
|
+
* **Description**: Protected route. Handles general traffic routed to the Web User Interface (WUI). It expects to receive the `X-FORWARDED-CLIENT-CERT` header set by the inbound of the cluster when a client presents its certifcate.
|
103
|
+
* **Upstream**: WUI service at `0.wui_channel_name:80`.
|
104
|
+
* **Plugins**:
|
105
|
+
** `serverless-post-function`: Transforms the content of `X-FORWARDED-CLIENT-CERT` header into a JWT that KSDS can understand.
|
106
|
+
|
107
|
+
=== Execution
|
108
|
+
Once configured, you can run the APISIX component by deploying it with the appropriate manifests or through a Kubernetes setup, if integrated.
|
109
|
+
|
110
|
+
== Architecture
|
111
|
+
The APISIX component is built on top of the Apache APISIX API Gateway, integrating various upstream services such as Dex (for identity management), KSDS, and WUI. The architecture incorporates multiple plugins to enable OpenID Connect-based authentication, certificate validation, and route management for multiple microservices.
|
112
|
+
|
113
|
+
image::routing_diagram.png[Routing Diagram]
|
114
|
+
|
115
|
+
== Tree
|
116
|
+
The repository structure is as follows:
|
117
|
+
```plaintext
|
118
|
+
.
|
119
|
+
├── README.adoc # Documentation for the APISIX component.
|
120
|
+
├── componentref.cue # Auto-generated component reference.
|
121
|
+
├── kmodule.cue # Module details for the APISIX component.
|
122
|
+
├── manifest.cue # Configuration manifest for the APISIX component.
|
123
|
+
├── openid-connect.cue # Lua script for handling OpenID Connect. (Temporal fix, solved in newer version of APISIX)
|
124
|
+
├── serviceref.cue # Auto-generated service reference.
|
125
|
+
└── settings/ # Configuration folder for APISIX.
|
126
|
+
├── apisix_settings.cue # Main configuration file for APISIX.
|
127
|
+
└── types/ # Type definitions for services, plugins, routes.
|
128
|
+
```
|
129
|
+
|
130
|
+
== License
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
// Automatically generated file. Do not edit.
|
3
|
+
package component
|
4
|
+
|
5
|
+
import (
|
6
|
+
k "kumori.systems/kumori/@1.1.6:kumori"
|
7
|
+
m "...:kmodule"
|
8
|
+
)
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
#Artifact: k.#Artifact & {
|
13
|
+
spec: m.spec
|
14
|
+
ref: {
|
15
|
+
version: m.version
|
16
|
+
if m.prerelease != _|_ {
|
17
|
+
prerelease: m.prerelease
|
18
|
+
}
|
19
|
+
if m.buildmetadata != _|_ {
|
20
|
+
buildmetadata: m.buildmetadata
|
21
|
+
}
|
22
|
+
domain: m.domain
|
23
|
+
module: m.module
|
24
|
+
kind: "component"
|
25
|
+
}
|
26
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
module: kumori.systems/components/apisix/@0.0.1
|
@@ -0,0 +1,30 @@
|
|
1
|
+
package kmodule
|
2
|
+
|
3
|
+
{
|
4
|
+
domain: "kumori.systems"
|
5
|
+
module: "components/apisix"
|
6
|
+
cue: "0.4.2"
|
7
|
+
version: [
|
8
|
+
0,
|
9
|
+
0,
|
10
|
+
1,
|
11
|
+
]
|
12
|
+
dependencies: {
|
13
|
+
"kumori.systems/kumori": {
|
14
|
+
target: "kumori.systems/kumori/@1.1.6"
|
15
|
+
query: "1.1.6"
|
16
|
+
}
|
17
|
+
"kumori.systems/builtins/inbound": {
|
18
|
+
target: "kumori.systems/builtins/inbound/@1.3.0"
|
19
|
+
query: "1.3.0"
|
20
|
+
}
|
21
|
+
}
|
22
|
+
sums: {
|
23
|
+
"kumori.systems/kumori/@1.1.6": "jsXEYdYtlen2UgwDYbUCGWULqQIigC6HmkexXkyp/Mo="
|
24
|
+
"kumori.systems/builtins/inbound/@1.3.0": "F3nipPPUCZ4YpsAh+Xnh9t8W1Tu98eX6SHRVM3BbRYs="
|
25
|
+
}
|
26
|
+
spec: [
|
27
|
+
1,
|
28
|
+
0,
|
29
|
+
]
|
30
|
+
}
|
@@ -0,0 +1,159 @@
|
|
1
|
+
package component
|
2
|
+
|
3
|
+
import (
|
4
|
+
Settings ".../settings"
|
5
|
+
k "kumori.systems/kumori/@1.1.6:kumori"
|
6
|
+
)
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
// #openid_connect_lua: _
|
11
|
+
|
12
|
+
#Artifact: {
|
13
|
+
ref: name: ""
|
14
|
+
description: {
|
15
|
+
srv: {
|
16
|
+
|
17
|
+
server: {
|
18
|
+
http: { protocol: "tcp", port: 9080 }
|
19
|
+
}
|
20
|
+
|
21
|
+
client: {
|
22
|
+
// _cfgp.channelsCount channels are created with generic names
|
23
|
+
for k, v in [0] * _cfgp.channelsCount {
|
24
|
+
"service_\(k)": _
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
duplex: {}
|
29
|
+
|
30
|
+
}
|
31
|
+
|
32
|
+
let _cfgp = config.parameter
|
33
|
+
|
34
|
+
config: {
|
35
|
+
parameter: {
|
36
|
+
channelsCount: *10 | int // The number of client channels to create
|
37
|
+
|
38
|
+
apisixSettings: {
|
39
|
+
Settings.#ApisixConfig
|
40
|
+
nginx_config: envs: [
|
41
|
+
"ABW_DEPLOYMENT_TOKENS_SECRET",
|
42
|
+
"IDP_CLIENT_ID",
|
43
|
+
"IDP_CLIENT_SECRET",
|
44
|
+
]
|
45
|
+
}
|
46
|
+
apisixStandalone: Settings.#ApisixStandalone
|
47
|
+
|
48
|
+
instance_size: {
|
49
|
+
bandwidth: *1000 | number
|
50
|
+
container_size: k.#ContainerSize | *{
|
51
|
+
memory: {size: 2000, unit: "M"}
|
52
|
+
cpu: {size: 2000, unit: "m"}
|
53
|
+
mincpu: 1000
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
resource: {
|
58
|
+
abw_deployment_tokens_secret: k.#Secret
|
59
|
+
idp_client_id: k.#Secret
|
60
|
+
idp_client_secret: k.#Secret
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
|
65
|
+
size: {
|
66
|
+
bandwidth: {
|
67
|
+
size: _cfgp.instance_size.bandwidth
|
68
|
+
unit: "M"
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
probe: apisix_standalone: {
|
73
|
+
|
74
|
+
liveness: {
|
75
|
+
|
76
|
+
protocol: tcp: port: srv.server.http.port
|
77
|
+
|
78
|
+
startupGraceWindow: {
|
79
|
+
unit: "ms",
|
80
|
+
duration: 60000,
|
81
|
+
probe: true
|
82
|
+
}
|
83
|
+
|
84
|
+
frequency: "medium"
|
85
|
+
timeout: 30000
|
86
|
+
}
|
87
|
+
|
88
|
+
|
89
|
+
readiness: {
|
90
|
+
protocol: tcp: port: srv.server.http.port
|
91
|
+
frequency: "medium"
|
92
|
+
timeout: 30000
|
93
|
+
}
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
code: {
|
98
|
+
|
99
|
+
apisix_standalone: {
|
100
|
+
name: "apisix_standalone"
|
101
|
+
|
102
|
+
image: {
|
103
|
+
hub: {
|
104
|
+
name: "docker.io"
|
105
|
+
secret: ""
|
106
|
+
}
|
107
|
+
tag: "apache/apisix:3.9.1-debian"
|
108
|
+
}
|
109
|
+
|
110
|
+
entrypoint: ["/bin/entrypoint.sh"]
|
111
|
+
|
112
|
+
user: {
|
113
|
+
userid: 0
|
114
|
+
groupid: 0
|
115
|
+
}
|
116
|
+
|
117
|
+
mapping: {
|
118
|
+
filesystem: {
|
119
|
+
"/bin/entrypoint.sh": {
|
120
|
+
data: value: Settings.#Entrypoint
|
121
|
+
mode: 0o755
|
122
|
+
rebootOnUpdate: true
|
123
|
+
}
|
124
|
+
|
125
|
+
"/usr/local/apisix/conf/config.yaml": {
|
126
|
+
data: value: _cfgp.apisixSettings
|
127
|
+
rebootOnUpdate: true
|
128
|
+
format: "yaml"
|
129
|
+
}
|
130
|
+
|
131
|
+
"/usr/local/apisix/apisix/plugins/openid-connect.lua": {
|
132
|
+
data: value: #openid_connect_lua
|
133
|
+
rebootOnUpdate: true
|
134
|
+
format: "text"
|
135
|
+
}
|
136
|
+
|
137
|
+
"/tmp/apisix.yaml": {
|
138
|
+
data: value: _cfgp.apisixStandalone
|
139
|
+
format: "yaml"
|
140
|
+
}
|
141
|
+
}
|
142
|
+
|
143
|
+
env: {
|
144
|
+
GATEWAY_PORT: value: "9080"
|
145
|
+
|
146
|
+
// Access tokens signing secret
|
147
|
+
ABW_DEPLOYMENT_TOKENS_SECRET: secret: "abw_deployment_tokens_secret"
|
148
|
+
|
149
|
+
IDP_CLIENT_ID: secret: "idp_client_id"
|
150
|
+
IDP_CLIENT_SECRET: secret: "idp_client_secret"
|
151
|
+
}
|
152
|
+
}
|
153
|
+
|
154
|
+
size: _cfgp.instance_size.container_size
|
155
|
+
}
|
156
|
+
|
157
|
+
}
|
158
|
+
}
|
159
|
+
}
|