Docs
Live demo

Put an application behind the SSO gate

Discover a Kubernetes Ingress, adopt it, deploy the SSO gate and grant access via API.

On this page

Needs a Kubernetes target, an Admin API token and an Ingress:

bash
export PRINCIPAL_URL=https://principal.example.com
export AUTH="Authorization: Bearer prn_oat_..."
export CLUSTER=<kubernetes target id>

1. Discover the new Ingress#

bash
curl -sX POST "$PRINCIPAL_URL/api/v2/applications/candidates/refresh" \
  -H "$AUTH" -H "Content-Type: application/json" \
  -d "{\"cluster_id\":\"$CLUSTER\"}"

Returns 202 with job_id. Background scan takes ~30 seconds.

2. Find the candidate#

bash
curl -sH "$AUTH" \
  "$PRINCIPAL_URL/api/v2/applications/candidates?cluster_id=$CLUSTER&limit=100"
json
{"items":[{"id":"8e64b939-…","decision":"allowlisted",
  "source":{"namespace":"tools","ingress_name":"tool-x","host":"tool-x.example.com",
    "path":"/","sso_gate_path":"/oauth2","tls":true},
  "source_hash":"sha256:…"}],"has_more":false}

Pick source.host with "decision":"allowlisted" (Lists). One candidate per Ingress-host covers source.paths, gated at source.path. Add include_blocked=true for blocked system Ingresses (reason_code). Existing apps appear in GET /applications (parent_target_id=$CLUSTER): skip to step 4.

3. Add it as an application#

  1. Preview adoption:
    bash
    curl -sX POST "$PRINCIPAL_URL/api/v2/applications/adoption-preview" \
      -H "$AUTH" -H "Content-Type: application/json" \
      -d "{\"cluster_id\":\"$CLUSTER\",\"candidate_ids\":[\"<candidate id>\"]}"
    Check items and blocked (reason), copy preview_id.
  2. Confirm:
    bash
    curl -sX POST "$PRINCIPAL_URL/api/v2/applications" \
      -H "$AUTH" -H "Content-Type: application/json" \
      -d "{\"cluster_id\":\"$CLUSTER\",\"preview_id\":\"<preview id>\",
        \"candidate_ids\":[\"<candidate id>\"]}"

Returns 201. Save applications[0].id as $APP. On 409 (expired or Ingress changed), preview again.

4. Preview the sign-in client and gate#

bash
curl -sX POST "$PRINCIPAL_URL/api/v2/applications/$APP/sign-in/preview" \
  -H "$AUTH" -H "Content-Type: application/json" \
  -d '{"contract_version":1,"operation":"create","client_id":"tool-x",
    "name":"Tool X","auth_gate":{"enabled":true}}'

Returns preview_id, source_hash, blockers and operations (dex_client_create, auth_gate_create). Resolve any blockers (code, message) first.

Optional auth_gate fields:

Field Default Effect
keep_users_logged_in_for
168h
Session lifetime
send_groups_header
true
Sends groups in X-Auth-Request-Groups
send_authorization_header
false
Sends ID token in Authorization
ingress_class_name
Ingress class
Gate Ingress class. Your Ingress can move to it while the gate stays
tls
Ingress secret
source: inherit, secret, issuer, cluster_issuer, disabled
manage_ingress_annotations
true
Manages annotations (false requires manual setup)

Set "principal_group_claims_mode":"access_groups" beside client_id to send only groups granting access to this app.

5. Apply#

bash
curl -s --max-time 120 -X POST \
  "$PRINCIPAL_URL/api/v2/applications/$APP/sign-in/apply" \
  -H "$AUTH" -H "Content-Type: application/json" \
  -d '{"preview_id":"<preview id>","expected_source_hash":"<source_hash>",
    "operation":"create","client_id":"tool-x"}'

Waits ~30 seconds until ready, returning 200 with applied: true. On 409, re-run step 4.

6. Let people in#

Nobody passes the gate without a rule.

  1. Create a reusable template once:
    bash
    curl -sX POST "$PRINCIPAL_URL/api/v2/access-templates" \
      -H "$AUTH" -H "Content-Type: application/json" \
      -d '{"name":"app-sign-in","engine":"application",
        "description":"Sign in to the application",
        "body":{"language":2,"engine":"application",
        "statements":[{"class":"application","object":{},
        "selector":"exact","permissions":["login"]}]}}'
  2. Grant it to a group (find IDs via GET /identities with kind=group, or "kind":"user"):
    bash
    curl -sX POST "$PRINCIPAL_URL/api/v2/policies/ensure" \
      -H "$AUTH" -H "Content-Type: application/json" \
      -d "{\"target_id\":\"$APP\",\"identity_id\":\"<group id>\",
        \"kind\":\"group\",\"template_name\":\"app-sign-in\"}"
  3. Apply policy.id:
    bash
    curl -sX POST "$PRINCIPAL_URL/api/v2/policies/<policy.id>/apply" \
      -H "$AUTH" -H "Content-Type: application/json" -d '{}'

Members can now sign in. Leaving the group or deleting the rule revokes access and ends sessions.

7. Verify the result#

  1. Request the app unauthenticated:
    bash
    curl -s -o /dev/null -w '%{http_code} %{redirect_url}\n' \
      https://tool-x.example.com/
    Expect 302 https://tool-x.example.com/oauth2/start?rd=%2F.
  2. Check gate state:
    bash
    curl -sH "$AUTH" "$PRINCIPAL_URL/api/v2/applications/$APP/sign-in"
    Expect auth_gate_options.ingress_protection.state to be protected (unprotected gives reason). Rules: GET /policies (target_id=$APP).

Limits and lifecycle#

Topic Behavior
One gate per Ingress
Second gate hits dex_auth_gate_already_exists. No wildcard or domain-wide gate.
Whole Ingress gated
Non-browser traffic (webhooks, API keys) fails. Use a separate Ingress.
Regex paths
Mounts at <prefix>/oauth2, or /oauth2/<prefix> if regex catches it. Check source.sso_gate_path.
Update / delete
Steps 4–5 with "operation":"update" (omitted fields stay) or "delete" (removes client, gate and annotations, leaves rules).

Scripts written for Principal 6.x#

Legacy /targets/{id}/applications/... routes return Deprecation and Link headers (adopt new Ingresses in step 3 first). PUT .../access (group_ids, user_ids) and PUT .../access/groups manage rules declaratively:

Difference Detail
Permissions
PUT needs applications:manage, access:manage, access:apply. GET needs applications:read, access:read (else 403).
Service accounts
Rejected in user_ids (400), omitted from GET, untouched by PUT.
Stepwise updates
Removes omitted rules, then adds and applies new ones sequentially. Retry after partial failure.
Async sign-out
200 queues rule removal and session end in background.
Rule listing
groups and users include unapplied and failed rules.
Full ownership
Removes omitted rules, including console and temporary ones (.../groups: groups only).

In the console

Same workflow: Resources → Applications (Applications).

↑ ↓ to moveEnter to openEsc to close