Skip to content

Commit b4646ea

Browse files
committed
Review feedback
1 parent d575881 commit b4646ea

9 files changed

Lines changed: 24 additions & 19 deletions

File tree

docs/guides/operations/aws-kms-signer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ signer:
5959
key_id: "arn:aws:kms:us-east-1:123456789012:key/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
6060
region: "us-east-1" # optional but recommended
6161
profile: "prod" # optional; omit when using IAM role/env creds
62-
timeout: "10s" # must be > 0
62+
timeout: "1s" # must be > 0
6363
max_retries: 3 # must be >= 0
6464
```
6565

pkg/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ type P2PConfig struct {
312312

313313
// SignerConfig contains all signer configuration parameters
314314
type SignerConfig struct {
315-
SignerType string `mapstructure:"signer_type" yaml:"signer_type" comment:"Type of remote signer to use (file, grpc, kms)"`
315+
SignerType string `mapstructure:"signer_type" yaml:"signer_type" comment:"Type of remote signer to use (file, kms)"`
316316
SignerPath string `mapstructure:"signer_path" yaml:"signer_path" comment:"Path to the signer file or address"`
317317
KMS SignerKMSConfig `mapstructure:"kms" yaml:"kms"`
318318
}

pkg/signer/aws/signer.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ func (s *KmsSigner) Sign(ctx context.Context, message []byte) ([]byte, error) {
158158
maxAttempts := maxRetries + 1
159159

160160
for attempt := 0; attempt < maxAttempts; attempt++ {
161+
if err := ctx.Err(); err != nil {
162+
return nil, err
163+
}
161164
if attempt > 0 {
162165
// Exponential backoff: 100ms, 200ms, 400ms, ...
163166
backoff := time.Duration(100<<uint(attempt-1)) * time.Millisecond
@@ -180,15 +183,15 @@ func (s *KmsSigner) Sign(ctx context.Context, message []byte) ([]byte, error) {
180183
if err != nil {
181184
lastErr = err
182185
if !isRetryableKMSError(err) {
183-
return nil, fmt.Errorf("KMS Sign failed with non-retryable error: %w", err)
186+
return nil, fmt.Errorf("AWS KMS sign failed with non-retryable error: %w", err)
184187
}
185188
continue
186189
}
187190

188191
return out.Signature, nil
189192
}
190193

191-
return nil, fmt.Errorf("KMS Sign failed after %d attempts: %w", maxAttempts, lastErr)
194+
return nil, fmt.Errorf("AWS KMS sign failed after %d attempts: %w", maxAttempts, lastErr)
192195
}
193196

194197
// GetPublic returns the cached public key.
@@ -212,8 +215,9 @@ func (s *KmsSigner) GetAddress() ([]byte, error) {
212215
if s.address == nil {
213216
return nil, fmt.Errorf("address not loaded")
214217
}
215-
216-
return s.address, nil
218+
r := make([]byte, len(s.address))
219+
copy(r, s.address)
220+
return r, nil
217221
}
218222

219223
func isRetryableKMSError(err error) bool {

pkg/signer/aws/signer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func TestSign_KMSFailure(t *testing.T) {
131131

132132
_, err = s.Sign(context.Background(), []byte("hello world"))
133133
require.Error(t, err)
134-
assert.Contains(t, err.Error(), "KMS Sign failed")
134+
assert.Contains(t, err.Error(), "AWS KMS sign failed")
135135
assert.Equal(t, int32(4), atomic.LoadInt32(&calls), "default retries should make 4 attempts")
136136
}
137137

pkg/signer/factory.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ func newSigner(ctx context.Context, config *rollconf.Config, passphrase string,
3030
if passphrase == "" {
3131
return nil, fmt.Errorf("passphrase is required when using local file signer")
3232
}
33+
if config.Signer.SignerPath == "" {
34+
return nil, fmt.Errorf("signer path is required when using local file signer")
35+
}
3336

34-
// Resolve signer path; allow absolute, relative to node root, or relative to CWD if resolution fails
3537
signerPath, err := filepath.Abs(strings.TrimSuffix(config.Signer.SignerPath, "signer.json"))
3638
if err != nil {
3739
return nil, err

pkg/signer/gcp/signer.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func kmsSignerFromClient(ctx context.Context, client KMSClient, keyName string,
105105
return nil, fmt.Errorf("gcp kms client is required")
106106
}
107107

108-
o := Options{Timeout: 10 * time.Second, MaxRetries: 3}
108+
o := Options{Timeout: 1 * time.Second, MaxRetries: 3}
109109
if opts != nil {
110110
if opts.Timeout > 0 {
111111
o.Timeout = opts.Timeout
@@ -181,6 +181,9 @@ func (s *KmsSigner) Sign(ctx context.Context, message []byte) ([]byte, error) {
181181
maxAttempts := maxRetries + 1
182182

183183
for attempt := 0; attempt < maxAttempts; attempt++ {
184+
if err := ctx.Err(); err != nil {
185+
return nil, err
186+
}
184187
if attempt > 0 {
185188
// Exponential backoff with cap: 100ms, 200ms, 400ms, ... up to 5s.
186189
backoff := retryBackoff(attempt)
@@ -203,7 +206,7 @@ func (s *KmsSigner) Sign(ctx context.Context, message []byte) ([]byte, error) {
203206
if err != nil {
204207
lastErr = err
205208
if !isRetryableKMSError(err) {
206-
return nil, fmt.Errorf("KMS Sign failed with non-retryable error: %w", err)
209+
return nil, fmt.Errorf("GCP KMS sign failed with non-retryable error: %w", err)
207210
}
208211
continue
209212
}
@@ -279,8 +282,9 @@ func (s *KmsSigner) GetAddress() ([]byte, error) {
279282
if s.address == nil {
280283
return nil, fmt.Errorf("address not loaded")
281284
}
282-
283-
return s.address, nil
285+
r := make([]byte, len(s.address))
286+
copy(r, s.address)
287+
return r, nil
284288
}
285289

286290
func isRetryableKMSError(err error) bool {

test/e2e/evm_kms_e2e_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package e2e
44

55
import (
66
"context"
7-
"flag"
87
"fmt"
98
"os"
109
"path/filepath"
@@ -29,8 +28,6 @@ func TestEvmSequencerWithAWSKMSSignerE2E(t *testing.T) {
2928
if testing.Short() {
3029
t.Skip("skip e2e in short mode")
3130
}
32-
flag.Parse()
33-
3431
kmsKeyID := os.Getenv("EVNODE_E2E_AWS_KMS_KEY_ID")
3532
if kmsKeyID == "" {
3633
t.Skip("set EVNODE_E2E_AWS_KMS_KEY_ID to run AWS KMS EVM e2e test")
@@ -69,7 +66,6 @@ func TestEvmSequencerWithGCPKMSSignerE2E(t *testing.T) {
6966
if testing.Short() {
7067
t.Skip("skip e2e in short mode")
7168
}
72-
flag.Parse()
7369

7470
kmsKeyName := os.Getenv("EVNODE_E2E_GCP_KMS_KEY_NAME")
7571
if kmsKeyName == "" {

types/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func GetRandomNextSignedHeader(ctx context.Context, signedHeader *SignedHeader,
195195
Signer: signedHeader.Signer,
196196
}
197197

198-
signature, err := GetSignature(ctx, signedHeader.Header, signer)
198+
signature, err := GetSignature(ctx, newSignedHeader.Header, signer)
199199
if err != nil {
200200
return nil, err
201201
}

types/utils_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package types_test
22

33
import (
4-
"context"
54
// Import bytes package
65
"testing"
76
"time" // Used for time.Time comparison
@@ -79,7 +78,7 @@ func TestGetFirstSignedHeader(t *testing.T) {
7978
noopSigner, err := noop.NewNoopSigner(privKey)
8079
assert.NoError(t, err)
8180

82-
firstSignedHeader, err := types.GetFirstSignedHeader(context.Background(), noopSigner, tc.chainID)
81+
firstSignedHeader, err := types.GetFirstSignedHeader(t.Context(), noopSigner, tc.chainID)
8382
assert.NoError(t, err)
8483
assert.NotNil(t, firstSignedHeader)
8584
assert.Equal(t, uint64(1), firstSignedHeader.Height())

0 commit comments

Comments
 (0)