File tree 4 files changed +34
-3
lines changed
4 files changed +34
-3
lines changed Original file line number Diff line number Diff line change 6
6
7
7
- Relax username validation to allow emails
8
8
[ #2364 ] ( https://github.com/juanfont/headscale/pull/2364 )
9
+ - Remove invalid routes and add stronger constraints for routes to avoid API panic
10
+ [ #2371 ] ( https://github.com/juanfont/headscale/pull/2371 )
9
11
10
12
## 0.24.0 (2025-01-17)
11
13
Original file line number Diff line number Diff line change @@ -251,10 +251,15 @@ func routesToPtables(routes []*v1.Route) pterm.TableData {
251
251
isPrimaryStr = strconv .FormatBool (route .GetIsPrimary ())
252
252
}
253
253
254
+ var nodeName string
255
+ if route .GetNode () != nil {
256
+ nodeName = route .GetNode ().GetGivenName ()
257
+ }
258
+
254
259
tableData = append (tableData ,
255
260
[]string {
256
261
strconv .FormatUint (route .GetId (), Base10 ),
257
- route . GetNode (). GetGivenName () ,
262
+ nodeName ,
258
263
route .GetPrefix (),
259
264
strconv .FormatBool (route .GetAdvertised ()),
260
265
strconv .FormatBool (route .GetEnabled ()),
Original file line number Diff line number Diff line change @@ -521,6 +521,27 @@ func NewHeadscaleDatabase(
521
521
},
522
522
Rollback : func (db * gorm.DB ) error { return nil },
523
523
},
524
+ {
525
+ // Add a constraint to routes ensuring they cannot exist without a node.
526
+ ID : "202501221827" ,
527
+ Migrate : func (tx * gorm.DB ) error {
528
+ // Remove any invalid routes associated with a node that does not exist.
529
+ if tx .Migrator ().HasTable (& types.Route {}) && tx .Migrator ().HasTable (& types.Node {}) {
530
+ err := tx .Exec ("delete from routes where node_id not in (select id from nodes)" ).Error
531
+ if err != nil {
532
+ return err
533
+ }
534
+ }
535
+
536
+ err := tx .AutoMigrate (& types.Route {})
537
+ if err != nil {
538
+ return err
539
+ }
540
+
541
+ return nil
542
+ },
543
+ Rollback : func (db * gorm.DB ) error { return nil },
544
+ },
524
545
},
525
546
)
526
547
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ import (
13
13
type Route struct {
14
14
gorm.Model
15
15
16
- NodeID uint64
16
+ NodeID uint64 `gorm:"not null"`
17
17
Node * Node
18
18
19
19
// TODO(kradalby): change this custom type to netip.Prefix
@@ -79,7 +79,6 @@ func (rs Routes) Proto() []*v1.Route {
79
79
for _ , route := range rs {
80
80
protoRoute := v1.Route {
81
81
Id : uint64 (route .ID ),
82
- Node : route .Node .Proto (),
83
82
Prefix : route .Prefix .String (),
84
83
Advertised : route .Advertised ,
85
84
Enabled : route .Enabled ,
@@ -88,6 +87,10 @@ func (rs Routes) Proto() []*v1.Route {
88
87
UpdatedAt : timestamppb .New (route .UpdatedAt ),
89
88
}
90
89
90
+ if route .Node != nil {
91
+ protoRoute .Node = route .Node .Proto ()
92
+ }
93
+
91
94
if route .DeletedAt .Valid {
92
95
protoRoute .DeletedAt = timestamppb .New (route .DeletedAt .Time )
93
96
}
You can’t perform that action at this time.
0 commit comments