feat: authenticated Malysis analyzer with tenant exclusion support (#313)

* feat: authenticated Malysis analyzer with tenant exclusion support

When SafeDep Cloud credentials are available (keychain or environment),
PMG now uses an authenticated malware analysis query against
api.safedep.io instead of the unauthenticated community endpoint
(community-api.safedep.io). The API key and tenant ID are supplied via
the gRPC connection.

The authenticated response may carry a tenant-specific malicious package
exclusion. This is honored as an opt-in trust signal: a flagged package
is downgraded to allow only when a concrete exclusion (non-empty ID) is
present for the exact package version queried. Exclusions are never
honored for community queries and never weaken the verdict for packages
that were not flagged. Allowed-by-exclusion packages are surfaced as a
warning so the trust decision is never silent.

Changes are additive; non-authenticated usage is unchanged. Credential
resolution is extracted into internal/cloudauth and reused by both the
analyzer factory and the existing cloud sync client.

* fix: surface tenant exclusions in proxy mode; clarify comments

- Warn when proxy interceptor allows a flagged package due to a tenant
  exclusion, matching the guard flow so the trust decision is not silent.
- Remove stray doc comment above warnIfExcluded.
- Clarify that a verified-malware verdict can be downgraded by an
  exclusion in applyExclusion.

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Abhisek Datta
2026-06-01 15:32:22 +05:30
committed by GitHub
co-authored by Claude
parent 5018f8e2ff
commit f6e1d9e733
10 changed files with 331 additions and 61 deletions
+27
View File
@@ -0,0 +1,27 @@
package analyzer
import (
"github.com/safedep/dry/log"
"github.com/safedep/pmg/internal/cloudauth"
)
// NewMalysisAnalyzer creates the malysis query analyzer best suited for the
// current environment. When SafeDep Cloud credentials are available (via
// keychain or environment), it returns an authenticated analyzer that queries
// api.safedep.io and honors tenant-specific package exclusions. Otherwise it
// falls back to the unauthenticated community analyzer.
func NewMalysisAnalyzer(config MalysisQueryAnalyzerConfig) (PackageVersionAnalyzer, error) {
creds, closeResolver, err := cloudauth.ResolveCredentials()
if err != nil {
log.Debugf("SafeDep Cloud credentials unavailable, using community malysis analyzer: %v", err)
return NewMalysisQueryAnalyzer(config)
}
defer func() {
if closeErr := closeResolver(); closeErr != nil {
log.Warnf("failed to close credential resolver: %v", closeErr)
}
}()
log.Debugf("SafeDep Cloud credentials found, using authenticated malysis analyzer")
return NewMalysisAuthenticatedQueryAnalyzer(config, creds)
}