Publish curated Unraid-AppOps-Gateway source from ad0a390e431166c3198a2ac3bec010c2b44f2dea
This commit is contained in:
1 parent
29c1e3d5a1
commit
98d31477f9
35 files changed
+7264
-185
No files matched your search
@@ -21,6 +21,7 @@ from .setup_service import apply_stored_connector_settings
|
||||
GENERIC_EXECUTOR_ACTIONS = {
|
||||
"container.restart",
|
||||
"controller.artifact.promote",
|
||||
"controller.managed-storage.initialize",
|
||||
"deployment.targets.sync",
|
||||
"deployment.runnerless.provision",
|
||||
"deployment.target.deploy_workmesh",
|
||||
@@ -69,6 +70,10 @@ APPROVAL_EXECUTOR_ACTIONS = {
|
||||
"unraid.vm.pause",
|
||||
}
|
||||
|
||||
MCP_TYPED_EXECUTOR_ACTIONS = APPROVAL_EXECUTOR_ACTIONS | {
|
||||
"controller.managed-storage.initialize",
|
||||
}
|
||||
|
||||
HUMAN_APPROVAL_ONLY_ACTIONS = {"deployment.target.promote_workmesh", "privatemuse.comfyui.install_artifact"}
|
||||
|
||||
_APPROVAL_STEPS = {
|
||||
@@ -148,7 +153,7 @@ def approval_execution_supported(action: str) -> bool:
|
||||
|
||||
def mcp_execution_supported(action: str) -> bool:
|
||||
"""MCP is a no-human-approval surface; never admit human-only executors."""
|
||||
return approval_execution_supported(action) and action not in HUMAN_APPROVAL_ONLY_ACTIONS
|
||||
return action in MCP_TYPED_EXECUTOR_ACTIONS and action not in HUMAN_APPROVAL_ONLY_ACTIONS
|
||||
|
||||
|
||||
def _execute_deployment_target_sync(
|
||||
@@ -1758,7 +1763,7 @@ def execute_governed_action(
|
||||
small allowlist of typed rollback/post-check capable executors below is reachable.
|
||||
"""
|
||||
|
||||
if not approval_execution_supported(action):
|
||||
if not mcp_execution_supported(action):
|
||||
return {
|
||||
"success": False,
|
||||
"status": "failed",
|
||||
@@ -1786,6 +1791,24 @@ def execute_governed_action(
|
||||
original_policy_decision=original_policy_decision,
|
||||
)
|
||||
|
||||
if action == "controller.managed-storage.initialize":
|
||||
if target != "tower/deployment-controller":
|
||||
return {
|
||||
"success": False,
|
||||
"status": "failed",
|
||||
"result": "blocked",
|
||||
"message": "Managed storage initialization accepts only tower/deployment-controller.",
|
||||
"policyDecision": "blocked",
|
||||
"originalPolicyDecision": original_policy_decision,
|
||||
}
|
||||
return _execute_managed_appdata_initialize(
|
||||
session,
|
||||
source=source,
|
||||
risk=risk,
|
||||
reason=reason,
|
||||
original_policy_decision=original_policy_decision,
|
||||
)
|
||||
|
||||
if action == "runner.fleet.upgrade_v2":
|
||||
if target.strip().lower() != "tower/runner-fleet-v2":
|
||||
return {
|
||||
@@ -2058,6 +2081,161 @@ def execute_governed_action(
|
||||
}
|
||||
|
||||
|
||||
def _execute_managed_appdata_initialize(
|
||||
session: Session,
|
||||
*,
|
||||
source: str,
|
||||
risk: str,
|
||||
reason: str,
|
||||
original_policy_decision: str,
|
||||
) -> dict[str, Any]:
|
||||
"""Initialize only the fixed storage marker after trust and policy opt-in."""
|
||||
from .deployment_broker import DeploymentBrokerClient
|
||||
from .enrollment_plane import EnrollmentPlane
|
||||
from .secret_store import get_secret
|
||||
|
||||
action = "controller.managed-storage.initialize"
|
||||
target = "tower/deployment-controller"
|
||||
trust = EnrollmentPlane.get_trust_config(session)
|
||||
if (
|
||||
trust is None
|
||||
or trust.trusted_appdata_root != "/var/lib/docker/volumes/itworx-managed-appdata/_data"
|
||||
or trust.managed_appdata_backup_acknowledged is not True
|
||||
):
|
||||
audit = log_event(
|
||||
session,
|
||||
source="action",
|
||||
identity=source,
|
||||
action_id=action,
|
||||
target=target,
|
||||
target_type="controller",
|
||||
risk=risk,
|
||||
policy_decision="allowed",
|
||||
reason="Managed Docker-root storage requires an explicit trusted selector and backup acknowledgement.",
|
||||
result="blocked",
|
||||
redacted_metadata={"executor": action, "trustOptIn": False},
|
||||
)
|
||||
return {
|
||||
"success": False,
|
||||
"status": "failed",
|
||||
"result": "blocked",
|
||||
"message": "Managed storage is not explicitly selected and acknowledged in enrollment trust.",
|
||||
"auditId": audit.id,
|
||||
"policyDecision": "allowed",
|
||||
"originalPolicyDecision": original_policy_decision,
|
||||
}
|
||||
|
||||
bootstrap_secret = get_secret(session, trust.bootstrap_secret_ref, touch=False)
|
||||
if not bootstrap_secret:
|
||||
audit = log_event(
|
||||
session,
|
||||
source="action",
|
||||
identity=source,
|
||||
action_id=action,
|
||||
target=target,
|
||||
target_type="controller",
|
||||
risk=risk,
|
||||
policy_decision="allowed",
|
||||
reason="Controller bootstrap capability is unavailable by its configured reference.",
|
||||
result="failed",
|
||||
redacted_metadata={"executor": action, "secretMaterialReturned": False},
|
||||
)
|
||||
return {
|
||||
"success": False,
|
||||
"status": "failed",
|
||||
"result": "failed",
|
||||
"message": "Controller bootstrap capability is unavailable.",
|
||||
"auditId": audit.id,
|
||||
"policyDecision": "allowed",
|
||||
"originalPolicyDecision": original_policy_decision,
|
||||
}
|
||||
|
||||
steps = [
|
||||
"Verify the exact target, trust selector and backup acknowledgement",
|
||||
"Authenticate the fixed controller request with bootstrap HMAC and replay protection",
|
||||
"Validate the protected controller, target registry, repository root and fixed Docker volume",
|
||||
"Initialize the selector only if the managed Docker volume is empty and unchanged",
|
||||
"Re-read the fixed selector and record sanitized controller readiness",
|
||||
]
|
||||
job = create_job(
|
||||
session,
|
||||
action_id=action,
|
||||
target=target,
|
||||
source=source,
|
||||
risk=risk,
|
||||
policy_decision="allowed",
|
||||
steps=steps,
|
||||
)
|
||||
start_job(session, job)
|
||||
set_job_progress(session, job, 20, "Validating fixed managed-storage initialization prerequisites.")
|
||||
try:
|
||||
result = DeploymentBrokerClient().initialize_managed_appdata(secret=bootstrap_secret)
|
||||
reported_status = result.get("status")
|
||||
status = (
|
||||
reported_status
|
||||
if isinstance(reported_status, str)
|
||||
and reported_status in {"initialized", "already_initialized"}
|
||||
else "refused"
|
||||
)
|
||||
success = (
|
||||
status in {"initialized", "already_initialized"}
|
||||
and result.get("trustedAppdataRoot") == trust.trusted_appdata_root
|
||||
and result.get("backupLocation") == "dockerRootDir"
|
||||
)
|
||||
message = (
|
||||
"Managed storage selector initialized and verified."
|
||||
if success
|
||||
else "Managed storage initialization was refused or unavailable."
|
||||
)
|
||||
except Exception:
|
||||
result = {"status": "error"}
|
||||
status = "error"
|
||||
success = False
|
||||
message = "Managed storage initialization was refused or unavailable."
|
||||
|
||||
completed = complete_job(
|
||||
session,
|
||||
job,
|
||||
status="succeeded" if success else "failed",
|
||||
result_summary=message,
|
||||
)
|
||||
audit = log_event(
|
||||
session,
|
||||
source="action",
|
||||
identity=source,
|
||||
action_id=action,
|
||||
target=target,
|
||||
target_type="controller",
|
||||
risk=risk,
|
||||
policy_decision="allowed",
|
||||
reason=reason,
|
||||
result="success" if success else "failed",
|
||||
execution_plan={"steps": steps, "jobId": completed.id},
|
||||
after_state={
|
||||
"status": status,
|
||||
"trustedAppdataRoot": trust.trusted_appdata_root if success else None,
|
||||
"backupLocation": "dockerRootDir" if success else None,
|
||||
},
|
||||
redacted_metadata={
|
||||
"executor": action,
|
||||
"target": target,
|
||||
"integration": "mcp" if source == "chatgpt-mcp" else "operator",
|
||||
"originalPolicyDecision": original_policy_decision,
|
||||
"secretMaterialReturned": False,
|
||||
},
|
||||
)
|
||||
return {
|
||||
"success": success,
|
||||
"status": "success" if success else "failed",
|
||||
"result": "success" if success else "failed",
|
||||
"message": message,
|
||||
"jobId": completed.id,
|
||||
"auditId": audit.id,
|
||||
"policyDecision": "allowed",
|
||||
"originalPolicyDecision": original_policy_decision,
|
||||
}
|
||||
|
||||
|
||||
def execute_approved_action(session: Session, approval: Approval) -> dict[str, Any]:
|
||||
if not approval_execution_supported(approval.action):
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user