Skip to content

Agent Mesh

controlplane: make biscuit TTL admin-configurable and cap it to the OIDC token's expiry

Antonio Ojea22cf927901a2
diff --git a/cmd/sam-control-plane/main.go b/cmd/sam-control-plane/main.go
index 8a9d077d..00aa67e2 100644
--- a/cmd/sam-control-plane/main.go
+++ b/cmd/sam-control-plane/main.go
@@ -41,6 +41,7 @@ var (
keyRotationInterval time.Duration
keyGracePeriod time.Duration
leaseDuration time.Duration
+ biscuitTTL time.Duration
adminTokenPath string
insecureSkipTLSVerify bool
logLevel string
@@ -120,6 +121,7 @@ func main() {
KeyGracePeriod: keyGracePeriod,
InsecureSkipTLSVerify: insecureSkipTLSVerify,
BiscuitTimeout: 10 * time.Second,
+ BiscuitTTL: biscuitTTL,
AdminToken: adminToken,
AutoApproveEnrollment: autoApproveEnrollment,
}
@@ -153,6 +155,7 @@ func main() {
rootCmd.Flags().DurationVar(&keyRotationInterval, "key-rotation-interval", 24*time.Hour, "Key rotation interval (e.g. 24h). 0 disables rotation.")
rootCmd.Flags().DurationVar(&keyGracePeriod, "key-grace-period", 1*time.Hour, "Key grace period for rotated keys.")
rootCmd.Flags().DurationVar(&leaseDuration, "lease-duration", 15*time.Minute, "Router lease registration TTL.")
+ rootCmd.Flags().DurationVar(&biscuitTTL, "biscuit-ttl", api.BiscuitTokenTTL, "Lifespan minted into every issued Biscuit's expiration fact. Capped to the OIDC token's own expiry when shorter.")
rootCmd.Flags().StringVar(&adminTokenPath, "admin-token-path", "", "Path to file containing the token for authenticating policy REST API requests (or env SAM_ADMIN_TOKEN)")
rootCmd.Flags().BoolVar(&insecureSkipTLSVerify, "insecure-skip-tls-verify", false, "Skip TLS verification for OIDC providers")
rootCmd.Flags().StringVar(&logLevel, "log-level", "info", "Log level (debug, info, warn, error)")
diff --git a/internal/controlplane/config.go b/internal/controlplane/config.go
index bc78fce4..c785fbb2 100644
--- a/internal/controlplane/config.go
+++ b/internal/controlplane/config.go
@@ -17,6 +17,8 @@ package controlplane
import (
"fmt"
"time"
+
+ "github.com/google/sam/api"
)
// Options holds configuration for the control plane.
@@ -32,6 +34,7 @@ type Options struct {
KeyGracePeriod time.Duration
InsecureSkipTLSVerify bool
BiscuitTimeout time.Duration
+ BiscuitTTL time.Duration // Lifespan minted into every issued Biscuit's expiration() fact; defaults to api.BiscuitTokenTTL
AdminToken string // Optional: administrative bearer token for protecting policy and enrollment queue REST APIs
AutoApproveEnrollment bool // If true, valid bootstrap token enrollment requests are immediately approved without administrative manual gate
}
@@ -54,6 +57,9 @@ func (o *Options) Default() {
if o.KeyGracePeriod <= 0 {
o.KeyGracePeriod = 1 * time.Hour
}
+ if o.BiscuitTTL <= 0 {
+ o.BiscuitTTL = api.BiscuitTokenTTL
+ }
}
// Validate ensures options are valid.
diff --git a/internal/controlplane/server.go b/internal/controlplane/server.go
index 4062d564..ac14981f 100644
--- a/internal/controlplane/server.go
+++ b/internal/controlplane/server.go
@@ -506,8 +506,12 @@ func (s *Server) HandleRegister(w http.ResponseWriter, r *http.Request) {
finalRoles := []string{req.RequestedRole}
finalRoles = append(finalRoles, customAccessRoles...)
- // Mint token
- biscuitExpiry := time.Now().Add(api.BiscuitTokenTTL)
+ // Mint token. A biscuit must never outlive the OIDC token that vouched
+ // for it, so its expiration is capped at whichever comes first.
+ biscuitExpiry := time.Now().Add(s.config.BiscuitTTL)
+ if token.Expiry.Before(biscuitExpiry) {
+ biscuitExpiry = token.Expiry
+ }
biscuitData, _, err := identity.MintBiscuitToken(privKey, claims, token, pID, biscuitExpiry, finalRoles, policyRoles, req.Labels)
if err != nil {
logger.Errorw("Biscuit minting failed", "peer_id", req.PeerId, "error", err)
@@ -562,7 +566,7 @@ func (s *Server) HandleRegister(w http.ResponseWriter, r *http.Request) {
BiscuitToken: biscuitData,
ControlPlanePublicKey: pubKey,
RouterAddresses: routerAddrs, // routers nodes multiaddresses
- Expiration: token.Expiry.Unix(),
+ Expiration: biscuitExpiry.Unix(),
}
respData, err := proto.Marshal(resp)
@@ -687,7 +691,7 @@ func (s *Server) HandleRefresh(w http.ResponseWriter, r *http.Request) {
}
var biscuitBytes []byte
- biscuitExpiry := time.Now().Add(api.BiscuitTokenTTL)
+ biscuitExpiry := time.Now().Add(s.config.BiscuitTTL)
if nodeRecord.EnrollmentType == "OIDC" {
var claims jwt.MapClaims
@@ -1194,7 +1198,7 @@ func (s *Server) HandleEnroll(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Internal server error", http.StatusInternalServerError)
return
}
- biscuitBytes, err := identity.MintBootstrapBiscuitToken(privKey, pID, tokenRecord.Role, time.Now().Add(api.BiscuitTokenTTL), policyRoles, req.Labels)
+ biscuitBytes, err := identity.MintBootstrapBiscuitToken(privKey, pID, tokenRecord.Role, time.Now().Add(s.config.BiscuitTTL), policyRoles, req.Labels)
if err != nil {
logger.Errorf("Failed to mint bootstrap biscuit: %v", err)
http.Error(w, "Internal server error", http.StatusInternalServerError)
@@ -1547,7 +1551,7 @@ func (s *Server) HandleAdminEnrollmentAction(w http.ResponseWriter, r *http.Requ
}
// Admin approval is the attestation of the operator-declared labels
// recorded on the pending request.
- biscuitBytes, err := identity.MintBootstrapBiscuitToken(privKey, pID, tokenRecord.Role, time.Now().Add(api.BiscuitTokenTTL), policyRoles, enrollReq.Labels)
+ biscuitBytes, err := identity.MintBootstrapBiscuitToken(privKey, pID, tokenRecord.Role, time.Now().Add(s.config.BiscuitTTL), policyRoles, enrollReq.Labels)
if err != nil {
logger.Errorf("Failed to mint bootstrap biscuit: %v", err)
http.Error(w, "Internal server error", http.StatusInternalServerError)
@@ -1672,9 +1676,9 @@ func (s *Server) buildApprovedBootstrapEnrollResponse(ctx context.Context, biscu
routerAddrs = append(routerAddrs, r.Addresses...)
}
- expiration := time.Now().Add(api.BiscuitTokenTTL).Unix()
+ expiration := time.Now().Add(s.config.BiscuitTTL).Unix()
if resolvedAt != nil {
- expiration = resolvedAt.Add(api.BiscuitTokenTTL).Unix()
+ expiration = resolvedAt.Add(s.config.BiscuitTTL).Unix()
}
return &api.BootstrapEnrollResponse{