|
| 1 | +--- |
| 2 | +layout: docs |
| 3 | +menu: |
| 4 | + docsplatform_{{.version}}: |
| 5 | + identifier: external-console-integration |
| 6 | + name: External Console Integration |
| 7 | + parent: integrations |
| 8 | + weight: 60 |
| 9 | +menu_name: docsplatform_{{.version}} |
| 10 | +section_menu_id: guides |
| 11 | +--- |
| 12 | + |
| 13 | +# Integrating an External Console with the KubeDB Platform |
| 14 | + |
| 15 | +This guide is for **Cloud Service Providers (CSPs)** and ISVs who already operate their |
| 16 | +own web console and want to embed the KubeDB Platform console for their end users, so that |
| 17 | +a user who signs in to the CSP console is transparently signed in to the KubeDB console |
| 18 | +hosted on a subdomain — with no second login prompt. |
| 19 | + |
| 20 | +All endpoints referenced here are documented in the |
| 21 | +[KubeDB Platform API Reference](../../../api/). The most relevant pages are: |
| 22 | + |
| 23 | +- [Administrative-Org Admin](../../../api/administration/admin-org/) — the admin user |
| 24 | + APIs used to provision and maintain the mirrored user. |
| 25 | +- [Public & Basic-auth User APIs](../../../api/users-settings/public-user-apis/) — the |
| 26 | + public `POST /user/signin` endpoint that establishes the browser session. |
| 27 | +- [Authenticated User APIs](../../../api/users-settings/authenticated-user/) — `GET |
| 28 | + /user/signout` and other session-scoped calls. |
| 29 | +- [Client Organizations](../../../api/client-organizations/overview/) — the |
| 30 | + managed-service-provider model for granting each user scoped access to clusters. |
| 31 | + |
| 32 | +## 1. Goal |
| 33 | + |
| 34 | +A CSP already has a console where its customers sign in. The CSP wants to offer KubeDB |
| 35 | +(managed databases) as a feature. The KubeDB Platform console is hosted on a **subdomain of |
| 36 | +the CSP's console**, for example: |
| 37 | + |
| 38 | +| Role | Host | |
| 39 | +|------|------| |
| 40 | +| CSP console (the CSP's existing product; identity provider) | `https://console.acme.com` | |
| 41 | +| KubeDB Platform console **and** API server (per-CSP deployment) | `https://db.acme.com` | |
| 42 | + |
| 43 | +The requirement: **when a user logs into the CSP console, the CSP backend should |
| 44 | +seamlessly log that same user into the KubeDB console.** The user's identity of record |
| 45 | +lives in the CSP console; the KubeDB Platform holds a *mirror* of that identity that the |
| 46 | +CSP backend controls. |
| 47 | + |
| 48 | +This is achieved with two flows: |
| 49 | + |
| 50 | +1. **Provisioning (once per user)** — the CSP backend creates a mirrored KubeDB user |
| 51 | + with the admin API, authenticating with a site-admin **personal access token**. The CSP |
| 52 | + generates and stores that user's KubeDB password; the end user never sees or types it. |
| 53 | +2. **Session handoff (every CSP login)** — the CSP backend performs a server-side sign-in |
| 54 | + to the KubeDB Platform on the user's behalf, captures the resulting session cookies, and |
| 55 | + hands them to the user's browser scoped to the KubeDB subdomain. |
| 56 | + |
| 57 | +Because both consoles share the registrable domain `acme.com`, the browser treats |
| 58 | +`console.acme.com` → `db.acme.com` as **same-site**, so the handoff works cleanly. |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +## 2. Prerequisites |
| 63 | + |
| 64 | +- A per-CSP KubeDB Platform deployment reachable at the subdomain (`https://db.acme.com`), |
| 65 | + serving both the web console and the `/api/v1` REST API. |
| 66 | +- A site-admin **personal access token** issued to the CSP, held **only** by the CSP |
| 67 | + backend — never shipped to a browser. It is sent as an `Authorization: token <TOKEN>` |
| 68 | + header and authorizes the `/api/v1/admin/*` calls (which require the |
| 69 | + `admin_of_administrative_org` relation). See |
| 70 | + [Administrative-Org Admin](../../../api/administration/admin-org/). |
| 71 | +- The administrative organization slug (e.g. `appscode`) to pass as the `?org=` context on |
| 72 | + admin calls. |
| 73 | +- TLS on both hosts. All calls below assume `https://`. |
| 74 | +- The mirrored KubeDB users must **not** have 2FA enabled — `POST /user/signin` rejects |
| 75 | + 2FA-enrolled accounts with HTTP `405`. Since the CSP console is the identity provider, |
| 76 | + leave 2FA off on the mirror and enforce MFA in the CSP console instead. |
| 77 | + |
| 78 | +Throughout, replace the placeholders: |
| 79 | + |
| 80 | +- `db.acme.com` → your KubeDB Platform subdomain (shown as `<akp-host>` in the API reference) |
| 81 | +- `$AKP_TOKEN` → your site-admin token |
| 82 | +- `appscode` → your administrative-org slug |
| 83 | + |
| 84 | +--- |
| 85 | + |
| 86 | +## 3. Phase 1 — Provision the mirrored user (once, at CSP signup) |
| 87 | + |
| 88 | +When a customer signs up (or is first granted database access) on the CSP console, the |
| 89 | +CSP backend creates the corresponding user in the KubeDB Platform. Do **not** use the public |
| 90 | +signup flow — user creation is an admin operation. |
| 91 | + |
| 92 | +The CSP backend generates a strong random password for the KubeDB identity and **stores |
| 93 | +it** (encrypted) alongside the CSP user record. This password is an internal credential |
| 94 | +used only for the server-side handoff in Phase 2; the end user never learns it. |
| 95 | + |
| 96 | +### 3.1 Create the user |
| 97 | + |
| 98 | +`POST /api/v1/admin/users?org=<slug>` — body is a `CreateUserOption` |
| 99 | +([reference](../../../api/administration/admin-org/)): |
| 100 | + |
| 101 | +```bash |
| 102 | +curl -X POST 'https://db.acme.com/api/v1/admin/users?org=appscode' \ |
| 103 | + -H "Authorization: token $AKP_TOKEN" \ |
| 104 | + -H 'Content-Type: application/json' \ |
| 105 | + --data-raw '{ |
| 106 | + "username": "acme-user-42", |
| 107 | + "email": "jane@customer.example.com", |
| 108 | + "password": "<STRONG_RANDOM_PASSWORD_GENERATED_AND_STORED_BY_CSP>", |
| 109 | + "full_name": "Jane Doe", |
| 110 | + "must_change_password": false, |
| 111 | + "send_notify": false |
| 112 | + }' |
| 113 | +``` |
| 114 | + |
| 115 | +| Field | Type | Required | Notes for CSP integration | |
| 116 | +|-------|------|----------|---------------------------| |
| 117 | +| `username` | string | yes | Stable, collision-free (e.g. prefix with your tenant slug). | |
| 118 | +| `email` | string | yes | The user's email. | |
| 119 | +| `password` | string | yes | CSP-generated random secret; store it encrypted. | |
| 120 | +| `full_name` | string | no | Display name. | |
| 121 | +| `must_change_password` | boolean | no | **Set `false`** — a forced change breaks the automated handoff. | |
| 122 | +| `send_notify` | boolean | no | **Set `false`** — the CSP owns all user communication. | |
| 123 | + |
| 124 | +**Response:** `201 Created` — the created `User`. Persist the mapping |
| 125 | +`CSP user ↔ KubeDB username` in the CSP database. |
| 126 | + |
| 127 | +### 3.2 Keep the profile in sync (optional) |
| 128 | + |
| 129 | +When the user edits their name/email in the CSP console, mirror it with `POST |
| 130 | +/api/v1/admin/users/{username}/update?org=<slug>` — body is a `Profile` |
| 131 | +([reference](../../../api/administration/admin-org/)): |
| 132 | + |
| 133 | +```bash |
| 134 | +curl -X POST 'https://db.acme.com/api/v1/admin/users/acme-user-42/update?org=appscode' \ |
| 135 | + -H "Authorization: token $AKP_TOKEN" \ |
| 136 | + -H 'Content-Type: application/json' \ |
| 137 | + --data-raw '{ |
| 138 | + "name": "acme-user-42", |
| 139 | + "full_name": "Jane A. Doe", |
| 140 | + "email": "jane@customer.example.com", |
| 141 | + "keep_email_private": false, |
| 142 | + "language": "en-US", |
| 143 | + "description": "Mirrored from CSP console" |
| 144 | + }' |
| 145 | +``` |
| 146 | + |
| 147 | +### 3.3 Rotate the password (optional) |
| 148 | + |
| 149 | +If the CSP rotates the stored KubeDB credential, push the new value with `POST |
| 150 | +/api/v1/admin/users/{username}/change-password?org=<slug>` — body is an |
| 151 | +`UpdatePasswordParams` |
| 152 | +([reference](../../../api/administration/admin-org/)): |
| 153 | + |
| 154 | +```bash |
| 155 | +curl -X POST 'https://db.acme.com/api/v1/admin/users/acme-user-42/change-password?org=appscode' \ |
| 156 | + -H "Authorization: token $AKP_TOKEN" \ |
| 157 | + -H 'Content-Type: application/json' \ |
| 158 | + --data-raw '{ "password": "<NEW_STRONG_RANDOM_PASSWORD>", "retype": "<NEW_STRONG_RANDOM_PASSWORD>" }' |
| 159 | +``` |
| 160 | + |
| 161 | +### 3.4 Deprovision (on CSP account deletion) |
| 162 | + |
| 163 | +When a CSP user is disabled or deleted, revoke KubeDB access with `DELETE |
| 164 | +/api/v1/admin/users/{username}?org=<slug>` (or `PATCH` the user with `active:false` / |
| 165 | +`prohibit_login:true` to keep the record). See |
| 166 | +[Edit / Delete user](../../../api/administration/admin-org/). |
| 167 | + |
| 168 | + |
| 169 | + |
| 170 | +--- |
| 171 | + |
| 172 | +## 4. Phase 2 — Session handoff (every time the user opens the KubeDB console) |
| 173 | + |
| 174 | +The public sign-in endpoint **`POST /api/v1/user/signin`** authenticates a username + |
| 175 | +password and, on success, **sets the session, CSRF (`_csrf`), and NATS cookies** — the same |
| 176 | +cookies the web console relies on |
| 177 | +([reference](../../../api/users-settings/public-user-apis/)). The trick is |
| 178 | +that these cookies are obtained by the CSP backend server-to-server, then delivered to the |
| 179 | +user's browser so it holds a valid `db.acme.com` session. |
| 180 | + |
| 181 | +### 4.1 The sign-in call |
| 182 | + |
| 183 | +`POST /api/v1/user/signin` — body is a `SignInParams`: |
| 184 | + |
| 185 | +```bash |
| 186 | +curl -X POST 'https://db.acme.com/api/v1/user/signin' \ |
| 187 | + -H 'Content-Type: application/json' \ |
| 188 | + --data-raw '{ |
| 189 | + "username": "acme-user-42", |
| 190 | + "password": "<STORED_KUBEDB_PASSWORD>", |
| 191 | + "remember": true |
| 192 | + }' \ |
| 193 | + -c cookie.txt -D headers.txt |
| 194 | +``` |
| 195 | + |
| 196 | +| Field | Type | Required | Description | |
| 197 | +|-------|------|----------|-------------| |
| 198 | +| `username` | string | yes | The mirrored KubeDB username. | |
| 199 | +| `password` | string | yes | The CSP-stored password for that user. | |
| 200 | +| `remember` | boolean | no | Persist the session across browser restarts. | |
| 201 | + |
| 202 | +**Response:** `200 OK` with no body. The `Set-Cookie` headers (captured in `headers.txt`, |
| 203 | +jarred in `cookie.txt`) carry the session, `_csrf`, and NATS cookies. Non-200 statuses: |
| 204 | +`404` (no such user), `405` (login prohibited / inactive / 2FA enrolled), `422` |
| 205 | +(validation error). |
| 206 | + |
| 207 | +> **CSRF on later calls.** Any subsequent **state-changing** API call made server-side with |
| 208 | +> these cookies must echo the `_csrf` cookie value in an `X-Csrf-Token` header, e.g.: |
| 209 | +> |
| 210 | +> ```bash |
| 211 | +> curl -X POST 'https://db.acme.com/api/v1/user/settings/profile' \ |
| 212 | +> -H 'Content-Type: application/json' \ |
| 213 | +> -H "X-Csrf-Token: <VALUE_OF__csrf_COOKIE>" \ |
| 214 | +> -b cookie.txt --data-raw '{ ... }' |
| 215 | +> ``` |
| 216 | +
|
| 217 | +### 4.2 Delivering the cookies to the browser |
| 218 | +
|
| 219 | +The CSP backend can sign in, but a backend cannot set cookies in the browser for a domain |
| 220 | +other than the one that served the response. So the piece that **re-emits** the captured |
| 221 | +cookies must run on the KubeDB host itself. Host a small **launch endpoint on the KubeDB |
| 222 | +subdomain**, e.g. `https://db.acme.com/csp-sso/launch`, in one of two ways: |
| 223 | +
|
| 224 | +- **Reverse proxy** a path prefix (`db.acme.com/csp-sso/*`) on the KubeDB ingress to the CSP |
| 225 | + backend, or |
| 226 | +- run a **tiny CSP-owned handler co-located on the subdomain**. |
| 227 | +
|
| 228 | +Either way the launch endpoint is same-origin with the KubeDB console, so the `Set-Cookie` |
| 229 | +headers it returns are accepted by the browser for `db.acme.com`. |
| 230 | +
|
| 231 | +The end-to-end handoff: |
| 232 | +
|
| 233 | +1. User is already authenticated on `console.acme.com` and clicks **"Open Databases"**. |
| 234 | +2. The CSP console backend mints a **short-lived, single-use handoff token** (signed, ~30 s |
| 235 | + TTL) identifying the CSP user, and redirects the browser to |
| 236 | + `https://db.acme.com/csp-sso/launch?ticket=<handoff-token>`. |
| 237 | +3. The launch endpoint validates the ticket, looks up the mapped KubeDB username + |
| 238 | + stored password, and performs the **server-side sign-in** (§4.1). |
| 239 | +4. The launch endpoint copies the sign-in response's `Set-Cookie` headers onto its **own |
| 240 | + redirect response** to the browser, then `302`s to `https://db.acme.com/`. |
| 241 | +5. The browser now holds a valid KubeDB session cookie for `db.acme.com` and loads the |
| 242 | + KubeDB console fully authenticated — no login prompt. |
| 243 | +
|
| 244 | + |
| 245 | +
|
| 246 | +### 4.3 Optional: shared-domain single sign-on |
| 247 | +
|
| 248 | +If your KubeDB Platform deployment is configured to set its session cookie with |
| 249 | +`Domain=.acme.com` (the shared parent domain) instead of the default host-only cookie, the |
| 250 | +same session is valid on **both** `console.acme.com` and `db.acme.com`. In that case the |
| 251 | +launch endpoint can set the cookie once and the user moves between the two consoles without |
| 252 | +re-handoff. This requires the KubeDB Platform cookie-domain setting; confirm with your |
| 253 | +deployment before relying on it. The per-launch flow in §4.2 works regardless and is the |
| 254 | +safe default. |
| 255 | +
|
| 256 | +--- |
| 257 | +
|
| 258 | +## 5. Granting database access (Client Organizations) |
| 259 | +
|
| 260 | +Provisioning a mirrored user establishes an identity, but that user still needs **access to |
| 261 | +clusters and databases**. The KubeDB Platform's managed-service-provider model — **Client |
| 262 | +Organizations** — is designed exactly for CSPs. As a site admin, the CSP: |
| 263 | +
|
| 264 | +1. Creates a client organization and imports spoke clusters into it — |
| 265 | + `POST /api/v1/user/client/create` and |
| 266 | + `POST /api/v1/user/client/{orgname}/add-cluster` |
| 267 | + ([Client Org Management](../../../api/client-organizations/management/)). |
| 268 | +2. Creates a per-cluster user with scoped permissions and (optionally) fetches a kubeconfig |
| 269 | + for them — |
| 270 | + `POST /api/v1/clusters/{owner}/{cluster}/permission/user/create` and |
| 271 | + `GET /api/v1/clusters/{owner}/{cluster}/permission/user/{id}/kubeconfig` |
| 272 | + ([Cluster User Permissions](../../../api/client-organizations/cluster-user-permissions/)). |
| 273 | +
|
| 274 | +Map each CSP customer to a client organization and each mirrored user to that org's |
| 275 | +per-cluster permission set, so that when the user lands on the KubeDB console (via the |
| 276 | +handoff above) they see exactly the clusters and databases they are entitled to. The |
| 277 | +equivalent UI walkthrough is in the |
| 278 | +[Client Organization guide](../../client-organization/create-client-organization/). |
| 279 | +
|
| 280 | +--- |
| 281 | +
|
| 282 | +## 6. Logout |
| 283 | +
|
| 284 | +When the user logs out of the CSP console, also terminate the KubeDB session so a shared |
| 285 | +browser can't keep the console open. Call `GET /api/v1/user/signout` with the user's cookies |
| 286 | +and CSRF token ([reference](../../../api/users-settings/authenticated-user/)): |
| 287 | +
|
| 288 | +```bash |
| 289 | +curl -X GET 'https://db.acme.com/api/v1/user/signout' \ |
| 290 | + -H "X-Csrf-Token: <VALUE_OF__csrf_COOKIE>" \ |
| 291 | + -b cookie.txt |
| 292 | +``` |
| 293 | +
|
| 294 | +If you use shared-domain SSO (§4.3), clear the `.acme.com` cookie on logout as well. |
| 295 | +
|
| 296 | +--- |
| 297 | +
|
| 298 | +## 7. API summary |
| 299 | +
|
| 300 | +| Step | When | Method & path | Auth | |
| 301 | +|------|------|---------------|------| |
| 302 | +| Create mirrored user | CSP signup (once) | `POST /api/v1/admin/users?org=<slug>` | `Authorization: token` (site admin) | |
| 303 | +| Sync profile | On CSP profile edit | `POST /api/v1/admin/users/{username}/update?org=<slug>` | `Authorization: token` (site admin) | |
| 304 | +| Rotate password | On credential rotation | `POST /api/v1/admin/users/{username}/change-password?org=<slug>` | `Authorization: token` (site admin) | |
| 305 | +| Deprovision | On CSP account deletion | `DELETE /api/v1/admin/users/{username}?org=<slug>` | `Authorization: token` (site admin) | |
| 306 | +| Grant cluster access | On entitlement change | Client-org + permission APIs (§5) | `Authorization: token` (site admin / org admin) | |
| 307 | +| Server-side sign-in | Each console open | `POST /api/v1/user/signin` | Mirror user password → sets cookies | |
| 308 | +| Authenticated API call | As needed | any `/api/v1/...` | Session cookie + `X-Csrf-Token: <_csrf>` | |
| 309 | +| Logout | On CSP logout | `GET /api/v1/user/signout` | Session cookie + `X-Csrf-Token: <_csrf>` | |
| 310 | +
|
| 311 | +Explore any of these interactively in the |
| 312 | +[Interactive API Reference](../../../api/reference/). |
| 313 | +
|
| 314 | +--- |
| 315 | +
|
| 316 | +## 8. Security checklist |
| 317 | +
|
| 318 | +- **Site-admin token** stays server-side, in a secret manager. Rotate it periodically. Its |
| 319 | + compromise means full control of every mirrored user. Generate/manage tokens via the |
| 320 | + [access-token APIs](../../../api/users-settings/public-user-apis/). |
| 321 | +- **Stored KubeDB passwords** are internal credentials: generate them randomly (high |
| 322 | + entropy), encrypt at rest, and never expose them to the browser or the end user. |
| 323 | +- **Handoff ticket** must be short-lived (seconds), single-use, signed/encrypted, and bound |
| 324 | + to the authenticated CSP session — it is the only thing standing between a URL and a KubeDB |
| 325 | + session. Never put the KubeDB password in the URL. |
| 326 | +- **Cookie flags**: ensure the session cookies delivered to the browser are `Secure`, |
| 327 | + `HttpOnly`, and `SameSite=Lax` (Lax suffices because `console.acme.com` → `db.acme.com` |
| 328 | + is same-site and the handoff is a top-level navigation). |
| 329 | +- **TLS everywhere**. |
| 330 | +- **No 2FA on mirrors** (see §2); enforce MFA in the CSP console instead. |
| 331 | +- **Logout propagation** (§6) so a KubeDB session never outlives the CSP session on a shared |
| 332 | + device. |
| 333 | +- **Deprovisioning** (§3.4) so access is revoked in both consoles together. |
0 commit comments