Skip to content

Agent Mesh

fix(identity,controlplane,python): pass configurable BiscuitTimeout to VerifyAndExtractPeerID and add missing httpx dependency

Antonio Ojea45774465c672
diff --git a/charts/sam-mesh/templates/bootstrap-job.yaml b/charts/sam-mesh/templates/bootstrap-job.yaml
index f3e9c094..c4d3a9eb 100644
--- a/charts/sam-mesh/templates/bootstrap-job.yaml
+++ b/charts/sam-mesh/templates/bootstrap-job.yaml
@@ -41,7 +41,7 @@ metadata:
labels:
{{- include "sam-mesh.labels" . | nindent 4 }}
spec:
- activeDeadlineSeconds: 120
+ activeDeadlineSeconds: 300
template:
metadata:
labels:
diff --git a/internal/controlplane/server.go b/internal/controlplane/server.go
index fd4ea5a8..9561f71e 100644
--- a/internal/controlplane/server.go
+++ b/internal/controlplane/server.go
@@ -508,7 +508,7 @@ func (s *Server) HandleRefresh(w http.ResponseWriter, r *http.Request) {
}
// Verify current biscuit signature and extract peer ID
- pID, err := identity.VerifyAndExtractPeerID(trustedKeys, currentBiscuitBytes)
+ pID, err := identity.VerifyAndExtractPeerID(trustedKeys, currentBiscuitBytes, s.config.BiscuitTimeout)
if err != nil {
logger.Warnw("Invalid biscuit presented for refresh", "error", err)
http.Error(w, "Invalid biscuit: "+err.Error(), http.StatusUnauthorized)
@@ -814,7 +814,7 @@ func (s *Server) HandlePolicies(w http.ResponseWriter, r *http.Request) {
for _, k := range validKeys {
trustedKeys = append(trustedKeys, k.Public)
}
- peerID, err := identity.VerifyAndExtractPeerID(trustedKeys, biscuitBytes)
+ peerID, err := identity.VerifyAndExtractPeerID(trustedKeys, biscuitBytes, s.config.BiscuitTimeout)
if err == nil {
nodeRecord, nodeErr := s.store.GetNode(r.Context(), peerID.String())
if nodeErr == nil && nodeRecord != nil && !nodeRecord.Banned {
diff --git a/internal/controlplane/server_test.go b/internal/controlplane/server_test.go
index 473fb998..fb3bc7c5 100644
--- a/internal/controlplane/server_test.go
+++ b/internal/controlplane/server_test.go
@@ -33,6 +33,7 @@ import (
"time"
"github.com/biscuit-auth/biscuit-go/v2"
+ "github.com/biscuit-auth/biscuit-go/v2/datalog"
"github.com/golang-jwt/jwt/v5"
"github.com/google/sam/api"
"github.com/google/sam/internal/node"
@@ -631,7 +632,7 @@ func TestEnrollmentWorkflow(t *testing.T) {
if err != nil {
t.Fatalf("failed to unmarshal biscuit: %v", err)
}
- authorizer, err := b.Authorizer(cpPub)
+ authorizer, err := b.Authorizer(cpPub, biscuit.WithWorldOptions(datalog.WithMaxDuration(srv.config.BiscuitTimeout)))
if err != nil {
t.Fatal(err)
}
diff --git a/internal/identity/biscuit.go b/internal/identity/biscuit.go
index 11a66bd6..a728a177 100644
--- a/internal/identity/biscuit.go
+++ b/internal/identity/biscuit.go
@@ -332,18 +332,23 @@ func MintBootstrapBiscuitToken(signingKey ed25519.PrivateKey, remotePeer peer.ID
// VerifyAndExtractPeerID checks that the biscuit is signed by one of the trusted keys and returns the peer ID.
// This function does NOT perform time checks, making it suitable for token refresh flows.
-func VerifyAndExtractPeerID(trustedPublicKeys []ed25519.PublicKey, biscuitData []byte) (peer.ID, error) {
+func VerifyAndExtractPeerID(trustedPublicKeys []ed25519.PublicKey, biscuitData []byte, timeout time.Duration) (peer.ID, error) {
b, err := biscuit.Unmarshal(biscuitData)
if err != nil {
return "", fmt.Errorf("malformed biscuit: %w", err)
}
+ var authOpts []biscuit.AuthorizerOption
+ if timeout > 0 {
+ authOpts = append(authOpts, biscuit.WithWorldOptions(datalog.WithMaxDuration(timeout)))
+ }
+
var authorizer biscuit.Authorizer
var verified bool
var lastErr error
for _, pubKey := range trustedPublicKeys {
- auth, err := b.Authorizer(pubKey)
+ auth, err := b.Authorizer(pubKey, authOpts...)
if err != nil {
lastErr = err
continue
diff --git a/internal/identity/biscuit_test.go b/internal/identity/biscuit_test.go
index da31b9db..0987ab0a 100644
--- a/internal/identity/biscuit_test.go
+++ b/internal/identity/biscuit_test.go
@@ -511,7 +511,7 @@ func TestVerifyAndExtractPeerID_MultipleTrustedKeys(t *testing.T) {
// trustedPublicKeys has pub1 first, pub2 second (pub2 is the signer)
trustedKeys := []ed25519.PublicKey{pub1, pub2}
- extractedPeer, err := VerifyAndExtractPeerID(trustedKeys, biscuitData)
+ extractedPeer, err := VerifyAndExtractPeerID(trustedKeys, biscuitData, 5*time.Second)
if err != nil {
t.Fatalf("VerifyAndExtractPeerID failed with multiple trusted keys: %v", err)
}
diff --git a/sam-mcp-python/pyproject.toml b/sam-mcp-python/pyproject.toml
index eda7a8b3..1c5e374f 100644
--- a/sam-mcp-python/pyproject.toml
+++ b/sam-mcp-python/pyproject.toml
@@ -10,6 +10,7 @@ readme = "README.md"
requires-python = ">=3.10"
dependencies = [
"mcp>=1.0.0",
+ "httpx>=0.20.0",
]
[project.optional-dependencies]