Skip to content

Commit

Permalink
fix: addresses review comments (fixup)
Browse files Browse the repository at this point in the history
  • Loading branch information
pallabpain committed Mar 7, 2024
1 parent 6099d3b commit d0b500b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
24 changes: 10 additions & 14 deletions hscontrol/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,16 @@ func (h *Headscale) Serve() error {
if err := h.loadACLPolicy(); err != nil {
log.Error().Err(err).Msg("failed to reload ACL policy")
}

if h.ACLPolicy != nil {
log.Info().
Msg("ACL policy successfully reloaded, notifying nodes of change")

ctx := types.NotifyCtx(context.Background(), "acl-sighup", "na")
h.nodeNotifier.NotifyAll(ctx, types.StateUpdate{
Type: types.StateFullUpdate,
})
}
default:
log.Info().
Str("signal", sig.String()).
Expand Down Expand Up @@ -933,10 +943,6 @@ func (h *Headscale) loadACLPolicy() error {
}

h.ACLPolicy = pol

log.Info().
Str("path", aclPath).
Msg("ACL policy successfully loaded, notifying nodes of change")
}
case types.ACLPolicyModeDB:
acl, err := h.db.GetACL()
Expand All @@ -955,22 +961,12 @@ func (h *Headscale) loadACLPolicy() error {
}

h.ACLPolicy = pol

log.Info().
Msg("ACL policy successfully reloaded, notifying nodes of change")
default:
log.Warn().
Str("mode", string(h.cfg.ACL.PolicyMode)).
Msg("Unknown ACL policy mode")
}

if h.ACLPolicy != nil {
ctx := types.NotifyCtx(context.Background(), "acl-sighup", "na")
h.nodeNotifier.NotifyAll(ctx, types.StateUpdate{
Type: types.StateFullUpdate,
})
}

return nil
}

Expand Down
5 changes: 3 additions & 2 deletions hscontrol/grpcv1.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,15 +691,16 @@ func (api headscaleV1APIServer) SetACL(
return nil, errors.Wrap(err, types.ErrInvalidACLPolicyFormat.Error())
}

api.h.ACLPolicy = a

resp, err := api.h.db.SetACL(&types.ACL{
Policy: polBytes,
})
if err != nil {
return nil, err
}

// Set the new policy in the ACLPolicy and notify all nodes.
api.h.ACLPolicy = a

ctx := types.NotifyCtx(context.Background(), "acl-update", "na")
api.h.nodeNotifier.NotifyAll(ctx, types.StateUpdate{
Type: types.StateFullUpdate,
Expand Down
6 changes: 3 additions & 3 deletions hscontrol/types/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ type ACL struct {
ID uint64 `gorm:"primary_key"`
Policy datatypes.JSON

CreatedAt *time.Time
Expiration *time.Time
LastSeen *time.Time
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt *time.Time
}

func (a *ACL) Proto() *v1.ACL {
Expand Down

0 comments on commit d0b500b

Please sign in to comment.