Skip to content

Commit 70689a3

Browse files
committed
Skip keyless verification for private third-party plugins
1 parent d3752d8 commit 70689a3

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

plugin/install.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,22 @@ func (c *InstallConfig) Install() (string, error) {
161161

162162
} else {
163163
// Attempt to verify by artifact attestations.
164-
// If there are no attestations, it will be ignored without errors.
164+
repo, err := c.fetchRepository()
165+
if err != nil {
166+
return "", fmt.Errorf("Failed to get GitHub repository metadata: %s", err)
167+
}
168+
// If the repository is private, artifact attestations is not always available
169+
// because it requires GitHub Enterprise Cloud plan, so we skip verification here.
170+
if repo.Private != nil && *repo.Private {
171+
skipVerify = true
172+
}
173+
165174
log.Printf("[DEBUG] Download artifact attestations")
166175
attestations, err := c.fetchArtifactAttestations(checksumsFile)
167176
if err != nil {
168177
var gerr *github.ErrorResponse
169-
// If experimental mode is enabled, enforces that attestations are present.
178+
// If there are no attestations, it will be ignored without errors.
179+
// However, experimental mode is enabled, enforces that attestations are present.
170180
if errors.As(err, &gerr) && gerr.Response.StatusCode == 404 && !IsExperimentalModeEnabled() {
171181
log.Printf("[DEBUG] Artifact attestations not found and will be ignored: %s", err)
172182
skipVerify = true
@@ -239,6 +249,18 @@ func (c *InstallConfig) fetchReleaseAssets() (map[string]*github.ReleaseAsset, e
239249
return assets, nil
240250
}
241251

252+
// fetchRepository fetches GitHub repository metadata.
253+
func (c *InstallConfig) fetchRepository() (*github.Repository, error) {
254+
ctx := context.Background()
255+
client, err := newGitHubClient(ctx, c)
256+
if err != nil {
257+
return nil, err
258+
}
259+
260+
repo, _, err := client.Repositories.Get(ctx, c.SourceOwner, c.SourceRepo)
261+
return repo, err
262+
}
263+
242264
// fetchArtifactAttestations fetches GitHub Artifact Attestations based on the given io.ReadSeeker.
243265
func (c *InstallConfig) fetchArtifactAttestations(artifact io.ReadSeeker) ([]*github.Attestation, error) {
244266
bytes, err := io.ReadAll(artifact)

0 commit comments

Comments
 (0)