# Control Plane Setup

Source: https://docs.formance.com/v4.0/deploy/self-hosted/installation/control-plane

Stack: v4.0

Use this guide to configure the Enterprise control plane: Dex (OIDC provider), Membership (management API), and Console (web interface). Prepare the Membership signing and crypto keys and production credentials before installation, then complete the remaining configuration and initial setup.

The Membership service is versioned independently from the stack. The `admin wizard` bootstrap command landed in `v2.0.0`, so the instructions on this page depend on which Membership release the Helm chart you're installing ships. Pick yours below.

## Components Overview

| Component      | Description                                         | Default URL                |
| -------------- | --------------------------------------------------- | -------------------------- |
| **Dex**        | OIDC/OAuth2 provider for authentication             | `dex.<your-domain>`        |
| **Membership** | Management API for organizations, users, and stacks | `membership.<your-domain>` |
| **Console**    | Web interface for managing your Formance stack      | `console.<your-domain>`    |

## Membership signing and crypto keys

The Operator automatically provisions signing keys for each stack's Auth service. Membership is deployed separately by Helm and requires its own signing and crypto keys; the Operator does not provision them.

Before installing Enterprise Edition, provision two Kubernetes Secrets in `formance-system`:

- `membership-signing-key` — a PEM-encoded PKCS#1 RSA private key under `signing.key`.
- `membership-crypto-key` — a stable cookie and OIDC state encryption key under `crypto.key`.

