Compare commits

..

153 Commits

Author SHA1 Message Date
Pascal Fischer
0aeac50803 Merge branch 'peers-get-account-refactoring' into refactor/optimize-peer-expiration 2025-01-17 14:53:26 +01:00
Pascal Fischer
f1ee844446 fix import 2025-01-17 13:39:31 +01:00
Pascal Fischer
5acfe00de1 Merge branch 'main' into peers-get-account-refactoring
# Conflicts:
#	management/server/peer.go
2025-01-17 13:38:16 +01:00
Pascal Fischer
232c9788b9 revert: add some logs 2025-01-17 12:04:06 +01:00
Pascal Fischer
93c8f9476c add metrics 2025-01-17 11:31:26 +01:00
Pascal Fischer
c6d16724fb fix key check 2025-01-17 02:24:40 +01:00
Pascal Fischer
3556d6a1fc disable suite test 2025-01-17 02:15:59 +01:00
Pascal Fischer
96e9c3683c disable suite test 2025-01-17 02:07:23 +01:00
Pascal Fischer
a4a5a2eb23 remove test changes 2025-01-17 01:50:04 +01:00
Pascal Fischer
a78a313fcf disable suite test 2025-01-17 01:37:40 +01:00
Pascal Fischer
aa34dda05a run cancel in defer 2025-01-17 01:11:09 +01:00
Pascal Fischer
eeb688cb5e cleanup after sync 2025-01-17 01:08:29 +01:00
Pascal Fischer
f78b629f40 cleanup after sync 2025-01-17 01:05:26 +01:00
Pascal Fischer
5c8be070f0 rename peers in test 2025-01-17 00:59:52 +01:00
Pascal Fischer
833fec0029 add logs 2025-01-17 00:35:58 +01:00
Pascal Fischer
66f003d00f temporarily disable old test suite test 2025-01-17 00:24:49 +01:00
Pascal Fischer
14a3461e86 use bool instead of int 2025-01-16 23:30:24 +01:00
Pascal Fischer
b853c87e36 fix scheduler mock 2025-01-16 23:00:47 +01:00
Pascal Fischer
5d3832c597 update total amount of test peers 2025-01-16 22:46:25 +01:00
Pascal Fischer
1fd6583e5f update total amount of test peers 2025-01-16 22:34:04 +01:00
Pascal Fischer
d0ab68c599 simplify isRunning 2025-01-16 21:54:29 +01:00
Pascal Fischer
d45255b1b7 limit peer inactivity 2025-01-16 21:36:26 +01:00
Pascal Fischer
2af95886f8 reformat 2025-01-16 21:33:32 +01:00
Pascal Fischer
97ff9a3e5d [management] Improve group peer/resource counting (#3192) 2025-01-16 21:32:12 +01:00
Pascal Fischer
b6a558b523 check if job is running 2025-01-16 21:30:56 +01:00
Pascal Fischer
f597379be5 fix store test 2025-01-16 21:01:20 +01:00
Pascal Fischer
265ded0508 don't reschedule expiration on connection and disconnect and run expiration even if peer is disconnected 2025-01-16 20:36:13 +01:00
bcmmbaga
d962f7fd27 Remove context in db calls
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2025-01-16 20:53:05 +03:00
bcmmbaga
30ae3aa030 Skip user check for system initiated peer deletion
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2025-01-16 20:52:41 +03:00
Pascal Fischer
aeb6e53e51 remove mysql from api benchmark tests 2025-01-15 15:37:11 +01:00
bcmmbaga
4afaabb33c Use peers and groups map for peers validation
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2025-01-15 12:50:25 +03:00
bcmmbaga
6367fe4f74 go mod tidy
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2025-01-15 11:52:50 +03:00
bcmmbaga
22798ada25 Fix tests
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2025-01-15 11:51:08 +03:00
bcmmbaga
2fb399aa7d Refactor GetValidatedPeers
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2025-01-15 11:49:40 +03:00
bcmmbaga
6a81ca2e52 Bump integrations version
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2025-01-15 11:44:03 +03:00
Pascal Fischer
e27db948ae update expectations 2025-01-15 00:19:42 +01:00
Pascal Fischer
167c80da40 update expectations 2025-01-14 23:38:23 +01:00
Pascal Fischer
7241a16ff7 Merge remote-tracking branch 'origin/peers-get-account-refactoring' into peers-get-account-refactoring 2025-01-14 23:28:20 +01:00
Pascal Fischer
30b023d126 update expectations 2025-01-14 23:28:06 +01:00
bcmmbaga
7baef8c502 Merge remote-tracking branch 'origin/peers-get-account-refactoring' into peers-get-account-refactoring 2025-01-15 00:09:25 +03:00
bcmmbaga
b15ee5c07c Refactor ToGroupsInfo to process slices of groups
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2025-01-15 00:09:10 +03:00
Pascal Fischer
b1e8ed889e update timeouts 2025-01-14 21:28:48 +01:00
Pascal Fischer
44f69c70e0 fix validator 2025-01-14 21:01:15 +01:00
Pascal Fischer
a5731fe509 fix validator 2025-01-14 20:56:19 +01:00
Pascal Fischer
61b38e56e4 fix validator 2025-01-14 20:51:07 +01:00
Pascal Fischer
29ea44b874 update expectations 2025-01-14 20:44:06 +01:00
bcmmbaga
84aea32118 Refactor peer scheduler to retry every 3 seconds on errors
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2025-01-14 22:13:11 +03:00
bcmmbaga
acb5340d40 Merge remote-tracking branch 'origin/peers-get-account-refactoring' into peers-get-account-refactoring 2025-01-14 22:11:22 +03:00
Pascal Fischer
8b7766e34d update expectations 2025-01-14 20:10:04 +01:00
Pascal Fischer
2706ede08e update expectations 2025-01-14 19:42:48 +01:00
Pascal Fischer
3483139903 update expectations 2025-01-14 19:17:48 +01:00
bcmmbaga
ce7385119a Use integrated validator direct
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2025-01-14 20:58:43 +03:00
bcmmbaga
cd15c85d5b Add status error for generic result error
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2025-01-14 20:54:44 +03:00
Pascal Fischer
9ff56eae64 update cloud expectations 2025-01-14 18:43:50 +01:00
Pascal Fischer
47a18db186 update local benchmark expectations 2025-01-14 18:04:20 +01:00
Pascal Fischer
aa0480c5e6 [management] Update benchmark workflow (#3181) 2025-01-14 15:14:56 +01:00
bcmmbaga
eb062c07ec Adjust benchmarks
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2025-01-14 12:09:52 +03:00
bcmmbaga
7a9c75db91 Adjust benchmarks
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2025-01-13 23:19:30 +03:00
bcmmbaga
c603c40a53 Add get peer groups tests
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2025-01-13 20:56:51 +03:00
bcmmbaga
48af90c770 Get account direct from store without buffer
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2025-01-13 19:18:18 +03:00
bcmmbaga
3cc6d3862d Improve peer performance
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2025-01-13 17:52:39 +03:00
bcmmbaga
d1e5d584f7 Fix merge
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2025-01-13 16:12:34 +03:00
bcmmbaga
b1325267d8 Merge branch 'main' into peers-get-account-refactoring
# Conflicts:
#	management/server/peer.go
2025-01-13 15:54:37 +03:00
bcmmbaga
2e596fbf1a use account object to get validated peers
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2025-01-10 13:37:38 +03:00
bcmmbaga
fa1eaa0aec fix store tests
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2025-01-09 13:38:09 +03:00
bcmmbaga
baf211203a fix merge
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2025-01-08 23:17:54 +03:00
bcmmbaga
9d86f76a24 Merge branch 'main' into peers-get-account-refactoring
# Conflicts:
#	management/server/account.go
#	management/server/account_test.go
#	management/server/ephemeral.go
#	management/server/ephemeral_test.go
#	management/server/http/handlers/peers/peers_handler.go
#	management/server/http/handlers/peers/peers_handler_test.go
#	management/server/integrated_validator.go
#	management/server/mock_server/account_mock.go
#	management/server/peer.go
#	management/server/store/sql_store.go
#	management/server/store/sql_store_test.go
#	management/server/store/store.go
#	management/server/testdata/store_with_expired_peers.sql
#	management/server/user.go
2025-01-08 22:31:10 +03:00
bcmmbaga
9a96b91d9d Fix merge
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-12-09 14:21:28 +01:00
bcmmbaga
a05bd464cd Merge branch 'main' into peers-get-account-refactoring
# Conflicts:
#	management/server/peer.go
2024-12-06 13:45:23 +03:00
bcmmbaga
a3663fb444 Merge branch 'main' into peers-get-account-refactoring 2024-11-29 10:15:10 +03:00
bcmmbaga
8c4613b456 Merge branch 'main' into peers-get-account-refactoring 2024-11-28 17:41:13 +03:00
bcmmbaga
d66140fc82 Fix merge
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-28 15:08:42 +03:00
bcmmbaga
dea6886394 Merge branch 'main' into peers-get-account-refactoring
# Conflicts:
#	management/server/peer.go
2024-11-28 15:07:52 +03:00
bcmmbaga
1ba6eb62a6 Retrieve all groups for peers and restrict groups for regular users
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-28 15:01:44 +03:00
bcmmbaga
f87bc601c6 Add account locks and remove redundant ephemeral check
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-28 14:03:08 +03:00
bcmmbaga
cde0e51c72 Refactor test names and remove duplicate TestPostgresql_SavePeerStatus
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-28 12:30:38 +03:00
bcmmbaga
a22d5041e3 Add missing tests
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-28 12:21:15 +03:00
bcmmbaga
fde9f2ffda Add store locks and prevent fetching setup keys peers when retrieving user peers with empty userID
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-28 12:18:02 +03:00
bcmmbaga
21561a2b07 Merge branch 'main' into peers-get-account-refactoring
# Conflicts:
#	management/server/sql_store_test.go
2024-11-27 13:20:14 +03:00
bcmmbaga
b2139875d9 Merge branch 'nameserver-get-account-refactoring' into peers-get-account-refactoring
# Conflicts:
#	management/server/account.go
#	management/server/http/peers_handler.go
#	management/server/peer.go
2024-11-27 13:18:17 +03:00
bcmmbaga
2e6bbaca96 Merge branch 'main' into nameserver-get-account-refactoring
# Conflicts:
#	management/server/sql_store_test.go
#	management/server/status/error.go
#	management/server/testdata/extended-store.sql
2024-11-26 15:49:31 +03:00
bcmmbaga
72bfc9d07e Merge branch 'dns-get-account-refactoring' into nameserver-get-account-refactoring 2024-11-25 19:20:53 +03:00
bcmmbaga
79822cdc15 Merge branch 'policy-get-account-refactoring' into dns-get-account-refactoring 2024-11-25 19:17:38 +03:00
bcmmbaga
bdb2a76eae Merge branch 'main' into policy-get-account-refactoring
# Conflicts:
#	management/server/policy.go
#	management/server/posture_checks_test.go
#	management/server/sql_store.go
#	management/server/sql_store_test.go
#	management/server/status/error.go
#	management/server/store.go
#	management/server/testdata/extended-store.sql
2024-11-25 19:03:55 +03:00
bcmmbaga
82746d93ee Use UTC time in test
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-21 17:15:07 +03:00
bcmmbaga
0ee56e14d9 fix lint
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-19 10:47:26 +03:00
bcmmbaga
20fc8e879e fix tests
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-19 00:54:07 +03:00
bcmmbaga
b60e2c3261 prevent duplicate rules during updates
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-18 22:48:38 +03:00
bcmmbaga
df98c67ac8 prevent changing ruleID when not empty
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-18 18:46:52 +03:00
bcmmbaga
ec6438e643 Use update strength and simplify check
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-18 17:12:13 +03:00
bcmmbaga
6dd56e3328 Merge branch 'posturechecks-get-account-refactoring' into policy-get-account-refactoring 2024-11-18 16:58:04 +03:00
bcmmbaga
48edfa601f add tests
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-18 16:43:19 +03:00
bcmmbaga
a2a49bdd47 fix peer fields updated after save
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-18 16:43:09 +03:00
bcmmbaga
a2fb274b86 remove duplicate store method
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-18 15:09:30 +03:00
bcmmbaga
a61e9da3e9 run peer ops in transaction
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-18 15:06:25 +03:00
bcmmbaga
d4c712493a Merge branch 'groups-get-account-refactoring' into posturechecks-get-account-refactoring 2024-11-15 20:52:59 +03:00
bcmmbaga
1ff8f616a8 Merge branch 'main' into groups-get-account-refactoring 2024-11-15 20:52:37 +03:00
bcmmbaga
51c1ec283c Add locks and remove log
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-15 19:34:57 +03:00
bcmmbaga
4ef3890bf7 Fix typo
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-15 17:48:00 +03:00
bcmmbaga
92b9e11d3f Merge branch 'main' into groups-get-account-refactoring
# Conflicts:
#	management/server/group.go
2024-11-15 13:34:59 +03:00
bcmmbaga
f6f7260897 Fix tests
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-14 19:34:05 +03:00
bcmmbaga
c557c98390 Refactor peer to use store methods
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-14 19:33:57 +03:00
bcmmbaga
7d849a92c0 Refactor peer handlers
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-14 19:32:34 +03:00
bcmmbaga
f5e7449d01 Add lock for peer store methods
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-14 19:24:51 +03:00
bcmmbaga
8420a52563 Refactor ephemeral peers
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-14 13:04:49 +03:00
bcmmbaga
6315644065 Add peer store methods
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-14 13:04:36 +03:00
bcmmbaga
ef55b9eccc Add tests
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-13 20:41:41 +03:00
bcmmbaga
218345e0ff Refactor name server groups to use store methods
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-13 20:41:30 +03:00
bcmmbaga
a4d905ffe7 Fix tests
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-13 16:56:22 +03:00
bcmmbaga
ed047ec9dd Add account locking and merge group deletion methods
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-13 16:16:30 +03:00
bcmmbaga
4b943c34b7 Add tests
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-13 13:16:32 +03:00
bcmmbaga
560190519d Refactor dns settings to use store methods
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-13 13:15:47 +03:00
bcmmbaga
9bc8e6e29e Merge branch 'posturechecks-get-account-refactoring' into policy-get-account-refactoring 2024-11-12 23:53:46 +03:00
bcmmbaga
9872bee41d Refactor anyGroupHasPeers to retrieve all groups once
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-12 23:53:29 +03:00
bcmmbaga
3a915decd7 Add policy tests
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-12 20:15:47 +03:00
bcmmbaga
50e6389a1d Merge branch 'posturechecks-get-account-refactoring' into policy-get-account-refactoring 2024-11-12 19:06:27 +03:00
bcmmbaga
bbaee18cd5 Fix typo
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-12 19:05:57 +03:00
bcmmbaga
32d1b2d602 Retrieve policy groups and posture checks once for validation
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-12 18:53:10 +03:00
bcmmbaga
2a59f04540 Merge branch 'posturechecks-get-account-refactoring' into policy-get-account-refactoring 2024-11-12 17:16:52 +03:00
bcmmbaga
446de5e2bc Merge branch 'groups-get-account-refactoring' into posturechecks-get-account-refactoring 2024-11-12 17:15:55 +03:00
bcmmbaga
147971fdfe Merge branch 'groups-get-account-refactoring' into policy-get-account-refactoring 2024-11-12 17:15:16 +03:00
bcmmbaga
ed259a6a03 Merge branch 'main' into groups-get-account-refactoring
# Conflicts:
#	management/server/account.go
#	management/server/status/error.go
2024-11-12 17:14:45 +03:00
bcmmbaga
a3abc211b3 Add tests
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-12 17:11:56 +03:00
bcmmbaga
00023bf110 Merge branch 'groups-get-account-refactoring' into posturechecks-get-account-refactoring 2024-11-12 15:55:34 +03:00
bcmmbaga
2806d73161 Add tests
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-12 13:38:34 +03:00
bcmmbaga
2d7f08c609 Fix tests
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-12 11:18:16 +03:00
bcmmbaga
0c0fd380bd Refactor policy get and save account to use store methods
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-12 11:17:16 +03:00
bcmmbaga
ffce48ca5f Merge branch 'groups-get-account-refactoring' into policy-get-account-refactoring 2024-11-11 23:08:34 +03:00
bcmmbaga
d23b5c892b Retrieve modified peers once for group events
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-11 22:58:22 +03:00
bcmmbaga
113c21b0e1 Change setup key log level to debug for missing group
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-11 22:57:24 +03:00
bcmmbaga
ab00c41dad fix sonar
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-11 22:38:24 +03:00
bcmmbaga
664d1388aa fix merge
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-11 22:29:59 +03:00
bcmmbaga
010a8bfdc1 Merge branch 'main' into groups-get-account-refactoring
# Conflicts:
#	management/server/group.go
#	management/server/group/group.go
#	management/server/setupkey.go
#	management/server/sql_store.go
#	management/server/status/error.go
#	management/server/store.go
2024-11-11 21:10:02 +03:00
bcmmbaga
601d429d82 fix tests
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-11 16:26:12 +03:00
bcmmbaga
d54b6967ce fix refactor
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-11 12:38:34 +03:00
bcmmbaga
174e07fefd Refactor posture checks to remove get and save account
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-11 12:37:19 +03:00
bcmmbaga
871500c5cc fix merge
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-09 01:52:09 +03:00
bcmmbaga
cc04aef7b4 Merge branch 'setupkey-get-account-refactoring' into groups-get-account-refactoring 2024-11-09 01:50:10 +03:00
bcmmbaga
3ed8b9cee9 fix missing group removed from setup key activity
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-09 01:48:28 +03:00
bcmmbaga
bdeb95c58c Run groups ops in transaction
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-09 01:17:01 +03:00
bcmmbaga
6dc185e141 Preserve store engine in SqlStore transactions
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-09 01:16:03 +03:00
bcmmbaga
7100be83cd Add AddPeer and RemovePeer methods to Group struct
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-09 01:14:30 +03:00
bcmmbaga
d58cf50127 Merge branch 'setupkey-get-account-refactoring' into groups-get-account-refactoring
# Conflicts:
#	management/server/sql_store.go
2024-11-08 19:48:13 +03:00
bcmmbaga
40af1a50e3 Merge branch 'feature/get-account-refactoring' into setupkey-get-account-refactoring
# Conflicts:
#	management/server/sql_store.go
2024-11-08 19:17:28 +03:00
bcmmbaga
ac05f69131 fix tests
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-08 18:58:19 +03:00
bcmmbaga
8126d95316 refactor GetGroupByID and add NewGroupNotFoundError
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-08 18:58:04 +03:00
bcmmbaga
0a70e4c5d4 Refactor groups to use store methods
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-08 18:39:36 +03:00
bcmmbaga
106fc75936 refactor account peers update
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-08 18:38:32 +03:00
bcmmbaga
f8b5eedd38 add account lock and return auto groups map on validation
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-08 10:14:13 +03:00
bcmmbaga
931521d505 get only required groups for auto-group validation
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-08 00:59:37 +03:00
bcmmbaga
1a5f3c653c add check for regular user
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-08 00:37:47 +03:00
bcmmbaga
78044c226d add lock to get account groups
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-08 00:32:14 +03:00
bcmmbaga
389c9619af Refactor setup key handling to use store methods
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
2024-11-08 00:31:41 +03:00
19 changed files with 612 additions and 616 deletions

View File

@@ -24,7 +24,7 @@ jobs:
copyback: false
release: "14.1"
prepare: |
pkg install -y go pkgconf xorg
pkg install -y go
# -x - to print all executed commands
# -e - to faile on first error

View File

@@ -255,10 +255,6 @@ func (w *WorkerICE) closeAgent(cancel context.CancelFunc) {
defer w.muxAgent.Unlock()
cancel()
if w.agent == nil {
return
}
if err := w.agent.Close(); err != nil {
w.log.Warnf("failed to close ICE agent: %s", err)
}

View File

@@ -1,4 +1,4 @@
//go:build !(linux && 386)
//go:build !(linux && 386) && !freebsd
package main
@@ -876,7 +876,7 @@ func openURL(url string) error {
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
case "linux", "freebsd":
case "linux":
err = exec.Command("xdg-open", url).Start()
default:
err = fmt.Errorf("unsupported platform")

View File

@@ -1,4 +1,4 @@
//go:build freebsd || openbsd || netbsd || dragonfly
//go:build darwin
package main
@@ -9,22 +9,18 @@ import (
log "github.com/sirupsen/logrus"
)
const defaultFontPath = "/Library/Fonts/Arial Unicode.ttf"
func (s *serviceClient) setDefaultFonts() {
paths := []string{
"/usr/local/share/fonts/TTF/DejaVuSans.ttf",
"/usr/local/share/fonts/dejavu/DejaVuSans.ttf",
"/usr/local/share/noto/NotoSans-Regular.ttf",
"/usr/local/share/fonts/noto/NotoSans-Regular.ttf",
"/usr/local/share/fonts/liberation-fonts-ttf/LiberationSans-Regular.ttf",
// TODO: add other bsd paths
if runtime.GOOS != "darwin" {
return
}
for _, fontPath := range paths {
if _, err := os.Stat(fontPath); err == nil {
os.Setenv("FYNE_FONT", fontPath)
log.Debugf("Using font: %s", fontPath)
return
}
if _, err := os.Stat(defaultFontPath); err != nil {
log.Errorf("Failed to find default font file: %v", err)
return
}
log.Errorf("Failed to find any suitable font files for %s", runtime.GOOS)
os.Setenv("FYNE_FONT", defaultFontPath)
}

View File

@@ -1,18 +0,0 @@
package main
import (
"os"
log "github.com/sirupsen/logrus"
)
const defaultFontPath = "/Library/Fonts/Arial Unicode.ttf"
func (s *serviceClient) setDefaultFonts() {
if _, err := os.Stat(defaultFontPath); err != nil {
log.Errorf("Failed to find default font file: %v", err)
return
}
os.Setenv("FYNE_FONT", defaultFontPath)
}

View File

@@ -1,4 +1,4 @@
//go:build !(linux && 386)
//go:build !(linux && 386) && !freebsd
package main

View File

@@ -256,10 +256,12 @@ func TestClient_Sync(t *testing.T) {
t.Fatal(err)
}
ch := make(chan *mgmtProto.SyncResponse, 1)
ch := make(chan *mgmtProto.SyncResponse, 5)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go func() {
err = client.Sync(context.Background(), info, func(msg *mgmtProto.SyncResponse) error {
err = client.Sync(ctx, info, func(msg *mgmtProto.SyncResponse) error {
ch <- msg
return nil
})
@@ -289,6 +291,7 @@ func TestClient_Sync(t *testing.T) {
case <-time.After(3 * time.Second):
t.Error("timeout waiting for test to finish")
}
}
func Test_SystemMetaDataFromClient(t *testing.T) {

View File

@@ -473,12 +473,7 @@ func (am *DefaultAccountManager) peerLoginExpirationJob(ctx context.Context, acc
return peerSchedulerRetryInterval, true
}
var peerIDs []string
for _, peer := range expiredPeers {
peerIDs = append(peerIDs, peer.ID)
}
log.WithContext(ctx).Debugf("discovered %d peers to expire for account %s", len(peerIDs), accountID)
log.WithContext(ctx).Debugf("discovered %d peers to expire for account %s", len(expiredPeers), accountID)
if err := am.expireAndUpdatePeers(ctx, accountID, expiredPeers); err != nil {
log.WithContext(ctx).Errorf("failed updating account peers while expiring peers for account %s", accountID)
@@ -490,6 +485,9 @@ func (am *DefaultAccountManager) peerLoginExpirationJob(ctx context.Context, acc
}
func (am *DefaultAccountManager) checkAndSchedulePeerLoginExpiration(ctx context.Context, accountID string) {
if am.peerLoginExpiry.IsJobRunning(accountID) {
return
}
am.peerLoginExpiry.Cancel(ctx, []string{accountID})
if nextRun, ok := am.getNextPeerExpiration(ctx, accountID); ok {
go am.peerLoginExpiry.Schedule(ctx, nextRun, accountID, am.peerLoginExpirationJob(ctx, accountID))
@@ -526,6 +524,9 @@ func (am *DefaultAccountManager) peerInactivityExpirationJob(ctx context.Context
// checkAndSchedulePeerInactivityExpiration periodically checks for inactive peers to end their sessions
func (am *DefaultAccountManager) checkAndSchedulePeerInactivityExpiration(ctx context.Context, accountID string) {
if am.peerInactivityExpiry.IsJobRunning(accountID) {
return
}
am.peerInactivityExpiry.Cancel(ctx, []string{accountID})
if nextRun, ok := am.getNextInactivePeerExpiration(ctx, accountID); ok {
go am.peerInactivityExpiry.Schedule(ctx, nextRun, accountID, am.peerInactivityExpirationJob(ctx, accountID))

View File

@@ -89,17 +89,17 @@ func (am *DefaultAccountManager) GetValidatedPeers(ctx context.Context, accountI
}
peers, err = transaction.GetAccountPeers(ctx, store.LockingStrengthShare, accountID)
if err != nil {
return err
}
settings, err = transaction.GetAccountSettings(ctx, store.LockingStrengthShare, accountID)
return err
})
if err != nil {
return nil, err
}
settings, err = am.Store.GetAccountSettings(ctx, store.LockingStrengthShare, accountID)
if err != nil {
return nil, err
}
return am.integratedPeerValidator.GetValidatedPeers(accountID, groups, peers, settings.Extra)
}

View File

@@ -254,13 +254,13 @@ func Test_SyncProtocol(t *testing.T) {
}
// expired peers come separately.
if len(networkMap.GetOfflinePeers()) != 1 {
t.Fatal("expecting SyncResponse to have NetworkMap with 1 offline peer")
if len(networkMap.GetOfflinePeers()) != 2 {
t.Fatal("expecting SyncResponse to have NetworkMap with 2 offline peer")
}
expiredPeerPubKey := "RlSy2vzoG2HyMBTUImXOiVhCBiiBa5qD5xzMxkiFDW4="
if networkMap.GetOfflinePeers()[0].WgPubKey != expiredPeerPubKey {
t.Fatalf("expecting SyncResponse to have NetworkMap with 1 offline peer with a key %s", expiredPeerPubKey)
if !(networkMap.GetOfflinePeers()[0].WgPubKey == expiredPeerPubKey || networkMap.GetOfflinePeers()[1].WgPubKey == expiredPeerPubKey) {
t.Fatalf("expecting SyncResponse to have NetworkMap with 2 offline peer with a key %s", expiredPeerPubKey)
}
if networkMap.GetPeerConfig() == nil {

View File

@@ -1,13 +1,13 @@
package server_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"testing"
)
func TestManagement(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Management Service Suite")
}
// import (
// . "github.com/onsi/ginkgo"
// . "github.com/onsi/gomega"
//
// "testing"
// )
//
// func TestManagement(t *testing.T) {
// RegisterFailHandler(Fail)
// RunSpecs(t, "Management Service Suite")
// }

File diff suppressed because it is too large Load Diff

View File

@@ -126,8 +126,8 @@ func (am *DefaultAccountManager) MarkPeerConnected(ctx context.Context, peerPubK
}()
var peer *nbpeer.Peer
var settings *types.Settings
var expired bool
var settings *types.Settings
var err error
err = am.Store.ExecuteInTransaction(ctx, func(transaction store.Store) error {
@@ -136,6 +136,11 @@ func (am *DefaultAccountManager) MarkPeerConnected(ctx context.Context, peerPubK
return err
}
settings, err = transaction.GetAccountSettings(ctx, store.LockingStrengthShare, accountID)
if err != nil {
return err
}
expired, err = updatePeerStatusAndLocation(ctx, am.geo, transaction, peer, connected, realIP, accountID)
return err
})
@@ -144,11 +149,6 @@ func (am *DefaultAccountManager) MarkPeerConnected(ctx context.Context, peerPubK
}
if peer.AddedWithSSOLogin() {
settings, err = am.Store.GetAccountSettings(ctx, store.LockingStrengthShare, accountID)
if err != nil {
return err
}
if peer.LoginExpirationEnabled && settings.PeerLoginExpirationEnabled {
am.checkAndSchedulePeerLoginExpiration(ctx, accountID)
}
@@ -676,11 +676,6 @@ func (am *DefaultAccountManager) SyncPeer(ctx context.Context, sync PeerSync, ac
var err error
var postureChecks []*posture.Checks
settings, err := am.Store.GetAccountSettings(ctx, store.LockingStrengthShare, accountID)
if err != nil {
return nil, nil, nil, err
}
err = am.Store.ExecuteInTransaction(ctx, func(transaction store.Store) error {
peer, err = transaction.GetPeerByPeerPubKey(ctx, store.LockingStrengthUpdate, sync.WireGuardPubKey)
if err != nil {
@@ -698,6 +693,11 @@ func (am *DefaultAccountManager) SyncPeer(ctx context.Context, sync PeerSync, ac
}
}
settings, err := transaction.GetAccountSettings(ctx, store.LockingStrengthShare, accountID)
if err != nil {
return err
}
if peerLoginExpired(ctx, peer, settings) {
return status.NewPeerLoginExpiredError()
}
@@ -790,17 +790,16 @@ func (am *DefaultAccountManager) LoginPeer(ctx context.Context, login PeerLogin)
var isPeerUpdated bool
var postureChecks []*posture.Checks
settings, err := am.Store.GetAccountSettings(ctx, store.LockingStrengthShare, accountID)
if err != nil {
return nil, nil, nil, err
}
err = am.Store.ExecuteInTransaction(ctx, func(transaction store.Store) error {
peer, err = transaction.GetPeerByPeerPubKey(ctx, store.LockingStrengthUpdate, login.WireGuardPubKey)
if err != nil {
return err
}
settings, err := transaction.GetAccountSettings(ctx, store.LockingStrengthShare, accountID)
if err != nil {
return err
}
// this flag prevents unnecessary calls to the persistent store.
shouldStorePeer := false
@@ -1228,8 +1227,7 @@ func (am *DefaultAccountManager) getNextPeerExpiration(ctx context.Context, acco
var nextExpiry *time.Duration
for _, peer := range peersWithExpiry {
// consider only connected peers because others will require login on connecting to the management server
if peer.Status.LoginExpired || !peer.Status.Connected {
if peer.Status.LoginExpired {
continue
}
_, duration := peer.LoginExpired(settings.PeerLoginExpiration)

View File

@@ -12,6 +12,7 @@ import (
type Scheduler interface {
Cancel(ctx context.Context, IDs []string)
Schedule(ctx context.Context, in time.Duration, ID string, job func() (nextRunIn time.Duration, reschedule bool))
IsJobRunning(ID string) bool
}
// MockScheduler is a mock implementation of Scheduler
@@ -38,6 +39,10 @@ func (mock *MockScheduler) Schedule(ctx context.Context, in time.Duration, ID st
log.WithContext(ctx).Errorf("MockScheduler doesn't have Schedule function defined")
}
func (mock *MockScheduler) IsJobRunning(_ string) bool {
return false
}
// DefaultScheduler is a generic structure that allows to schedule jobs (functions) to run in the future and cancel them.
type DefaultScheduler struct {
// jobs map holds cancellation channels indexed by the job ID
@@ -124,3 +129,7 @@ func (wm *DefaultScheduler) Schedule(ctx context.Context, in time.Duration, ID s
}()
}
func (wm *DefaultScheduler) IsJobRunning(ID string) bool {
return wm.jobs[ID] != nil
}

View File

@@ -1307,7 +1307,7 @@ func (s *SqlStore) GetPeersByIDs(ctx context.Context, lockStrength LockingStreng
func (s *SqlStore) GetAccountPeersWithExpiration(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*nbpeer.Peer, error) {
var peers []*nbpeer.Peer
result := s.db.Clauses(clause.Locking{Strength: string(lockStrength)}).
Where("login_expiration_enabled = ? AND user_id IS NOT NULL AND user_id != ''", true).
Where("login_expiration_enabled = ? AND peer_status_login_expired = ? AND user_id IS NOT NULL AND user_id != ''", true, false).
Find(&peers, accountIDCondition, accountID)
if err := result.Error; err != nil {
log.WithContext(ctx).Errorf("failed to get peers with expiration from the store: %s", result.Error)

View File

@@ -14,12 +14,13 @@ import (
"time"
"github.com/google/uuid"
"github.com/netbirdio/netbird/management/server/util"
"github.com/rs/xid"
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/netbirdio/netbird/management/server/util"
nbdns "github.com/netbirdio/netbird/dns"
resourceTypes "github.com/netbirdio/netbird/management/server/networks/resources/types"
routerTypes "github.com/netbirdio/netbird/management/server/networks/routers/types"
@@ -2669,7 +2670,7 @@ func TestSqlStore_GetAccountPeers(t *testing.T) {
{
name: "should retrieve peers for an existing account ID",
accountID: "bf1c8084-ba50-4ce7-9439-34653001fc3b",
expectedCount: 4,
expectedCount: 5,
},
{
name: "should return no peers for a non-existing account ID",
@@ -2809,7 +2810,7 @@ func TestSqlStore_GetUserPeers(t *testing.T) {
name: "should retrieve peers for another valid account ID and user ID",
accountID: "bf1c8084-ba50-4ce7-9439-34653001fc3b",
userID: "edafee4e-63fb-11ec-90d6-0242ac120003",
expectedCount: 2,
expectedCount: 3,
},
{
name: "should return no peers for existing account ID with empty user ID",

View File

@@ -21,6 +21,7 @@ var newSqlite = func(b *testing.B) Store {
}
func BenchmarkTest_StoreWrite(b *testing.B) {
b.Skipf("skipping benchmark")
cases := []benchCase{
{name: "SqliteStore_Write", storeFn: newSqlite, size: 100},
{name: "SqliteStore_Write", storeFn: newSqlite, size: 500},
@@ -50,6 +51,7 @@ func BenchmarkTest_StoreWrite(b *testing.B) {
}
func BenchmarkTest_StoreRead(b *testing.B) {
b.Skipf("skipping benchmark")
cases := []benchCase{
{name: "SqliteStore_Read", storeFn: newSqlite, size: 100},
{name: "SqliteStore_Read", storeFn: newSqlite, size: 500},

View File

@@ -29,6 +29,7 @@ INSERT INTO accounts VALUES('bf1c8084-ba50-4ce7-9439-34653001fc3b','','2024-10-0
INSERT INTO setup_keys VALUES('','bf1c8084-ba50-4ce7-9439-34653001fc3b','A2C8E62B-38F5-4553-B31E-DD66C696CEBB','Default key','reusable','2021-08-19 20:46:20.005936822+02:00','2321-09-18 20:46:20.005936822+02:00','2021-08-19 20:46:20.005936822+02:00',0,0,NULL,'[]',0,0);
INSERT INTO peers VALUES('cfvprsrlo1hqoo49ohog','bf1c8084-ba50-4ce7-9439-34653001fc3b','5rvhvriKJZ3S9oxYToVj5TzDM9u9y8cxg7htIMWlYAg=','72546A29-6BC8-4311-BCFC-9CDBF33F1A48','"100.64.114.31"','f2a34f6a4731','linux','Linux','11','unknown','Debian GNU/Linux','','0.12.0','','',NULL,'','','','{"Cloud":"","Platform":""}',NULL,'f2a34f6a4731','f2a34f6a4731','2023-03-02 09:21:02.189035775+01:00',0,0,0,'','ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILzUUSYG/LGnV8zarb2SGN+tib/PZ+M7cL4WtTzUrTpk',0,1,0,'2023-03-01 19:48:19.817799698+01:00','2024-10-02 17:00:32.527947+02:00',0,'""','','',0);
INSERT INTO peers VALUES('cg05lnblo1hkg2j514p0','bf1c8084-ba50-4ce7-9439-34653001fc3b','RlSy2vzoG2HyMBTUImXOiVhCBiiBa5qD5xzMxkiFDW4=','','"100.64.39.54"','expiredhost','linux','Linux','22.04','x86_64','Ubuntu','','development','','',NULL,'','','','{"Cloud":"","Platform":""}',NULL,'expiredhost','expiredhost','2023-03-02 09:19:57.276717255+01:00',0,1,0,'edafee4e-63fb-11ec-90d6-0242ac120003','ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMbK5ZXJsGOOWoBT4OmkPtgdPZe2Q7bDuS/zjn2CZxhK',0,1,0,'2023-03-02 09:14:21.791679181+01:00','2024-10-02 17:00:32.527947+02:00',0,'""','','',0);
INSERT INTO peers VALUES('cg05lnblo1hkg2j514p1','bf1c8084-ba50-4ce7-9439-34653001fc3b','RlSy2vzoG2HyMBTUImXOiVhCBiiBa5qD5xzMxkiFDW5=','','"100.64.39.54"','tobeexpiredhost','linux','Linux','22.04','x86_64','Ubuntu','','development','','',NULL,'','','','{"Cloud":"","Platform":""}',NULL,'tobeexpiredhost','tobeexpiredhost','2023-03-02 09:19:57.276717255+01:00',0,0,0,'edafee4e-63fb-11ec-90d6-0242ac120003','ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMbK5ZXJsGOOWoBT4OmkPtgdPZe2Q7bDuS/zjn2CZxhK',0,1,0,'2023-03-02 09:14:21.791679181+01:00','2024-10-02 17:00:32.527947+02:00',0,'""','','',0);
INSERT INTO peers VALUES('cg3161rlo1hs9cq94gdg','bf1c8084-ba50-4ce7-9439-34653001fc3b','mVABSKj28gv+JRsf7e0NEGKgSOGTfU/nPB2cpuG56HU=','','"100.64.117.96"','testhost','linux','Linux','22.04','x86_64','Ubuntu','','development','','',NULL,'','','','{"Cloud":"","Platform":""}',NULL,'testhost','testhost','2023-03-06 18:21:27.252010027+01:00',0,0,0,'edafee4e-63fb-11ec-90d6-0242ac120003','ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINWvvUkFFcrj48CWTkNUb/do/n52i1L5dH4DhGu+4ZuM',0,0,0,'2023-03-07 09:02:47.442857106+01:00','2024-10-02 17:00:32.527947+02:00',0,'""','','',0);
INSERT INTO peers VALUES('csrnkiq7qv9d8aitqd50','bf1c8084-ba50-4ce7-9439-34653001fc3b','mVABSKj28gv+JRsf7e0NEGKgSOGTfU/nPB2cpuG56HU=','','"100.64.117.96"','testhost','linux','Linux','22.04','x86_64','Ubuntu','','development','','',NULL,'','','','{"Cloud":"","Platform":""}',NULL,'testhost','testhost','2023-03-06 18:21:27.252010027+01:00',0,0,0,'f4f6d672-63fb-11ec-90d6-0242ac120003','ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINWvvUkFFcrj48CWTkNUb/do/n52i1L5dH4DhGu+4ZuM',0,0,1,'2023-03-07 09:02:47.442857106+01:00','2024-10-02 17:00:32.527947+02:00',0,'""','','',0);
INSERT INTO users VALUES('f4f6d672-63fb-11ec-90d6-0242ac120003','bf1c8084-ba50-4ce7-9439-34653001fc3b','user',0,0,'','[]',0,NULL,'2024-10-02 17:00:32.528196+02:00','api',0,'');

View File

@@ -71,7 +71,7 @@ func TestTimeBasedAuthSecretsManager_SetupRefresh(t *testing.T) {
ttl := util.Duration{Duration: 2 * time.Second}
secret := "some_secret"
peersManager := NewPeersUpdateManager(nil)
peer := "some_peer"
peer := "some_peer_SetupRefresh"
updateChannel := peersManager.CreateChannel(context.Background(), peer)
rc := &Relay{
@@ -169,7 +169,7 @@ func TestTimeBasedAuthSecretsManager_CancelRefresh(t *testing.T) {
ttl := util.Duration{Duration: time.Hour}
secret := "some_secret"
peersManager := NewPeersUpdateManager(nil)
peer := "some_peer"
peer := "some_peer_CancelRefresh"
rc := &Relay{
Addresses: []string{"localhost:0"},