SCIM Gateway

repository·master·Indexed 42 days ago

https://github.com/jelhub/scimgateway

An identity integration gateway that translates SCIM 1.1 and 2.0 requests into endpoint-specific protocols including REST, SQL, NoSQL, LDAP, and SOAP. Version 6.2.10 provides pre-built plugins for Microsoft Entra ID, MongoDB, MS SQL Server, SAP HANA, and Active Directory, enabling seamless identity provisioning to diverse target systems.

Tokens
16.6K
Snippets
37
Records
69
Agent score
53%

What's inside SCIM Gateway

  1. What is SCIM Gateway

    master
    SCIM Gateway is an identity integration gateway that translates SCIM 1.1 and SCIM 2.0 requests into endpoint-specific protocols. It allows you to turn any destination (such as REST, SQL, NoSQL, LDAP, or SOAP) into a SCIM-compatible interface, preventing vendor lock-in by acting as a translation layer between identity providers and target systems.
  2. Understand the local `saml` package in SCIM Gateway

    master

    The lib/saml directory contains a modified local copy of the node-saml package (v4.0.0). This local version is used instead of the standard npm package to ensure compatibility when SCIM Gateway plugins are compiled into standalone binaries using bun build --compile.

    In the original node-saml package, XML templates were loaded from the file system using fs.readFileSync and __dirname. When compiled into a binary, these absolute paths from the build machine would fail on other machines (resulting in ENOENT errors). The local version solves this by inlining the XML templates as string constants directly within the code, removing the runtime dependency on external .template files.

  3. Implement Gateway Chaining

    master

    Chain multiple gateways (gateway1 → gateway2 → gateway3 → endpoint). Each gateway validates authorization and forwards the request unless passThrough is enabled.

    Gateway 1 configuration:

    {
      "scimgateway": {
        "chainingBaseUrl": "https://gateway2:8880",
        "auth": {
          "passThrough": {
            "enabled": false
          }
        }
      }
    }

    In chaining mode, the plugin binary is only used for initialization. A simplified plugin implementation is sufficient:

    import { ScimGateway } from 'scimgateway'
    const scimgateway = new ScimGateway()
    const config = scimgateway.getConfig()
    scimgateway.authPassThroughAllowed = true
    scimgateway.pluginAndOrFilterEnabled = false
  4. Configure SCIM Gateway as a Windows Task for auto-start

    master

    To ensure SCIM Gateway starts automatically on Windows, create a task in Task Scheduler (taskschd.msc) with these settings:

    TabSettingValue
    GeneralNameSCIM Gateway
    GeneralUserSYSTEM
    GeneralPrivilegesRun with highest privileges
    TriggersBegin the taskAt startup
    ActionsStart a program<bun-install-path>\bun.exe
    ActionsArgumentsc:\my-scimgateway
    SettingsStop the task if it runs longer thanDisabled

    Verification:

    1. Confirm the process appears in Task Manager after running the task.
    2. Confirm the process disappears after clicking 'End'.
    3. Confirm auto-start after a system reboot.
  5. Build a custom SCIM plugin

    master

    To create a custom plugin for SCIM Gateway, follow these steps:

    1. Scaffold: Copy an existing example plugin (e.g., lib/plugin-mssql.ts and config/plugin-mssql.json) and rename them with your own prefix (e.g., plugin-mine).
    2. Configure: Set a unique port in your new configuration file (e.g., config/plugin-mine.json).
    3. Register: Import your plugin in index.ts using import './lib/plugin-mine.ts'.
    4. Initialize: Ensure you perform the mandatory plugin initialization in your entry point.
    5. Verify: Start the gateway to confirm the plugin is loaded.

    Recommended Editor: Visual Studio Code is recommended as it provides IntelliSense for all scimgateway methods.

    // Example registration in index.ts
    import './lib/plugin-mine.ts';
  6. Integrate Microsoft Entra ID as an Identity Provider

    master

    Microsoft Entra ID can provision users to SCIM Gateway, which then forwards them to your endpoint plugin.

    Plugin Configuration

    Your plugin must support the following configuration structure for authentication:

    "scimgateway": {
      "scim": { "version": "2.0" },
      "auth": {
        "bearerToken": [
          { "token": "shared-secret" }
        ],
        "bearerJwt": [
          { "azureTenantId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" }
        ]
      }
    }
    • token must match the "Secret Token" in Entra ID provisioning.
    • azureTenantId must match the Entra tenant ID.
    • If "Secret Token" is blank in Entra ID, bearerJwt is used automatically.

    Required Attribute Mappings

    ObjectSourceTargetMatching
    UseruserPrincipalNameuserNamePrecedence #1
    GroupdisplayNamedisplayNamePrecedence #1
    Groupmembersmembers—

    Entra ID Behavior

    • Deletions: Entra ID sends PATCH { "active": "False" } instead of a DELETE request.
    • Keep-alive: Entra ID periodically checks for non-existent users/groups.
    • Existence Check: Entra ID checks for existence before creating users.
    "scimgateway": {
      "scim": { "version": "2.0" },
      "auth": {
        "bearerToken": [{ "token": "shared-secret" }],
        "bearerJwt": [{ "azureTenantId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" }]
      }
    }
  7. Run SCIM Gateway manually

    master

    You can start the SCIM Gateway using bun. Depending on your directory structure, use one of the following commands:

    # If in the package root
    bun .
    
    # Using the absolute path to the directory
    bun c:\my-scimgateway
    
    # Using the path to the entrypoint
    bun c:\my-scimgateway\index.ts

    Press Ctrl+C to stop the process.

    bun .
  8. Deploy SCIM Gateway using Docker

    master

    Single Image Build

    To build and run a single container, follow these steps:

    mkdir /opt/my-scimgateway
    cd /opt/my-scimgateway
    bun init -y
    bun install scimgateway
    bun pm trust scimgateway
    cp ./config/docker/* .
    cp ./config/docker/.dockerignore .
    
    # Build the image
    docker build --platform linux/amd64 --force-rm=true -t my-scimgateway:1.0.0 .
    
    # Create and run the container
    docker create --init --ulimit memlock=-1:-1 --name my-scimgateway -p 8880:8880 my-scimgateway:1.0.0
    docker start my-scimgateway

    Note: If using encrypted configuration files, pass -e SEED=<random> during the docker create step.

    Docker Compose Setup

    For a persistent setup using Docker Compose:

    mkdir /opt/my-scimgateway && cd /opt/my-scimgateway
    bun init -y && bun install scimgateway && bun pm trust scimgateway
    cp ./config/docker/* .
    
    # Setup user and config directory
    adduser scimgateway
    mkdir /home/scimgateway/config
    
    # Copy plugin configuration to the persistent volume
    scp config/plugin-loki.json scimgateway@host:/home/scimgateway/config/
    
    # Start the stack
    docker-compose up --build -d

    Provided Compose Files

    • docker-compose.yml: Main file for setting exposed ports and environment variables.
    • Dockerfile: Main image definition.
    • DataDockerfile: Used for volume mapping.
    • docker-compose-debug.yml: Used to attach a VS Code debugger.
    • docker-compose-mssql.yml: Example including an MSSQL container.
    docker build --platform linux/amd64 --force-rm=true -t my-scimgateway:1.0.0 .
  9. Configure the Entra ID Provisioning Plugin

    master

    The plugin-entra-id provisions users and groups to Microsoft Entra ID via the Microsoft Graph API.

    1. App Registration Requirements

    Register an app in Microsoft Entra ID → App registrations and grant the following Application permissions (Microsoft Graph):

    • Directory.ReadWriteAll (Required)
    • Organization.ReadWrite.All (Required)
    • AuditLog.Read.All (Optional: for map.user.signInActivity; requires Entra ID Premium)
    • UserAuthenticationMethod.ReadWrite.All (Optional: for map.user.mfa)
    • RoleEligibilitySchedule.ReadWrite.Directory (Optional: for PIM roles)
    • RoleManagement.ReadWrite.Directory (Optional: for PIM roles)
    • EntitlementManagement.ReadWrite.All (Optional: for Access Packages)

    Note: After adding permissions, you must click Grant admin consent.

    2. Plugin Configuration

    In your index.ts, import the plugin:

    import './lib/plugin-entra-id.ts'
    export {}

    Configure config/plugin-entra-id.json with your credentials. clientSecret and proxy passwords are automatically encrypted on the first connection:

    {
      "scimgateway": {
        "scim": { "version": "2.0", "skipTypeConvert": true },
        "auth": {
          "basic": [
            { "username": "gwadmin", "password": "password", "readOnly": false }
          ]
        }
      },
      "endpoint": {
        "entity": {
          "undefined": {
            "connection": {
              "baseUrls": [],
              "auth": {
                "type": "oauth",
                "options": {
                  "azureTenantId": "<Tenant ID>",
                  "clientId": "<Application ID>",
                  "clientSecret": "<Secret value>"
                }
              }
            }
          }
        }
      }
    }
  10. Install SCIM Gateway using Bun

    master

    To install SCIM Gateway, you must first have Bun installed. The installation process initializes a new project and copies example files (including index.ts, lib/, and config/) into your directory.

    Note: Running bun pm trust scimgateway is required to allow the postinstall script to copy these example files into your package directory.

    mkdir c:\my-scimgateway
    cd c:\my-scimgateway
    bun init -y
    bun install scimgateway
    bun pm trust scimgateway
  11. Configure SCIM Gateway plugins

    master

    Plugins are defined by an entry point in index.ts and a corresponding configuration file. Each plugin requires a TypeScript file and a JSON configuration file that share the same name prefix.

    Example structure:

    • lib/plugin-entra-id.ts
    • config/plugin-entra-id.json

    The JSON configuration file must contain two top-level objects:

    1. scimgateway: Contains gateway core settings (port, auth, logging, TLS).
    2. endpoint: Contains plugin-specific connection details (host, credentials, mappings).

    To start one or more plugins, import them in your index.ts entry point.

    // Start one or more plugins:
    import './lib/plugin-entra-id.ts'
    export {}
  12. Upgrade SCIM Gateway

    master

    The recommended upgrade path is to rename your existing package folder, perform a fresh installation, and then manually copy your customized index.ts, config/, and lib/ files from the old installation to the new one.

    Minor upgrade:

    bun install scimgateway

    Major upgrade:

    bun install scimgateway@latest

    Note: Major upgrades may break existing plugins. Review the changelog before proceeding.

    Production Note: To exclude example plugins in production environments using npm or Node.js, set the environment variable SCIMGATEWAY_POSTINSTALL_SKIP=true or add scimgateway_postinstall_skip = true to your .npmrc file.

    # Minor upgrade
    bun install scimgateway
    
    # Major upgrade
    bun install scimgateway@latest