Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions internal/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
_ "embed"
"encoding/json"
"fmt"
"io"
"net"
Expand Down Expand Up @@ -621,8 +622,8 @@ EOF
fmt.Sprintf("GOTRUE_RATE_LIMIT_WEB3=%v", utils.Config.Auth.RateLimit.Web3),
}

// Since signing key is validated by ResolveJWKS, simply read the key file.
if keys, err := afero.ReadFile(fsys, utils.Config.Auth.SigningKeysPath); err == nil && len(keys) > 0 {
// Serialise default or custom signing keys
if keys, err := json.Marshal(utils.Config.Auth.SigningKeys); err == nil {
env = append(env, "GOTRUE_JWT_KEYS="+string(keys))
// TODO: deprecate HS256 when it's no longer supported
env = append(env, "GOTRUE_JWT_VALID_METHODS=HS256,RS256,ES256")
Expand Down
22 changes: 22 additions & 0 deletions pkg/config/apikeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import (
"crypto"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/rsa"
"encoding/base64"
"math/big"
"time"

"github.com/go-errors/errors"
"github.com/golang-jwt/jwt/v5"
"github.com/google/uuid"
"github.com/supabase/cli/pkg/cast"
)

const (
Expand Down Expand Up @@ -46,6 +49,25 @@ func (a *auth) generateAPIKeys() error {
} else if len(a.JwtSecret.Value) < 16 {
return errors.Errorf("Invalid config for auth.jwt_secret. Must be at least 16 characters")
}
// Generate default signing key (P-256 curve for ES256)
if len(a.SigningKeysPath) == 0 {
privateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
return errors.Errorf("failed to generate ECDSA key: %w", err)
}
a.SigningKeys = append(a.SigningKeys, JWK{
KeyType: "EC",
KeyID: uuid.New().String(),
Use: "sig",
KeyOps: []string{"sign", "verify"},
Algorithm: "ES256",
Extractable: cast.Ptr(true),
Curve: "P-256",
X: base64.RawURLEncoding.EncodeToString(privateKey.PublicKey.X.Bytes()),
Y: base64.RawURLEncoding.EncodeToString(privateKey.PublicKey.Y.Bytes()),
PrivateExponent: base64.RawURLEncoding.EncodeToString(privateKey.D.Bytes()),
})
}
// Generate anon key if not provided
if len(a.AnonKey.Value) == 0 {
signed, err := a.generateJWT("anon")
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,7 @@ func (a *auth) ResolveJWKS(ctx context.Context) (string, error) {
jwks.Keys = append(jwks.Keys, json.RawMessage(publicKeyEncoded))
}
// Fallback to JWT_SECRET for backward compatibility
if len(a.SigningKeys) == 0 {
if len(a.SigningKeysPath) == 0 {
jwtSecret := secretJWK{
KeyType: "oct",
KeyBase64URL: base64.RawURLEncoding.EncodeToString([]byte(a.JwtSecret.Value)),
Expand Down