Skip to content

Agent Mesh

Revert "hub libp2p key identity"

Antonio Ojea28980d9c4e0c
diff --git a/.github/k8s/sam-hub-template.yaml b/.github/k8s/sam-hub-template.yaml
index 1a3bfb02..150beffe 100644
--- a/.github/k8s/sam-hub-template.yaml
+++ b/.github/k8s/sam-hub-template.yaml
@@ -64,12 +64,6 @@ spec:
name: sam-hub-secret
key: sam-hub-key
optional: true # Make it optional so it doesn't block local kind testing if not created
- - name: SAM_LIBP2P_KEY
- valueFrom:
- secretKeyRef:
- name: sam-hub-secret
- key: sam-libp2p-key
- optional: true
ports:
- containerPort: 4001
protocol: TCP
@@ -104,7 +98,6 @@ spec:
- "--tls-cert-file=/etc/sam/certs/tls.crt"
- "--tls-key-file=/etc/sam/certs/tls.key"
- "--policy-file=/etc/sam/policies/policies.yaml"
- - "--libp2p-key=$(SAM_LIBP2P_KEY)"
resources:
requests:
cpu: 100m
diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml
index 0a5cc9e9..f9fea58d 100644
--- a/.github/workflows/deploy.yaml
+++ b/.github/workflows/deploy.yaml
@@ -163,22 +163,13 @@ jobs:
export NAMESPACE="sam-${ENV_NAME}"
# Idempotently provision the sam-hub-secret if it doesn't already exist
if ! kubectl get secret sam-hub-secret -n ${NAMESPACE} >/dev/null 2>&1; then
- echo "Generating a new random 32-byte hex key for SAM_HUB_KEY and SAM_LIBP2P_KEY..."
+ echo "Generating a new random 32-byte hex key for SAM_HUB_KEY..."
HUB_KEY=$(openssl rand -hex 32)
- LIBP2P_KEY=$(openssl rand -hex 32)
kubectl create secret generic sam-hub-secret \
--namespace=${NAMESPACE} \
- --from-literal=sam-hub-key="${HUB_KEY}" \
- --from-literal=sam-libp2p-key="${LIBP2P_KEY}"
+ --from-literal=sam-hub-key="${HUB_KEY}"
else
- echo "sam-hub-secret already exists in namespace ${NAMESPACE}."
- # Check if sam-libp2p-key is missing, and patch it if needed
- if ! kubectl get secret sam-hub-secret -n ${NAMESPACE} -o json | grep -q '"sam-libp2p-key"'; then
- echo "sam-libp2p-key is missing from existing secret. Generating and patching..."
- LIBP2P_KEY=$(openssl rand -hex 32)
- LIBP2P_KEY_BASE64=$(echo -n "${LIBP2P_KEY}" | base64 | tr -d '\n')
- kubectl patch secret sam-hub-secret -n ${NAMESPACE} --type='json' -p="[{\"op\": \"add\", \"path\": \"/data/sam-libp2p-key\", \"value\": \"${LIBP2P_KEY_BASE64}\"}]"
- fi
+ echo "sam-hub-secret already exists in namespace ${NAMESPACE}. Skipping generation."
fi
- name: Copy Wildcard TLS Secret to sam-hub
diff --git a/cmd/sam-hub/main.go b/cmd/sam-hub/main.go
index ad6246bc..dbe38674 100644
--- a/cmd/sam-hub/main.go
+++ b/cmd/sam-hub/main.go
@@ -36,7 +36,6 @@ import (
"github.com/libp2p/go-libp2p"
dht "github.com/libp2p/go-libp2p-kad-dht"
pubsub "github.com/libp2p/go-libp2p-pubsub"
- "github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
@@ -97,7 +96,6 @@ var (
tlsCAFile string
externalMultiaddrs []string
allowedAudiencesFlag string
- libp2pKeyHex string
)
var logger = golog.Logger("sam-hub")
@@ -128,8 +126,7 @@ func NewHub(ctx context.Context, policy *api.PolicyConfig) (*Hub, error) {
return nil, fmt.Errorf("failed to create connection manager: %w", err)
}
- // Multi-transport setup for firewall traversal
- opts := []libp2p.Option{
+ h, err := libp2p.New(
libp2p.Transport(libp2pquic.NewTransport),
libp2p.Transport(tcp.NewTCPTransport),
libp2p.ListenAddrStrings(listenAddrs...),
@@ -140,28 +137,7 @@ func NewHub(ctx context.Context, policy *api.PolicyConfig) (*Hub, error) {
libp2p.ConnectionManager(cm),
libp2p.EnableAutoNATv2(),
libp2p.EnableNATService(),
- }
-
- if libp2pKeyHex != "" {
- logger.Infof("Initializing libp2p host with static PeerID...")
- seed, err := hex.DecodeString(strings.TrimSpace(libp2pKeyHex))
- if err != nil {
- return nil, fmt.Errorf("failed to decode libp2p key hex: %w", err)
- }
- if len(seed) != ed25519.SeedSize {
- return nil, fmt.Errorf("invalid libp2p key seed size: %d, expected %d", len(seed), ed25519.SeedSize)
- }
- priv := ed25519.NewKeyFromSeed(seed)
- libp2pPrivKey, err := crypto.UnmarshalEd25519PrivateKey(priv)
- if err != nil {
- return nil, fmt.Errorf("failed to unmarshal libp2p private key: %w", err)
- }
- opts = append(opts, libp2p.Identity(libp2pPrivKey))
- } else {
- logger.Warnf("No libp2p key configured, using a dynamic ephemeral identity")
- }
-
- h, err := libp2p.New(opts...)
+ )
if err != nil {
return nil, err
}
@@ -728,7 +704,6 @@ func main() {
rootCmd.Flags().StringVar(&oidcIssuer, "issuer", defIssuer, "OIDC Issuer URL")
rootCmd.Flags().StringVar(&clientID, "client-id", os.Getenv("SAM_OIDC_ID"), "OIDC Client ID")
rootCmd.Flags().StringVar(&biscuitHex, "key", os.Getenv("SAM_HUB_KEY"), "Hub Private Key (32-byte Hex)")
- rootCmd.Flags().StringVar(&libp2pKeyHex, "libp2p-key", os.Getenv("SAM_LIBP2P_KEY"), "Hub libp2p Private Key (32-byte Hex)")
rootCmd.Flags().StringSliceVar(&listenAddrs, "listen", []string{"/ip4/0.0.0.0/udp/8080/quic-v1", "/ip4/0.0.0.0/tcp/8080"}, "libp2p Listen Addrs")
rootCmd.Flags().StringSliceVar(&externalMultiaddrs, "external-multiaddr", []string{}, "External multiaddrs to announce")
rootCmd.Flags().StringVar(&meshName, "mesh", DefaultMeshName, "Mesh federation name")