Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ jobs:
- 'scripts/tests/test-oauth2-proxy-sso-redirects.sh'
- 'scripts/tests/longhorn-ui-readonly/**'
- 'scripts/tests/test-dex-theme-mount.sh'
- 'scripts/tests/customer-agent/**'
- 'scripts/tests/test-umami-tracking-probe.sh'
- 'scripts/tests/fixtures/umami-curl-stub.sh'
- 'scripts/verify-umami-tracking.sh'
Expand Down Expand Up @@ -3707,6 +3708,12 @@ jobs:
env:
LONGHORN_UI_NATIVE_TEST: "1"
run: go test -race -count=1 -v ./scripts/tests/longhorn-ui-readonly
- name: 🔐 Prove native portal machine token boundaries
if: matrix.suite == 'native'
timeout-minutes: 5
env:
CUSTOMER_AGENT_NATIVE_TEST: "1"
run: go test -count=1 -timeout=4m -v ./scripts/tests/customer-agent
- name: 🐤 Validate staged OpenBao standby repair
if: matrix.suite == 'contracts'
run: |
Expand Down
89 changes: 89 additions & 0 deletions docs/portal-machine-identity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Portal machine identity

The customer Dex is prepared with a confidential client `business-portal-agent`
for portal automation. Its client-credentials grant is disabled in production.
The client has no browser redirect and no cross-client trust. It is separate
from the `business-portal` browser client and represents no human user.

The native vault-seed Password generator creates its credential once in a durable
Kubernetes Secret. Its create-only PushSecret stores it at
`apps/customer-identity/portal-agent-client`, property `client-secret`, in OpenBao.
An ExternalSecret projects that value into customer Dex through
`CUSTOMER_PORTAL_AGENT_CLIENT_SECRET`. The portal needs only the issuer's public
signing keys. Agents must never read, print, copy or transmit the credential or
production tokens. A future caller receives the credential through its own
reviewed native workload projection.

After a separate reviewed activation, request `grant_type=client_credentials`
and `scope=openid` at the issuer's token endpoint. The explicitly activated native
fixture of the pinned Dex distribution returns both `access_token` and `id_token`
as signed JWTs with these claims:

| Claim | Value |
| --- | --- |
| `iss` | `https://login.devantler.tech` |
| `aud` | `business-portal-agent` (one string) |
| `sub` | `ChVidXNpbmVzcy1wb3J0YWwtYWdlbnQ` |
| `exp - iat` | 300 seconds |

The subject encodes the client ID and an empty connector. The browser sign-in
verifier must refuse that subject. Dex's grant list is global: after activation,
the browser client's credential can also obtain client-credentials tokens, but those have the
browser audience and its own empty-connector subject. Neither token belongs to
the portal's machine allow-list or its human sign-in flow. Refresh tokens and
`offline_access` are unavailable for client credentials.

## Activation and acceptance

The production grant list contains only `authorization_code`, so both the
browser and machine clients are refused client-credentials issuance. Preparing
the static client and its credential does not enable that grant or portal API
access.

