Skip to content
Open
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
3 changes: 3 additions & 0 deletions skills/ai-security/model-supply-chain/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .model_supply_chain import ModelSupplyChain

__all__ = ["ModelSupplyChain"]
43 changes: 43 additions & 0 deletions skills/ai-security/model-supply-chain/model_supply_chain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from skills import Skill
from skills.helper import get_model_provenance

class ModelSupplyChain(Skill):
def __init__(self):
super().__init__()
self.potential_provenance_gates = [
"trust_remote_code",
"final_artifact_provenance",
"signed_slsa_attestation",
]

def audit(self, code):
# Existing code to check for model supply chain issues
# ...

# Check for trust_remote_code=True
if "from_pretrained" in code and "trust_remote_code=True" in code:
self.issues.append("Model loaded with trust_remote_code=True")

# Check for final artifact provenance
if "snapshot_download" in code:
model_dir = get_model_provenance(code)
if not model_dir:
self.issues.append("Model loaded without final artifact provenance")

# Check for signed SLSA attestation
if "signed_slsa_attestation" in code:
attestation = get_model_provenance(code)
if not attestation:
self.issues.append("Model loaded without signed SLSA attestation")

return self.issues

def get_provenance_gates(self):
return self.potential_provenance_gates

def get_model_provenance(code):
# Implement logic to extract model provenance from code
# For example, parse the code to extract the model directory
# or the signed SLSA attestation
# ...
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import unittest
from skills.ai_security.model_supply_chain.model_supply_chain import ModelSupplyChain

class TestModelSupplyChain(unittest.TestCase):
def test_audit(self):
code = """
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained(
"research-lab/custom-architecture-llm",
revision="main",
trust_remote_code=True,
)
"""
skill = ModelSupplyChain()
issues = skill.audit(code)
self.assertIn("Model loaded with trust_remote_code=True", issues)

def test_get_provenance_gates(self):
skill = ModelSupplyChain()
gates = skill.get_provenance_gates()
self.assertIn("trust_remote_code", gates)
self.assertIn("final_artifact_provenance", gates)
self.assertIn("signed_slsa_attestation", gates)