Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
db-tools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
yzy
db-tools
Commits
d62d5510
Commit
d62d5510
authored
Oct 23, 2026
by
wangteng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
登录用户体系
parent
57ae0d02
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
4 deletions
+21
-4
deploy/deploy_server.py
deploy/deploy_server.py
+10
-1
web/backend/core/security.py
web/backend/core/security.py
+2
-2
web/backend/tests/test_security.py
web/backend/tests/test_security.py
+7
-1
web/docs/system-security.md
web/docs/system-security.md
+2
-0
No files found.
deploy/deploy_server.py
View file @
d62d5510
...
@@ -192,7 +192,15 @@ def main() -> None:
...
@@ -192,7 +192,15 @@ def main() -> None:
"
rm
-
rf
/
opt
/
web
/
db
-
tool
/
assets
&&
tar
xzf
/
tmp
/
dbtool
-
frontend
.
tgz
-
C
/
opt
/
web
/
db
-
tool
/
"
"
rm
-
rf
/
opt
/
web
/
db
-
tool
/
assets
&&
tar
xzf
/
tmp
/
dbtool
-
frontend
.
tgz
-
C
/
opt
/
web
/
db
-
tool
/
"
"
&&
test
-
f
/
opt
/
web
/
db
-
tool
/
index
.
html
"
"
&&
test
-
f
/
opt
/
web
/
db
-
tool
/
index
.
html
"
)
)
run("
systemctl
restart
db
-
tool
&&
sleep
4
&&
systemctl
is
-
active
db
-
tool
&&
ss
-
tlnp
|
grep
8767
")
run("
systemctl
restart
db
-
tool
")
# 首次补建账户表、加载路由可能超过 4 秒,以认证接口就绪为准。
run(
"
for
attempt
in
$
(
seq
1
30
);
do
"
"
STATUS
=
$
(
curl
-
s
--
max
-
time
2
-
o
/
dev
/
null
-
w
'%{http_code}'
http
:
//
127.0
.
0.1
:
8767
/
api
/
health
);
"
'if [ "
$
STATUS
" = "
401
" ] && systemctl is-active --quiet db-tool; then '
"
systemctl
is
-
active
db
-
tool
;
exit
0
;
fi
;
sleep
1
;
done
;
"
"
journalctl
-
u
db
-
tool
-
n
30
--
no
-
pager
;
exit
1
"
)
# 健康接口也要求登录;无凭证应返回 401,同时验证服务连通和认证生效。
# 健康接口也要求登录;无凭证应返回 401,同时验证服务连通和认证生效。
for probe_url in ("
http
:
//
127.0
.
0.1
:
8767
/
api
/
health
", "
http
:
//
127.0
.
0.1
/
db
-
tool
/
api
/
health
"):
for probe_url in ("
http
:
//
127.0
.
0.1
:
8767
/
api
/
health
", "
http
:
//
127.0
.
0.1
/
db
-
tool
/
api
/
health
"):
probe_status = run("
curl
-
sS
--
max
-
time
15
-
o
/
dev
/
null
-
w
'%{http_code}'
" + shlex.quote(probe_url))
probe_status = run("
curl
-
sS
--
max
-
time
15
-
o
/
dev
/
null
-
w
'%{http_code}'
" + shlex.quote(probe_url))
...
@@ -210,6 +218,7 @@ def main() -> None:
...
@@ -210,6 +218,7 @@ def main() -> None:
)
)
result = run(
result = run(
"
cd
/
opt
/
app
/
db
-
tool
&&
APP_ENV
=
production
PYTHONPATH
=/
opt
/
app
/
db
-
tool
"
"
cd
/
opt
/
app
/
db
-
tool
&&
APP_ENV
=
production
PYTHONPATH
=/
opt
/
app
/
db
-
tool
"
"
LD_LIBRARY_PATH
=/
opt
/
app
/
db
-
tool
/
web
/
oracle_client
/
linux
/
instantclient_19_32
"
"
/
opt
/
app
/
db
-
tool
/
.
venv
/
bin
/
python
-
c
" + shlex.quote(probe)
"
/
opt
/
app
/
db
-
tool
/
.
venv
/
bin
/
python
-
c
" + shlex.quote(probe)
)
)
try:
try:
...
...
web/backend/core/security.py
View file @
d62d5510
...
@@ -325,8 +325,8 @@ class SecurityMiddleware(BaseHTTPMiddleware):
...
@@ -325,8 +325,8 @@ class SecurityMiddleware(BaseHTTPMiddleware):
request.state.audit_rejection = (exc.detail if isinstance(exc.detail, str) else exc.detail.get('message', '请求被拒绝'))[:300]
request.state.audit_rejection = (exc.detail if isinstance(exc.detail, str) else exc.detail.get('message', '请求被拒绝'))[:300]
return JSONResponse(status_code=status, content={"
detail
": exc.detail}, headers={"
Cache
-
Control
": "
no
-
store
", 'X-Request-ID': request.state.audit_request_id})
return JSONResponse(status_code=status, content={"
detail
": exc.detail}, headers={"
Cache
-
Control
": "
no
-
store
", 'X-Request-ID': request.state.audit_request_id})
finally:
finally:
# 登录请求单独记录到登录日志;
其余请求保留完整操作轨迹,
不采集敏感请求体。
# 登录请求单独记录到登录日志;
登录状态检查不记操作日志,其余请求
不采集敏感请求体。
if not public:
if not public
and path != "
/
api
/
auth
/
me
"
:
await run_in_threadpool(write_audit, request, status, started)
await run_in_threadpool(write_audit, request, status, started)
elif path == "
/
api
/
auth
/
login
" and not getattr(request.state, "
login_logged
", False):
elif path == "
/
api
/
auth
/
login
" and not getattr(request.state, "
login_logged
", False):
await run_in_threadpool(write_rejected_login, request, status)
await run_in_threadpool(write_rejected_login, request, status)
web/backend/tests/test_security.py
View file @
d62d5510
...
@@ -386,7 +386,9 @@ class SecurityTests(unittest.TestCase):
...
@@ -386,7 +386,9 @@ class SecurityTests(unittest.TestCase):
table_design
.
_design_sessions_pop
(
'design-test'
,
design
.
user_id
)
table_design
.
_design_sessions_pop
(
'design-test'
,
design
.
user_id
)
def
test_audit_and_logout
(
self
):
def
test_audit_and_logout
(
self
):
self
.
assertEqual
(
self
.
client
.
get
(
"/api/auth/me"
).
status_code
,
401
)
self
.
assertEqual
(
self
.
login
().
status_code
,
200
)
self
.
assertEqual
(
self
.
login
().
status_code
,
200
)
self
.
assertEqual
(
self
.
client
.
get
(
"/api/auth/me"
).
status_code
,
200
)
self
.
client
.
get
(
"/api/backup/dashboard-summary"
)
self
.
client
.
get
(
"/api/backup/dashboard-summary"
)
self
.
client
.
get
(
"/api/system/users"
)
self
.
client
.
get
(
"/api/system/users"
)
self
.
assertEqual
(
self
.
client
.
post
(
"/api/auth/logout"
).
status_code
,
204
)
self
.
assertEqual
(
self
.
client
.
post
(
"/api/auth/logout"
).
status_code
,
204
)
...
@@ -395,16 +397,20 @@ class SecurityTests(unittest.TestCase):
...
@@ -395,16 +397,20 @@ class SecurityTests(unittest.TestCase):
events
=
db
.
query
(
AuditLog
).
all
()
events
=
db
.
query
(
AuditLog
).
all
()
self
.
assertTrue
(
any
(
e
.
username
==
"tester"
and
e
.
status_code
==
403
for
e
in
events
))
self
.
assertTrue
(
any
(
e
.
username
==
"tester"
and
e
.
status_code
==
403
for
e
in
events
))
self
.
assertTrue
(
any
(
e
.
path
==
"/api/auth/logout"
for
e
in
events
))
self
.
assertTrue
(
any
(
e
.
path
==
"/api/auth/logout"
for
e
in
events
))
self
.
assertFalse
(
any
(
e
.
path
==
"/api/auth/me"
for
e
in
events
))
self
.
assertNotIn
(
self
.
password
,
str
([
e
.
__dict__
for
e
in
events
]))
self
.
assertNotIn
(
self
.
password
,
str
([
e
.
__dict__
for
e
in
events
]))
def
test_audit_identity_and_expired_session_are_explicit
(
self
):
def
test_audit_identity_and_expired_session_are_explicit
(
self
):
self
.
client
.
get
(
'/api/
auth/me
'
,
headers
=
{
'X-User'
:
'cdadmin'
})
self
.
client
.
get
(
'/api/
backup/dashboard-summary
'
,
headers
=
{
'X-User'
:
'cdadmin'
})
self
.
assertEqual
(
self
.
login
().
status_code
,
200
)
self
.
assertEqual
(
self
.
login
().
status_code
,
200
)
token
=
self
.
client
.
cookies
.
get
(
security
.
COOKIE_NAME
)
token
=
self
.
client
.
cookies
.
get
(
security
.
COOKIE_NAME
)
with
self
.
sessions
()
as
db
:
with
self
.
sessions
()
as
db
:
db
.
get
(
AuthSession
,
security
.
digest
(
token
)).
expires_at
=
datetime
.
utcnow
()
-
timedelta
(
seconds
=
1
)
db
.
get
(
AuthSession
,
security
.
digest
(
token
)).
expires_at
=
datetime
.
utcnow
()
-
timedelta
(
seconds
=
1
)
db
.
commit
()
db
.
commit
()
self
.
assertEqual
(
self
.
client
.
get
(
'/api/auth/me'
).
status_code
,
401
)
self
.
assertEqual
(
self
.
client
.
get
(
'/api/auth/me'
).
status_code
,
401
)
with
self
.
sessions
()
as
db
:
self
.
assertEqual
(
db
.
query
(
AuditLog
).
filter_by
(
path
=
'/api/auth/me'
).
count
(),
0
)
self
.
assertEqual
(
self
.
client
.
get
(
'/api/backup/dashboard-summary'
).
status_code
,
401
)
with
self
.
sessions
()
as
db
:
with
self
.
sessions
()
as
db
:
rows
=
db
.
query
(
AuditLog
).
order_by
(
AuditLog
.
id
).
all
()
rows
=
db
.
query
(
AuditLog
).
order_by
(
AuditLog
.
id
).
all
()
self
.
assertEqual
(
rows
[
0
].
identity_status
,
'anonymous'
)
self
.
assertEqual
(
rows
[
0
].
identity_status
,
'anonymous'
)
...
...
web/docs/system-security.md
View file @
d62d5510
...
@@ -35,6 +35,8 @@
...
@@ -35,6 +35,8 @@
小型 JSON 请求只保留白名单内的对象标识、角色/菜单关联、状态、表名和配置项,不保存完整请求体、响应体、SQL、业务行数据、规则代码、明文密码、验证码、Cookie、令牌及密钥。用户/角色/菜单新增、修改、删除、重置与解锁保留安全字段的变更前后快照和关联名称;按 ID 访问的数据源、校验任务、监测任务、备份任务、规则、表设计配置也记录安全对象快照。详情中的空快照可能是非配置操作、对象不存在或升级前未采集,不能据此推断没有发生变更。HTTP 202 只表示已受理,后台执行最终结果须看任务或报告,不写成执行成功。
小型 JSON 请求只保留白名单内的对象标识、角色/菜单关联、状态、表名和配置项,不保存完整请求体、响应体、SQL、业务行数据、规则代码、明文密码、验证码、Cookie、令牌及密钥。用户/角色/菜单新增、修改、删除、重置与解锁保留安全字段的变更前后快照和关联名称;按 ID 访问的数据源、校验任务、监测任务、备份任务、规则、表设计配置也记录安全对象快照。详情中的空快照可能是非配置操作、对象不存在或升级前未采集,不能据此推断没有发生变更。HTTP 202 只表示已受理,后台执行最终结果须看任务或报告,不写成执行成功。
登录状态检查接口
`/api/auth/me`
仍执行认证校验,但不写入操作日志(包括未登录或会话过期的检查请求)。
列表支持按账号、姓名、功能、操作、对象、来源地址、请求编号及时间范围查询。详情接口同样要求操作日志权限。仅提供只读查询,没有修改或删除审计接口。来源页面由前端提供且仅作为参考,身份和功能判定以服务端会话和接口为准。升级时增量补列,保留原始历史记录,不回填无法确认的身份或配置值。
列表支持按账号、姓名、功能、操作、对象、来源地址、请求编号及时间范围查询。详情接口同样要求操作日志权限。仅提供只读查询,没有修改或删除审计接口。来源页面由前端提供且仅作为参考,身份和功能判定以服务端会话和接口为准。升级时增量补列,保留原始历史记录,不回填无法确认的身份或配置值。
审计时间存储为 UTC,页面按浏览器当地时区显示。来源地址由 ASGI 的 client 提供,应用不自行采信转发头;Nginx / Uvicorn 应仅信任已配置的反向代理。接口返回 202 表示已接受后台任务,其最终执行结果继续在已有业务操作记录中查看。
审计时间存储为 UTC,页面按浏览器当地时区显示。来源地址由 ASGI 的 client 提供,应用不自行采信转发头;Nginx / Uvicorn 应仅信任已配置的反向代理。接口返回 202 表示已接受后台任务,其最终执行结果继续在已有业务操作记录中查看。
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment