Revoke a removed node's certificate, and require --api-client with a mirror's mutual TLS
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
fe5b7f88f0
commit
9b61bbc983
16 files changed
+268
-32
No files matched your search
@@ -49,6 +49,9 @@ type Service struct {
|
||||
// requireIdentity refuses agents that present no certificate. It is off
|
||||
// only for the insecure development path.
|
||||
requireIdentity bool
|
||||
// revokedAt is when a node was removed, whose certificates issued before
|
||||
// then are refused; nil checks nothing.
|
||||
revokedAt func(ctx context.Context, nodeID string) (time.Time, error)
|
||||
|
||||
mu sync.RWMutex
|
||||
conns map[string]*conn
|
||||
@@ -137,6 +140,47 @@ func New(inv *inventory.Store, status StatusSink, requireIdentity bool, log *slo
|
||||
}
|
||||
}
|
||||
|
||||
// admit decides whether the peer on ctx may be nodeID.
|
||||
func (s *Service) admit(ctx context.Context, nodeID string) error {
|
||||
// The certificate decides who this is, not the message.
|
||||
//
|
||||
// Without this check an agent could register as any node in the fleet and
|
||||
// receive that node's shards — which is the same exposure the stream had
|
||||
// before TLS, just with encryption on top. mTLS is only worth having if the
|
||||
// identity it proves is the one actually used.
|
||||
if peer := peerFrom(ctx); peer.Verified {
|
||||
if peer.CommonName != nodeID {
|
||||
s.log.Warn("rejecting an agent claiming a node id its certificate does not authorize",
|
||||
"certificate_cn", peer.CommonName, "claimed", nodeID)
|
||||
return connect.NewError(connect.CodePermissionDenied,
|
||||
fmt.Errorf("certificate authorizes node %q, not %q", peer.CommonName, nodeID))
|
||||
}
|
||||
if s.revokedAt != nil {
|
||||
at, err := s.revokedAt(ctx, nodeID)
|
||||
if err != nil {
|
||||
// Unknown is not "not revoked": the agent retries.
|
||||
return connect.NewError(connect.CodeUnavailable, fmt.Errorf("checking revocation: %w", err))
|
||||
}
|
||||
if !at.IsZero() && !peer.IssuedAt.After(at) {
|
||||
s.log.Warn("rejecting a removed node's certificate", "node", nodeID,
|
||||
"issued", peer.IssuedAt, "removed", at)
|
||||
return connect.NewError(connect.CodePermissionDenied, fmt.Errorf(
|
||||
"node %q was removed from the cluster, and its certificate with it; onboard it again", nodeID))
|
||||
}
|
||||
}
|
||||
} else if s.requireIdentity {
|
||||
return connect.NewError(connect.CodeUnauthenticated,
|
||||
errors.New("no verified client certificate"))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetRevocations has agents refused whose certificate was issued before
|
||||
// their node was removed.
|
||||
func (s *Service) SetRevocations(f func(ctx context.Context, nodeID string) (time.Time, error)) {
|
||||
s.revokedAt = f
|
||||
}
|
||||
|
||||
// Handler returns the HTTP path and handler to mount.
|
||||
//
|
||||
// The handler is wrapped so the verified client identity reaches the stream:
|
||||
@@ -182,22 +226,8 @@ func (s *Service) Connect(
|
||||
return connect.NewError(connect.CodeInvalidArgument, errors.New("node_id is required"))
|
||||
}
|
||||
|
||||
// The certificate decides who this is, not the message.
|
||||
//
|
||||
// Without this check an agent could register as any node in the fleet and
|
||||
// receive that node's shards — which is the same exposure the stream had
|
||||
// before TLS, just with encryption on top. mTLS is only worth having if the
|
||||
// identity it proves is the one actually used.
|
||||
if peer := peerFrom(ctx); peer.Verified {
|
||||
if peer.CommonName != nodeID {
|
||||
s.log.Warn("rejecting an agent claiming a node id its certificate does not authorize",
|
||||
"certificate_cn", peer.CommonName, "claimed", nodeID)
|
||||
return connect.NewError(connect.CodePermissionDenied,
|
||||
fmt.Errorf("certificate authorizes node %q, not %q", peer.CommonName, nodeID))
|
||||
}
|
||||
} else if s.requireIdentity {
|
||||
return connect.NewError(connect.CodeUnauthenticated,
|
||||
errors.New("no verified client certificate"))
|
||||
if err := s.admit(ctx, nodeID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
node := NodeFromRegister(reg)
|
||||
|
||||
Reference in new issue
Block a user