@@ -4,13 +4,16 @@ import (
44 "crypto"
55 "crypto/ecdsa"
66 "crypto/elliptic"
7+ "crypto/rand"
78 "crypto/rsa"
89 "encoding/base64"
910 "math/big"
1011 "time"
1112
1213 "github.com/go-errors/errors"
1314 "github.com/golang-jwt/jwt/v5"
15+ "github.com/google/uuid"
16+ "github.com/supabase/cli/pkg/cast"
1417)
1518
1619const (
@@ -46,6 +49,25 @@ func (a *auth) generateAPIKeys() error {
4649 } else if len (a .JwtSecret .Value ) < 16 {
4750 return errors .Errorf ("Invalid config for auth.jwt_secret. Must be at least 16 characters" )
4851 }
52+ // Generate default signing key (P-256 curve for ES256)
53+ if len (a .SigningKeysPath ) == 0 {
54+ privateKey , err := ecdsa .GenerateKey (elliptic .P256 (), rand .Reader )
55+ if err != nil {
56+ return errors .Errorf ("failed to generate ECDSA key: %w" , err )
57+ }
58+ a .SigningKeys = append (a .SigningKeys , JWK {
59+ KeyType : "EC" ,
60+ KeyID : uuid .New ().String (),
61+ Use : "sig" ,
62+ KeyOps : []string {"sign" , "verify" },
63+ Algorithm : "ES256" ,
64+ Extractable : cast .Ptr (true ),
65+ Curve : "P-256" ,
66+ X : base64 .RawURLEncoding .EncodeToString (privateKey .PublicKey .X .Bytes ()),
67+ Y : base64 .RawURLEncoding .EncodeToString (privateKey .PublicKey .Y .Bytes ()),
68+ PrivateExponent : base64 .RawURLEncoding .EncodeToString (privateKey .D .Bytes ()),
69+ })
70+ }
4971 // Generate anon key if not provided
5072 if len (a .AnonKey .Value ) == 0 {
5173 signed , err := a .generateJWT ("anon" )
0 commit comments