hexaqueue-cli 0.4.0__tar.gz → 0.6.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. {hexaqueue_cli-0.4.0 → hexaqueue_cli-0.6.0}/PKG-INFO +11 -6
  2. {hexaqueue_cli-0.4.0 → hexaqueue_cli-0.6.0}/README.md +5 -0
  3. {hexaqueue_cli-0.4.0 → hexaqueue_cli-0.6.0}/pyproject.toml +7 -7
  4. {hexaqueue_cli-0.4.0 → hexaqueue_cli-0.6.0}/pyproject.toml.orig +7 -7
  5. {hexaqueue_cli-0.4.0 → hexaqueue_cli-0.6.0}/src/hexaqueue_cli/adapters/local.py +47 -10
  6. {hexaqueue_cli-0.4.0 → hexaqueue_cli-0.6.0}/src/hexaqueue_cli/adapters/presenter.py +69 -10
  7. {hexaqueue_cli-0.4.0 → hexaqueue_cli-0.6.0}/src/hexaqueue_cli/commands/__init__.py +2 -0
  8. hexaqueue_cli-0.6.0/src/hexaqueue_cli/commands/admin.py +172 -0
  9. {hexaqueue_cli-0.4.0 → hexaqueue_cli-0.6.0}/src/hexaqueue_cli/commands/collateral.py +14 -0
  10. hexaqueue_cli-0.6.0/src/hexaqueue_cli/commands/mcp.py +117 -0
  11. {hexaqueue_cli-0.4.0 → hexaqueue_cli-0.6.0}/src/hexaqueue_cli/commands/run.py +21 -1
  12. hexaqueue_cli-0.6.0/src/hexaqueue_cli/commands/scanner.py +198 -0
  13. hexaqueue_cli-0.6.0/src/hexaqueue_cli/commands/server.py +181 -0
  14. {hexaqueue_cli-0.4.0 → hexaqueue_cli-0.6.0}/src/hexaqueue_cli/commands/workflow.py +18 -3
  15. hexaqueue_cli-0.6.0/src/hexaqueue_cli/domain/models.py +11 -0
  16. {hexaqueue_cli-0.4.0 → hexaqueue_cli-0.6.0}/src/hexaqueue_cli/domain/session.py +23 -16
  17. {hexaqueue_cli-0.4.0 → hexaqueue_cli-0.6.0}/src/hexaqueue_cli/main.py +62 -17
  18. {hexaqueue_cli-0.4.0 → hexaqueue_cli-0.6.0}/src/hexaqueue_cli/ports/client.py +20 -0
  19. hexaqueue_cli-0.4.0/src/hexaqueue_cli/domain/models.py +0 -47
  20. {hexaqueue_cli-0.4.0 → hexaqueue_cli-0.6.0}/src/hexaqueue_cli/__init__.py +0 -0
  21. {hexaqueue_cli-0.4.0 → hexaqueue_cli-0.6.0}/src/hexaqueue_cli/adapters/__init__.py +0 -0
  22. {hexaqueue_cli-0.4.0 → hexaqueue_cli-0.6.0}/src/hexaqueue_cli/commands/node.py +0 -0
  23. {hexaqueue_cli-0.4.0 → hexaqueue_cli-0.6.0}/src/hexaqueue_cli/commands/suite.py +0 -0
  24. {hexaqueue_cli-0.4.0 → hexaqueue_cli-0.6.0}/src/hexaqueue_cli/domain/__init__.py +0 -0
  25. {hexaqueue_cli-0.4.0 → hexaqueue_cli-0.6.0}/src/hexaqueue_cli/domain/options.py +0 -0
  26. {hexaqueue_cli-0.4.0 → hexaqueue_cli-0.6.0}/src/hexaqueue_cli/domain/parser.py +0 -0
  27. {hexaqueue_cli-0.4.0 → hexaqueue_cli-0.6.0}/src/hexaqueue_cli/infra/__init__.py +0 -0
  28. {hexaqueue_cli-0.4.0 → hexaqueue_cli-0.6.0}/src/hexaqueue_cli/infra/bootstrap.py +0 -0
  29. {hexaqueue_cli-0.4.0 → hexaqueue_cli-0.6.0}/src/hexaqueue_cli/infra/options.py +0 -0
  30. {hexaqueue_cli-0.4.0 → hexaqueue_cli-0.6.0}/src/hexaqueue_cli/ports/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hexaqueue-cli
