### Example OSA Pattern Data Structure (JSON) Source: https://github.com/opensecurityarchitecture/osa-data/blob/main/README.md Demonstrates the structure of a security pattern, including metadata, diagram paths, content details, applicable NIST 800-53 controls, and compliance mappings. ```json { "id": "SP-011", "title": "Cloud Computing Pattern", "metadata": { "status": "published", "authors": ["Phaedrus"] }, "controls": [ {"id": "AC-01", "name": "Access Control Policies and Procedures", "family": "AC"}, {"id": "SC-07", "name": "Boundary Protection", "family": "SC"} ], "controlFamilySummary": {"AC": 5, "SC": 12, "SA": 8} } ``` -------------------------------- ### List NIST CSF 2.0 Functions using jq Source: https://context7.com/opensecurityarchitecture/osa-data/llms.txt This example shows how to access and list the functions defined within the NIST Cybersecurity Framework 2.0 structure from a JSON file. It uses jq to iterate through the functions and display their ID, name, and description. ```bash # List all CSF 2.0 functions jq -r '.functions[] | "\(.id): \(.name) - \(.description)"' csf-2.json # Output: # GV: Govern - The organization's cybersecurity risk management strategy... ``` -------------------------------- ### Read Control Manifest using jq Source: https://context7.com/opensecurityarchitecture/osa-data/llms.txt This section demonstrates how to query the control manifest file (`_manifest.json`) to enumerate NIST 800-53 Rev 5 controls. Examples include filtering controls by family, counting controls per family, and determining the number of controls in a specific baseline (e.g., Low). ```bash # Get all controls in a specific family jq -r '.controls[] | select(.family == "AC") | "\(.id): \(.name)"' data/controls/_manifest.json # Count controls by family jq -r '[.controls[].family] | group_by(.) | .[] | "\(.[0]): \(length)"' data/controls/_manifest.json # Output: AC: 20, AT: 5, AU: 11, CA: 7, CM: 8, CP: 10, ... # Get controls in Low baseline jq -r '.controls[] | select(.baseline_low == true) | .id' data/controls/_manifest.json | wc -l # Output: 191 ``` -------------------------------- ### Extract Controls for a Pattern using jq Source: https://context7.com/opensecurityarchitecture/osa-data/llms.txt This section shows how to extract specific control information associated with a security pattern. It covers retrieving all control IDs, filtering for critical controls, and grouping controls by their respective families. The examples use a specific pattern file for demonstration. ```bash # Get all control IDs for Cloud Computing pattern jq '.controls[].id' data/patterns/SP-011-pattern-cloud-computing.json # Output: "AC-01", "AC-02", "AC-03", "AC-04", "AC-13", "AT-01", ... # Get critical controls only jq -r '.controls[] | select(.emphasis == "critical") | "\(.id): \(.name)"' data/patterns/SP-011-pattern-cloud-computing.json # Output: # AC-02: Account Management # AC-03: Access Enforcement # AU-06: Audit Monitoring, Analysis, And Reporting # CA-07: Continuous Monitoring # CM-02: Baseline Configuration # IA-02: User Identification And Authentication # SA-09: External Information System Services # Get controls grouped by family jq -r '[.controls[] | {family, id, name}] | group_by(.family) | .[] | "\(.[0].family): \([.[].id] | join(", "))"' data/patterns/SP-011-pattern-cloud-computing.json ``` -------------------------------- ### Build Control to Pattern Index (Python) Source: https://context7.com/opensecurityarchitecture/osa-data/llms.txt This Python script constructs a reverse index mapping control IDs to the patterns that utilize them. It iterates through pattern files, extracts control references, and stores them in a dictionary for efficient lookup. The example shows how to find all patterns referencing a specific control. ```python import json from pathlib import Path from collections import defaultdict def build_control_to_pattern_index(): """Build an index of which patterns use each control.""" index = defaultdict(list) patterns_dir = Path("data/patterns") for pattern_file in patterns_dir.glob("SP-*.json"): if pattern_file.name.startswith("_"): continue with open(pattern_file) as f: pattern = json.load(f) pattern_ref = {"id": pattern["id"], "title": pattern["title"]} for control in pattern.get("controls", []): index[control["id"]].append(pattern_ref) return dict(index) # Find all patterns that reference AC-02 (Account Management) index = build_control_to_pattern_index() print("Patterns using AC-02 (Account Management):") for p in index.get("AC-02", []): print(f" {p['id']}: {p['title']}") ``` -------------------------------- ### Validate OSA JSON Files with ajv-cli (Bash) Source: https://github.com/opensecurityarchitecture/osa-data/blob/main/README.md Provides commands to install and use the `ajv-cli` tool for validating JSON files against provided schemas. This ensures data integrity for patterns and controls. ```bash # Using ajv-cli npm install -g ajv-cli ajv validate -s data/schema/pattern.schema.json -d "data/patterns/*.json" ajv validate -s data/schema/control.schema.json -d "data/controls/*.json" ``` -------------------------------- ### Example NIST 800-53 Control Data Structure (JSON) Source: https://github.com/opensecurityarchitecture/osa-data/blob/main/README.md Illustrates the data format for a NIST 800-53 control, including its ID, name, family, description, baseline indicators, and legacy compliance mappings. ```json { "id": "AC-04", "name": "Information Flow Enforcement", "family": "AC", "family_name": "Access Control", "control_class": "Technical", "baseline_low": true, "baseline_moderate": true, "baseline_high": true, "iso17799": ["10.6.2", "11.4.5"], "cobit41": ["DS5.10"], "pci_dss_v2": ["4.1"] } ``` -------------------------------- ### Get Threats and Mitigating Controls for a Pattern (jq) Source: https://context7.com/opensecurityarchitecture/osa-data/llms.txt This jq command extracts detailed information about threats within a specific pattern file, including their IDs, names, and the controls that mitigate them. It's useful for understanding the security posture of a given pattern. ```bash jq -r '.threats[] | "\(.id) - \(.name)\n Mitigated by: \(.mitigatedBy | join(", "))\n"' data/patterns/SP-011-pattern-cloud-computing.json ``` -------------------------------- ### Get Categories by Function (jq) Source: https://context7.com/opensecurityarchitecture/osa-data/llms.txt This command uses jq to filter and extract category IDs and names from a JSON file based on a specified function. It's useful for understanding the categories associated with different security functions. ```bash jq -r '.categories[] | select(.function == "PR") | "\(.id): \(.name)"' csf-2.json ``` -------------------------------- ### Bash Command for Pushing to GitHub Source: https://github.com/opensecurityarchitecture/osa-data/blob/main/CLAUDE.md This bash command is used to push the local changes in the repository to the main branch on GitHub. It assumes that the repository has already been initialized and a remote origin is configured. ```bash git push origin main ``` -------------------------------- ### Read Pattern Manifest using jq Source: https://context7.com/opensecurityarchitecture/osa-data/llms.txt This snippet shows how to access and query the pattern manifest file (`_manifest.json`) to retrieve information about available security patterns. It covers listing published patterns, identifying draft patterns, and counting patterns by their status. ```bash # Get all published patterns jq -r '.patterns[] | select(.status != "draft" and .status != "test") | "\(.id): \(.title) (\(.controls) controls)"' data/patterns/_manifest.json # Get draft patterns (in development) jq -r '.patterns[] | select(.status == "draft") | "\(.id): \(.title)"' data/patterns/_manifest.json # Output: # SP-012: Secure Software Development Lifecycle # SP-027: Secure AI Integration # SP-029: Zero Trust Architecture # SP-030: API Security # ... # Pattern counts by status jq -r '[.patterns[].status // "published"] | group_by(.) | .[] | "\(.[0]): \(length)"' data/patterns/_manifest.json # Output: draft: 17, published: 25, test: 1 ``` -------------------------------- ### Query Patterns by Control Family using jq Source: https://context7.com/opensecurityarchitecture/osa-data/llms.txt This snippet demonstrates how to use jq to filter and display security patterns based on their control family summaries. It allows users to find patterns with specific control requirements or counts within a given family. The output format is customizable. ```bash # Find patterns with more than 5 Access Control (AC) requirements jq -r 'select(.controlFamilySummary.AC > 5) | "\(.id): \(.title) (AC: \(.controlFamilySummary.AC))"' data/patterns/*.json # Output: # SP-001: Client Module (AC: 12) # SP-002: Server Module (AC: 14) # SP-029: Zero Trust Architecture (AC: 15) # Find all patterns with System and Communications Protection (SC) controls jq -r 'select(.controlFamilySummary.SC != null) | "\(.id): \(.title) - SC controls: \(.controlFamilySummary.SC)"' data/patterns/*.json # List patterns by total control count (sorted) jq -r '"\(.controls | length)\t\(.id)\t\(.title)"' data/patterns/*.json | sort -rn | head -10 ``` -------------------------------- ### Load and Query Pattern Data (Python) Source: https://context7.com/opensecurityarchitecture/osa-data/llms.txt This Python script demonstrates how to load pattern manifest and specific pattern data from JSON files using the `pathlib` and `json` modules. It shows how to access metadata like total patterns and extract specific information, such as critical controls within a pattern. ```python import json from pathlib import Path # Load pattern manifest manifest_path = Path("data/patterns/_manifest.json") with open(manifest_path) as f: manifest = json.load(f) print(f"Total patterns: {manifest['total_patterns']}") # Load a specific pattern pattern_file = Path("data/patterns/SP-011-pattern-cloud-computing.json") with open(pattern_file) as f: cloud_pattern = json.load(f) # Get critical controls critical_controls = [c for c in cloud_pattern["controls"] if c.get("emphasis") == "critical"] print(f"\nCritical controls for {cloud_pattern['title']}:") for ctrl in critical_controls: print(f" {ctrl['id']}: {ctrl['name']}") ``` -------------------------------- ### Bash Command for Navigating to Workspace Source: https://github.com/opensecurityarchitecture/osa-data/blob/main/CLAUDE.md This bash command changes the current directory to the specified OSA workspace path. This is typically the first step before running any other commands within the project. ```bash cd /Users/russellwing/osa-workspace ``` -------------------------------- ### Look Up Control Compliance Mappings using jq Source: https://context7.com/opensecurityarchitecture/osa-data/llms.txt This snippet illustrates how to query compliance framework mappings for NIST 800-53 controls. It demonstrates retrieving all mappings for a control, finding controls mapped to a specific requirement in a framework (like PCI-DSS), and identifying controls with specific compliance references (like SOC 2 CC6.1). ```bash # Get all compliance mappings for AC-04 (Information Flow Enforcement) jq '.compliance_mappings' data/controls/AC-04.json # Output: # { # "iso_27002_2022": ["5.14", "8.20", "8.3"], # "pci_dss_v4": ["1.1", "1.3", "1.3.1", "1.3.2", "1.4.2", "1.4.3"], # "cis_controls_v8": ["12.6", "13.4", "3.3", "4.6"], # "soc2_tsc": ["CC6.1", "CC6.1-POF6", "CC6.6", "CC6.6-POF6"] # } # Find all controls mapped to a specific PCI-DSS requirement for f in data/controls/*.json; do jq -r --arg req "1.3" 'select(.compliance_mappings.pci_dss_v4 | index($req)) | "\(.id): \(.name)"' "$f" 2>/dev/null done # Output: AC-04: Information Flow Enforcement, SC-07: Boundary Protection, ... # Get controls with SOC 2 CC6.1 mapping jq -r 'select(.compliance_mappings.soc2_tsc | index("CC6.1")) | .id' data/controls/*.json ``` -------------------------------- ### Validate JSON Files using Python and ajv-cli Source: https://context7.com/opensecurityarchitecture/osa-data/llms.txt This section provides methods for validating OSA JSON files against their respective schemas. It includes using a built-in Python script for validation and demonstrates how to use the `ajv-cli` tool for JSON schema validation, specifying schema and data file paths. ```bash # Using the built-in validation script python3 scripts/validate_json.py # Output: # Validating OSA JSON data files # # Patterns: # OK: SP-001-0802pattern-001.json # OK: SP-002-0802pattern-002.json # ... # # Controls: # OK: AC-01.json # OK: AC-02.json # ... # # Validation complete: 234 files OK, 0 errors # Using ajv-cli for schema validation npm install -g ajv-cli ajv validate -s data/schema/pattern.schema.json -d "data/patterns/SP-011*.json" ajv validate -s data/schema/control.schema.json -d "data/controls/AC-*.json" ``` -------------------------------- ### Find Patterns by Threat Type (jq) Source: https://context7.com/opensecurityarchitecture/osa-data/llms.txt This jq command filters pattern JSON files to find those addressing specific threat types, identified by keywords in their 'threats.name' field. It outputs the ID and title of matching patterns. ```bash jq -r 'select(.threats != null) | select(.threats[].name | test("Credential|Authentication"; "i")) | "\(.id): \(.title)"' data/patterns/*.json ``` -------------------------------- ### Find Patterns with High Access Control Requirements (jq) Source: https://github.com/opensecurityarchitecture/osa-data/blob/main/README.md This jq command filters JSON files in the 'data/patterns/' directory to find patterns where the 'AC' (Access Control) score in 'controlFamilySummary' is greater than 5. It outputs the pattern ID, title, and its AC score. ```bash jq -r 'select(.controlFamilySummary.AC > 5) | "\(.id): \(.title) (AC: \(.controlFamilySummary.AC))"' data/patterns/*.json ``` -------------------------------- ### Extract Control IDs for a Specific Pattern (jq) Source: https://github.com/opensecurityarchitecture/osa-data/blob/main/README.md This jq command extracts all control IDs from a specified pattern JSON file. It targets the 'controls' array within the JSON and outputs each 'id' found. ```bash jq '.controls[].id' data/patterns/SP-011-pattern-cloud-computing.json ``` -------------------------------- ### Python Script for Validating JSON Files Source: https://github.com/opensecurityarchitecture/osa-data/blob/main/CLAUDE.md This Python script is used to validate all JSON files within the workspace. It ensures data integrity and adherence to schema definitions. It is typically run as part of the CI validation workflow. ```python import os import json def validate_json_files(directory): for root, _, files in os.walk(directory): for file in files: if file.endswith(".json"): filepath = os.path.join(root, file) try: with open(filepath, 'r') as f: json.load(f) print(f"Successfully validated: {filepath}") except json.JSONDecodeError as e: print(f"Error decoding JSON in {filepath}: {e}") except Exception as e: print(f"An unexpected error occurred with {filepath}: {e}") if __name__ == "__main__": workspace_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) data_dir = os.path.join(workspace_dir, 'data') scripts_dir = os.path.join(workspace_dir, 'scripts') # Validate data JSONs print("--- Validating data directory ---") validate_json_files(data_dir) # Validate schema JSONs print("\n--- Validating schema directory ---") schema_dir = os.path.join(data_dir, 'schema') validate_json_files(schema_dir) # Validate specific scripts if they contain JSON or related logic # For this example, we assume validate_json.py itself is the script to run # and its own validation is implicit in its execution. print("\n--- Validation complete ---") ``` -------------------------------- ### Load Control Data and PCI Mappings (Python) Source: https://context7.com/opensecurityarchitecture/osa-data/llms.txt This Python code defines functions to load NIST 800-53 control data by ID and retrieve PCI-DSS v4 compliance mappings. It iterates through a list of access control IDs to display their corresponding PCI requirements, facilitating compliance analysis. ```python import json from pathlib import Path def get_control(control_id: str) -> dict: """Load a NIST 800-53 control by ID.""" control_path = Path(f"data/controls/{control_id}.json") with open(control_path) as f: return json.load(f) def get_pci_mappings(control_id: str) -> list: """Get PCI-DSS v4 requirements mapped to a control.""" control = get_control(control_id) return control.get("compliance_mappings", {}).get("pci_dss_v4", []) # Example: Get PCI-DSS mappings for access control requirements ac_controls = ["AC-01", "AC-02", "AC-03", "AC-04"] for ctrl_id in ac_controls: pci_reqs = get_pci_mappings(ctrl_id) if pci_reqs: print(f"{ctrl_id}: PCI-DSS {', '.join(pci_reqs)}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.