more logging to troubleshoot crew management

This commit is contained in:
Evan Jarrett
2025-10-25 08:54:44 -05:00
parent 2026780e11
commit 8201d9977d
3 changed files with 20 additions and 0 deletions
+5
View File
@@ -97,13 +97,18 @@ func (p *ProxyBlobStore) checkWriteAccess(ctx context.Context) error {
if p.ctx.Authorizer == nil {
return nil // No authorization check if authorizer not configured
}
fmt.Printf("[checkWriteAccess] Checking write access for userDID=%s to holdDID=%s\n", p.ctx.DID, p.ctx.HoldDID)
allowed, err := p.ctx.Authorizer.CheckWriteAccess(ctx, p.ctx.HoldDID, p.ctx.DID)
if err != nil {
fmt.Printf("[checkWriteAccess] Authorization check error: %v\n", err)
return fmt.Errorf("authorization check failed: %w", err)
}
if !allowed {
fmt.Printf("[checkWriteAccess] Write access DENIED for userDID=%s to holdDID=%s\n", p.ctx.DID, p.ctx.HoldDID)
return fmt.Errorf("write access denied to hold %s", p.ctx.HoldDID)
}
fmt.Printf("[checkWriteAccess] Write access ALLOWED for userDID=%s to holdDID=%s\n", p.ctx.DID, p.ctx.HoldDID)
return nil
}
+9
View File
@@ -55,18 +55,27 @@ func CheckReadAccessWithCaptain(captain *atproto.CaptainRecord, userDID string)
// - Must be authenticated
// - Must be hold owner OR crew member
func CheckWriteAccessWithCaptain(captain *atproto.CaptainRecord, userDID string, isCrew bool) bool {
fmt.Printf("[CheckWriteAccessWithCaptain] userDID=%s captain.Owner=%s isCrew=%v\n", userDID, captain.Owner, isCrew)
if userDID == "" {
// Anonymous writes not allowed
fmt.Printf("[CheckWriteAccessWithCaptain] DENIED: Anonymous user\n")
return false
}
// Check if DID is the hold owner
if userDID == captain.Owner {
// Owner always has write access
fmt.Printf("[CheckWriteAccessWithCaptain] ALLOWED: User is hold owner\n")
return true
}
// Check if DID is a crew member
if isCrew {
fmt.Printf("[CheckWriteAccessWithCaptain] ALLOWED: User is crew member\n")
} else {
fmt.Printf("[CheckWriteAccessWithCaptain] DENIED: User is not owner or crew\n")
}
return isCrew
}
+6
View File
@@ -265,27 +265,33 @@ func (a *RemoteHoldAuthorizer) IsCrewMember(ctx context.Context, holdDID, userDI
// Check approval cache first (15min TTL)
if approved, err := a.getCachedApproval(holdDID, userDID); err == nil && approved {
fmt.Printf("[IsCrewMember] Using cached APPROVAL: holdDID=%s userDID=%s\n", holdDID, userDID)
return true, nil
}
// Check denial cache with backoff
if blocked, err := a.isBlockedByDenialBackoff(holdDID, userDID); err == nil && blocked {
// Still in backoff period - don't query again
fmt.Printf("[IsCrewMember] BLOCKED by denial backoff cache: holdDID=%s userDID=%s\n", holdDID, userDID)
return false, nil
}
// Cache miss or expired - query XRPC endpoint
fmt.Printf("[IsCrewMember] Cache miss, querying hold: holdDID=%s userDID=%s\n", holdDID, userDID)
isCrew, err := a.isCrewMemberNoCache(ctx, holdDID, userDID)
if err != nil {
fmt.Printf("[IsCrewMember] Query error: %v\n", err)
return false, err
}
// Update cache based on result
if isCrew {
// Cache approval for 15 minutes
fmt.Printf("[IsCrewMember] Query result: APPROVED, caching for 15min\n")
_ = a.cacheApproval(holdDID, userDID, 15*time.Minute)
} else {
// Cache denial with exponential backoff
fmt.Printf("[IsCrewMember] Query result: DENIED, caching with backoff\n")
_ = a.cacheDenial(holdDID, userDID)
}