Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion signature/policy_eval_signedby.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"errors"
"fmt"
"time"

"github.com/containers/image/v5/internal/multierr"
"github.com/containers/image/v5/internal/private"
Expand Down Expand Up @@ -40,7 +41,8 @@ func (pr *prSignedBy) isSignatureAuthorAccepted(ctx context.Context, image priva
}

// FIXME: move this to per-context initialization
mech, trustedIdentities, err := newEphemeralGPGSigningMechanism(data)
// Import the keys with a 60s timeout to avoid hanging indefinitely. see issues.redhat.com/browse/OCPBUGS-57893
mech, trustedIdentities, err := newEphemeralGPGSigningMechanismWithTimeout(data, 60*time.Second)
if err != nil {
return sarRejected, nil, err
}
Expand Down Expand Up @@ -114,3 +116,24 @@ func (pr *prSignedBy) isRunningImageAllowed(ctx context.Context, image private.U
}
return false, summary
}

func newEphemeralGPGSigningMechanismWithTimeout(blobs [][]byte, timeout time.Duration) (signingMechanismWithPassphrase, []string, error) {
type result struct {
mech signingMechanismWithPassphrase
keys []string
err error
}
done := make(chan result, 1)

go func() {
mech, keys, err := newEphemeralGPGSigningMechanism(blobs)
done <- result{mech, keys, err}
}()

select {
case <-time.After(timeout):
return nil, nil, fmt.Errorf("GPG/OpenPGP key import timed out after %s", timeout)
case r := <-done:
return r.mech, r.keys, r.err
}
}