Skip to content

Commit 551da78

Browse files
authored
Error sanitize (#919)
* connString games * handlers should not expose db err messages * shadow fix * hide password * make gen * security boundary * logger fix, spelling * mod * metrics oops
1 parent b8d3d82 commit 551da78

5 files changed

Lines changed: 65 additions & 36 deletions

File tree

documentation/en/configuration/metrics-reference.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,6 @@
77
This document lists all Prometheus metrics exported by Curio. All metrics use the `curio_` namespace prefix.
88

99
> **Note**: This file is auto-generated from source code. Run `make docsgen-metrics` to update.
10-
## Database Metrics (HarmonyDB)
11-
12-
| Metric | Type | Description |
13-
|--------|------|-------------|
14-
| `curio_db_errors` | gauge/counter | Total error count. |
15-
| `curio_db_hits` | gauge/counter | Total number of uses. |
16-
| `curio_db_open_connections` | gauge/counter | Total connection count. |
17-
| `curio_db_total_wait` | gauge/counter | Total delay. A numerator over hits to get average wait. |
18-
| `curio_db_waits` | histogram | The histogram of waits for query completions. |
19-
| `curio_db_which_host` | histogram | The index of the hostname being used |
20-
2110
## Task Metrics (HarmonyTask)
2211

2312
| Metric | Type | Description |

documentation/en/design/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,21 @@ To address these issues in Curio, we have implemented a GPU picker library calle
116116
<figure><img src="../.gitbook/assets/2024-06-04-040735_1470x522_scrot (1).png" alt=""><figcaption><p>Curio FFISelect in action</p></figcaption></figure>
117117

118118
This approach ensures efficient and conflict-free GPU usage, with each task being handled by a dedicated GPU, thus resolving the historical issues observed with the `lotus-miner` scheduler.
119+
120+
# Security Boundary
121+
122+
This is what Curio expects an SP to secure in order to have a safe experience.
123+
Curio is cluster software which coordinates directly and through the database. It also communicates to the public through chain providers (Lotus) and the market node. To secure this properly, ensure that only trusted people & services have access to:
124+
- logs: (these include inputs to failing processes)
125+
- physical machines,
126+
- virtual machine access (ssh) for Curio, Lotus, or Yugabyte
127+
- Curio or Lotus' or Yugabyte's open ports (with exceptions noted by Lotus, and the Curio market node)
128+
-- This includes the admin web ui for Curio which exposes numerous capabilities beyond viewing.
129+
130+
Safe to share with untrusted parties: (will not receive private information)
131+
- Prometheus output
132+
- alerts can be sent to untrusted receivers
133+
- CuView (at your own risk) has modes for light investigation.
134+
135+
Curio team recommends a network (VPN) containing all the pieces to have limited access.
136+
Logs are mostly clean except for errors which try to be as specific as possible, so partial redaction may be best here if sharing with untrusted parties.

market/mk12/mk12_utils.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ func GetDealStatus(ctx context.Context, db *harmonydb.DB, req DealStatusRequest,
262262
uuid = $1;`, req.DealUUID)
263263

264264
if err != nil {
265-
return errResp(fmt.Sprintf("failed to query the db for deal status: %s", err))
265+
reqLog.Errorw("failed to query deal status", "err", err)
266+
return errResp("failed to query the db for deal status")
266267
}
267268

268269
if len(pdeals) > 1 {

market/mk20/http/http.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func AuthMiddleware(db *harmonydb.DB, cfg *config.CurioConfig) func(http.Handler
7272
allowed, client, err := mk20.Auth(authHeader, db, cfg)
7373
if err != nil {
7474
log.Errorw("failed to authenticate request", "err", err)
75-
http.Error(w, "Error during authentication: "+err.Error(), http.StatusInternalServerError)
75+
http.Error(w, "Error during authentication", http.StatusInternalServerError)
7676
return
7777
}
7878

@@ -86,7 +86,7 @@ func AuthMiddleware(db *harmonydb.DB, cfg *config.CurioConfig) func(http.Handler
8686
allowed, err := mk20.AuthenticateClient(db, idStr, client)
8787
if err != nil {
8888
log.Errorw("failed to authenticate client", "err", err)
89-
http.Error(w, err.Error(), http.StatusUnauthorized)
89+
http.Error(w, "Error during authentication", http.StatusInternalServerError)
9090
return
9191
}
9292
if !allowed {

pdp/handlers.go

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ func (p *PDPService) handleCreateProofSet(w http.ResponseWriter, r *http.Request
191191
// Step 3: Get the sender address from 'eth_keys' table where role = 'pdp' limit 1
192192
fromAddress, err := p.getSenderAddress(ctx)
193193
if err != nil {
194-
http.Error(w, "Failed to get sender address: "+err.Error(), http.StatusInternalServerError)
194+
log.Errorf("Failed to get sender address: %v", err)
195+
http.Error(w, "Failed to get sender address", http.StatusInternalServerError)
195196
return
196197
}
197198

@@ -364,7 +365,8 @@ func (p *PDPService) handleGetProofSetCreationStatus(w http.ResponseWriter, r *h
364365
http.Error(w, "Proof set creation not found for given txHash", http.StatusNotFound)
365366
return
366367
}
367-
http.Error(w, "Failed to query proof set creation: "+err.Error(), http.StatusInternalServerError)
368+
log.Errorf("Failed to query proof set creation: %v", err)
369+
http.Error(w, "Failed to query proof set creation", http.StatusInternalServerError)
368370
return
369371
}
370372

@@ -402,7 +404,8 @@ func (p *PDPService) handleGetProofSetCreationStatus(w http.ResponseWriter, r *h
402404
http.Error(w, "Message status not found for given txHash", http.StatusInternalServerError)
403405
return
404406
}
405-
http.Error(w, "Failed to query message status: "+err.Error(), http.StatusInternalServerError)
407+
log.Errorf("Failed to query message status: %v", err)
408+
http.Error(w, "Failed to query message status", http.StatusInternalServerError)
406409
return
407410
}
408411

@@ -422,7 +425,8 @@ func (p *PDPService) handleGetProofSetCreationStatus(w http.ResponseWriter, r *h
422425
http.Error(w, "Proof set not found despite proofset_created = true", http.StatusInternalServerError)
423426
return
424427
}
425-
http.Error(w, "Failed to query proof set: "+err.Error(), http.StatusInternalServerError)
428+
log.Errorf("Failed to query proof set: %v", err)
429+
http.Error(w, "Failed to query proof set", http.StatusInternalServerError)
426430
return
427431
}
428432
response.ProofSetId = &proofSetId
@@ -485,7 +489,8 @@ func (p *PDPService) handleGetProofSet(w http.ResponseWriter, r *http.Request) {
485489
http.Error(w, "Proof set not found", http.StatusNotFound)
486490
return
487491
}
488-
http.Error(w, "Failed to retrieve proof set: "+err.Error(), http.StatusInternalServerError)
492+
log.Errorf("Failed to retrieve proof set: %v", err)
493+
http.Error(w, "Failed to retrieve proof set", http.StatusInternalServerError)
489494
return
490495
}
491496

@@ -510,7 +515,8 @@ func (p *PDPService) handleGetProofSet(w http.ResponseWriter, r *http.Request) {
510515
ORDER BY root_id, subroot_offset
511516
`, proofSetId)
512517
if err != nil {
513-
http.Error(w, "Failed to retrieve proof set roots: "+err.Error(), http.StatusInternalServerError)
518+
log.Errorf("Failed to retrieve proof set roots: %v", err)
519+
http.Error(w, "Failed to retrieve proof set roots", http.StatusInternalServerError)
514520
return
515521
}
516522

@@ -522,7 +528,8 @@ func (p *PDPService) handleGetProofSet(w http.ResponseWriter, r *http.Request) {
522528
WHERE id = $1
523529
`, proofSetId).Scan(&nextChallengeEpoch)
524530
if err != nil {
525-
http.Error(w, "Failed to retrieve next challenge epoch: "+err.Error(), http.StatusInternalServerError)
531+
log.Errorf("Failed to retrieve next challenge epoch: %v", err)
532+
http.Error(w, "Failed to retrieve next challenge epoch", http.StatusInternalServerError)
526533
return
527534
}
528535

@@ -615,7 +622,8 @@ func (p *PDPService) handleAddRootToProofSet(w http.ResponseWriter, r *http.Requ
615622
http.Error(w, "Proof set not found", http.StatusNotFound)
616623
return
617624
}
618-
http.Error(w, "Failed to retrieve proof set: "+err.Error(), http.StatusInternalServerError)
625+
log.Errorf("Failed to retrieve proof set: %v", err)
626+
http.Error(w, "Failed to retrieve proof set", http.StatusInternalServerError)
619627
return
620628
}
621629

@@ -725,7 +733,8 @@ func (p *PDPService) handleAddRootToProofSet(w http.ResponseWriter, r *http.Requ
725733
WHERE ppr.service = $1 AND ppr.piece_cid = ANY($2)
726734
`, serviceLabel, subrootCIDsList)
727735
if err != nil {
728-
return false, err
736+
log.Errorf("Failed to retrieve pdp_piecerefs: %v", err)
737+
return false, fmt.Errorf("failed to retrieve pdp_piecerefs")
729738
}
730739
defer rows.Close()
731740

@@ -811,7 +820,8 @@ func (p *PDPService) handleAddRootToProofSet(w http.ResponseWriter, r *http.Requ
811820
return true, nil
812821
}, harmonydb.OptionRetry())
813822
if err != nil {
814-
http.Error(w, "Failed to validate subroots: "+err.Error(), http.StatusBadRequest)
823+
log.Errorf("Failed to validate subroots: %v", err)
824+
http.Error(w, "Failed to validate subroots", http.StatusBadRequest)
815825
return
816826
}
817827

