Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ benchmarks/data/** linguist-vendored
*.whl binary

# --- Source archive hygiene (excluded from `git archive`) -----------------
.github export-ignore
# `.github/` must stay in archives. GitHub's generated source tarballs honour
# export-ignore, and OpenSSF Scorecard reads workflow files from that tarball:
# excluding it makes SAST, Token-Permissions, Pinned-Dependencies and
# Dangerous-Workflow see zero workflows and score them 0/inconclusive.
.shared-templates export-ignore
.gitattributes export-ignore
.gitignore export-ignore
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
name: CodeQL

# Static analysis for Go. Runs on every push to main (so Scorecard's SAST
# check sees analyses for default-branch commits) and weekly to pick up new
# CodeQL queries without waiting for a code change.
# Static analysis for Go. Runs on pull requests and every push to main, so
# findings are caught before merge and Scorecard's SAST check sees analyses
# for both PR head commits and default-branch commits. Runs weekly to pick up
# new CodeQL queries without waiting for a code change.
on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: "30 4 * * 1"
workflow_dispatch:
Expand Down
63 changes: 63 additions & 0 deletions internal/testaudit/archive_hygiene_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package testaudit

import (
"archive/tar"
"bytes"
"compress/gzip"
"errors"
"io"
"os"
"os/exec"
"path/filepath"
"testing"
)

// GitHub's generated source tarballs honour export-ignore from .gitattributes,
// and tarball-based scanners (OpenSSF Scorecard) read workflow files from
// those archives. Marking .github/ as export-ignore therefore drops every
// workflow, making SAST, Token-Permissions, Pinned-Dependencies and
// Dangerous-Workflow see zero workflows and score 0 or inconclusive.
//
// `git check-attr` does not resolve directory patterns the way archive
// generation does, so this test inspects a real `git archive HEAD`.
func TestSourceArchivesIncludeCI(t *testing.T) {
root := repoRoot(t)

if _, err := os.Stat(filepath.Join(root, ".git")); err != nil {
t.Skip("not a git checkout")
}
if _, err := exec.LookPath("git"); err != nil {
t.Skip("git not installed")
}

var buf bytes.Buffer
cmd := exec.Command("git", "-C", root, "archive", "--format=tar.gz", "HEAD")
cmd.Stdout = &buf
if err := cmd.Run(); err != nil {
t.Fatalf("git archive HEAD: %v", err)
}

gz, err := gzip.NewReader(&buf)
if err != nil {
t.Fatalf("gzip.NewReader: %v", err)
}
defer gz.Close()

tr := tar.NewReader(gz)
for {
hdr, err := tr.Next()
if errors.Is(err, io.EOF) {
break
}
if err != nil {
t.Fatalf("tar reader: %v", err)
}
if hdr.Name == ".github/workflows/ci.yml" {
return
}
}

t.Fatal(".github/workflows/ci.yml is missing from `git archive HEAD`; " +
"an export-ignore rule in .gitattributes hides CI configuration from " +
"source archives and tarball-based scanners")
}
Loading