Repository navigation
feat(portal): prepare a separate machine identity #6440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
devantler
wants to merge
5
commits into
main
Choose a base branch
from
codex/customer-agent-identity-6439
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7f1ed72
feat(portal): prepare a separate machine identity
devantler e68f73d
test(portal): check native fixture response cleanup
devantler 9309c96
fix(portal): authorize the exact machine credential seed path
devantler e09b6df
refactor(tests): separate native customer identity fixtures
devantler db8116c
fix(portal): keep machine token issuance disabled until activation
devantler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...structure/vault-seed/external-secret-generated-customer-identity-portal-agent-client.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
k8s/bases/infrastructure/vault-seed/password-customer-identity-portal-agent-client.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
22 changes: 22 additions & 0 deletions
22
...ses/infrastructure/vault-seed/push-secret-push-customer-identity-portal-agent-client.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
20 changes: 20 additions & 0 deletions
20
k8s/providers/hetzner/apps/customer-identity/external-secret-dex-portal-agent-client.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.