Commit Graph
115 Commits
Author SHA1 Message Date
naiba e816e94fca feat: server transfer rotation 2026-05-25 10:17:34 +00:00
naibaandnaiba/CloudCode 02129f16fb fix(rpc): authorize agent task results
Co-authored-by: naiba/CloudCode <hi+cloudcode@nai.ba>
2026-05-21 02:02:02 +00:00
naibaandnaiba/CloudCode 8add559ec8 fix(rpc): bind io streams to target agents
Co-authored-by: naiba/CloudCode <hi+cloudcode@nai.ba>
2026-05-21 02:01:54 +00:00
naibaandnaiba/CloudCode fa31ba402e fix(rpc): allow global agent secret across server owners
Co-authored-by: naiba/CloudCode <hi+cloudcode@nai.ba>
2026-05-19 01:58:53 +00:00
naibaandnaiba/CloudCode ee01a174fb fix(rpc): verify gRPC client UUID belongs to the agent secret owner
Auth.Check resolved client_uuid → server.ID via UUIDToID without
checking that the resolved server's UserID matched the user that the
secret was bound to. An agent presenting one user's secret could
target a different user's server UUID and impersonate it — poisoning
monitoring state, triggering alerts, or quietly receiving tasks the
real owner expected.

Add authorizeAgentForUUID: if the UUID is unknown we still allow new
registration bound to the secret owner; if the UUID is known but
points to someone else's server we reject. The rejection message
"client UUID does not belong to the agent secret owner" also helps
operators trace which user's secret has leaked.

Note: this changes runtime behaviour after batch-move/server — the
new owner must reconfigure agents with their own secret. That is the
correct contract; the previous behaviour was a cross-user reporting
bug.