Activation is tracked separately in [#6448](https://github.com/devantler-tech/platform/issues/6448).
It requires a reviewed Git change after a signed business-site
release supporting the strict machine verifier and rejecting empty-connector
subjects in browser sign-in is deployed and verified. The supporting source is
[business-site #665](https://github.com/devantler-tech/business-site/pull/665);
source merge alone does not establish deployment. Only then enable the Dex grant
and add the following non-secret settings to the platform's portal-settings
projection, starting with no write grants:

```dotenv
PORTAL_AGENT_AUDIENCE=business-portal-agent
PORTAL_AGENT_SUBJECTS=[{"issuer":"https://login.devantler.tech","subject":"ChVidXNpbmVzcy1wb3J0YWwtYWdlbnQ","grants":[]}]
```

The native regression exercises the exact first-party image selected by the
customer Dex HelmRelease with disposable synthetic credentials and memory
storage. It first proves the actual production grant configuration refuses both
clients with `unsupported_grant_type` and emits no tokens. Only after that proof
passes does it add `client_credentials` to a copied configuration in memory for
an explicitly activated test-only fixture. That fixture verifies both
signatures, the identity and lifetime of both tokens, wrong-credential and
offline-access refusals, the browser client's separate identity, and rejection
of a browser redirect for the machine client:

```sh
CUSTOMER_AGENT_NATIVE_TEST=1 go test -count=1 -v ./scripts/tests/customer-agent
```

Production acceptance still requires normal protected GitOps deployment,
metadata-only readback of generation, PushSecret and projection readiness, and
an approved native verifier that obtains a token internally and calls the live
portal API without exposing credentials, tokens, or response data to logs.
Verify a read succeeds, an ungranted write fails, and browser/machine credentials
cannot cross either authentication boundary. Synthetic native proof does not
establish this production outcome.

## Pinned source

The deployed image's build record names Dex revision
`75eb19238e10fc4750e7efb05a4031b254b04029`. Its
[client-credentials handler](https://github.com/dexidp/dex/blob/75eb19238e10fc4750e7efb05a4031b254b04029/server/grants/clientcredentials.go)
uses the client ID with an empty connector. Its
[token issuer](https://github.com/dexidp/dex/blob/75eb19238e10fc4750e7efb05a4031b254b04029/server/tokens/issuer.go)
signs both token types with the configured ID-token lifetime. The
[claims implementation](https://github.com/dexidp/dex/blob/75eb19238e10fc4750e7efb05a4031b254b04029/server/tokens/claims.go)
encodes that subject and uses the requesting client as the sole audience when no
cross-client scope is requested.
6 changes: 6 additions & 0 deletions k8s/bases/infrastructure/vault-config/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,9 @@ spec:
path "secret/data/apps/customer-identity/portal-client" {
capabilities = ["create", "update", "read"]
}
path "secret/data/apps/customer-identity/portal-agent-client" {
capabilities = ["create", "update", "read"]
}
# The portal database's two login passwords (create-only seed)
# and its CA certificate, pushed from the business-site
# namespace for the portal's projected Secret. Exact keys only.
Expand Down Expand Up @@ -1212,6 +1215,9 @@ spec:
path "secret/metadata/apps/customer-identity/portal-client" {
capabilities = ["create", "update", "read"]
}
path "secret/metadata/apps/customer-identity/portal-agent-client" {
capabilities = ["create", "update", "read"]
}
path "secret/metadata/apps/business-site/portal-db" {
capabilities = ["create", "update", "read"]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
name: generated-customer-identity-portal-agent-client
namespace: openbao
spec:
refreshInterval: "0"
target:
name: generated-customer-identity-portal-agent-client
creationPolicy: Owner
dataFrom:
- sourceRef:
generatorRef:
apiVersion: generators.external-secrets.io/v1alpha1
kind: Password
name: customer-identity-portal-agent-client
3 changes: 3 additions & 0 deletions k8s/bases/infrastructure/vault-seed/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ resources:
- password-customer-identity-portal-client.yaml
- external-secret-generated-customer-identity-portal-client.yaml
- push-secret-push-customer-identity-portal-client.yaml
- password-customer-identity-portal-agent-client.yaml
- external-secret-generated-customer-identity-portal-agent-client.yaml
- push-secret-push-customer-identity-portal-agent-client.yaml
- password-business-site-portal-db-migrator.yaml
- password-business-site-portal-db-web.yaml
- external-secret-generated-business-site-portal-db-migrator.yaml
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: generators.external-secrets.io/v1alpha1
kind: Password
metadata:
name: customer-identity-portal-agent-client
namespace: openbao
spec:
length: 48
digits: 12
symbols: 0
noUpper: false
allowRepeat: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Native generation and durable custody, separate from the browser client.
# Create-only preserves the restored OpenBao credential after a cluster rebuild.
apiVersion: external-secrets.io/v1alpha1
kind: PushSecret
metadata:
name: push-customer-identity-portal-agent-client
namespace: openbao
spec:
refreshInterval: 1h
updatePolicy: IfNotExists
secretStoreRefs:
- name: openbao
kind: ClusterSecretStore
selector:
secret:
name: generated-customer-identity-portal-agent-client
data:
- match:
secretKey: password
remoteRef:
remoteKey: apps/customer-identity/portal-agent-client
property: client-secret
Comment thread
devantler marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# The machine client's own credential, generated and retained by vault-seed.
# Projected only into customer Dex; the portal verifies signed JWTs using JWKS.
apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
name: customer-dex-portal-agent-client
namespace: customer-identity
spec:
refreshInterval: 1h
secretStoreRef:
name: openbao
kind: ClusterSecretStore
target:
name: customer-dex-portal-agent-client
creationPolicy: Owner
data:
- secretKey: client-secret
remoteRef:
key: apps/customer-identity/portal-agent-client
property: client-secret
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ spec:
secretKeyRef:
name: customer-dex-portal-client
key: client-secret
- name: CUSTOMER_PORTAL_AGENT_CLIENT_SECRET
valueFrom:
secretKeyRef:
name: customer-dex-portal-agent-client
key: client-secret
config:
issuer: https://login.devantler.tech
# The Devantler Tech theme, as on the platform Dex: the wordmark as the
Expand Down Expand Up @@ -199,3 +204,10 @@ spec:
# The portal is served at the root of its own host.
redirectURIs:
- https://portal.devantler.tech/callback
# No redirect or cross-client trust: this client represents itself only.
# Portal authorization is a separate, initially disabled allow-list.
- id: business-portal-agent
name: Devantler Tech portal agent
public: false
secretEnv: CUSTOMER_PORTAL_AGENT_CLIENT_SECRET
redirectURIs: []
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ resources:
- external-secret-db-dex.yaml
- database-dex.yaml
- external-secret-dex-portal-client.yaml
- external-secret-dex-portal-agent-client.yaml
- helm-repository-dex.yaml
- config-map-dex-theme.yaml
- helm-release-dex.yaml
Expand Down
123 changes: 123 additions & 0 deletions scripts/tests/customer-agent/fixture_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package customeragent_test

import (
"bytes"
"context"
"encoding/json"
"io"
"net/http"
"os/exec"
"regexp"
"strings"
"testing"
"time"
)

type nativeFixture struct {
client *http.Client
baseURL string
}

func nativeDockerOutput(t *testing.T, args ...string) []byte {
t.Helper()
output, err := exec.CommandContext(t.Context(), "docker", args...).Output()
if err != nil {
t.Fatalf("owned native fixture Docker operation %s failed: %v", args[0], err)
}
return output
}

func ownedNativeContainer(t *testing.T, args ...string) string {
t.Helper()
id := bytes.TrimSpace(nativeDockerOutput(t, args...))
if !regexp.MustCompile(`^[a-f0-9]{64}$`).Match(id) {
t.Fatal("owned native fixture did not return a container ID")
}
containerID := string(id)
t.Cleanup(func() {
// The test context is cancelled before cleanups; cleanup needs its own bound.
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := exec.CommandContext(ctx, "docker", "rm", "--force", containerID).Run(); err != nil {
t.Error("owned native fixture container cleanup failed")
}
})
return containerID
}

func nativeFixtureEndpoint(t *testing.T, containerID, port string) nativeFixture {
t.Helper()
endpoint := strings.TrimSpace(string(nativeDockerOutput(t, "port", containerID, port)))
if !strings.HasPrefix(endpoint, "127.0.0.1:") {
t.Fatal("could not resolve the fixture's loopback-only endpoint")
}
return nativeFixture{
baseURL: "http://" + endpoint,
client: &http.Client{Timeout: 2 * time.Second, CheckRedirect: func(*http.Request, []*http.Request) error {
return http.ErrUseLastResponse
}},
}
}

func (fixture nativeFixture) get(t *testing.T, path string) (*http.Response, error) {
t.Helper()
request, err := http.NewRequestWithContext(t.Context(), http.MethodGet, fixture.baseURL+path, nil)
if err != nil {
t.Fatal(err)
}
return fixture.client.Do(request)
}

func (fixture nativeFixture) waitReady(t *testing.T, path string) {
t.Helper()
deadline := time.Now().Add(30 * time.Second)
for {
response, err := fixture.get(t, path)
ready := err == nil && response.StatusCode == http.StatusOK
if response != nil {
_ = response.Body.Close()
}
if ready {
return
}
if time.Now().After(deadline) {
t.Fatal("isolated native fixture did not become ready")
}
time.Sleep(100 * time.Millisecond)
}
}

func (fixture nativeFixture) jsonRequest(t *testing.T, token, method, path string, payload any) (int, map[string]any) {
t.Helper()
var input io.Reader
if payload != nil {
data, err := json.Marshal(payload)
if err != nil {
t.Fatal(err)
}
input = bytes.NewReader(data)
}
request, err := http.NewRequestWithContext(t.Context(), method, fixture.baseURL+"/v1/"+path, input)
if err != nil {
t.Fatal(err)
}
request.Header.Set("Content-Type", "application/json")
request.Header.Set("X-Vault-Token", token)
response, err := fixture.client.Do(request)
if err != nil {
t.Fatal("native synthetic ACL request failed")
}
defer closeFixtureResponse(t, response)
result := map[string]any{}
if response.StatusCode != http.StatusNoContent && json.NewDecoder(io.LimitReader(response.Body, 1<<20)).Decode(&result) != nil {
t.Fatal("native ACL response was invalid")
}
return response.StatusCode, result
}

func closeFixtureResponse(t *testing.T, response *http.Response) {
t.Helper()
if err := response.Body.Close(); err != nil {
t.Error("native fixture response could not close")
}
}
Loading
Loading