@@ -876,7 +886,8 @@ func (p *PDPService) handleAddRootToProofSet(w http.ResponseWriter, r *http.Requ
876886
// Step 7: Get the sender address from 'eth_keys' table where role = 'pdp' limit 1
877887
fromAddress, err := p.getSenderAddress(ctx)
878888
if err != nil {
879-
http.Error(w, "Failed to get sender address: "+err.Error(), http.StatusInternalServerError)
889+
log.Errorf("Failed to get sender address: %v", err)
890+
http.Error(w, "Failed to get sender address", http.StatusInternalServerError)
880891
return
881892
}
882893

@@ -919,7 +930,7 @@ func (p *PDPService) handleAddRootToProofSet(w http.ResponseWriter, r *http.Requ
919930
log.Errorw("Failed to insert AddRoots into message_waits_eth",
920931
"txHash", txHashLower,
921932
"error", err)
922-
return false, err // Return false to rollback the transaction
933+
return false, errors.New("failed to insert AddRoots into message_waits_eth") // Return false to rollback the transaction
923934
}
924935

925936
// Update proof set for initialization upon first add
@@ -928,7 +939,8 @@ func (p *PDPService) handleAddRootToProofSet(w http.ResponseWriter, r *http.Requ
928939
WHERE id = $1 AND prev_challenge_request_epoch IS NULL AND challenge_request_msg_hash IS NULL AND prove_at_epoch IS NULL
929940
`, proofSetIDUint64)
930941
if err != nil {
931-
return false, err
942+
log.Errorf("Failed to update proof set for initialization upon first add: %v", err)
943+
return false, errors.New("failed to update proof set for initialization upon first add")
932944
}
933945

934946
// Insert into pdp_proofset_roots
@@ -961,7 +973,8 @@ func (p *PDPService) handleAddRootToProofSet(w http.ResponseWriter, r *http.Requ
961973
subrootInfo.PDPPieceRefID,
962974
)
963975
if err != nil {
964-
return false, err
976+
log.Errorf("Failed to insert into pdp_proofset_roots: %v", err)
977+
return false, errors.New("failed to insert into pdp_proofset_roots")
965978
}
966979
}
967980
}
@@ -1039,7 +1052,8 @@ func (p *PDPService) handleGetRootAdditionStatus(w http.ResponseWriter, r *http.
10391052
http.Error(w, "Proof set not found", http.StatusNotFound)
10401053
return
10411054
}
1042-
http.Error(w, "Failed to retrieve proof set: "+err.Error(), http.StatusInternalServerError)
1055+
log.Errorf("Failed to retrieve proof set: %v", err)
1056+
http.Error(w, "Failed to retrieve proof set", http.StatusInternalServerError)
10431057
return
10441058
}
10451059

@@ -1069,7 +1083,8 @@ func (p *PDPService) handleGetRootAdditionStatus(w http.ResponseWriter, r *http.
10691083
ORDER BY add_message_index, subroot_offset
10701084
`, proofSetID, txHash)
10711085
if err != nil {
1072-
http.Error(w, "Failed to query root additions: "+err.Error(), http.StatusInternalServerError)
1086+
log.Errorf("Failed to query root additions: %v", err)
1087+
http.Error(w, "Failed to query root additions", http.StatusInternalServerError)
10731088
return
10741089
}
10751090

@@ -1088,7 +1103,8 @@ func (p *PDPService) handleGetRootAdditionStatus(w http.ResponseWriter, r *http.
10881103
http.Error(w, "Transaction status not found", http.StatusNotFound)
10891104
return
10901105
}
1091-
http.Error(w, "Failed to query transaction status: "+err.Error(), http.StatusInternalServerError)
1106+
log.Errorf("Failed to query transaction status: %v", err)
1107+
http.Error(w, "Failed to query transaction status", http.StatusInternalServerError)
10921108
return
10931109
}
10941110

