getsops/sops · error

failed to decrypt sops data key with pgp: zero bytes returne

Error message

failed to decrypt sops data key with pgp: zero bytes returned

What it means

Error "failed to decrypt sops data key with pgp: zero bytes returned" thrown in getsops/sops.

Source

Thrown at pgp/keysource.go:466

// the error from stdout.
func (key *MasterKey) decryptWithGnuPG(ctx context.Context) ([]byte, error) {
	args := []string{
		"-d",
	}
	stdout, stderr, err := gpgExec(ctx, key.gnuPGHomeDir, args, strings.NewReader(key.EncryptedKey))
	if err != nil {
		return nil, fmt.Errorf("failed to decrypt sops data key with pgp: %s",
			strings.TrimSpace(stderr.String()))
	}
	result := stdout.Bytes()
	if len(result) == 0 {
		// This can happen if an older GnuPG version is used to decrypt a key encrypted with a
		// newer GnuPG version that used an AEAD cipher, which the old version does not support.
		// Apparently some GnuPG versions drop the unspuported packets, which results in a decrypted
		// data of 0 bytes, and returns nothing with exit code 0.
		//
		// (See https://github.com/getsops/sops/issues/896#issuecomment-2688079300 for more infos.)
		return nil, fmt.Errorf("failed to decrypt sops data key with pgp: zero bytes returned")
	}
	return result, nil
}

// NeedsRotation returns whether the data key needs to be rotated
// or not.
func (key *MasterKey) NeedsRotation() bool {
	return time.Since(key.CreationDate) > (pgpTTL)
}

// ToString returns the string representation of the key, i.e. its
// fingerprint.
func (key *MasterKey) ToString() string {
	return key.Fingerprint
}

// ToMap converts the MasterKey into a map for serialization purposes.
func (key MasterKey) ToMap() map[string]interface{} {

View on GitHub (pinned to 13442bb981)

When it happens

Trigger: Thrown at pgp/keysource.go:466 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of getsops/sops@13442bb981 (2026-09-01). Data as JSON: /api/errors/07d479d516c256f6. Report an issue: GitHub.