Platform scripts, MCP servers, deployment and docs for the KAB runs
- Scripts to run workflows from a YAML context or run inputs (kab_run_workflow.py, with --input name=@file), store per-project discovery connections, bootstrap agent MCP keys, refresh the KAB token, publish reports and build estate snapshots. - Hyperscaler discovery servers extended in place; cloud-knowledge folded into them. - deploy/crucible-kab-dev.yaml: the Discovery package agent and the Assessment agents. - Platform issue write-ups and current-wiring notes under docs/platform-issues/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -34,6 +34,9 @@ AZURE_DATA = {
|
||||
"sql": ["microsoft.sql/servers", "microsoft.sql/servers/databases"],
|
||||
"cosmos_db": ["microsoft.documentdb/databaseaccounts"],
|
||||
"storage_accounts": ["microsoft.storage/storageaccounts"],
|
||||
"postgresql": ["microsoft.dbforpostgresql/flexibleservers", "microsoft.dbforpostgresql/servers"],
|
||||
"mysql": ["microsoft.dbformysql/flexibleservers", "microsoft.dbformysql/servers"],
|
||||
"redis": ["microsoft.cache/redis", "microsoft.cache/redisenterprise"],
|
||||
}
|
||||
AZURE_ORG_POLICIES = {
|
||||
"assignments": ["microsoft.authorization/policyassignments"],
|
||||
@@ -50,14 +53,45 @@ AZURE_PILLARS = {"cost": "cost", "security": "security", "highavailability": "re
|
||||
"performance": "performance", "operationalexcellence": "operations"}
|
||||
|
||||
|
||||
AZURE_RESOURCE_GROUP = r"[-\w.()]{1,90}"
|
||||
|
||||
|
||||
def _azure_root(connection: Dict[str, Any]) -> tuple:
|
||||
"""(managementGroups or subscriptions, its id, the resource group or None) from the connection's scope root."""
|
||||
parts = str(connection.get("scope_root", "")).strip("/").split("/")
|
||||
if len(parts) == 2 and parts[0] in ("managementGroups", "subscriptions") and parts[1]:
|
||||
return parts[0], parts[1], None
|
||||
if (len(parts) == 4 and parts[0] == "subscriptions" and parts[1] and parts[2].lower() == "resourcegroups"
|
||||
and re.fullmatch(AZURE_RESOURCE_GROUP, parts[3]) and not parts[3].endswith(".")):
|
||||
return "subscriptions", parts[1], parts[3]
|
||||
raise ValueError("scope_root must be managementGroups/<id>, subscriptions/<id> or "
|
||||
"subscriptions/<id>/resourceGroups/<name>")
|
||||
|
||||
|
||||
def _azure_scope(connection: Dict[str, Any]) -> Dict[str, List[str]]:
|
||||
"""The query scope: the connection's root, and nothing the caller can widen."""
|
||||
kind, _, identifier = str(connection.get("scope_root", "")).strip("/").partition("/")
|
||||
if not identifier or "/" in identifier or kind not in ("managementGroups", "subscriptions"):
|
||||
raise ValueError("scope_root must be managementGroups/<id> or subscriptions/<id>")
|
||||
kind, identifier, _ = _azure_root(connection)
|
||||
return {kind: [identifier]}
|
||||
|
||||
|
||||
def _azure_scoped_query(query: str, connection: Dict[str, Any]) -> str:
|
||||
"""The query narrowed to the connection's resource group, when its scope root names one.
|
||||
|
||||
Resource Graph scopes by subscription or management group only, so a resource group is a filter placed straight
|
||||
after the table. Rows outside any resource group (the subscription itself, subscription-wide policy assignments
|
||||
and Advisor findings) still apply to the group, so they stay. A join, union or lookup could read a second table
|
||||
without the filter, so a resource-group scope refuses them.
|
||||
"""
|
||||
_, _, group = _azure_root(connection)
|
||||
if group is None:
|
||||
return query
|
||||
if re.search(r"\b(join|union|lookup)\b", query, re.IGNORECASE):
|
||||
raise PermissionError("a resource-group scope allows no join, union or lookup")
|
||||
table, bar, rest = query.partition("|")
|
||||
narrowed = f"{table.strip()} | where isempty(resourceGroup) or resourceGroup =~ '{group}'"
|
||||
return f"{narrowed} |{rest}" if bar else narrowed
|
||||
|
||||
|
||||
def _azure_endpoints(connection: Dict[str, Any]) -> Dict[str, str]:
|
||||
return AZURE_CLOUDS.get(str(connection.get("cloud") or "public"), AZURE_CLOUDS["public"])
|
||||
|
||||
@@ -97,7 +131,7 @@ async def _azure_graph(query: str, top: int, skip_token: Optional[str] = None) -
|
||||
response = await _with_backoff(lambda: _azure_client().post(
|
||||
f"{_azure_endpoints(connection)['arm']}/providers/Microsoft.ResourceGraph/resources",
|
||||
params={"api-version": AZURE_GRAPH_VERSION}, headers={"Authorization": f"Bearer {token}"},
|
||||
json={"query": query, "options": options, **_azure_scope(connection)}))
|
||||
json={"query": _azure_scoped_query(query, connection), "options": options, **_azure_scope(connection)}))
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
@@ -109,6 +143,8 @@ async def _azure_page(tool: str, arguments: Dict[str, Any], query: str, finish=N
|
||||
return _refuse("invalid_page_token", "page_token isn't one this server issued")
|
||||
try:
|
||||
body = await _azure_graph(query, _page_size(arguments), upstream)
|
||||
except PermissionError as error:
|
||||
return _refuse("outside_scope", str(error))
|
||||
except Exception as error:
|
||||
return _upstream_failed("azure", error)
|
||||
items = [finish(i) for i in body.get("data", [])] if finish else body.get("data", [])
|
||||
@@ -156,7 +192,9 @@ async def _azure_locks(tool: str, arguments: Dict[str, Any]) -> Dict[str, Any]:
|
||||
subscription = await _azure_lock_subscription(arguments)
|
||||
if not subscription:
|
||||
return _refuse("outside_scope", "subscription_id must name a subscription under this connection's scope")
|
||||
base = f"{_azure_endpoints(connection)['arm']}/subscriptions/{subscription}/providers/Microsoft.Authorization/locks"
|
||||
group = _azure_root(connection)[2]
|
||||
within = f"/resourceGroups/{group}" if group else ""
|
||||
base = f"{_azure_endpoints(connection)['arm']}/subscriptions/{subscription}{within}/providers/Microsoft.Authorization/locks"
|
||||
# A page token carries ARM's next link, and the bearer token goes wherever it points, so it must stay here.
|
||||
url = upstream or f"{base}?api-version={AZURE_LOCKS_VERSION}"
|
||||
if not url.startswith(f"{base}?"):
|
||||
|
||||
Reference in New Issue
Block a user