fix(secretengine): report a full volume as an environment failure, not a bad credential (#1842)

This commit is contained in:
sam committed 2026-11-09 14:37:17 +11:00
1 parent 96236b6186
commit 70eef0ec99
3 files changed
+58 -5

No files matched your search

+37 -4
View File
@@ -5,7 +5,10 @@ import (
"encoding/json"
"errors"
"fmt"
"io/fs"
"path/filepath"
"strings"
"syscall"
"github.com/go-git/go-git/v6"
@@ -94,9 +97,9 @@ func (b *boot) openRepositoryConnection(ctx context.Context, principal access.Pr
if !connection.Permitted(string(principal.IdentityID), operation) {
return failure("operation_denied", fmt.Sprintf("Allow this agent to %s through %s before continuing.", operation, connection.Name))
}
token, err := b.secrets.Resolve(connection.Token)
if err != nil || token == "" {
return failure("credential_unavailable", fmt.Sprintf("The credential for %s is unavailable. Check its secret reference.", connection.Name))
token, code, message := b.connectionToken(ctx, connection)
if code != "" {
return failure(code, message)
}
host := strings.TrimRight(connection.Host, "/")
if !strings.Contains(host, "://") {
@@ -106,7 +109,10 @@ func (b *boot) openRepositoryConnection(ctx context.Context, principal access.Pr
cfg := b.cfgHolder.Get()
username := connection.Account
gitToken := token
var minted forge.GitCredential
var (
minted forge.GitCredential
err error
)
if issuer, ok := out.Forge.(forge.GitCredentialIssuer); ok {
minted, err = issuer.GitCredential(ctx, repository.Owner, repository.Name)
switch {
@@ -138,6 +144,33 @@ func (b *boot) openRepositoryConnection(ctx context.Context, principal access.Pr
return out, nil
}
// connectionToken resolves the connection's credential, or returns a failure
// code and message. A full volume is reported as such, not as a bad reference.
func (b *boot) connectionToken(ctx context.Context, connection config.ForgeConnection) (string, string, string) {
token, err := b.secrets.Resolve(connection.Token)
if volume, full := exhaustedVolume(err); full {
b.log.ErrorContext(ctx, "secret resolution failed: host resource exhausted", "connection", connection.ID, "volume", volume, "error", err)
return "", "environment_exhausted", fmt.Sprintf("The host has run out of space on %s, so the credential for %s cannot be read. Free space there.", volume, connection.Name)
}
if err != nil || token == "" {
return "", "credential_unavailable", fmt.Sprintf("The credential for %s is unavailable. Check its secret reference.", connection.Name)
}
return token, "", ""
}
// exhaustedVolume reports whether err is a full volume or quota and names the
// volume, so the failure reads as an environment problem rather than a
// misconfigured secret.
func exhaustedVolume(err error) (string, bool) {
if !errors.Is(err, syscall.ENOSPC) && !errors.Is(err, syscall.EDQUOT) {
return "", false
}
if pathErr, ok := errors.AsType[*fs.PathError](err); ok {
return filepath.Dir(pathErr.Path), true
}
return "the host volume", true
}
// commitIdentity is the author of commits made through a connection: its
// configured commit identity, else the identity the forge minted with the
// credential, else the root bot fields, else its account.