Skip to content

Commit

Permalink
KMS client debug
Browse files Browse the repository at this point in the history
  • Loading branch information
pschork committed Jan 13, 2025
1 parent b98073d commit 8daa5b7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
22 changes: 15 additions & 7 deletions api/clients/v2/dispersal_request_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"context"
"crypto/ecdsa"
"fmt"

grpc "github.com/Layr-Labs/eigenda/api/grpc/node/v2"
"github.com/Layr-Labs/eigenda/api/hashing"
aws2 "github.com/Layr-Labs/eigenda/common/aws"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/kms"
)

Expand All @@ -33,20 +34,27 @@ func NewDispersalRequestSigner(
endpoint string,
keyID string) (DispersalRequestSigner, error) {

keyManager := kms.New(kms.Options{
Region: region,
BaseEndpoint: aws.String(endpoint),
})
// Load the AWS SDK configuration, which will automatically detect credentials
// from environment variables, IAM roles, or AWS config files
cfg, err := config.LoadDefaultConfig(ctx,
config.WithRegion(region),
)
if err != nil {
return nil, fmt.Errorf("failed to load AWS config: %w", err)
}

// Create KMS client with the loaded configuration
kmsClient := kms.NewFromConfig(cfg)

key, err := aws2.LoadPublicKeyKMS(ctx, keyManager, keyID)
key, err := aws2.LoadPublicKeyKMS(ctx, kmsClient, keyID)
if err != nil {
return nil, fmt.Errorf("failed to get ecdsa public key: %w", err)
}

return &requestSigner{
keyID: keyID,
publicKey: key,
keyManager: keyManager,
keyManager: kmsClient,
}, nil
}

Expand Down
17 changes: 17 additions & 0 deletions disperser/cmd/controller/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"fmt"

"github.com/Layr-Labs/eigenda/common"
Expand All @@ -11,6 +12,8 @@ import (
"github.com/Layr-Labs/eigenda/disperser/cmd/controller/flags"
"github.com/Layr-Labs/eigenda/disperser/controller"
"github.com/Layr-Labs/eigenda/indexer"
"github.com/Layr-Labs/eigensdk-go/aws/kms"
"github.com/ethereum/go-ethereum/crypto"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -100,5 +103,19 @@ func NewConfig(ctx *cli.Context) (Config, error) {
if !config.DisperserStoreChunksSigningDisabled && config.DisperserKMSKeyID == "" {
return Config{}, fmt.Errorf("DisperserKMSKeyID is required when StoreChunks() signing is enabled")
}

// KMS debugging
kmsClient, err := kms.NewKMSClient(context.Background(), config.AwsClientConfig.Region)
if err != nil {
fmt.Printf("failed to create KMS client: %v\n", err)
return config, nil
}
pubKey, err := kms.GetECDSAPublicKey(context.Background(), kmsClient, config.DisperserKMSKeyID)
if err != nil {
fmt.Printf("failed to get public key from KMS: %v\n", err)
return config, nil
}
addr := crypto.PubkeyToAddress(*pubKey)
fmt.Printf("public key: %v, address: %s\n", pubKey, addr.Hex())
return config, nil
}

0 comments on commit 8daa5b7

Please sign in to comment.