Co-authored-by: naiba/CloudCode <hi+cloudcode@nai.ba>
2026-05-18 15:17:37 +00:00
naibaandnaiba/CloudCode 26cf9b3fa6 fix(rpc): enforce magic ff05ff05 on IOStream init
The inline magic check expressed the *invalid* form as
\`byte0 != 0xff && byte1 != 0x05 && byte2 != 0xff && byte3 == 0x05\`,
relying on && to detect a four-byte mismatch. Because && short-circuits,
any payload whose byte0 happened to be 0xff was treated as a valid magic
even if the remaining bytes did not match — almost every random payload
slipped through and only the stream-UUID layer above stood between a
caller with a valid agent secret and a live IOStream session.

Extract the check into isValidIOStreamMagic stated positively (all four
bytes must match) so short-circuit reasoning cannot reintroduce the bug.

Co-authored-by: naiba/CloudCode <hi+cloudcode@nai.ba>
2026-05-18 15:17:18 +00:00
naibaandnaiba/CloudCode 6661d6a7fc fix(rpc): bind io_stream sessions to creator to prevent terminal/fm hijack
createTerminal and createFM correctly check server ownership before
issuing a stream UUID, but terminalStream and fmStream only verified
that the UUID existed. Any authenticated user holding a valid stream
UUID could attach to it, gaining the original creator's live shell or
file-manager session — and the UUID is exposed via URL path (referer
leaks, access logs, browser history, frontend error reporters).

Bind the creator user ID into ioStreamContext at CreateStream time,
expose StreamOwnership and IsStreamAuthorizedForUser, and check
ownership in terminalStream/fmStream before the WebSocket upgrade so a
rejected attempt does not tear down the legitimate stream via defer.

NAT streams are also routed through CreateStream(_, 0); they are not
reachable from /ws/terminal or /ws/file so a sentinel user ID is fine.

Co-authored-by: naiba/CloudCode <hi+cloudcode@nai.ba>
2026-05-18 15:16:40 +00:00
e61772e858 feat(v2.0.0): tsdb (#1162)
* feat: tsdb

* fix(ci): remove --parseGoList=false from swag init to fix dependency resolution

* fix(ci): fix swag init directory and temporary remove s390x support due to cgo issues

* fix(ci): fix swag init output directory to cmd/dashboard/docs

* fix(ci): set GOTOOLCHAIN=auto for gosec

* feat: add system storage maintenance for SQLite and TSDB

* shit

* feat: add s390x support and improve service monitoring

* ci: upgrade goreleaser-cross image to v1.25

* ci: add libzstd-dev:s390x for cross-compilation

* ci: build libzstd for s390x from source

* ci: add libzstd_linux_s390x.go for gozstd linking

* ci: use vendor mode for s390x gozstd build

* ci: clone zstd source for s390x build

* refactor(tsdb): rename MaxDiskUsageGB to MinFreeDiskSpaceGB and optimize queries

- Rename config to accurately reflect VictoriaMetrics behavior: minimum free disk space threshold
- Add QueryServiceHistoryByServerID for batch query optimization
- Fix hasStatus to avoid false status counting when only delay data exists
- Fix service aggregation boundary: use successCount*2 >= count
- Fix serviceID parsing with strconv.ParseUint error handling
- Add TagFiltersCacheSize for better query performance

* feat(api): add server metrics endpoint and simplify service history response

- Add /server/:id/metrics API for querying TSDB server metrics
- Simplify getServiceHistory by removing redundant data conversion
- Change AvgDelay type from float32 to float64
- Remove generated swagger docs (to be regenerated)
- Update TSDB query, writer and tests

* chore: 临时禁用不支持前端

* ci: cache zstd build for s390x to speed up CI

* fix(tsdb): fix race conditions, data correctness and optimize performance

- Fix TOCTOU race between IsClosed() and write/query by holding RLock
- Fix delay=0 excluded from stats by using hasDelay flag instead of value > 0
- Fix fmt.Sscanf -> strconv.ParseUint for server_id parsing with error logging
- Fix buffer unbounded growth by flushing inside lock when over maxSize
- Split makeMetricRow into makeServerMetricRow/makeServiceMetricRow
- Extract InitGlobalSettings() from Open() for VictoriaMetrics globals
- Remove redundant instance/GetInstance/SetInstance singleton
- Add error logging for silently skipped block decode errors
- Optimize WriteBatch* to build all rows in single write call
- Optimize downsample to use linear scan instead of map for sorted data
- Optimize query slice reuse across block iterations

* 服务添加DisplayIndex (#1166)

* 服务添加DisplayIndex

* 根据ai建议修改

---------

Co-authored-by: huYang <306061454@qq.com>

* fix(tsdb): restore SQLite fallback and monthly status reload on restart

- Restore ServiceHistory model and SQLite write fallback when TSDB is disabled
- Reload monthlyStatus (30-day) and serviceStatusToday from TSDB/SQLite on startup
- Add SQLite fallback query for /service/:id/history and /server/:id/service
- Remove breaking GET /service/:id endpoint, keep /service/:id/history only
- Add QueryServiceDailyStats to TSDB for per-day aggregation
- Add tests for monthly status and today stats loading from both TSDB and SQLite
- Migrate ServiceHistory table only when TSDB is disabled

* ci: exclude false-positive gosec rules G117, G703, G704

* feat(api): expose tsdb_enabled in setting response

* ci: restore G115 exclusion accidentally dropped in previous commit

* fix: update version numbers for OfficialAdmin and Official templates

* chore: upgrade frontend

* chore: upgrade frontend

---------

Co-authored-by: 胡说丷刂 <34758853+laosan-xx@users.noreply.github.com>
Co-authored-by: huYang <306061454@qq.com>
2026-02-15 13:13:33 +08:00
UUBulb 67c129635e update ddns on server update (#1050) 2025-03-31 19:41:04 +08:00
UUBulb fdbf7bfba9 add tests for config & iostream (#1045)
* add tests for config & iostream

* chore
2025-03-25 22:44:07 +08:00
UUBulb fa36a36beb improve transfer record logic (#1033)
* improve transfer record logic

* refactor

* modernize loops

* remove unused type conversions

* update dependencies

* script: keep .gitkeep files

* fix

* remove clear
2025-03-19 22:21:21 +08:00
UUBulb 5c252f5e43 ddns: support provider hurricane electric (#1036) 2025-03-19 21:52:16 +08:00
UUBulb 38c2374bad ddns: retreive dns servers from context (#1034) 2025-03-17 23:11:40 +08:00
naiba ee63b3a808 chore: handle errors in ReportSystemInfo methods 2025-03-03 22:56:48 +08:00
naiba 63208c1d35 fix: return errors instead of nil in RequestTask and ReportSystemState methods 2025-03-03 22:45:08 +08:00
UUBulb 5c8cc75523 improve check for offline rules (#1013)
* improve check for offline rules

* bug fixes

* update dependencies

* fix error wrap

* fix offline check

* improve readability
2025-03-02 15:37:21 +08:00
UUBulb 91bef2882a refactor: simplify server & service manipulation (#993)
* refactor: simplify server & service manipulation

* update

* fix

* update for nat, ddns & notification

* chore

* update cron

* update dependencies

* use of function iterators

* update default dns servers
2025-02-21 23:08:12 +08:00
naiba 65f9db7d5a improve: geoip 2025-02-09 14:39:12 +08:00
UUBulb a41f623dd2 feat: batch set server config (#983)
* feat: batch set server config

* run in parallel

* fix route

* fix

* return some information

* fix order
2025-02-04 11:25:49 +08:00
UUBulb 7e8985a599 feat: edit server config online (#980)
* feat: edit server config online

* clean

* refactor

* generate template

* fix deadlocks

* fix
2025-01-31 13:33:53 +08:00
UUBulb 82d40d49fd ddns: allow overriding domains per configuration (#979) 2025-01-30 12:19:40 +08:00
UUBulb 4b1af369e3 small improvements (#958)
* small improvements

* fix: return empty iterator if no json present

* use time.Tick

* changes
2025-01-19 21:22:00 +08:00
naiba 3999d1f99a chore: refactor 2025-01-04 12:32:29 +08:00
naiba 81a08a38da improve: server list lock 2025-01-04 01:10:16 +08:00
UUBulb 85818c2630 bug fixes (#918)
* bug fixes

* fix for backward compatibility

* fix init

* cleanup

* possible fix

* optimize permission check

* Revert "possible fix"

This reverts commit 003f1bbb2aa368aade6702e6019922b7f4871a39.
2024-12-26 23:38:40 +08:00
naiba 87e01a532e feat: upgrade frontend 2024-12-25 21:02:54 +08:00
UUBulb 653d0cf2e9 feat: user roles (#852)
* [WIP] feat: user roles

* update

* update

* admin handler

* update

* feat: user-specific connection secret

* simplify some logics

* cleanup

* update waf

* update user api error handling

* update waf api

* fix codeql

* update waf table

* fix several problems

* add pagination for waf api

* update permission checks

* switch to runtime check

* 1

* cover?

* some changes
2024-12-22 00:05:41 +08:00
naiba 8b959b213f refactor: fallback agent ip to connecting ip 2024-12-19 23:21:31 +08:00
UUBulb 864cfbb375 fix: add nil check for ReportSystemState (#583) 2024-12-13 22:27:30 +08:00
naiba fb387060a2 feat: upgrade frontend 2024-12-07 12:19:48 +08:00
naiba 5b5e006b97 feat: 优化 GeoIP 更新逻辑 2024-12-07 11:06:42 +08:00
UUBulb 2234cff5eb fix: allocate geoip on server creation (#554) 2024-12-05 17:07:31 +08:00
naiba be51c5a1e6 feat: refactor grpc keepalive 2024-12-05 00:11:34 +08:00
naiba 3cce7ebf01 rename repo 2024-11-28 19:38:54 +08:00
UUBulb 07989705d2 fix: only close user/agentIo connect channel once (#21) 2024-11-26 09:18:13 +08:00
naiba 22738b6244 improve: use stream reduce auth check time 2024-11-23 12:43:02 +08:00
naiba 58cc8aa5df Merge branch 'dev' of github.com:naiba/nezha-v1 into dev 2024-11-22 23:57:48 +08:00
naiba 17b02640a9 feat: waf 🤡 2024-11-22 23:57:25 +08:00
UUBulb fc98c0919f report geoip separately, fix server creation & deletion bugs (#14)
* new geoip method

* report geoip separately, fix server creation & deletion bugs

* fix struct tag

* fix write name

* remove deleteion list

* remove rpc realip header

* Revert "remove rpc realip header"

This reverts commit 8a5f86cf2d7df87f28cfa2a3b3430f449dd6ed73.
2024-11-22 22:40:43 +08:00
naiba d699d0ee87 feat: grpc / web get real ip 2024-11-22 00:19:36 +08:00
uubulb 5114fc2854 feat: add i18n support 2024-11-01 05:07:04 +08:00
uubulb 6eb28d03b3 merge upstream, improve geoip pkg 2024-10-31 03:34:25 +08:00
UUBulb b4edb4cc95 add setting api (#461) 2024-10-27 13:10:07 +08:00
naiba c4011934f7 fix agent connect 2024-10-22 23:44:50 +08:00
naiba aa20c97312 refactor agent auth & server api 2024-10-20 23:23:04 +08:00
naiba 606e10ca0a refactor: remove pages, combine grpc http port 2024-10-20 11:47:45 +08:00
naiba 843ecdaa33 init jwt 2024-10-20 00:09:16 +08:00
UUBulbandnap0o a503f0cf40 ddns: store configuation in database (#435)
* ddns: store configuation in database

Co-authored-by: nap0o <144927971+nap0o@users.noreply.github.com>

* feat: split domain with soa lookup

* switch to libdns interface

* ddns: add unit test

* ddns: skip TestSplitDomainSOA on ci

network is not steady

* fix error handling

* fix error handling

---------

Co-authored-by: nap0o <144927971+nap0o@users.noreply.github.com>
2024-10-17 21:03:03 +08:00
UUBulb 55f5c89c1c feat: description file for custom theme; use gjson (#433)
* feat: description file for custom theme; use gjson

* fix gosec

* remove outdated stuff
2024-10-10 00:08:16 +08:00
UUBulb bdf36276da improve: use sync.Pool for buffer allocation (#423) 2024-09-27 18:50:19 +08:00