Repository navigation
fix(mdm): provider MDM read-only + close webhook trust-injection (T-021/SEC-004) #270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
56ba68d
1922bf4
f338424
b2ba83d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package api | ||
|
|
||
| import ( | ||
| "io" | ||
| "log/slog" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/eigeninference/d-inference/coordinator/registry" | ||
| "github.com/eigeninference/d-inference/coordinator/store" | ||
| ) | ||
|
|
||
| func mdmTestServer(t *testing.T) *Server { | ||
| t.Helper() | ||
| logger := slog.New(slog.NewTextHandler(io.Discard, nil)) | ||
| st := store.NewMemory(store.Config{AdminKey: "test-key"}) | ||
| reg := registry.New(logger) | ||
| return NewServer(reg, st, ServerConfig{}, logger) | ||
| } | ||
|
|
||
| // TestMDMWebhookSecretGate verifies the optional shared-secret layer: when a | ||
| // secret is configured, callers without it are rejected before the body is read; | ||
| // with it, the request is accepted. | ||
| func TestMDMWebhookSecretGate(t *testing.T) { | ||
| srv := mdmTestServer(t) | ||
| srv.SetMDMWebhookSecret("s3cret") | ||
|
|
||
| // No token → forbidden. | ||
| rec := httptest.NewRecorder() | ||
| req := httptest.NewRequest(http.MethodPost, "/v1/mdm/webhook", strings.NewReader("{}")) | ||
| srv.HandleMDMWebhook(rec, req) | ||
| if rec.Code != http.StatusForbidden { | ||
| t.Fatalf("missing token: want 403, got %d", rec.Code) | ||
| } | ||
|
|
||
| // Wrong token → forbidden. | ||
| rec = httptest.NewRecorder() | ||
| req = httptest.NewRequest(http.MethodPost, "/v1/mdm/webhook?token=wrong", strings.NewReader("{}")) | ||
| srv.HandleMDMWebhook(rec, req) | ||
| if rec.Code != http.StatusForbidden { | ||
| t.Fatalf("wrong token: want 403, got %d", rec.Code) | ||
| } | ||
|
|
||
| // Correct token (query param) → accepted (200; body is empty JSON, no-op). | ||
| rec = httptest.NewRecorder() | ||
| req = httptest.NewRequest(http.MethodPost, "/v1/mdm/webhook?token=s3cret", strings.NewReader("{}")) | ||
| srv.HandleMDMWebhook(rec, req) | ||
| if rec.Code != http.StatusOK { | ||
| t.Fatalf("correct token (query): want 200, got %d", rec.Code) | ||
| } | ||
|
|
||
| // Correct token (header) → accepted. | ||
| rec = httptest.NewRecorder() | ||
| req = httptest.NewRequest(http.MethodPost, "/v1/mdm/webhook", strings.NewReader("{}")) | ||
| req.Header.Set("X-Webhook-Token", "s3cret") | ||
| srv.HandleMDMWebhook(rec, req) | ||
| if rec.Code != http.StatusOK { | ||
| t.Fatalf("correct token (header): want 200, got %d", rec.Code) | ||
| } | ||
| } | ||
|
|
||
| // TestMDMWebhookNoSecretConfigured verifies that when no secret is set, the | ||
| // endpoint does not 403 (it relies on the solicited-command gate instead). | ||
| func TestMDMWebhookNoSecretConfigured(t *testing.T) { | ||
| srv := mdmTestServer(t) | ||
| rec := httptest.NewRecorder() | ||
| req := httptest.NewRequest(http.MethodPost, "/v1/mdm/webhook", strings.NewReader("{}")) | ||
| srv.HandleMDMWebhook(rec, req) | ||
| if rec.Code != http.StatusOK { | ||
| t.Fatalf("no secret configured: want 200, got %d", rec.Code) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,6 +79,18 @@ if [ -n "$MICROMDM_API_KEY" ]; then | |
| -days 3650 -subj "/CN=localhost" 2>/dev/null | ||
| fi | ||
|
|
||
| # If the coordinator is configured with EIGENINFERENCE_MDM_WEBHOOK_SECRET it | ||
| # rejects any MDM callback that doesn't present that secret. MicroMDM has no | ||
| # option to set a header on the command webhook, so the shared secret rides | ||
| # as a ?token= query param (the coordinator also accepts the X-Webhook-Token | ||
| # header — see HandleMDMWebhook). These MUST stay in sync: setting the secret | ||
| # on the coordinator without this token would 403 every legitimate | ||
| # SecurityInfo/MDA callback and stall provider hardware-trust verification. | ||
| MDM_WEBHOOK_URL="http://localhost:8080/v1/mdm/webhook" | ||
| if [ -n "${EIGENINFERENCE_MDM_WEBHOOK_SECRET:-}" ]; then | ||
| MDM_WEBHOOK_URL="${MDM_WEBHOOK_URL}?token=${EIGENINFERENCE_MDM_WEBHOOK_SECRET}" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
| fi | ||
|
|
||
| echo "Starting MicroMDM..." | ||
| micromdm serve \ | ||
| -server-url "https://${DOMAIN:-localhost}" \ | ||
|
|
@@ -89,7 +101,7 @@ if [ -n "$MICROMDM_API_KEY" ]; then | |
| -tls-key /data/micromdm/server.key \ | ||
| -http-addr :9002 \ | ||
| -http-proxy-headers \ | ||
| -command-webhook-url http://localhost:8080/v1/mdm/webhook \ | ||
| -command-webhook-url "${MDM_WEBHOOK_URL}" \ | ||
| >> /data/micromdm.log 2>&1 & | ||
|
|
||
| # Wait for MicroMDM to be ready, then import push cert if needed | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
EIGENINFERENCE_MDM_WEBHOOK_SECRETis set here, the server starts rejecting webhook calls that lack the token, but the repo's MicroMDM launch path still usescoordinator/deploy/start.shwith-command-webhook-url http://localhost:8080/v1/mdm/webhookand does not append?token=...or set theX-Webhook-Tokenheader. In deployments that follow that script and enable the new recommended secret, every legitimate SecurityInfo/MDA callback will get 403 before the MDM client sees it, so provider hardware trust verification will time out.Useful? React with 👍 / 👎.