> For the complete documentation index, see [llms.txt](https://www.health-samurai.io/docs/interbox/llms.txt).
> Use it to discover all available pages before guessing URLs.

---
# Testing locally with k3d

You can rehearse the full secure deployment (internal-style ingress, TLS and an
SSO login gate) on a laptop with [k3d](https://k3d.io) (k3s in Docker) before
you touch a real cloud. It exercises the same chart and the same
[Securing dashboard access](../secure/dashboard-access.md) wiring. Only the identity provider and the
cert issuer differ from production.

This page walks through one flow: oauth2-proxy at the ingress logs you in through
Dex, then Interbox shows its own sign-in and you enter the administrator password.
That is two logins, the same shape as production behind a gate such as Entra ID.
[Signing in once](#signing-in-once-through-interbox) at the end shows the
alternative where Interbox talks to Dex itself.

> The credentials and self-signed certs here are **throwaway, local-only**. Never
> reuse them anywhere real.

**Prerequisites:** `k3d`, `kubectl`, `helm`, `docker`, `openssl`, and a POSIX
shell. On Windows, use Git Bash. The steps ran on k3d 5.9 (k3s 1.35),
ingress-nginx chart 4.15.1, cert-manager 1.21.3, Dex 2.45.1, oauth2-proxy 7.15.2,
the `interbox` chart 0.4.0 and the `healthsamurai/interbox:2.5.3` image.

Save every file below in one working folder and run the commands from it.

## 1. Cluster and ingress controller

k3d ships Traefik; swap it for `ingress-nginx` (so the oauth2-proxy auth
annotations work as they do on AKS), and map host ports to the ingress:

```sh
k3d cluster create interbox \
  --k3s-arg "--disable=traefik@server:0" \
  -p "8081:80@loadbalancer" -p "8443:443@loadbalancer" --wait

helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm install ingress-nginx ingress-nginx/ingress-nginx \
  -n ingress-nginx --create-namespace \
  --set controller.service.type=LoadBalancer --wait
```

`k3d cluster create` adds the cluster to your default kubeconfig and switches to it.
Run `kubectl config current-context` and check that it says `k3d-interbox` before
you continue. To keep your other contexts untouched, add
`--kubeconfig-update-default=false --kubeconfig-switch-context=false` to the create
command, then run `k3d kubeconfig get interbox > kubeconfig` and
`export KUBECONFIG=$PWD/kubeconfig` in each shell.

`*.localhost` resolves to loopback in your browser and in `curl`, so
`interbox.localhost:8443` reaches the ingress with no `/etc/hosts` edits.

## 2. Postgres

A throwaway in-cluster Postgres is enough (its `postgres` superuser has
`CREATEDB`, so the engine self-creates the `interbox` db):

```sh
kubectl create deploy interbox-pg --image=postgres:18-alpine
kubectl set env deploy/interbox-pg POSTGRES_USER=postgres POSTGRES_HOST_AUTH_METHOD=trust POSTGRES_DB=postgres
kubectl expose deploy/interbox-pg --port=5432
kubectl rollout status deploy/interbox-pg
```

## 3. cert-manager and a local CA

Install cert-manager, then create a **self-signed CA** issuer, the local stand-in
for the internal CA you'd use for a private host in production:

```sh
helm repo add jetstack https://charts.jetstack.io
helm install cert-manager jetstack/cert-manager \
  -n cert-manager --create-namespace --set crds.enabled=true --wait
```

```yaml
# ca-issuer.yaml
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata: { name: selfsigned }
spec: { selfSigned: {} }
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata: { name: local-ca, namespace: cert-manager }
spec:
  isCA: true
  commonName: interbox-local-ca
  secretName: local-ca
  issuerRef: { name: selfsigned, kind: ClusterIssuer, group: cert-manager.io }
---
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata: { name: local-ca }
spec: { ca: { secretName: local-ca } }
```

```sh
kubectl apply -f ca-issuer.yaml
```

An ingress annotated `cert-manager.io/cluster-issuer: local-ca` now gets a cert.

## 4. An identity provider (Dex)

In production this is Entra ID / Okta. Locally, run [Dex](https://dexidp.io) with
one static test user and an OIDC client. The user is `user@interbox.local` with
the password `password`. The `hash` below is its bcrypt hash. To use another
password, generate the hash with
`docker run --rm httpd:2-alpine htpasswd -bnBC 10 "" 'password' | tr -d ':\n' | sed 's/\$2y/\$2a/'`.

The issuer is `https://dex.localhost:8443/dex`, served through the ingress with a
cert from the local CA. The client has two redirect URIs: `/oauth2/callback` for
oauth2-proxy and `/api/auth/callback` for
[Signing in once](#signing-in-once-through-interbox).

```yaml
# dex.yaml
apiVersion: v1
kind: Namespace
metadata: { name: dex }
---
apiVersion: v1
kind: ConfigMap
metadata: { name: dex, namespace: dex }
data:
  config.yaml: |
    issuer: https://dex.localhost:8443/dex
    storage: { type: memory }
    web: { http: 0.0.0.0:5556 }
    oauth2: { skipApprovalScreen: true }
    enablePasswordDB: true
    staticClients:
      - id: interbox-dashboard
        name: Interbox dashboard
        secret: throwaway-dex-client-secret
        redirectURIs:
          - https://interbox.localhost:8443/oauth2/callback
          - https://interbox.localhost:8443/api/auth/callback
    staticPasswords:
      - email: user@interbox.local
        username: user
        userID: "1"
        hash: "$2a$10$brurDOJTkimn28kwrNM/QOX9ZOdi7QfUz3lW9LK/Ao5sRPT/p3rTm"
---
apiVersion: apps/v1
kind: Deployment
metadata: { name: dex, namespace: dex }
spec:
  selector: { matchLabels: { app: dex } }
  template:
    metadata: { labels: { app: dex } }
    spec:
      containers:
        - name: dex
          image: ghcr.io/dexidp/dex:v2.45.1
          args: [dex, serve, /etc/dex/config.yaml]
          ports: [{ containerPort: 5556 }]
          volumeMounts: [{ name: config, mountPath: /etc/dex }]
      volumes:
        - name: config
          configMap: { name: dex }
---
apiVersion: v1
kind: Service
metadata: { name: dex, namespace: dex }
spec:
  selector: { app: dex }
  ports: [{ port: 5556 }]
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: dex
  namespace: dex
  annotations:
    cert-manager.io/cluster-issuer: local-ca
spec:
  ingressClassName: nginx
  tls: [{ hosts: [dex.localhost], secretName: dex-tls }]
  rules:
    - host: dex.localhost
      http:
        paths:
          - { path: /, pathType: Prefix, backend: { service: { name: dex, port: { number: 5556 } } } }
```

```sh
kubectl apply -f dex.yaml
kubectl -n dex rollout status deploy/dex
curl -sk https://dex.localhost:8443/dex/.well-known/openid-configuration | grep '"issuer"'
```

The last command prints `"issuer": "https://dex.localhost:8443/dex",`.

## 5. The login gate (oauth2-proxy)

Run oauth2-proxy against Dex. It sends the browser to the public Dex address and
calls Dex's token and key endpoints through the in-cluster service, so it needs
no cluster DNS for `dex.localhost` (hence `--skip-oidc-discovery`).
`--approval-prompt=auto` stops oauth2-proxy asking Dex for its approval screen on
every login. oauth2-proxy answers at `interbox.localhost/oauth2`, on the same host
as the dashboard, for the cookie and the callback.

Generate its cookie secret into a Secret first:

```sh
kubectl create secret generic oauth2-proxy --from-literal=cookie-secret="$(openssl rand -hex 16)"
```

```yaml
# oauth2-proxy.yaml
apiVersion: apps/v1
kind: Deployment
metadata: { name: oauth2-proxy }
spec:
  selector: { matchLabels: { app: oauth2-proxy } }
  template:
    metadata: { labels: { app: oauth2-proxy } }
    spec:
      containers:
        - name: oauth2-proxy
          image: quay.io/oauth2-proxy/oauth2-proxy:v7.15.2
          args:
            - --provider=oidc
            - --skip-oidc-discovery=true
            - --oidc-issuer-url=https://dex.localhost:8443/dex
            - --login-url=https://dex.localhost:8443/dex/auth
            - --redeem-url=http://dex.dex.svc.cluster.local:5556/dex/token
            - --oidc-jwks-url=http://dex.dex.svc.cluster.local:5556/dex/keys
            - --client-id=interbox-dashboard
            - --client-secret=throwaway-dex-client-secret
            - --redirect-url=https://interbox.localhost:8443/oauth2/callback
            - --cookie-secure=true
            - --email-domain=*
            - --approval-prompt=auto
            - --http-address=0.0.0.0:4180
            - --reverse-proxy=true
            - --upstream=static://202
          env:
            - name: OAUTH2_PROXY_COOKIE_SECRET
              valueFrom: { secretKeyRef: { name: oauth2-proxy, key: cookie-secret } }
          ports: [{ containerPort: 4180 }]
---
apiVersion: v1
kind: Service
metadata: { name: oauth2-proxy }
spec:
  selector: { app: oauth2-proxy }
  ports: [{ port: 4180 }]
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata: { name: oauth2-proxy }
spec:
  ingressClassName: nginx
  tls: [{ hosts: [interbox.localhost], secretName: interbox-tls }]
  rules:
    - host: interbox.localhost
      http:
        paths:
          - { path: /oauth2, pathType: Prefix, backend: { service: { name: oauth2-proxy, port: { number: 4180 } } } }
```

```sh
kubectl apply -f oauth2-proxy.yaml
kubectl rollout status deploy/oauth2-proxy
```

## 6. Interbox

Install the chart with the secure values (see [Securing dashboard access](../secure/dashboard-access.md)).
Pin the image to a released version: the chart picks its readiness probe from the
tag, and a floating tag such as `edge` names no version (see
[Readiness](deployment.md#readiness)). `pullPolicy: IfNotPresent` stops every pod
restart from asking Docker Hub again, which refuses anonymous pulls once you pass
its rate limit.

```yaml
# values.yaml
image:
  tag: "2.5.3"
  pullPolicy: IfNotPresent
config:
  AIDBOX_URL: "http://aidbox.placeholder.svc:8080"     # no Aidbox locally
  INTERBOX_WORKSPACE_GIT_URL: "https://github.com/HealthSamurai/interbox-workspace"
  INTERBOX_PUBLIC_URL: "https://interbox.localhost:8443"
secrets:
  DATABASE_URL: "postgres://postgres@interbox-pg:5432/interbox?sslmode=disable"
  AIDBOX_CLIENT_SECRET: "placeholder"
  INTERBOX_AUTH_ADMIN_PASSWORD: "throwaway-local-password-0123"
ingress:
  enabled: true
  className: nginx
  host: interbox.localhost
  tls:
    - { hosts: [interbox.localhost], secretName: interbox-tls }
  annotations:
    cert-manager.io/cluster-issuer: local-ca
    nginx.ingress.kubernetes.io/auth-url: "http://oauth2-proxy.default.svc.cluster.local:4180/oauth2/auth"
    nginx.ingress.kubernetes.io/auth-signin: "https://interbox.localhost:8443/oauth2/start?rd=$escaped_request_uri"
```

```sh
helm repo add healthsamurai https://healthsamurai.github.io/helm-charts
helm install interbox healthsamurai/interbox -f values.yaml
kubectl rollout status deploy/interbox
```

The chart also starts the [workspace service](deployment.md#the-workspace-service),
`interbox-workspace`, which clones and builds the workspace and publishes it.
The `interbox` pod runs no pipeline until it has loaded that build.

## 7. Verify

```sh
# unauthenticated -> redirected to the login gate (SSO enforced)
curl -sk -o /dev/null -D - https://interbox.localhost:8443/api/pipelines | grep -iE '^HTTP|^location'
#   HTTP/1.1 302 Moved Temporarily
#   Location: https://interbox.localhost:8443/oauth2/start?rd=%2Fapi%2Fpipelines   -> then on to Dex

# TLS served by the cert-manager CA
echo | openssl s_client -connect 127.0.0.1:8443 -servername interbox.localhost 2>/dev/null \
  | openssl x509 -noout -issuer
#   issuer=CN=interbox-local-ca
```

Connect `openssl` to `127.0.0.1`: on Windows it does not resolve `*.localhost`.

Then open `https://interbox.localhost:8443/` and accept the self-signed warning.
You log in twice:

1. oauth2-proxy sends you to Dex. Log in as `user@interbox.local` / `password`.
2. Interbox shows its own sign-in page. Single sign-on is off in Interbox here, so
   the page holds only the administrator password box. Enter
   `INTERBOX_AUTH_ADMIN_PASSWORD` from the values above.

Without a license, the dashboard then shows **Activate this instance**. That is the
dashboard: activate a license from there to start the engine.

## Signing in once through Interbox

Production often drops the second login by pointing Interbox's own sign-in at the
identity provider. You can do the same here, with three changes to the cluster.
The two-login flow above needs none of them, which is why this page leads with it.

1. **Name the issuer with a host that is not `*.localhost`.** The Interbox
   process fetches `<issuer>/.well-known/openid-configuration` itself
   ([What the issuer is](../secure/dashboard-access.md#what-the-issuer-is-and-how-to-find-it)).
   Bun, the runtime of the engine, resolves every `*.localhost` name to loopback
   inside the pod, whatever the cluster DNS says, and the fetch fails with
   `ECONNREFUSED`. Use `dex.127.0.0.1.nip.io` instead. The public `nip.io` DNS
   service resolves it to `127.0.0.1` for your browser, so this needs internet
   access. In `dex.yaml`, replace `dex.localhost` with `dex.127.0.0.1.nip.io` (the
   issuer and the Ingress host and TLS entry). `interbox.localhost` stays.
2. **Send that name to the ingress inside the cluster.** The host port `8443`
   exists only on your machine, so add a Service that exposes the controller on
   `8443` and rewrite the Dex name to it in CoreDNS (k3s reads
   `coredns-custom`):

   ```yaml
   # sso-dns.yaml
   apiVersion: v1
   kind: Service
   metadata: { name: ingress-8443, namespace: ingress-nginx }
   spec:
     selector:
       app.kubernetes.io/name: ingress-nginx
       app.kubernetes.io/component: controller
     ports: [{ name: https, port: 8443, targetPort: 443 }]
   ---
   apiVersion: v1
   kind: ConfigMap
   metadata: { name: coredns-custom, namespace: kube-system }
   data:
     dex.override: |
       rewrite name exact dex.127.0.0.1.nip.io ingress-8443.ingress-nginx.svc.cluster.local
   ```

3. **Trust the local CA in the pod.** Copy only the CA certificate (not its key)
   into a secret and mount it with `NODE_EXTRA_CA_CERTS`. Without it, discovery
   fails with `UNABLE_TO_VERIFY_LEAF_SIGNATURE`.

```sh
kubectl apply -f dex.yaml -f sso-dns.yaml
kubectl -n dex rollout restart deploy/dex
kubectl -n kube-system rollout restart deploy/coredns
kubectl -n cert-manager get secret local-ca -o jsonpath='{.data.ca\.crt}' | base64 -d > ca.crt
kubectl create secret generic local-ca-bundle --from-file=ca.crt=ca.crt
kubectl delete deploy oauth2-proxy
```

Merge these keys into `values.yaml`, where `config` and `secrets` already
exist, and drop the two `auth-*` annotations, since oauth2-proxy no longer
gates the ingress.

```yaml
config:
  INTERBOX_AUTH_ISSUER: "https://dex.127.0.0.1.nip.io:8443/dex"
  INTERBOX_AUTH_CLIENT_ID: "interbox-dashboard"
  INTERBOX_AUTH_PROVIDER_LABEL: "Dex"
  INTERBOX_AUTH_ALLOWED_EMAILS: "user@interbox.local"
  NODE_EXTRA_CA_CERTS: "/etc/local-ca/ca.crt"
secrets:
  INTERBOX_AUTH_CLIENT_SECRET: "throwaway-dex-client-secret"
volumes:
  - name: local-ca
    secret: { secretName: local-ca-bundle }
volumeMounts:
  - { name: local-ca, mountPath: /etc/local-ca, readOnly: true }
```

```sh
helm upgrade interbox healthsamurai/interbox -f values.yaml
```

Open `https://interbox.localhost:8443/`. The sign-in page offers **Sign in with
Dex** and, behind it, **Use the administrator password**. One login as
`user@interbox.local` reaches the dashboard. If discovery still fails,
`/api/auth/start` answers `503` and the engine log names the failing check.

## What changes on real cloud

| Local (here) | Production (e.g. AKS) |
| ------------ | --------------------- |
| ingress-nginx (mapped host ports) | ingress-nginx behind an **internal** LB, or AGIC |
| self-signed CA issuer | **DNS-01** (public zone) or your **internal CA** / Key Vault |
| **Dex** + static user | **Entra ID / Okta** (real OIDC app) |
| in-cluster Postgres pod | **managed Postgres** (private endpoint, `sslmode=verify-full`) |
| CoreDNS rewrite, `nip.io` host and mounted CA, only for [signing in once](#signing-in-once-through-interbox) | a provider the pods already reach by public DNS, with a certificate a public CA signed |

Everything else is identical: the chart, the ingress annotations, cert-manager and oauth2-proxy.
Tear down with `k3d cluster delete interbox`.
