| index 31348ab3c..f92f96b22 100644 |
| --- a/internal/host/egress_nudge.go |
| +++ b/internal/host/egress_nudge.go |
| @@ -11,7 +11,8 @@ import ( |
| // egressNudgeLoop tells root about an egress allow change as soon as the |
| // registry holds it (#328): every edgesFileWatchInterval it reads the |
| // registry's SnapshotFingerprint and, when that moved, lists the rows and |
| -// sends POST /egress?host= for each host whose egress_allow changed. |
| +// sends POST /egress?host= for each host whose egress_allow or |
| +// policy_expires_at changed. |
| // |
| // It watches SnapshotFingerprint, not Fingerprint: the policy columns |
| // (egress_allow, policy_expires_at) are kept out of Fingerprint, so a grant |
| @@ -52,11 +53,11 @@ type egressNudger struct { |
| } |
| logf func(format string, args ...any) |
| |
| - // nudged is each host's egress_allow as root last heard of it (or, |
| - // for a host first seen with none, as first seen). failing holds the |
| - // hosts whose last call failed: each is sent again on the next pass, |
| - // whatever its column holds by then. |
| - nudged map[string]string |
| + // nudged is each host's policy columns as root last heard of them |
| + // (or, for a host first seen with no allow, as first seen). failing |
| + // holds the hosts whose last call failed: each is sent again on the |
| + // next pass, whatever its columns hold by then. |
| + nudged map[string]egressNudgeKey |
| failing map[string]bool |
| fp string |
| haveFP bool |
| @@ -67,7 +68,7 @@ type egressNudger struct { |
| func newEgressNudger(c interface { |
| Egress(context.Context, string) error |
| }) *egressNudger { |
| - return &egressNudger{c: c, logf: log.Printf, nudged: map[string]string{}, failing: map[string]bool{}} |
| + return &egressNudger{c: c, logf: log.Printf, nudged: map[string]egressNudgeKey{}, failing: map[string]bool{}} |
| } |
| |
| // tick is one beat of the loop: a pass when the snapshot fingerprint moved |
| @@ -93,10 +94,16 @@ func (n *egressNudger) tick(ctx context.Context, reg egressNudgeRegistry) { |
| n.pass(ctx, rows) |
| } |
| |
| -// pass sends POST /egress for each row whose egress_allow differs from |
| -// what root last heard. A host first seen with an allow counts as changed; |
| -// one first seen with none does not. A failed call is logged (throttled) |
| -// and sent again on the next pass. Hosts no longer listed are forgotten. |
| +// egressNudgeKey is what a nudge is keyed on: the allow, and its expiry, |
| +// so a re-sign that re-opens a host root closed as expired lands at once. |
| +type egressNudgeKey struct{ allow, expires string } |
| + |
| +// pass sends POST /egress for each row whose egress_allow or |
| +// policy_expires_at differs from what root last heard. A host first seen |
| +// with an allow counts as changed; one first seen with none does not, and |
| +// nor does an expiry change with no allow before or after (root's desired |
| +// list is empty either way). A failed call is logged (throttled) and sent |
| +// again on the next pass. Hosts no longer listed are forgotten. |
| func (n *egressNudger) pass(ctx context.Context, rows []registry.Route) { |
| listed := make(map[string]bool, len(rows)) |
| failed := false |
| @@ -108,13 +115,14 @@ func (n *egressNudger) pass(ctx context.Context, rows []registry.Route) { |
| continue |
| } |
| listed[rt.Host] = true |
| + cur := egressNudgeKey{rt.EgressAllow, rt.PolicyExpiresAt} |
| prev, known := n.nudged[rt.Host] |
| switch { |
| case n.failing[rt.Host]: |
| - case !known && rt.EgressAllow == "": |
| - n.nudged[rt.Host] = "" |
| + case known && prev == cur: |
| continue |
| - case known && prev == rt.EgressAllow: |
| + case cur.allow == "" && (!known || prev.allow == ""): |
| + n.nudged[rt.Host] = cur |
| continue |
| } |
| if err := n.c.Egress(ctx, rt.Host); err != nil { |
| @@ -127,7 +135,7 @@ func (n *egressNudger) pass(ctx context.Context, rows []registry.Route) { |
| continue |
| } |
| delete(n.failing, rt.Host) |
| - n.nudged[rt.Host] = rt.EgressAllow |
| + n.nudged[rt.Host] = cur |
| } |
| for h := range n.nudged { |
| if !listed[h] { |