computePolicyHash computes a deterministic 8-character hex hash of the allow-only policy. Returns noPolicySentinel when the GitHub tool has no guard policy (i.e., min-integrity is unset). The hash is computed over the canonical form of all policy fields so that: - Same policy in different order → s
(github *GitHubToolConfig)
| 27 | // - Any policy field change → new hash → cache miss (correct isolation) |
| 28 | // - Workflows without policy → sentinel value "nopolicy" (consistent key format) |
| 29 | func computePolicyHash(github *GitHubToolConfig) string { |
| 30 | if github == nil || github.MinIntegrity == "" { |
| 31 | cacheIntegrityLog.Print("No guard policy configured, using nopolicy sentinel") |
| 32 | return noPolicySentinel |
| 33 | } |
| 34 | |
| 35 | canonical := buildCanonicalPolicy(github) |
| 36 | hash := sha256.Sum256([]byte(canonical)) |
| 37 | result := hex.EncodeToString(hash[:])[:8] |
| 38 | cacheIntegrityLog.Printf("Computed policy hash: %s (min-integrity=%s)", result, github.MinIntegrity) |
| 39 | return result |
| 40 | } |
| 41 | |
| 42 | // buildCanonicalPolicy builds the normalized string representation of the allow-only policy. |
| 43 | // All fields are always present (empty if unset), sorted and deduplicated, so the result |