{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:http6:policy-schema:v1",
  "title": "HTTP6 immutable policy content - proposed v1 profile",
  "description": "Structural schema for immutable policy content. A signed instance manifest binds this content by canonical digest. Admission additionally verifies signatures, reference authenticity, cross-field semantics, runtime evidence, ancestor conjunction, and authoritative state. Example values do not constitute an admitted deployment.",
  "type": "object",
  "properties": {
    "schema_version": {
      "const": "http6.policy.v1"
    },
    "policy_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 2048
    },
    "semantics": {
      "type": "object",
      "properties": {
        "profile": {
          "const": "http6-monotone-v1"
        },
        "default_decision": {
          "const": "deny"
        },
        "conflict_resolution": {
          "const": "deny_overrides"
        },
        "evaluation_error": {
          "const": "deny"
        },
        "ancestor_combiner": {
          "const": "conjunction"
        },
        "canonicalization": {
          "const": "RFC8785"
        },
        "engine_digest": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        "normalizer_digest": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        "action_registry_digest": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        "context_resolver_digest": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        "operation_adapter_digest": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        }
      },
      "required": [
        "profile",
        "default_decision",
        "conflict_resolution",
        "evaluation_error",
        "ancestor_combiner",
        "canonicalization",
        "engine_digest",
        "normalizer_digest",
        "action_registry_digest",
        "context_resolver_digest",
        "operation_adapter_digest"
      ],
      "additionalProperties": false
    },
    "iam": {
      "type": "object",
      "properties": {
        "tenant": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2048
        },
        "active_roles": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 2048
          },
          "minItems": 1,
          "maxItems": 64,
          "uniqueItems": true
        },
        "role_catalog_digest": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        "assignment_snapshot_digest": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        "role_grants": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "role": {
                "type": "string",
                "minLength": 1,
                "maxLength": 2048
              },
              "operations": {
                "type": "array",
                "items": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 2048
                },
                "minItems": 1,
                "maxItems": 128,
                "uniqueItems": true
              }
            },
            "required": [
              "role",
              "operations"
            ],
            "additionalProperties": false
          },
          "minItems": 1,
          "maxItems": 64,
          "uniqueItems": true
        }
      },
      "required": [
        "tenant",
        "active_roles",
        "role_catalog_digest",
        "assignment_snapshot_digest",
        "role_grants"
      ],
      "additionalProperties": false
    },
    "permissions": {
      "type": "object",
      "properties": {
        "allow": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/allow_rule"
          },
          "minItems": 0,
          "maxItems": 256,
          "uniqueItems": true
        },
        "deny": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/deny_rule"
          },
          "minItems": 0,
          "maxItems": 256,
          "uniqueItems": true
        }
      },
      "required": [
        "allow",
        "deny"
      ],
      "additionalProperties": false
    },
    "network": {
      "type": "object",
      "properties": {
        "broker_only": {
          "const": true
        },
        "reauthorize_redirects": {
          "const": true
        },
        "trust_bundle_digest": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        "source_route_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2048
        },
        "allow": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/destination"
          },
          "minItems": 0,
          "maxItems": 128,
          "uniqueItems": true
        },
        "deny": {
          "type": "object",
          "properties": {
            "dns_names": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1,
                "maxLength": 2048
              },
              "minItems": 0,
              "maxItems": 128,
              "uniqueItems": true
            },
            "service_identities": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1,
                "maxLength": 2048
              },
              "minItems": 0,
              "maxItems": 128,
              "uniqueItems": true
            },
            "ip_cidrs": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1,
                "maxLength": 2048
              },
              "minItems": 0,
              "maxItems": 128,
              "uniqueItems": true
            }
          },
          "required": [
            "dns_names",
            "service_identities",
            "ip_cidrs"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "broker_only",
        "reauthorize_redirects",
        "trust_bundle_digest",
        "source_route_id",
        "allow",
        "deny"
      ],
      "additionalProperties": false
    },
    "delegation": {
      "type": "object",
      "properties": {
        "enabled": {
          "type": "boolean"
        },
        "max_depth": {
          "type": "integer",
          "minimum": 0,
          "maximum": 64
        },
        "max_direct_children": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "max_total_descendants": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "child_template_digests": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^sha256:[0-9a-f]{64}$"
          },
          "minItems": 0,
          "maxItems": 128,
          "uniqueItems": true
        }
      },
      "required": [
        "enabled",
        "max_depth",
        "max_direct_children",
        "max_total_descendants",
        "child_template_digests"
      ],
      "additionalProperties": false,
      "allOf": [
        {
          "if": {
            "properties": {
              "enabled": {
                "const": false
              }
            }
          },
          "then": {
            "properties": {
              "max_depth": {
                "const": 0
              },
              "max_direct_children": {
                "const": 0
              },
              "max_total_descendants": {
                "const": 0
              },
              "child_template_digests": {
                "maxItems": 0
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "enabled": {
                "const": true
              }
            }
          },
          "then": {
            "properties": {
              "max_depth": {
                "minimum": 1
              },
              "max_direct_children": {
                "minimum": 1
              },
              "max_total_descendants": {
                "minimum": 1
              },
              "child_template_digests": {
                "minItems": 1
              }
            }
          }
        }
      ]
    },
    "lifecycle": {
      "type": "object",
      "properties": {
        "root_restart": {
          "const": "human_proof"
        },
        "child_restart": {
          "const": "live_parent_fresh_attestation"
        },
        "route_change": {
          "const": "new_admission"
        },
        "lease_seconds": {
          "type": "integer",
          "minimum": 1,
          "maximum": 9007199254740991
        },
        "max_lifetime_seconds": {
          "type": "integer",
          "minimum": 1,
          "maximum": 9007199254740991
        }
      },
      "required": [
        "root_restart",
        "child_restart",
        "route_change",
        "lease_seconds",
        "max_lifetime_seconds"
      ],
      "additionalProperties": false
    },
    "runtime": {
      "type": "object",
      "properties": {
        "launcher_digest": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        "enforcement_profile_digest": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        "approved_code_digests": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^sha256:[0-9a-f]{64}$"
          },
          "minItems": 1,
          "maxItems": 128,
          "uniqueItems": true
        },
        "machine_inventory_digest": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        "require_fresh_attestation": {
          "const": true
        },
        "require_nonexportable_instance_key": {
          "const": true
        },
        "inherit_instance_keys": {
          "const": false
        },
        "plugin_digests": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^sha256:[0-9a-f]{64}$"
          },
          "minItems": 0,
          "maxItems": 128,
          "uniqueItems": true
        }
      },
      "required": [
        "launcher_digest",
        "enforcement_profile_digest",
        "approved_code_digests",
        "machine_inventory_digest",
        "require_fresh_attestation",
        "require_nonexportable_instance_key",
        "inherit_instance_keys",
        "plugin_digests"
      ],
      "additionalProperties": false
    },
    "proof": {
      "type": "object",
      "properties": {
        "profile": {
          "const": "http6-computational-v1"
        },
        "action_body_bound": {
          "const": true
        },
        "one_use": {
          "const": true
        },
        "channel_bound": {
          "const": true
        },
        "strict_sequence": {
          "const": true
        },
        "ledger_namespace": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2048
        }
      },
      "required": [
        "profile",
        "action_body_bound",
        "one_use",
        "channel_bound",
        "strict_sequence",
        "ledger_namespace"
      ],
      "additionalProperties": false
    },
    "budgets": {
      "type": "object",
      "properties": {
        "ledger_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2048
        },
        "scope": {
          "const": "subtree"
        },
        "limits": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "dimension": {
                "enum": [
                  "operations",
                  "export_bytes",
                  "spend_minor",
                  "child_births",
                  "concurrent_workers"
                ]
              },
              "maximum": {
                "type": "integer",
                "minimum": 0,
                "maximum": 9007199254740991
              },
              "window_seconds": {
                "type": "integer",
                "minimum": 1,
                "maximum": 9007199254740991
              }
            },
            "required": [
              "dimension",
              "maximum",
              "window_seconds"
            ],
            "additionalProperties": false
          },
          "minItems": 0,
          "maxItems": 16,
          "uniqueItems": true
        }
      },
      "required": [
        "ledger_id",
        "scope",
        "limits"
      ],
      "additionalProperties": false
    },
    "audit": {
      "type": "object",
      "properties": {
        "event_types": {
          "type": "array",
          "items": {
            "enum": [
              "ignition",
              "birth",
              "decision",
              "outcome",
              "revoke",
              "recovery",
              "rejection"
            ]
          },
          "minItems": 1,
          "maxItems": 7,
          "uniqueItems": true
        },
        "private_reference_logging": {
          "const": false
        },
        "retention_seconds": {
          "type": "integer",
          "minimum": 1,
          "maximum": 9007199254740991
        }
      },
      "required": [
        "event_types",
        "private_reference_logging",
        "retention_seconds"
      ],
      "additionalProperties": false
    }
  },
  "required": [
    "schema_version",
    "policy_id",
    "semantics",
    "iam",
    "permissions",
    "network",
    "delegation",
    "lifecycle",
    "runtime",
    "proof",
    "budgets",
    "audit"
  ],
  "additionalProperties": false,
  "$defs": {
    "condition": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "field": {
              "enum": [
                "request.tenant",
                "request.amount_minor",
                "request.data_classification",
                "request.method",
                "request.tool",
                "request.recipient",
                "resource.owner",
                "resource.classification",
                "context.region",
                "context.attested",
                "context.source_zone",
                "context.purpose"
              ]
            },
            "operator": {
              "enum": [
                "eq",
                "ne",
                "in",
                "not_in",
                "lte",
                "gte"
              ]
            },
            "value": {
              "oneOf": [
                {
                  "type": [
                    "string",
                    "integer",
                    "boolean"
                  ],
                  "maxLength": 2048,
                  "minimum": -9007199254740991,
                  "maximum": 9007199254740991
                },
                {
                  "type": "array",
                  "items": {
                    "type": [
                      "string",
                      "integer",
                      "boolean"
                    ],
                    "maxLength": 2048,
                    "minimum": -9007199254740991,
                    "maximum": 9007199254740991
                  },
                  "minItems": 1,
                  "maxItems": 256,
                  "uniqueItems": true
                }
              ]
            }
          },
          "required": [
            "field",
            "operator",
            "value"
          ],
          "additionalProperties": false,
          "allOf": [
            {
              "if": {
                "properties": {
                  "operator": {
                    "enum": [
                      "in",
                      "not_in"
                    ]
                  }
                }
              },
              "then": {
                "properties": {
                  "value": {
                    "type": "array",
                    "items": {
                      "type": [
                        "string",
                        "integer",
                        "boolean"
                      ],
                      "maxLength": 2048,
                      "minimum": -9007199254740991,
                      "maximum": 9007199254740991
                    },
                    "minItems": 1,
                    "maxItems": 256,
                    "uniqueItems": true
                  }
                }
              },
              "else": {
                "properties": {
                  "value": {
                    "type": [
                      "string",
                      "integer",
                      "boolean"
                    ],
                    "maxLength": 2048,
                    "minimum": -9007199254740991,
                    "maximum": 9007199254740991
                  }
                }
              }
            },
            {
              "if": {
                "properties": {
                  "operator": {
                    "enum": [
                      "lte",
                      "gte"
                    ]
                  }
                }
              },
              "then": {
                "properties": {
                  "value": {
                    "type": "integer",
                    "minimum": -9007199254740991,
                    "maximum": 9007199254740991
                  }
                }
              }
            }
          ]
        },
        {
          "type": "object",
          "properties": {
            "all": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/condition"
              },
              "minItems": 1,
              "maxItems": 64,
              "uniqueItems": true
            }
          },
          "required": [
            "all"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "any": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/condition"
              },
              "minItems": 1,
              "maxItems": 64,
              "uniqueItems": true
            }
          },
          "required": [
            "any"
          ],
          "additionalProperties": false
        }
      ]
    },
    "allow_rule": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2048
        },
        "operations": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128,
            "pattern": "^[a-z][a-z0-9_.:-]*$"
          },
          "minItems": 1,
          "maxItems": 256,
          "uniqueItems": true
        },
        "destinations": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 2048
          },
          "minItems": 1,
          "maxItems": 256,
          "uniqueItems": true
        },
        "resources": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 2048
          },
          "minItems": 1,
          "maxItems": 256,
          "uniqueItems": true
        },
        "conditions": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/condition"
          },
          "minItems": 0,
          "maxItems": 64,
          "uniqueItems": true
        }
      },
      "required": [
        "id",
        "operations",
        "destinations",
        "resources",
        "conditions"
      ],
      "additionalProperties": false
    },
    "deny_rule": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2048
        },
        "operations": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128,
            "pattern": "^(?:\\*|[a-z][a-z0-9_.:-]*)$"
          },
          "minItems": 1,
          "maxItems": 256,
          "uniqueItems": true
        },
        "destinations": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 2048
          },
          "minItems": 1,
          "maxItems": 256,
          "uniqueItems": true
        },
        "resources": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 2048
          },
          "minItems": 1,
          "maxItems": 256,
          "uniqueItems": true
        },
        "conditions": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/condition"
          },
          "minItems": 0,
          "maxItems": 64,
          "uniqueItems": true
        }
      },
      "required": [
        "id",
        "operations",
        "destinations",
        "resources",
        "conditions"
      ],
      "additionalProperties": false
    },
    "destination": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2048
        },
        "dns_name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 253,
          "pattern": "^[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?$"
        },
        "service_identity": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2048
        },
        "ports": {
          "type": "array",
          "items": {
            "type": "integer",
            "minimum": 1,
            "maximum": 65535
          },
          "minItems": 1,
          "maxItems": 64,
          "uniqueItems": true
        },
        "protocols": {
          "type": "array",
          "items": {
            "enum": [
              "tls",
              "quic"
            ]
          },
          "minItems": 1,
          "maxItems": 2,
          "uniqueItems": true
        },
        "ip_cidrs": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 2048
          },
          "minItems": 1,
          "maxItems": 64,
          "uniqueItems": true
        }
      },
      "required": [
        "id",
        "dns_name",
        "service_identity",
        "ports",
        "protocols",
        "ip_cidrs"
      ],
      "additionalProperties": false
    }
  }
}
