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
@@ -52,6 +52,8 @@ var copyOrder = []string{
|
||||
"cluster_secrets",
|
||||
"node_engines",
|
||||
"control_planes",
|
||||
// Or a removed node's certificate would work again in the new store.
|
||||
"revoked_nodes",
|
||||
}
|
||||
|
||||
// notCopied are tables deliberately left behind.
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
-- Ported from the SQLite migration of the same number.
|
||||
-- Nodes removed from the cluster, and when. A certificate issued for one
|
||||
-- before that moment is refused when it connects: removing a node revokes
|
||||
-- the certificate it was given, and onboarding it again issues a new one.
|
||||
CREATE TABLE revoked_nodes (
|
||||
node_id TEXT PRIMARY KEY,
|
||||
revoked_at BIGINT NOT NULL
|
||||
);
|
||||
@@ -0,0 +1,7 @@
|
||||
-- Nodes removed from the cluster, and when. A certificate issued for one
|
||||
-- before that moment is refused when it connects: removing a node revokes
|
||||
-- the certificate it was given, and onboarding it again issues a new one.
|
||||
CREATE TABLE revoked_nodes (
|
||||
node_id TEXT PRIMARY KEY,
|
||||
revoked_at INTEGER NOT NULL
|
||||
);
|
||||
@@ -0,0 +1,29 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// RevokeNode records that a node was removed at a moment: every certificate
|
||||
// issued for it until then is refused from now on.
|
||||
func (s *DB) RevokeNode(ctx context.Context, nodeID string, at time.Time) error {
|
||||
_, err := s.db.ExecContext(ctx, `INSERT INTO revoked_nodes (node_id, revoked_at) VALUES (?, ?)
|
||||
ON CONFLICT (node_id) DO UPDATE SET revoked_at = excluded.revoked_at`, nodeID, millis(at))
|
||||
return err
|
||||
}
|
||||
|
||||
// NodeRevokedAt is when a node was last removed; zero if it never was.
|
||||
func (s *DB) NodeRevokedAt(ctx context.Context, nodeID string) (time.Time, error) {
|
||||
var at int64
|
||||
err := s.db.QueryRowContext(ctx, `SELECT revoked_at FROM revoked_nodes WHERE node_id = ?`, nodeID).Scan(&at)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return time.Time{}, nil
|
||||
}
|
||||
if err != nil {
|
||||
return time.Time{}, err
|
||||
}
|
||||
return fromMillis(at), nil
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestARemovedNodeIsRememberedWithItsLastRemoval(t *testing.T) {
|
||||
db := capacityStore(t)
|
||||
ctx := t.Context()
|
||||
if at, err := db.NodeRevokedAt(ctx, "gpu01"); err != nil || !at.IsZero() {
|
||||
t.Fatalf("never removed: %v, %v", at, err)
|
||||
}
|
||||
first := time.UnixMilli(1_700_000_000_000)
|
||||
if err := db.RevokeNode(ctx, "gpu01", first); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
second := first.Add(time.Hour)
|
||||
if err := db.RevokeNode(ctx, "gpu01", second); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if at, err := db.NodeRevokedAt(ctx, "gpu01"); err != nil || !at.Equal(second) {
|
||||
t.Errorf("got %v, %v; expected the second removal", at, err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user