Add both references to the `values.yaml` used by the [Enterprise install command](https://docs.formance.com/v4.0/deploy/self-hosted/installation/operator-setup#install):

```yaml
cloudprem:
  membership:
    config:
      auth:
        signingKey:
          existingSecret: membership-signing-key
          key: signing.key
        cryptoKey:
          existingSecret: membership-crypto-key
          key: crypto.key
```

The Secrets must exist before installation. These references tell Membership where to read the keys; they do not create them.

## Replace Default Secrets Before Production

The Helm chart includes predictable credentials for local evaluation. Do not use them in a production or shared environment. Treat the installation as incomplete until you replace every value in the table below and remove the default Dex user.

| Credential                    | Default                           | Purpose                                        |
| ----------------------------- | --------------------------------- | ---------------------------------------------- |
| Portal OAuth client secret    | `changeMe1`                       | Authenticates Portal to Membership             |
| Console OAuth client secret   | `changeMe2`                       | Authenticates Console to Membership            |
| Membership OIDC client secret | `changeMe`                        | Authenticates Membership to Dex                |
| Portal cookie secret          | `changeMe2`                       | Protects Portal sessions                       |
| Console cookie encryption key | `changeMe00`                      | Protects Console sessions                      |
| Dex static user               | `admin@formance.com` / `password` | Provides a local test login                    |
| PostgreSQL credentials        | `formance` / `formance`           | Authenticates services to the bundled database |

Generate an independent, cryptographically random value for each credential. Store the values in your secret manager and synchronize them to a Kubernetes Secret in the Formance namespace. Do not commit the secret values to your Helm values file.

The following example assumes a Secret named `formance-control-plane-secrets` already exists in the release namespace:

```yaml
# production-values.yaml
global:
  platform:
    portal:
      oauth:
        client:
          existingSecret: formance-control-plane-secrets
          secretKeys:
            secret: portal-oauth-client-secret
    consoleV3:
      oauth:
        client:
          existingSecret: formance-control-plane-secrets
          secretKeys:
            secret: console-oauth-client-secret

cloudprem:
  membership:
    config:
      oidc:
        existingSecret: formance-control-plane-secrets
        secretKeys:
          secret: membership-oidc-client-secret
    dex:
      envVars:
        - name: MEMBERSHIP_CLIENT_SECRET
          valueFrom:
            secretKeyRef:
              name: formance-control-plane-secrets
              key: membership-oidc-client-secret
      configOverrides:
        enablePasswordDB: false
        staticPasswords: []
  portal:
    config:
      cookie:
        existingSecret: formance-control-plane-secrets
        secretKeys:
          secret: portal-cookie-secret
  console-v3:
    config:
      cookie:
        existingSecret: formance-control-plane-secrets
        secretKeys:
          encryptionKey: console-cookie-encryption-key
```

`existingSecret` changes how the workloads read credentials; it does not create the Secret. Create it before the Helm release, or manage it with a controller such as External Secrets. Membership and Dex must read the same `membership-oidc-client-secret` value.

For PostgreSQL, use a managed database in production and reference its credentials through `global.postgresql.auth.existingSecret`. See [PostgreSQL configuration](https://docs.formance.com/v4.0/deploy/self-hosted/infrastructure/postgresql).

## Dex Configuration

[Dex](https://dexidp.io/) is deployed as the default OIDC provider. You can configure it to:

- Create local users for testing
- Connect to external identity providers (SAML, LDAP, OAuth2)
- Integrate with your existing SSO infrastructure

### Default Configuration

The default Dex configuration creates a simple setup for testing with a static admin user. For production, configure your own identity provider.

### Connecting to External Identity Providers

Dex configuration is set through `cloudprem.membership.dex.configOverrides`, which merges with the default Dex configuration generated by the Membership chart.

Configure SAML Provider

```yaml
# values.yaml
cloudprem:
  membership:
    dex:
      configOverrides:
        connectors:
          - type: saml
            id: saml
            name: SAML
            config:
              ssoURL: https://your-idp.example.com/sso
              ca: /path/to/ca.pem
              redirectURI: https://dex.your-domain.com/callback
              usernameAttr: name
              emailAttr: email
```

Configure LDAP Provider

```yaml
# values.yaml
cloudprem:
  membership:
    dex:
      configOverrides:
        connectors:
          - type: ldap
            id: ldap
            name: LDAP
            config:
              host: ldap.example.com:636
              insecureNoSSL: false
              bindDN: cn=admin,dc=example,dc=com
              bindPW: admin-password
              userSearch:
                baseDN: ou=users,dc=example,dc=com
                filter: "(objectClass=person)"
                username: uid
                idAttr: uid
                emailAttr: mail
                nameAttr: cn
```

Configure OAuth2 Provider (Okta, Auth0, etc.)

```yaml
# values.yaml
cloudprem:
  membership:
    dex:
      configOverrides:
        connectors:
          - type: oidc
            id: okta
            name: Okta
            config:
              issuer: https://your-org.okta.com
              clientID: your-client-id
              clientSecret: your-client-secret
              redirectURI: https://dex.your-domain.com/callback
              scopes:
                - openid
                - profile
                - email
```

### Using Your Own OIDC Provider

If you already have an OIDC provider (e.g., Keycloak), you can bypass Dex entirely:

```yaml
# values.yaml
global:
  platform:
    membership:
      relyingParty:
        scheme: "https"
        host: "keycloak.example.com"
        path: "/realms/master"

cloudprem:
  membership:
    dex:
      enabled: false
    config:
      oidc:
        clientId: "membership"
        clientSecret: "your-client-secret"
        scopes:
          - openid
          - email
          - federated:id
```

The `global.platform.membership.relyingParty` defines the OIDC issuer URL. Use the `path` field when your provider uses a sub-path (e.g., Keycloak realms).

### Membership Configuration

You can customize authentication behavior and stack defaults:

```yaml
cloudprem:
  membership:
    config:
      oidc:
        clientId: "membership"
        clientSecret: "changeMe"
        scopes:
          - openid
          - email
          - federated:id
      auth:
        loginWithSSO: false  # Enable email-based SSO selector
        tokenValidity:
          accessToken: "5m"
          refreshToken: "72h"
      stack:
        minimalStackModules:
          - Auth
          - Ledger
          - Gateway
        additionalModules:
          - Payments
          - Stargate
      fctl: true  # Enable fctl CLI support
```

## Service Ports

| Service    | Port | Protocol |
| ---------- | ---- | -------- |
| Membership | 8080 | HTTP     |
| Membership | 8082 | gRPC     |
| Dex        | 5556 | HTTP     |
| Portal     | 3000 | HTTP     |
| Console V3 | 3000 | HTTP     |

## Initial Setup with Membership CLI

The Membership CLI provides commands to configure your self-hosted deployment. You run these commands directly inside the Membership container.

### Accessing the Membership CLI

Connect to the Membership container:

```bash
kubectl exec -it -n formance-system deployment/membership -- sh
```

### Bootstrap with the wizard

Membership ships a single `admin wizard` command that creates the resources you need to get a fresh deployment running — users, organizations, private regions, and stacks. It runs either interactively or against a YAML config you supply, and the chart embeds the same config path so the install job can run it automatically on first boot.

#### Interactive

```bash
membership admin wizard
```

The wizard prompts you through a menu — create user, manage organizations, manage private regions, manage stacks. Each step asks for the inputs it needs (email, name, base URL, modules). Use this when you want a one-off setup with no values file changes.

#### From a config file (idempotent)

For repeatable installs, declare the resources in a YAML file and pass it with `--config`:

```bash
membership admin wizard --config /path/to/wizard.yaml
```

```yaml
# wizard.yaml
wizard:
  users:
    - id: "admin-uuid"
      email: "admin@your-company.com"
      role: "ADMIN"
  organizations:
    - id: "my-org"
      ownerId: "admin-uuid"
      name: "My Company"
      # Built-in policy ID applied to users who join the org without an explicit
      # policy assignment. 10 = OrganizationAdminStackAdmin, 8 = OrganizationAdmin,
      # 4 = OrganizationGuest, etc. See "Built-in policies" in /manage/identity/rbac.
      defaultPolicyId: 10
  regions:
    - id: "region-1"
      name: "default"
      baseUrl: "https://formance.your-domain.com"
      organizationId: "my-org"
  stacks:
    - id: "production"
      name: "production"
      organizationId: "my-org"
      regionId: "region-1"
      version: "v3.1"
      modules: ["Auth", "Ledger", "Gateway"]
```

The wizard reconciles each section idempotently: existing resources are checked against the config (and the wizard errors out if there's a mismatch), missing resources are created. Re-running with the same config is safe.

User-level `role` is the **system role** (whether the user is a platform admin), distinct from the org-level RBAC policy assigned via `defaultPolicyId`:

- `ADMIN` — full system access
- `USER` — standard access

The chart embeds this same YAML directly under `cloudprem.membership.config.wizard.setup` in your `values.yaml` and runs the wizard job once on first install — see [Wizard Bootstrap (Alternative to CLI)](#wizard-bootstrap-alternative-to-cli) below for the values-file variant used by the `ee-demo.yaml` profile.

### Available commands

The full membership CLI surface:

```
membership
├── serve              # Run the membership HTTP service
├── version            # Print version info
├── storage
│   └── migrations     # Database migration commands
├── admin
│   └── wizard         # Interactive or config-driven bootstrap
├── stargate           # Stargate relay service
├── stream             # Internal event-stream commands
├── cycle              # Stack-cycle worker
├── gc                 # Garbage collection
└── report             # Reporting tools
```

Run `membership <command> --help` to see flags for any subcommand.

## Configure Organization with fctl

After the initial setup, you can use `fctl` for additional configuration.

### Login to Your Cluster

```bash
fctl login --membership-uri "https://membership.<your-domain>/api"
```

### Configure Auto-Login for Your Domain

```bash
fctl cloud organizations update "<ORGANIZATION_ID>" \
  --domain=your-company.com \
  --default-organization-role=GUEST \
  --default-stack-role=GUEST
```

## Wizard Bootstrap (Alternative to CLI)

Instead of using the Membership CLI, you can auto-create users, organizations, regions, and stacks on first install using the wizard in your values file:

```yaml
cloudprem:
  membership:
    dex:
      configOverrides:
        staticPasswords:
          - email: "admin@example.com"
            hash: "$2a$10$..."  # bcrypt hash of password
            username: "admin"
            userID: "unique-uuid"
            role: ADMIN
    config:
      wizard:
        setup: |
          users:
            - id: "unique-uuid"
              email: "admin@example.com"
              role: "ADMIN"
          organizations:
            - id: "my-org"
              ownerId: "unique-uuid"
              name: "My Organization"
          regions:
            - id: "region-1"
              name: "production"
              organizationId: "my-org"
              baseUrl: "https://formance.example.com"
          stacks:
            - id: "main"
              name: "main"
              organizationId: "my-org"
              regionId: "region-1"
              version: "v3.1"
```

The wizard job runs once on first install and creates all the configured resources. This is the approach used by the `ee-demo.yaml` profile.

## Accessing the Console

After setup, access the Console at:

```
https://console.<your-domain>
```

Log in with your configured identity provider credentials.

## Verifying the Setup

### Check Component Health

```bash
# Check all pods are running
kubectl get pods -n formance-system

# Check services
kubectl get svc -n formance-system

# Check ingresses
kubectl get ingress -n formance-system
```

### Test Authentication

```bash
# Test Dex
curl -I "https://dex.<your-domain>/.well-known/openid-configuration"

# Test Membership API
curl -I "https://membership.<your-domain>/api/_info"

# Test Console
curl -I "https://console.<your-domain>"
```

## Troubleshooting

Cannot access Console

1. Verify ingress is configured:

```bash
kubectl get ingress -n formance-system
```

2. Check TLS certificate:

```bash
kubectl describe certificate -n formance-system
```

3. Check Console logs:

```bash
kubectl logs -n formance-system -l app=console
```

Authentication fails

1. Check Dex configuration:

```bash
kubectl get secret -n formance-system membership-dex-config -o jsonpath='{.data.config\.yaml}' | base64 -d
```

2. Verify Dex is accessible:

```bash
curl "https://dex.<your-domain>/.well-known/openid-configuration"
```

3. Check Dex logs:

```bash
kubectl logs -n formance-system -l app.kubernetes.io/name=dex
```

Membership CLI errors

1. Check Membership logs:

```bash
kubectl logs -n formance-system -l app=membership
```

2. Verify the migration state from inside the container:

```bash
kubectl exec -it -n formance-system deployment/membership -- membership storage migrations version
```

3. Verify PostgreSQL is running:

```bash
kubectl get pods -n formance-system -l app.kubernetes.io/name=postgresql
```
