fix(staterpc): log the cause of run credential lookup failures (#1808)
This commit is contained in:
3 files changed
+23
-6
No files matched your search
@@ -390,7 +390,7 @@ func (b *server) runCredentials(ctx context.Context) (*staterpc.TaskGrants, erro
|
|||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("state store does not support run credentials")
|
return nil, fmt.Errorf("state store does not support run credentials")
|
||||||
}
|
}
|
||||||
grants := &staterpc.TaskGrants{Store: store}
|
grants := &staterpc.TaskGrants{Store: store, Log: b.log}
|
||||||
if err := grants.Sweep(ctx); err != nil {
|
if err := grants.Sweep(ctx); err != nil {
|
||||||
return nil, fmt.Errorf("sweep expired run credentials: %w", err)
|
return nil, fmt.Errorf("sweep expired run credentials: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ func (s *server) harnessOrg(ctx context.Context, credential string) (string, err
|
|||||||
}
|
}
|
||||||
id, err := s.deps.Grants.taskFor(ctx, credential)
|
id, err := s.deps.Grants.taskFor(ctx, credential)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", status.Error(codes.Unavailable, "run credentials unavailable")
|
return "", s.deps.Grants.unavailable(ctx, "harnessOrg", err)
|
||||||
}
|
}
|
||||||
if id == 0 {
|
if id == 0 {
|
||||||
return "", status.Error(codes.Unauthenticated, "invalid task grant")
|
return "", status.Error(codes.Unauthenticated, "invalid task grant")
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
@@ -30,6 +31,22 @@ import (
|
|||||||
// expires.
|
// expires.
|
||||||
type TaskGrants struct {
|
type TaskGrants struct {
|
||||||
Store storecontract.RunCredentialStore
|
Store storecontract.RunCredentialStore
|
||||||
|
// Log records the cause of a credential store failure, which the caller
|
||||||
|
// only sees as unavailable. Nil discards.
|
||||||
|
Log *slog.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
// unavailable logs a credential store failure and returns what the caller is
|
||||||
|
// told. Context cancellation is the caller going away, not a fault.
|
||||||
|
func (g *TaskGrants) unavailable(ctx context.Context, rpc string, err error, attrs ...any) error {
|
||||||
|
if g.Log != nil {
|
||||||
|
level := slog.LevelError
|
||||||
|
if errors.Is(err, context.Canceled) {
|
||||||
|
level = slog.LevelDebug
|
||||||
|
}
|
||||||
|
g.Log.Log(ctx, level, "run credential store failed", append([]any{"rpc", rpc, "err", err}, attrs...)...)
|
||||||
|
}
|
||||||
|
return status.Error(codes.Unavailable, "run credentials unavailable")
|
||||||
}
|
}
|
||||||
|
|
||||||
// maxGrantLifetime caps any requested lifetime.
|
// maxGrantLifetime caps any requested lifetime.
|
||||||
@@ -167,7 +184,7 @@ func (g *TaskGrants) UnaryInterceptor() grpc.UnaryServerInterceptor {
|
|||||||
}
|
}
|
||||||
taskID, err := g.taskFor(ctx, token)
|
taskID, err := g.taskFor(ctx, token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, status.Error(codes.Unavailable, "run credentials unavailable")
|
return nil, g.unavailable(ctx, info.FullMethod, err)
|
||||||
}
|
}
|
||||||
if taskID == 0 {
|
if taskID == 0 {
|
||||||
return nil, status.Error(codes.Unauthenticated, "invalid task grant")
|
return nil, status.Error(codes.Unauthenticated, "invalid task grant")
|
||||||
@@ -215,7 +232,7 @@ func (s *taskGrantServer) RegisterTaskGrant(ctx context.Context, r *pb.RegisterT
|
|||||||
if _, ok := status.FromError(err); ok {
|
if _, ok := status.FromError(err); ok {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return nil, status.Error(codes.Unavailable, "run credentials unavailable")
|
return nil, s.deps.Grants.unavailable(ctx, "RegisterTaskGrant", err, "task", r.TaskId)
|
||||||
}
|
}
|
||||||
// No run starts unaudited: a start whose audit cannot be written is
|
// No run starts unaudited: a start whose audit cannot be written is
|
||||||
// undone.
|
// undone.
|
||||||
@@ -231,7 +248,7 @@ func (s *taskGrantServer) RevokeTaskGrant(ctx context.Context, r *pb.RevokeTaskG
|
|||||||
return nil, status.Error(codes.Unavailable, "task grants unavailable")
|
return nil, status.Error(codes.Unavailable, "task grants unavailable")
|
||||||
}
|
}
|
||||||
if err := s.deps.Grants.revoke(ctx, r.Token); err != nil {
|
if err := s.deps.Grants.revoke(ctx, r.Token); err != nil {
|
||||||
return nil, status.Error(codes.Unavailable, "run credentials unavailable")
|
return nil, s.deps.Grants.unavailable(ctx, "RevokeTaskGrant", err)
|
||||||
}
|
}
|
||||||
return &pb.RevokeTaskGrantResponse{}, nil
|
return &pb.RevokeTaskGrantResponse{}, nil
|
||||||
}
|
}
|
||||||
@@ -245,7 +262,7 @@ func (s *taskGrantServer) ResolveTaskGrant(ctx context.Context, r *pb.ResolveTas
|
|||||||
}
|
}
|
||||||
id, err := s.deps.Grants.taskFor(ctx, r.GetToken())
|
id, err := s.deps.Grants.taskFor(ctx, r.GetToken())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, status.Error(codes.Unavailable, "run credentials unavailable")
|
return nil, s.deps.Grants.unavailable(ctx, "ResolveTaskGrant", err)
|
||||||
}
|
}
|
||||||
if id == 0 {
|
if id == 0 {
|
||||||
return nil, status.Error(codes.NotFound, "run credential unknown or expired")
|
return nil, status.Error(codes.NotFound, "run credential unknown or expired")
|
||||||
|
|||||||
Reference in new issue
Block a user