feat: implement MDM enrollment authentication system#834
feat: implement MDM enrollment authentication system#834yeisonvargasf merged 1 commit intopyupio:mainfrom
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🚀 Artifacts — PR #834 by @nikkipin (source: nikkipin/safety)
Download the wheel file and binaries with gh CLI or from the workflow artifacts. 📦 Install & RunPre-requisites# Install uv if needed
curl -LsSf https://astral.sh/uv/install.sh | sh
# Create and enter artifacts directory
mkdir artifacts && cd artifactsQuick Test with Python Packagebash -c 'set -euo pipefail; echo; echo "WARNING: You are about to download and execute CI artifacts from PR #834 by @nikkipin (source: nikkipin/safety). Do NOT proceed unless you have reviewed the PR diff and trust the source."; echo; read -rp "Type I understand to continue: " C; [ "$C" = "I understand" ] || { echo "Aborted."; exit 1; }; gh run download 22233727102 -n dist -R pyupio/safety; uvx safety-*-py3-none-any.whl --version'Run other Safety commands as followsuvx safety-*-py3-none-any.whl auth status
uvx safety-*-py3-none-any.whl auth login
uvx safety-*-py3-none-any.whl scan
|
yeisonvargasf
left a comment
There was a problem hiding this comment.
Thank you @nikkipin! This looks great 👍
There is only 1 comment blocking this merge (Changelog).
Adds machine-to-machine (MDM) authentication as a new auth pathway alongside existing OAuth2 and API key methods, enabling headless/managed device enrollment. Core authentication: - MachineCredentialConfig: filelock-protected storage in auth.ini [machine] section - Platform-specific machine ID detection (Linux, macOS, Windows) with unified resolve_machine_id() layered resolution - MachineTokenAuth(httpx.Auth) with Basic Auth encoding - configure_auth_session() precedence: API key > OAuth2 > Machine token > Unauth - `safety auth enroll <key>` command (positional arg) with key validation and credential persistence; SAFETY_ENROLLMENT_KEY env var fallback - `safety auth status` extended for enrollment state display Platform client & TLS: - SafetyPlatformClient with single-client-per-invocation model — each CLI invocation resolves to exactly one auth path (API key, OAuth2, or machine token) - Shared TLS probe (safety/utils/tls_probe.py) with certifi → system trust store fallback for all auth paths (OAuth2, machine-token, enrollment) - Enrollment HTTP logic consolidated into SafetyPlatformClient, reusing shared _build_client_kwargs() for headers, proxy, TLS, and timeout - SAFETY_PLATFORM_V2_URL config for enrollment and system-scan endpoints Error handling: - Exit codes: 73 (non-retryable enrollment failure), 74 (machine ID unavailable), 75/EX_TEMPFAIL (retryable enrollment failure) - EnrollmentError, EnrollmentTransientFailure, MachineIdUnavailableError - 5xx → retryable, network errors after retry exhaustion → retryable - httpx.TransportError coverage (ReadError, WriteError, ProxyError, etc.) System-scan fix: - Pass auth.platform.http_client (authenticated) instead of the bare OAuth2Client, fixing MissingTokenError on the machine token path Config & env overrides: - get_config_setting() priority: env var → config file → enum default - Settings starting with SAFETY_ use their name directly as env var - Fix ENROLLMENT_ENDPOINT from /api/mdm/enroll/ to /api/enroll - Accept HTTP 201 for new enrollments; follow_redirects=True Testing: - Integration test harness (tests/integration/conftest.py) with server health check, isolated auth storage, CLI runner, and auth session bypass - Enrollment integration tests covering happy path, already-enrolled, force re-enroll, invalid key, env var enrollment, credential persistence - Handle Click 8.2+ read-only Context.protected_args in tests - Fix _is_oauth2_flow_command() to use ctx.protected_args (not protected_params, which doesn't exist in Click)
The CONTEXT_FEATURE_TYPE platform gate is temporarily commented out because the new MDM enrollment auth (#834) does not yet support server-side feature flags. Without this change, system-scan is inaccessible to MDM-authenticated users since the feature flag check fails silently and hides the command. The gate should be re-enabled once feature flag support is added to the MDM auth flow.
#837) The CONTEXT_FEATURE_TYPE platform gate is temporarily commented out because the new MDM enrollment auth (#834) does not yet support server-side feature flags. Without this change, system-scan is inaccessible to MDM-authenticated users since the feature flag check fails silently and hides the command. The gate should be re-enabled once feature flag support is added to the MDM auth flow.
Adds machine-to-machine (MDM) authentication as a new auth pathway alongside existing OAuth2 and API key methods, enabling headless/managed device enrollment.
Core authentication:
safety auth enroll <key>command (positional arg) with key validation and credential persistence; SAFETY_ENROLLMENT_KEY env var fallbacksafety auth statusextended for enrollment state displayPlatform client & TLS:
Error handling:
System-scan fix:
Config & env overrides:
Testing:
Description
Type of Change
Related Issues
Testing
Checklist
Additional Notes