3
- Version: 0.4.0
3
+ Version: 0.6.0
4
4
  Summary: Hexaqueue CLI - Modern developer and operator terminal interface
5
5
  Author: Richard West
6
6
  Author-email: Richard West <dopplereffect.us@gmail.com>
@@ -9,14 +9,14 @@ Requires-Dist: hexaqueue-core
9
9
  Requires-Dist: hexaqueue-server
10
10
  Requires-Dist: hexaqueue-worker
11
11
  Requires-Dist: hexaqueue-workflow
12
- Requires-Dist: hexastack-cli>=0.6.0
13
- Requires-Dist: hexastack-core>=0.6.0
14
- Requires-Dist: hexastack-cqrs>=0.6.0
15
- Requires-Dist: hexastack-grpc>=0.6.0
12
+ Requires-Dist: hexastack-cli>=0.11.0
13
+ Requires-Dist: hexastack-core>=0.11.0
14
+ Requires-Dist: hexastack-cqrs>=0.11.0
15
+ Requires-Dist: hexastack-grpc>=0.11.0
16
16
  Requires-Dist: pyyaml>=6.0.2
17
17
  Requires-Dist: rich>=13.8.0
18
18
  Requires-Dist: typer>=0.15.0
19
- Requires-Python: >=3.13
19
+ Requires-Python: >=3.12
20
20
  Description-Content-Type: text/markdown
21
21
 
22
22
  # 💻 `hexaqueue-cli`
