Service Principal Setup Guide

ML Pipelines Environment-Specific Service Principals

Date: 2025-09-30 Purpose: Create isolated service principals for ML pipeline deployments across environments


Service Principals to Create

Create these three service principals in your Databricks account:

1. Development Service Principal

  • Name: ml-pipelines-dev-service-principal

  • Purpose: Deploy and run ML pipelines in dev workspace

  • Workspace Access: Dev only

  • Permissions: Full access to dev catalog

2. Staging Service Principal

  • Name: ml-pipelines-staging-service-principal

  • Purpose: Deploy and run ML pipelines in staging workspace

  • Workspace Access: Staging only

  • Permissions: Full access to staging catalog

3. Production Service Principal

  • Name: ml-pipelines-prod-service-principal

  • Purpose: Deploy and run ML pipelines in prod workspace

  • Workspace Access: Prod only (most restrictive)

  • Permissions: Full access to prod catalog


Creation Steps

Option A: Via Databricks UI (Quickest)

  1. Navigate to Account Console

    • Go to https://accounts.cloud.databricks.com

    • Login as account admin

  2. Create Service Principals

    • Click "User Management" → "Service Principals"

    • Click "Add Service Principal"

    • For each environment (dev, staging, prod):

      • Name: ml-pipelines-{env}-service-principal

      • Click "Add"

      • COPY THE APPLICATION ID (you'll need this)

  3. Generate OAuth Secrets

    • Click on each service principal

    • Go to "OAuth Secrets" tab

    • Click "Generate Secret"

    • COPY SECRET (shown only once!)

    • Store in password manager

  4. Assign to Workspaces

    • For ml-pipelines-dev-service-principal:

      • Go to "Workspaces" → Dev workspace → "Permissions"

      • Add service principal with "User" role

    • Repeat for staging and prod service principals


GitHub OIDC Configuration

For each service principal, you need to configure GitHub OIDC trust.

Steps for Each Service Principal:

  1. Navigate to Service Principal Settings

    • Account Console → User Management → Service Principals

    • Click on the service principal (e.g., ml-pipelines-dev-service-principal)

  2. Configure GitHub OIDC

    • Go to "Authentication" tab

    • Click "Configure GitHub OIDC"

    • GitHub Organization: refresh-os

    • GitHub Repository: ml-pipelines (or leave blank for org-wide)

    • GitHub Environment (optional but recommended):

      • For dev SP: development

      • For staging SP: staging

      • For prod SP: production

    • Click "Save"

  3. Note the Client ID

    • The Application ID from step 1 is your OIDC Client ID

    • You'll use this in GitHub workflows


Information to Collect

After creating the service principals, fill out this table:

Service Principal
Application ID (UUID)
OIDC Client ID
Notes

ml-pipelines-dev-service-principal

____________________

Same as App ID

For GitHub dev workflow

ml-pipelines-staging-service-principal

____________________

Same as App ID

For GitHub staging workflow

ml-pipelines-prod-service-principal

____________________

Same as App ID

For GitHub prod workflow


Where to Use These IDs

1. databricks.yml Configuration

Recommendation: Use service_principal_name (Option A) - cleaner and more readable

2. GitHub Workflow Files

File: .github/workflows/ml_pipelines_dev_deploy.yml

File: .github/workflows/ml_pipelines_staging_deploy.yml

File: .github/workflows/ml_pipelines_prod_deploy.yml

File: /Users/taylorlaing/Development/refresh-os/infra-core/stacks/ml-databricks/main.tf


Verification Steps

After creating service principals and updating configurations:

Test 1: CLI Authentication

Test 2: GitHub OIDC

Test 3: Catalog Permissions


Security Best Practices

Principle of Least Privilege

  • Each service principal only has access to its environment's workspace

  • Each service principal only has permissions on its environment's catalog

  • Service principals cannot access developer sandbox catalogs

  • GitHub OIDC tied to specific GitHub environments

Secret Management

  • NEVER commit service principal secrets to git

  • Use GitHub OIDC (no secrets in GitHub at all)

  • Store OAuth secrets in password manager (only needed for manual testing)

  • Rotate secrets every 90 days (set calendar reminder)

Audit Trail

  • All deployments run as service principals (not personal accounts)

  • Service principal names clearly indicate purpose and environment

  • Databricks audit logs track all service principal actions

  • GitHub Actions logs provide deployment audit trail


Troubleshooting

Issue: "Service principal not found"

Cause: Service principal name typo or not created yet Fix: Verify service principal exists: databricks service-principals list --profile ref-admin

Issue: "OIDC authentication failed"

Cause: GitHub OIDC not configured or Client ID mismatch Fix:

  1. Verify OIDC configuration in Databricks account console

  2. Check Client ID matches Application ID in workflow file

  3. Ensure GitHub environment name matches OIDC configuration

Issue: "Permission denied on catalog"

Cause: Service principal lacks catalog permissions Fix: Run Terraform grants or manually grant via SQL:

Issue: "Cannot access workspace"

Cause: Service principal not assigned to workspace Fix: Account Console → Workspaces → [workspace] → Permissions → Add service principal


Next Steps

  1. Create the three service principals (via UI or CLI)

  2. Configure GitHub OIDC for each service principal

  3. Fill in the Application IDs in the table above

  4. Update GitHub workflow files with correct Client IDs

  5. Update databricks.yml with service principal names

  6. Add Terraform grants for catalog permissions

  7. Test authentication via CLI

  8. Test deployment via GitHub Actions


Document Version: 1.0 Last Updated: 2025-09-30 Author: Claude Code Status: Ready for Implementation

Last updated