@@ -1216,7 +1232,8 @@ func (p *PDPService) handleDeleteProofSetRoot(w http.ResponseWriter, r *http.Req
12161232
http.Error(w, "Proof set not found", http.StatusNotFound)
12171233
return
12181234
}
1219-
http.Error(w, "Failed to retrieve proof set: "+err.Error(), http.StatusInternalServerError)
1235+
log.Errorf("Failed to retrieve proof set: %v", err)
1236+
http.Error(w, "Failed to retrieve proof set", http.StatusInternalServerError)
12201237
return
12211238
}
12221239

@@ -1247,7 +1264,8 @@ func (p *PDPService) handleDeleteProofSetRoot(w http.ResponseWriter, r *http.Req
12471264
// Get the sender address
12481265
fromAddress, err := p.getSenderAddress(ctx)
12491266
if err != nil {
1250-
http.Error(w, "Failed to get sender address: "+err.Error(), http.StatusInternalServerError)
1267+
log.Errorf("Failed to get sender address: %v", err)
1268+
http.Error(w, "Failed to get sender address", http.StatusInternalServerError)
12511269
return
12521270
}
12531271

@@ -1285,7 +1303,8 @@ func (p *PDPService) handleDeleteProofSetRoot(w http.ResponseWriter, r *http.Req
12851303
return true, nil
12861304
}, harmonydb.OptionRetry())
12871305
if err != nil {
1288-
http.Error(w, "Failed to schedule delete root: "+err.Error(), http.StatusInternalServerError)
1306+
log.Errorf("Failed to schedule delete root: %v", err)
1307+
http.Error(w, "Failed to schedule delete root", http.StatusInternalServerError)
12891308
return
12901309
}
12911310

@@ -1341,7 +1360,8 @@ func (p *PDPService) handleGetProofSetRoot(w http.ResponseWriter, r *http.Reques
13411360
http.Error(w, "Root not found", http.StatusNotFound)
13421361
return
13431362
}
1344-
http.Error(w, "Failed to retrieve root: "+err.Error(), http.StatusInternalServerError)
1363+
log.Errorf("Failed to retrieve root: %v", err)
1364+
http.Error(w, "Failed to retrieve root", http.StatusInternalServerError)
13451365
return
13461366
}
13471367

@@ -1359,7 +1379,8 @@ func (p *PDPService) handleGetProofSetRoot(w http.ResponseWriter, r *http.Reques
13591379
ORDER BY subroot_offset
13601380
`, proofSetID, rootID)
13611381
if err != nil {
1362-
http.Error(w, "Failed to retrieve subroots: "+err.Error(), http.StatusInternalServerError)
1382+
log.Errorf("Failed to retrieve subroots: %v", err)
1383+
http.Error(w, "Failed to retrieve subroots", http.StatusInternalServerError)
13631384
return
13641385
}
13651386

0 commit comments

Comments
 (0)