@@ -26,8 +26,13 @@ Description-Content-Type: text/markdown
26
26
  [![PyPI: hexaqueue-cli](https://img.shields.io/pypi/v/hexaqueue-cli.svg)](https://pypi.org/project/hexaqueue-cli/)
27
27
  [![Python 3.13+](https://img.shields.io/badge/python-3.13+-blue.svg)](https://www.python.org/downloads/)
28
28
  [![Coverage](https://codecov.io/github/TheTrueSCU/hexaqueue/graph/badge.svg?component=hexaqueue_cli)](https://codecov.io/github/TheTrueSCU/hexaqueue)
29
+ [![Part of Hexaqueue](https://img.shields.io/badge/part%20of-hexaqueue-blue.svg)](https://dopplereffect.us/hexaqueue/)
30
+ [![Built with Hexastack](https://img.shields.io/badge/built%20with-hexastack-blueviolet.svg)](https://dopplereffect.us/hexastack/)
31
+ [![Governed by Hexaqual](https://img.shields.io/badge/governed%20by-hexaqual-10b981.svg)](https://dopplereffect.us/hexaqual/)
29
32
  [![License: Apache 2.0](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](../../LICENSE)
30
33
 
34
+ > Part of the [**Hexaqueue Scheduler**](https://dopplereffect.us/hexaqueue/) · Built on [**Hexastack**](https://dopplereffect.us/hexastack/) · Governed by [**Hexaqual**](https://dopplereffect.us/hexaqual/).
35
+
31
36
  ---
32
37
 
33
38
  ## 🏗️ Architecture & Dependencies
@@ -5,8 +5,13 @@
5
5
  [![PyPI: hexaqueue-cli](https://img.shields.io/pypi/v/hexaqueue-cli.svg)](https://pypi.org/project/hexaqueue-cli/)
6
6
  [![Python 3.13+](https://img.shields.io/badge/python-3.13+-blue.svg)](https://www.python.org/downloads/)
7
7
  [![Coverage](https://codecov.io/github/TheTrueSCU/hexaqueue/graph/badge.svg?component=hexaqueue_cli)](https://codecov.io/github/TheTrueSCU/hexaqueue)
8
+ [![Part of Hexaqueue](https://img.shields.io/badge/part%20of-hexaqueue-blue.svg)](https://dopplereffect.us/hexaqueue/)
9
+ [![Built with Hexastack](https://img.shields.io/badge/built%20with-hexastack-blueviolet.svg)](https://dopplereffect.us/hexastack/)
10
+ [![Governed by Hexaqual](https://img.shields.io/badge/governed%20by-hexaqual-10b981.svg)](https://dopplereffect.us/hexaqual/)
8
11
  [![License: Apache 2.0](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](../../LICENSE)
9
12
 
13
+ > Part of the [**Hexaqueue Scheduler**](https://dopplereffect.us/hexaqueue/) · Built on [**Hexastack**](https://dopplereffect.us/hexastack/) · Governed by [**Hexaqual**](https://dopplereffect.us/hexaqual/).
14
+
10
15
  ---
11
16
 
12
17
  ## 🏗️ Architecture & Dependencies
@@ -1,19 +1,19 @@
1
1
  [project]
2
2
  name = "hexaqueue-cli"
3
- version = "0.4.0"
3
+ version = "0.6.0"
4
4
  description = "Hexaqueue CLI - Modern developer and operator terminal interface"
5
5
  readme = "README.md"
6
6
  license = "Apache-2.0"
7
- requires-python = ">=3.13"
7
+ requires-python = ">=3.12"
8
8
  dependencies = [
9
9
  "hexaqueue-core",
10
10
  "hexaqueue-server",
11
11
  "hexaqueue-worker",
12
12
  "hexaqueue-workflow",
13
- "hexastack-cli>=0.6.0",
14
- "hexastack-core>=0.6.0",
15
- "hexastack-cqrs>=0.6.0",
16
- "hexastack-grpc>=0.6.0",
13
+ "hexastack-cli>=0.11.0",
14
+ "hexastack-core>=0.11.0",
15
+ "hexastack-cqrs>=0.11.0",
16
+ "hexastack-grpc>=0.11.0",
17
17
  "pyyaml>=6.0.2",
18
18
  "rich>=13.8.0",
19
19
  "typer>=0.15.0",
@@ -27,7 +27,7 @@ email = "dopplereffect.us@gmail.com"
27
27
  hq = "hexaqueue_cli.main:app"
28
28
 
29
29
  [build-system]
30
- requires = ["uv_build>=0.12.3,<0.13.0"]
30
+ requires = ["uv_build>=0.12.3,<0.14.0"]
31
31
  build-backend = "uv_build"
32
32
 
33
33
  [tool.uv.sources.hexaqueue-core]
@@ -1,22 +1,22 @@
1
1
  [project]
2
2
  name = "hexaqueue-cli"
3
- version = "0.4.0"
3
+ version = "0.6.0"
4
4
  description = "Hexaqueue CLI - Modern developer and operator terminal interface"
5
5
  readme = "README.md"
6
6
  license = "Apache-2.0"
7
7
  authors = [
8
8
  { name = "Richard West", email = "dopplereffect.us@gmail.com" }
9
9
  ]
10
- requires-python = ">=3.13"
10
+ requires-python = ">=3.12"
11
11
  dependencies = [
12
12
  "hexaqueue-core",
13
13
  "hexaqueue-server",
14
14
  "hexaqueue-worker",
15
15
  "hexaqueue-workflow",
16
- "hexastack-cli>=0.6.0",
17
- "hexastack-core>=0.6.0",
18
- "hexastack-cqrs>=0.6.0",
19
- "hexastack-grpc>=0.6.0",
16
+ "hexastack-cli>=0.11.0",
17
+ "hexastack-core>=0.11.0",
18
+ "hexastack-cqrs>=0.11.0",
19
+ "hexastack-grpc>=0.11.0",
20
20
  "pyyaml>=6.0.2",
21
21
  "rich>=13.8.0",
22
22
  "typer>=0.15.0",
@@ -26,7 +26,7 @@ dependencies = [
26
26
  hq = "hexaqueue_cli.main:app"
27
27
 
28
28
  [build-system]
29
- requires = ["uv_build>=0.12.3,<0.13.0"]
29
+ requires = ["uv_build>=0.12.3,<0.14.0"]
30
30
  build-backend = "uv_build"
31
31
 
32
32
  [tool.uv.sources]
@@ -8,6 +8,8 @@ Notes/Architectural Intent:
8
8
  from __future__ import annotations
9
9
 
10
10
  from collections.abc import AsyncIterator
11
+ from datetime import UTC, datetime
12
+ from pathlib import Path
11
13
  from uuid import uuid4
12
14
 
13
15
  from hexaqueue_cli.domain.models import ClusterStatsReport
@@ -46,7 +48,7 @@ def _check_job_mutation_permission(
46
48
  ) -> None:
47
49
  """Verify that caller has permission to mutate the job."""
48
50
  owner = _extract_job_owner(job)
49
- if owner != "default" and owner != user_id and not elevate:
51
+ if owner != user_id and not elevate:
50
52
  msg = (
51
53
  f"Permission denied: You are not the owner of job '{job.id}' (owned by '{owner}'). "
52
54
  f"To {action_name} this job, explicit administrative elevation (--admin / elevate=true) is required."
@@ -105,7 +107,7 @@ class LocalClientAdapter(ClientPort):
105
107
  self, run_id: str, user_id: str = "default", elevate: bool = False
106
108
  ) -> RunStatusReport:
107
109
  """Cancel run in local in-process controller."""
108
- if not elevate and user_id != "default":
110
+ if not elevate:
109
111
  jobs = await self._session.controller.list_jobs()
110
112
  run_jobs = [j for j in jobs if j.run_id == run_id]
111
113
  for j in run_jobs:
@@ -142,6 +144,28 @@ class LocalClientAdapter(ClientPort):
142
144
  c async for c in self._session.log_stream.stream_logs(job_id, follow=False)
143
145
  ]
144
146
 
147
+ async def get_log_download_url(
148
+ self,
149
+ job_id: str,
150
+ expires_in_seconds: int = 900,
151
+ user_id: str = "default",
152
+ elevate: bool = False,
153
+ ) -> str:
154
+ """Retrieve presigned direct download URL for job execution logs."""
155
+ from hexaqueue_core.domain.cqrs import (
156
+ GetJobLogDownloadUrlQuery,
157
+ PresignedDownloadUrl,
158
+ )
159
+
160
+ qry = GetJobLogDownloadUrlQuery(
161
+ job_id=job_id,
162
+ expires_in_seconds=expires_in_seconds,
163
+ user_id=user_id,
164
+ elevate=elevate,
165
+ )
166
+ res: PresignedDownloadUrl = self._session.pipeline.execute(qry)
167
+ return res.download_url
168
+
145
169
  async def stream_logs(
146
170
  self, job_id: str, follow: bool = False, tail: int | None = None
147
171
  ) -> AsyncIterator[LogChunk]:
@@ -207,8 +231,6 @@ class LocalClientAdapter(ClientPort):
207
231
  is_admin: bool = False,
208
232
  ) -> SchedulingDecisionReport:
209
233
  """Generate explainability report for a job in the local session."""
210
- from datetime import UTC, datetime
211
-
212
234
  from hexaqueue_core.domain.explainability import SchedulerExplainabilityEngine
213
235
  from hexaqueue_core.domain.redaction import MultiTenantRedactionFilter
214
236
  from hexaqueue_core.domain.scheduling import ResourceSlotPool
@@ -233,8 +255,6 @@ class LocalClientAdapter(ClientPort):
233
255
  is_admin: bool = False,
234
256
  ) -> FairShareTreeReport:
235
257
  """Generate fair-share tree report for the local session."""
236
- from datetime import UTC, datetime
237
-
238
258
  from hexaqueue_core.domain.explainability import (
239
259
  SchedulerExplainabilityEngine,
240
260
  )
@@ -262,6 +282,22 @@ class LocalClientAdapter(ClientPort):
262
282
  checksum = (
263
283
  checksum_sha256 if len(checksum_sha256) == 64 else checksum_sha256.zfill(64)
264
284
  )
285
+ staging_uri = f"memory://staging/collateral/{name}"
286
+ if target_path and Path(target_path).is_file():
287
+ if ".." in name or "/" in name or "\\" in name or Path(name).is_absolute():
288
+ raise ValueError(
289
+ f"Collateral name '{name}' contains illegal path components."
290
+ )
291
+ content = Path(target_path).read_bytes()
292
+ alloc = await self._session.storage.allocate_scratch(
293
+ job_id="collateral", size_mb=max(1, len(content) // (1024 * 1024))
294
+ )
295
+ mount_path = Path(alloc.mount_path).resolve()
296
+ dest = (mount_path / name).resolve()
297
+ if not dest.is_relative_to(mount_path):
298
+ raise ValueError("Path traversal detected in collateral destination.")
299
+ dest.write_bytes(content)
300
+ staging_uri = f"file://{dest}"
265
301
  return CollateralBundle(
266
302
  id=f"col-{uuid4().hex[:8]}",
267
303
  job_id="global",
@@ -271,7 +307,7 @@ class LocalClientAdapter(ClientPort):
271
307
  tier=tier,
272
308
  kind=kind,
273
309
  state=CollateralState.REGISTERED,
274
- staging_uri=f"s3://staging/collateral/{name}",
310
+ staging_uri=staging_uri,
275
311
  )
276
312
 
277
313
  async def create_bastion_session(
@@ -288,13 +324,14 @@ class LocalClientAdapter(ClientPort):
288
324
  "requires explicit administrative elevation (--admin)."
289
325
  )
290
326
  raise PermissionDeniedError(msg)
291
- return PtySessionInfo(
327
+ req = PtySessionRequest(
292
328
  session_id=session_id or f"bastion-{uuid4().hex[:8]}",
293
329
  job_id=f"bastion-{node_id}",
294
330
  user_id=user_id,
295
- pid=99999,
296
- is_active=True,
331
+ roles=["admin", "operator"],
332
+ command=["/bin/sh"],
297
333
  )
334
+ return await self._session.pty.create_session(req, job_owner=user_id)
298
335
 
299
336
 
300
337
  __all__ = [
@@ -21,6 +21,7 @@ from rich.tree import Tree
21
21
 
22
22
  from hexaqueue_cli.domain.models import ClusterStatsReport
23
23
  from hexaqueue_cli.domain.options import OutputFormat
24
+ from hexaqueue_core.domain.bastion import BastionSession
24
25
  from hexaqueue_core.domain.explainability import (
25
26
  FairShareNodeReport,
26
27
  FairShareTreeReport,
@@ -86,11 +87,7 @@ class CliPresenter:
86
87
  if hasattr(report.state, "value")
87
88
  else str(report.state)
88
89
  ),
89
- "outcome": (
90
- report.outcome.value
91
- if hasattr(report.outcome, "value")
92
- else (str(report.outcome) if report.outcome else None)
93
- ),
90
+ "outcome": (report.outcome.value if report.outcome is not None else None),
94
91
  "total_jobs": report.total_jobs,
95
92
  "completed_jobs": report.completed_jobs,
96
93
  "failed_jobs": report.failed_jobs,
@@ -236,11 +233,7 @@ class CliPresenter:
236
233
  )
237
234
 
238
235
  state_val = job.state.value if hasattr(job.state, "value") else str(job.state)
239
- outcome_val = (
240
- job.outcome.value
241
- if hasattr(job.outcome, "value")
242
- else (str(job.outcome) if job.outcome else None)
243
- )
236
+ outcome_val = job.outcome.value if job.outcome is not None else None
244
237
 
245
238
  data = {
246
239
  "id": job.id,
@@ -724,6 +717,72 @@ class CliPresenter:
724
717
  )
725
718
  self._console.print(table)
726
719
 
720
+ def render_bastion_sessions_table(
721
+ self,
722
+ sessions: list[BastionSession],
723
+ format_type: str | OutputFormat = OutputFormat.TABLE,
724
+ ) -> None:
725
+ """Render active administrative bastion sessions in requested format.
726
+
727
+ Args:
728
+ sessions: List of BastionSession records.
729
+ format_type: Output format (table, json, markdown, plain).
730
+ """
731
+ fmt = (
732
+ format_type.value
733
+ if isinstance(format_type, OutputFormat)
734
+ else str(format_type).lower().strip()
735
+ )
736
+ if fmt == OutputFormat.JSON.value:
737
+ dumped = [s.model_dump(mode="json") for s in sessions]
738
+ self._console.print(json.dumps(dumped, indent=2))
739
+ return
740
+
741
+ if fmt == OutputFormat.MARKDOWN.value:
742
+ lines = [
743
+ "| Session ID | Node ID | Operator | Protocol | Created (UTC) | Expires (UTC) | Active |",
744
+ "|---|---|---|---|---|---|---|",
745
+ ]
746
+ for s in sessions:
747
+ created_str = s.created_at.strftime("%Y-%m-%d %H:%M:%S")
748
+ expires_str = s.expires_at.strftime("%Y-%m-%d %H:%M:%S")
749
+ lines.append(
750
+ f"| {s.session_id} | {s.node_id} | {s.operator_id} | {s.protocol.value} | {created_str} | {expires_str} | {s.is_active} |"
751
+ )
752
+ self._console.print("\n".join(lines))
753
+ return
754
+
755
+ if fmt == OutputFormat.PLAIN.value:
756
+ for s in sessions:
757
+ self._console.print(
758
+ f"SESSION={s.session_id} NODE={s.node_id} OPERATOR={s.operator_id} PROTOCOL={s.protocol.value} ACTIVE={s.is_active}"
759
+ )
760
+ return
761
+
762
+ table = Table(title="Active Bastion Sessions", border_style="cyan")
763
+ table.add_column("Session ID", style="bold cyan")
764
+ table.add_column("Node ID", style="green")
765
+ table.add_column("Operator", style="yellow")
766
+ table.add_column("Protocol", style="magenta")
767
+ table.add_column("Created (UTC)", justify="center")
768
+ table.add_column("Expires (UTC)", justify="center")
769
+ table.add_column("Active", justify="center")
770
+
771
+ for s in sessions:
772
+ created_str = s.created_at.strftime("%Y-%m-%d %H:%M:%S")
773
+ expires_str = s.expires_at.strftime("%Y-%m-%d %H:%M:%S")
774
+ active_str = "[bold green]YES[/]" if s.is_active else "[bold red]NO[/]"
775
+ table.add_row(
776
+ s.session_id,
777
+ s.node_id,
778
+ s.operator_id,
779
+ s.protocol.value,
780
+ created_str,
781
+ expires_str,
782
+ active_str,
783
+ )
784
+ self._console.print(table)
785
+
727
786
  def build_top_dashboard(
728
787
  self,
729
788
  stats: ClusterStatsReport,
@@ -4,6 +4,7 @@ Notes/Architectural Intent:
4
4
  Exposes Typer subcommand modules for batch run pipelines and distributed workflow execution.
5
5
  """
6
6
 
7
+ from hexaqueue_cli.commands.admin import app as admin_app
7
8
  from hexaqueue_cli.commands.collateral import app as collateral_app
8
9
  from hexaqueue_cli.commands.node import app as node_app
9
10
  from hexaqueue_cli.commands.run import app as run_app
@@ -11,6 +12,7 @@ from hexaqueue_cli.commands.suite import app as suite_app
11
12
  from hexaqueue_cli.commands.workflow import app as workflow_app
12
13
 
13
14
  __all__ = [
15
+ "admin_app",
14
16
  "collateral_app",
15
17
  "node_app",
16
18
  "run_app",
@@ -0,0 +1,172 @@
1
+ """CLI subcommand group for administrative operations and bastion session governance.
2
+
3
+ Notes/Architectural Intent:
4
+ Provides `hq admin session` commands to mint zero-trust bastion sessions,
5
+ generate cloud-specific tunnel connection commands, audit active sessions,
6
+ and terminate maintenance leases across AWS SSM, GCP IAP, Azure Bastion,
7
+ Tailscale/Teleport, and Native Break-Glass setups.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import asyncio
13
+
14
+ import typer
15
+ from rich.console import Console
16
+ from rich.panel import Panel
17
+
18
+ from hexaqueue_cli.adapters.presenter import CliPresenter
19
+ from hexaqueue_cli.infra.options import format_option, resolve_format
20
+ from hexaqueue_core.adapters.bastion import (
21
+ AWSSSMAdapter,
22
+ AzureBastionAdapter,
23
+ GCPIAPAdapter,
24
+ NativeBreakGlassAdapter,
25
+ TailscaleTeleportAdapter,
26
+ )
27
+ from hexaqueue_core.domain.bastion import BastionProtocolType
28
+ from hexaqueue_core.ports.bastion import BastionAccessPort
29
+
30
+ app = typer.Typer(
31
+ name="admin",
32
+ help="Administrative operations and zero-trust session governance",
33
+ no_args_is_help=True,
34
+ )
35
+ session_app = typer.Typer(
36
+ name="session",
37
+ help="Manage and audit zero-trust bastion operator access sessions",
38
+ no_args_is_help=True,
39
+ )
40
+ app.add_typer(session_app, name="session")
41
+ console = Console()
42
+
43
+
44
+ def get_bastion_adapter(protocol: BastionProtocolType) -> BastionAccessPort:
45
+ """Resolve the appropriate bastion adapter for a given protocol."""
46
+ if protocol == BastionProtocolType.AWS_SSM:
47
+ return AWSSSMAdapter()
48
+ if protocol == BastionProtocolType.GCP_IAP:
49
+ return GCPIAPAdapter()
50
+ if protocol == BastionProtocolType.AZURE_BASTION:
51
+ return AzureBastionAdapter()
52
+ if protocol == BastionProtocolType.TAILSCALE_TELEPORT:
53
+ return TailscaleTeleportAdapter()
54
+ return NativeBreakGlassAdapter()
55
+
56
+
57
+ @session_app.command("create")
58
+ def create_session_cmd(
59
+ node_id: str = typer.Argument(..., help="Target compute node ID"),
60
+ operator: str = typer.Option(
61
+ "default", "--operator", "-o", help="Requesting operator identity"
62
+ ),
63
+ protocol: BastionProtocolType = typer.Option(
64
+ BastionProtocolType.NATIVE_BREAK_GLASS,
65
+ "--protocol",
66
+ "-p",
67
+ help="Bastion access protocol",
68
+ ),
69
+ duration: int = typer.Option(
70
+ 3600, "--duration", "-d", help="Lease duration in seconds"
71
+ ),
72
+ admin: bool = typer.Option(
73
+ False,
74
+ "--admin",
75
+ help="Assert explicit administrative elevation for bastion shell access",
76
+ ),
77
+ ) -> None:
78
+ """Mint an ephemeral zero-trust bastion session and generate connection command."""
79
+ if not admin:
80
+ console.print(
81
+ f"[bold red]Permission denied:[/] Minting bastion session on node '{node_id}' "
82
+ "requires explicit administrative elevation (--admin)."
83
+ )
84
+ raise typer.Exit(code=1)
85
+
86
+ adapter = get_bastion_adapter(protocol)
87
+
88
+ async def _create() -> None:
89
+ try:
90
+ session = await adapter.generate_session_token(
91
+ node_id=node_id,
92
+ operator_id=operator,
93
+ duration_seconds=duration,
94
+ )
95
+ cmd = await adapter.get_connection_command(node_id, session)
96
+
97
+ console.print(
98
+ f"[bold green]✓[/] Bastion session '[bold cyan]{session.session_id}[/]' "
99
+ f"minted for operator '[bold yellow]{operator}[/]'.\n"
100
+ f" Protocol: [magenta]{session.protocol.value}[/]\n"
101
+ f" Expires: [dim]{session.expires_at.strftime('%Y-%m-%d %H:%M:%S UTC')}[/]"
102
+ )
103
+ console.print(
104
+ Panel(
105
+ cmd.as_shell_string(),
106
+ title="[bold green]Connection Command[/]",
107
+ border_style="green",
108
+ )
109
+ )
110
+ except Exception as exc:
111
+ console.print(f"[bold red]Error creating bastion session:[/] {exc}")
112
+ raise typer.Exit(code=1) from exc
113
+
114
+ asyncio.run(_create())
115
+
116
+
117
+ @session_app.command("list")
118
+ def list_sessions_cmd(
119
+ protocol: BastionProtocolType = typer.Option(
120
+ BastionProtocolType.NATIVE_BREAK_GLASS,
121
+ "--protocol",
122
+ "-p",
123
+ help="Target bastion access protocol to audit",
124
+ ),
125
+ format_type: str = format_option(),
126
+ ) -> None:
127
+ """Audit and list active unexpired bastion sessions."""
128
+ resolved_fmt = resolve_format(format_type)
129
+ presenter = CliPresenter(console=console)
130
+ adapter = get_bastion_adapter(protocol)
131
+
132
+ async def _list() -> None:
133
+ try:
134
+ sessions = await adapter.audit_active_sessions()
135
+ presenter.render_bastion_sessions_table(sessions, resolved_fmt)
136
+ except Exception as exc:
137
+ console.print(f"[bold red]Error auditing bastion sessions:[/] {exc}")
138
+ raise typer.Exit(code=1) from exc
139
+
140
+ asyncio.run(_list())
141
+
142
+
143
+ @session_app.command("terminate")
144
+ def terminate_session_cmd(
145
+ session_id: str = typer.Argument(..., help="Target session ID to terminate"),
146
+ protocol: BastionProtocolType = typer.Option(
147
+ BastionProtocolType.NATIVE_BREAK_GLASS,
148
+ "--protocol",
149
+ "-p",
150
+ help="Bastion access protocol governing the session",
151
+ ),
152
+ ) -> None:
153
+ """Revoke an active bastion session immediately."""
154
+ adapter = get_bastion_adapter(protocol)
155
+
156
+ async def _terminate() -> None:
157
+ try:
158
+ await adapter.terminate_session(session_id)
159
+ console.print(
160
+ f"[bold green]✓[/] Bastion session '[bold cyan]{session_id}[/]' successfully terminated."
161
+ )
162
+ except Exception as exc:
163
+ console.print(f"[bold red]Error terminating bastion session:[/] {exc}")
164
+ raise typer.Exit(code=1) from exc
165
+
166
+ asyncio.run(_terminate())
167
+
168
+
169
+ __all__ = [
170
+ "app",
171
+ "get_bastion_adapter",
172
+ ]
@@ -78,6 +78,16 @@ def push_collateral_cmd(
78
78
  sha256_hash = hashlib.sha256(content).hexdigest()
79
79
  size_bytes = len(content)
80
80
  asset_name = name or file_path.name
81
+ if (
82
+ ".." in asset_name
83
+ or "/" in asset_name
84
+ or "\\" in asset_name
85
+ or Path(asset_name).is_absolute()
86
+ ):
87
+ console.print(
88
+ f"[bold red]Error:[/] Collateral name '{asset_name}' contains illegal path components."
89
+ )
90
+ raise typer.Exit(code=1)
81
91
 
82
92
  resolved_tier = CollateralTier(tier.upper())
83
93
  resolved_kind = CollateralKind(kind.upper())
@@ -91,6 +101,7 @@ def push_collateral_cmd(
91
101
  checksum_sha256=sha256_hash,
92
102
  tier=resolved_tier,
93
103
  kind=resolved_kind,
104
+ target_path=str(file_path),
94
105
  user_id=user,
95
106
  elevate=admin,
96
107
  )
@@ -108,6 +119,9 @@ def push_collateral_cmd(
108
119
  asyncio.run(_push())
109
120
 
110
121
 
122
+ # Register stage command alias
123
+ app.command("stage")(push_collateral_cmd)
124
+
111
125
  __all__ = [
112
126
  "app",
113
127
  ]