Skip to content

Commit cb7fb1f

Browse files
authored
feat: add scroll admin system (#166)
* feat: add admin system * fix: update frontend config * fix: admin system add default normal user * fix: production environment * fix: test
1 parent 8ad7c7d commit cb7fb1f

File tree

33 files changed

+997
-20
lines changed

33 files changed

+997
-20
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
apiVersion: v2
3+
description: admin-system-backend helm charts
4+
name: admin-system-backend
5+
version: 0.0.1
6+
appVersion: v0.1.0
7+
kubeVersion: ">=1.22.0-0"
8+
maintainers:
9+
- name: scroll-tech
10+
email: weichi@scroll.io
11+
dependencies:
12+
- name: common
13+
repository: "oci://ghcr.io/scroll-tech/scroll-sdk/helm"
14+
version: 1.5.1
15+
- name: external-secrets-lib
16+
repository: "oci://ghcr.io/scroll-tech/scroll-sdk/helm"
17+
version: 0.0.3

charts/admin-system-backend/README.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# admin-system-backend
2+
3+
![Version: 0.0.1](https://img.shields.io/badge/Version-0.0.1-informational?style=flat-square) ![AppVersion: v0.1.0](https://img.shields.io/badge/AppVersion-v0.1.0-informational?style=flat-square)
4+
5+
admin-system-backend helm charts
6+
7+
## Maintainers
8+
9+
| Name | Email | Url |
10+
| ---- | ------ | --- |
11+
| scroll-tech | <weichi@scroll.io> | |
12+
13+
## Requirements
14+
15+
Kubernetes: `>=1.22.0-0`
16+
17+
| Repository | Name | Version |
18+
|------------|------|---------|
19+
| oci://ghcr.io/scroll-tech/scroll-sdk/helm | common | 1.5.1 |
20+
| oci://ghcr.io/scroll-tech/scroll-sdk/helm | external-secrets-lib | 0.0.3 |
21+
22+
## Values
23+
24+
| Key | Type | Default | Description |
25+
|-----|------|---------|-------------|
26+
| command[0] | string | `"/bin/sh"` | |
27+
| command[1] | string | `"-c"` | |
28+
| command[2] | string | `"scroll-admin-system --config /app/config/admin-system-backend-config.json --genesis /app/genesis/genesis.json --http.port ${HTTP_PORT} --metrics --metrics.port ${METRICS_PORT}"` | |
29+
| configMaps.add-user.data."add-user.sh" | string | `"#!/bin/bash\necho \"Adding users...\"\npsql $SCROLL_ADMIN_AUTH_DB_CONFIG_DSN -c \"INSERT INTO users (username, role) VALUES ('admin', 1);\"\npsql $SCROLL_ADMIN_AUTH_DB_CONFIG_DSN -c \"INSERT INTO users (username, role) VALUES ('normal', 3);\"\necho \"Users added.\"\n"` | |
30+
| configMaps.add-user.enabled | bool | `true` | |
31+
| configMaps.model-conf.data."model.conf" | string | `"[request_definition]\nr = sub, obj, act\n[policy_definition]\np = sub, obj, act\n[role_definition]\ng = _, _\n[policy_effect]\ne = some(where (p.eft == allow))\n[matchers]\nm = g(r.sub, p.sub) && regexMatch(r.obj, p.obj) && regexMatch(r.act, p.act)\n"` | |
32+
| configMaps.model-conf.enabled | bool | `true` | |
33+
| configMaps.policy-csv.data."policy.csv" | string | `"p, undefined, ^\\/api\\/v1\\/login$, POST\np, undefined, ^\\/api\\/v1\\/otp\\/.*$, (GET)|(POST)\np, read, ^\\/api\\/v1\\/(chunk|batch|bundle|provertask|l2_block|prover|job)\\/.*$, GET\np, read, ^\\/api\\/v1\\/(chunk|batch|bundle|provertask|l2_block|prover)\\/search$, POST\np, readwrite, ^\\/api\\/v1\\/(chunk|batch|bundle|l2_block)\\/.*$, (POST)|(DELETE)\np, readwrite, ^\\/api\\/v1\\/provertask\\/(update|delete)$, (POST)|(DELETE)\np, admin, ^\\/api\\/v1\\/provertask\\/reassign$, POST\np, admin, ^\\/api\\/v1\\/(policy|user|prover_block|partner)\\/.*$,(GET)|(POST)|(DELETE)\np, admin, ^\\/api\\/v1\\/job\\/.*$, POST\ng, read, undefined\ng, readwrite, read\ng, admin, readwrite\n"` | |
34+
| configMaps.policy-csv.enabled | bool | `true` | |
35+
| controller.replicas | int | `1` | |
36+
| controller.strategy | string | `"Recreate"` | |
37+
| controller.type | string | `"deployment"` | |
38+
| envFrom[0].configMapRef.name | string | `"admin-system-backend-env"` | |
39+
| env[0].name | string | `"HTTP_PORT"` | |
40+
| env[0].value | string | `"8080"` | |
41+
| env[1].name | string | `"METRICS_PORT"` | |
42+
| env[1].value | string | `"8090"` | |
43+
| env[2].name | string | `"GIN_MODE"` | |
44+
| env[2].value | string | `"release"` | |
45+
| env[3].name | string | `"ENV"` | |
46+
| env[3].value | string | `"fake"` | |
47+
| env[4].name | string | `"CHAIN_ID"` | |
48+
| env[4].value | string | `"123456"` | |
49+
| global.fullnameOverride | string | `"admin-system-backend"` | |
50+
| global.nameOverride | string | `"admin-system-backend"` | |
51+
| image.pullPolicy | string | `"Always"` | |
52+
| image.repository | string | `"scrolltech/scroll-admin-system"` | |
53+
| image.tag | string | `"v0.1.2"` | |
54+
| initContainers.1-check-postgres-connection.args[0] | string | `"postgresql"` | |
55+
| initContainers.1-check-postgres-connection.args[1] | string | `"$(SCROLL_ADMIN_AUTH_DB_CONFIG_DSN)"` | |
56+
| initContainers.1-check-postgres-connection.args[2] | string | `"--timeout"` | |
57+
| initContainers.1-check-postgres-connection.args[3] | string | `"0"` | |
58+
| initContainers.1-check-postgres-connection.envFrom[0].configMapRef.name | string | `"admin-system-backend-env"` | |
59+
| initContainers.1-check-postgres-connection.image | string | `"atkrad/wait4x:latest"` | |
60+
| initContainers.2-migrate-db.command[0] | string | `"/bin/sh"` | |
61+
| initContainers.2-migrate-db.command[1] | string | `"-c"` | |
62+
| initContainers.2-migrate-db.command[2] | string | `"db_cli migrate --config /app/config/admin-system-backend-config.json"` | |
63+
| initContainers.2-migrate-db.envFrom[0].configMapRef.name | string | `"admin-system-backend-env"` | |
64+
| initContainers.2-migrate-db.image | string | `"scrolltech/scroll-admin-system:v0.1.2"` | |
65+
| initContainers.2-migrate-db.volumeMounts[0].mountPath | string | `"/app/config/"` | |
66+
| initContainers.2-migrate-db.volumeMounts[0].name | string | `"admin-system-backend"` | |
67+
| initContainers.3-add-user.command[0] | string | `"bash"` | |
68+
| initContainers.3-add-user.command[1] | string | `"-c"` | |
69+
| initContainers.3-add-user.command[2] | string | `"/add-user.sh"` | |
70+
| initContainers.3-add-user.envFrom[0].configMapRef.name | string | `"admin-system-backend-env"` | |
71+
| initContainers.3-add-user.image | string | `"postgres:latest"` | |
72+
| initContainers.3-add-user.volumeMounts[0].mountPath | string | `"/add-user.sh"` | |
73+
| initContainers.3-add-user.volumeMounts[0].name | string | `"add-user"` | |
74+
| initContainers.3-add-user.volumeMounts[0].subPath | string | `"add-user.sh"` | |
75+
| persistence.add-user.defaultMode | string | `"0777"` | |
76+
| persistence.add-user.enabled | bool | `true` | |
77+
| persistence.add-user.mountPath | string | `"/app/conf/add-user.sh"` | |
78+
| persistence.add-user.name | string | `"admin-system-backend-add-user"` | |
79+
| persistence.add-user.subPath | string | `"add-user.sh"` | |
80+
| persistence.add-user.type | string | `"configMap"` | |
81+
| persistence.app_name.enabled | bool | `true` | |
82+
| persistence.app_name.mountPath | string | `"/app/config/"` | |
83+
| persistence.app_name.name | string | `"admin-system-backend-config"` | |
84+
| persistence.app_name.type | string | `"configMap"` | |
85+
| persistence.genesis.enabled | bool | `true` | |
86+
| persistence.genesis.mountPath | string | `"/app/genesis/"` | |
87+
| persistence.genesis.name | string | `"genesis-config"` | |
88+
| persistence.genesis.type | string | `"configMap"` | |
89+
| persistence.model-conf.enabled | bool | `true` | |
90+
| persistence.model-conf.mountPath | string | `"/app/conf/model.conf"` | |
91+
| persistence.model-conf.name | string | `"admin-system-backend-model-conf"` | |
92+
| persistence.model-conf.subPath | string | `"model.conf"` | |
93+
| persistence.model-conf.type | string | `"configMap"` | |
94+
| persistence.policy-csv.enabled | bool | `true` | |
95+
| persistence.policy-csv.mountPath | string | `"/app/conf/policy.csv"` | |
96+
| persistence.policy-csv.name | string | `"admin-system-backend-policy-csv"` | |
97+
| persistence.policy-csv.subPath | string | `"policy.csv"` | |
98+
| persistence.policy-csv.type | string | `"configMap"` | |
99+
| probes.liveness.enabled | bool | `false` | |
100+
| probes.readiness.enabled | bool | `false` | |
101+
| probes.startup.enabled | bool | `false` | |
102+
| resources.limits.cpu | string | `"100m"` | |
103+
| resources.limits.memory | string | `"200Mi"` | |
104+
| resources.requests.cpu | string | `"50m"` | |
105+
| resources.requests.memory | string | `"50Mi"` | |
106+
| service.main.enabled | bool | `true` | |
107+
| service.main.ports.http.enabled | bool | `true` | |
108+
| service.main.ports.http.port | int | `8080` | |
109+
| service.main.ports.http.primary | bool | `true` | |
110+
| service.main.ports.http.protocol | string | `"HTTP"` | |
111+
| service.main.ports.metrics.enabled | bool | `true` | |
112+
| service.main.ports.metrics.port | int | `8090` | |
113+
| service.main.ports.metrics.targetPort | int | `8090` | |
114+
| service.main.primary | bool | `true` | |
115+
| serviceMonitor.main.enabled | bool | `true` | |
116+
| serviceMonitor.main.endpoints[0].interval | string | `"1m"` | |
117+
| serviceMonitor.main.endpoints[0].port | string | `"http"` | |
118+
| serviceMonitor.main.endpoints[0].scrapeTimeout | string | `"10s"` | |
119+
| serviceMonitor.main.labels.release | string | `"scroll-stack"` | |
120+
| serviceMonitor.main.serviceName | string | `"{{ include \"scroll.common.lib.chart.names.fullname\" $ }}"` | |
121+
122+
----------------------------------------------
123+
Autogenerated from chart metadata using [helm-docs v1.14.2](https://github.com/norwoodj/helm-docs/releases/v1.14.2)

charts/admin-system-backend/configs/.keep

Whitespace-only changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
{{- include "scroll.common.loader.init" . }}
3+
4+
{{- define "app-template.hardcodedValues" -}}
5+
# Set the nameOverride based on the release name if no override has been set
6+
{{ if not .Values.global.nameOverride }}
7+
global:
8+
nameOverride: "{{ .Release.Name }}"
9+
{{ end }}
10+
{{- end -}}
11+
{{- $_ := mergeOverwrite .Values (include "app-template.hardcodedValues" . | fromYaml) -}}
12+
13+
{{/* Render the templates */}}
14+
{{ include "scroll.common.loader.generate" . }}
15+
---
16+
{{- include "scrolllib.externalsecrets.tpl" . }}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{{- if .Values.global.isStandalone }}
2+
---
3+
apiVersion: v1
4+
kind: ConfigMap
5+
metadata:
6+
name: admin-system-backend-config
7+
data:
8+
{{ (.Files.Glob "configs/admin-system-backend-config.json").AsConfig | indent 2 }}
9+
---
10+
{{- end }}
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
---
2+
global:
3+
nameOverride: &app_name admin-system-backend
4+
fullnameOverride: *app_name
5+
6+
controller:
7+
replicas: 1
8+
strategy: Recreate
9+
type: deployment
10+
11+
image:
12+
repository: scrolltech/scroll-admin-system
13+
pullPolicy: Always
14+
tag: v0.1.2
15+
16+
env:
17+
- name: HTTP_PORT
18+
value: "8080"
19+
- name: METRICS_PORT
20+
value: "8090"
21+
- name: GIN_MODE
22+
value: "release"
23+
- name: ENV
24+
value: "fake"
25+
- name: CHAIN_ID
26+
value: "123456"
27+
28+
envFrom:
29+
- configMapRef:
30+
name: admin-system-backend-env
31+
32+
command: [
33+
"/bin/sh",
34+
"-c",
35+
"scroll-admin-system --config /app/config/admin-system-backend-config.json \
36+
--genesis /app/genesis/genesis.json \
37+
--http.port ${HTTP_PORT} \
38+
--metrics --metrics.port ${METRICS_PORT}",
39+
]
40+
41+
resources:
42+
requests:
43+
memory: "50Mi"
44+
cpu: "50m"
45+
limits:
46+
memory: "200Mi"
47+
cpu: "100m"
48+
49+
service:
50+
main:
51+
enabled: true
52+
primary: true
53+
ports:
54+
http:
55+
primary: true
56+
enabled: true
57+
port: 8080
58+
protocol: HTTP
59+
metrics:
60+
enabled: true
61+
port: 8090
62+
targetPort: 8090
63+
64+
probes:
65+
liveness:
66+
enabled: false
67+
readiness:
68+
enabled: false
69+
startup:
70+
enabled: false
71+
72+
73+
persistence:
74+
*app_name:
75+
enabled: true
76+
type: configMap
77+
mountPath: /app/config/
78+
name: admin-system-backend-config
79+
genesis:
80+
enabled: true
81+
type: configMap
82+
mountPath: /app/genesis/
83+
name: genesis-config
84+
model-conf:
85+
enabled: true
86+
type: configMap
87+
mountPath: /app/conf/model.conf
88+
subPath: model.conf
89+
name: admin-system-backend-model-conf
90+
policy-csv:
91+
enabled: true
92+
type: configMap
93+
mountPath: /app/conf/policy.csv
94+
subPath: policy.csv
95+
name: admin-system-backend-policy-csv
96+
add-user:
97+
enabled: true
98+
type: configMap
99+
mountPath: /app/conf/add-user.sh
100+
subPath: add-user.sh
101+
name: admin-system-backend-add-user
102+
defaultMode: "0777"
103+
104+
initContainers:
105+
1-check-postgres-connection:
106+
image: atkrad/wait4x:latest
107+
args:
108+
- postgresql
109+
- $(SCROLL_ADMIN_AUTH_DB_CONFIG_DSN)
110+
- --timeout
111+
- "0"
112+
envFrom:
113+
- configMapRef:
114+
name: admin-system-backend-env
115+
2-migrate-db:
116+
image: scrolltech/scroll-admin-system:v0.1.2
117+
command: [
118+
"/bin/sh",
119+
"-c",
120+
"db_cli migrate --config /app/config/admin-system-backend-config.json"
121+
]
122+
volumeMounts:
123+
- name: *app_name
124+
mountPath: /app/config/
125+
envFrom:
126+
- configMapRef:
127+
name: admin-system-backend-env
128+
3-add-user:
129+
image: postgres:latest
130+
command: ["bash", "-c", "/add-user.sh"]
131+
volumeMounts:
132+
- name: add-user
133+
mountPath: /add-user.sh
134+
subPath: add-user.sh
135+
envFrom:
136+
- configMapRef:
137+
name: admin-system-backend-env
138+
139+
configMaps:
140+
model-conf:
141+
enabled: true
142+
data:
143+
model.conf: |
144+
[request_definition]
145+
r = sub, obj, act
146+
[policy_definition]
147+
p = sub, obj, act
148+
[role_definition]
149+
g = _, _
150+
[policy_effect]
151+
e = some(where (p.eft == allow))
152+
[matchers]
153+
m = g(r.sub, p.sub) && regexMatch(r.obj, p.obj) && regexMatch(r.act, p.act)
154+
policy-csv:
155+
enabled: true
156+
data:
157+
policy.csv: |
158+
p, undefined, ^\/api\/v1\/login$, POST
159+
p, undefined, ^\/api\/v1\/otp\/.*$, (GET)|(POST)
160+
p, read, ^\/api\/v1\/(chunk|batch|bundle|provertask|l2_block|prover|job)\/.*$, GET
161+
p, read, ^\/api\/v1\/(chunk|batch|bundle|provertask|l2_block|prover)\/search$, POST
162+
p, readwrite, ^\/api\/v1\/(chunk|batch|bundle|l2_block)\/.*$, (POST)|(DELETE)
163+
p, readwrite, ^\/api\/v1\/provertask\/(update|delete)$, (POST)|(DELETE)
164+
p, admin, ^\/api\/v1\/provertask\/reassign$, POST
165+
p, admin, ^\/api\/v1\/(policy|user|prover_block|partner)\/.*$,(GET)|(POST)|(DELETE)
166+
p, admin, ^\/api\/v1\/job\/.*$, POST
167+
g, read, undefined
168+
g, readwrite, read
169+
g, admin, readwrite
170+
add-user:
171+
enabled: true
172+
data:
173+
add-user.sh: |
174+
#!/bin/bash
175+
echo "Adding users..."
176+
psql $SCROLL_ADMIN_AUTH_DB_CONFIG_DSN -c "INSERT INTO users (username, role) VALUES ('admin', 1);"
177+
psql $SCROLL_ADMIN_AUTH_DB_CONFIG_DSN -c "INSERT INTO users (username, role) VALUES ('normal', 3);"
178+
echo "Users added."
179+
180+
serviceMonitor:
181+
main:
182+
enabled: true
183+
labels:
184+
release: scroll-stack
185+
serviceName: '{{ include "scroll.common.lib.chart.names.fullname" $ }}'
186+
endpoints:
187+
- port: http
188+
interval: 1m
189+
scrapeTimeout: 10s

0 commit comments

Comments
 (0)