-
Notifications
You must be signed in to change notification settings - Fork 2
feat(ui): pxce implemented, local setup for remote zitadel in both au… #764
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8ba901f
feat(ui): pxce implemented, local setup for remote zitadel in both au…
rebEllieous 2167388
Merge remote-tracking branch 'origin/main' into feature/62-solar-ui-z…
rebEllieous 2ac8011
chore(ui): tidy up after the Zitadel integration
rebEllieous c3a50d5
Merge remote-tracking branch 'origin/main' into feature/62-solar-ui-z…
rebEllieous 0982234
fix(ui): derive ui-e2e backend URLs from UI_DEV_PORT and tighten auth…
rebEllieous 286e37e
Merge branch 'main' into feature/62-solar-ui-zitadel-integration
rebEllieous 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
Some comments aren't visible on the classic Files Changed page.
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
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,93 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # Registers the remote Zitadel as a JWT issuer in the UI dev cluster's API | ||
| # server, so it accepts SolAr UI id_tokens directly (--auth-mode=token). | ||
| # Only needed for token mode. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| KUBECTL="${KUBECTL:-kubectl}" | ||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" | ||
| WORK_DIR="${WORK_DIR:-$PROJECT_DIR/tmp/ui-dev}" | ||
|
|
||
| AUTH_CONFIG="$WORK_DIR/dex-auth-config.yaml" | ||
| AUTH_CONFIG_BASE="$WORK_DIR/dex-auth-config.base.yaml" | ||
|
|
||
| ISSUER="${ZITADEL_ISSUER:?ZITADEL_ISSUER is required}" | ||
| CLIENT_ID="${ZITADEL_CLIENT_ID:?ZITADEL_CLIENT_ID is required}" | ||
|
|
||
| # Guard against reconfiguring authentication on a non-local cluster. | ||
| CURRENT_CONTEXT="$($KUBECTL config current-context 2>/dev/null || true)" | ||
| EXPECTED_CONTEXT="${KIND_CLUSTER:+kind-${KIND_CLUSTER}}" | ||
| if [[ "${ALLOW_NON_LOCAL_CLUSTER:-false}" != "true" ]]; then | ||
| if [[ -n "$EXPECTED_CONTEXT" && "$CURRENT_CONTEXT" != "$EXPECTED_CONTEXT" ]]; then | ||
| echo "Refusing to run against context '${CURRENT_CONTEXT:-<none>}' (expected '$EXPECTED_CONTEXT')." >&2 | ||
| echo "Switch context or set ALLOW_NON_LOCAL_CLUSTER=true to override intentionally." >&2 | ||
| exit 1 | ||
| fi | ||
| if [[ -z "$EXPECTED_CONTEXT" && ! "$CURRENT_CONTEXT" =~ ^kind- ]]; then | ||
| echo "Refusing to reconfigure authentication on non-kind context: ${CURRENT_CONTEXT:-<none>}" >&2 | ||
|
rebEllieous marked this conversation as resolved.
|
||
| echo "Set ALLOW_NON_LOCAL_CLUSTER=true to override intentionally." >&2 | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| [[ -f "$AUTH_CONFIG" ]] || { echo "Missing $AUTH_CONFIG — run 'make ui-dev-cluster' first." >&2; exit 1; } | ||
|
|
||
| # Rebuilt from a Dex-only base, so a changed issuer or client ID can't leave a | ||
| # stale entry behind. The base must not already contain our block. | ||
| if [[ ! -f "$AUTH_CONFIG_BASE" ]]; then | ||
| if [[ "$(grep -c '^ - issuer:' "$AUTH_CONFIG")" -ne 1 ]]; then | ||
| echo "$AUTH_CONFIG has extra issuers and no $AUTH_CONFIG_BASE to rebuild from." >&2 | ||
| echo "Regenerate it with hack/generate-dex-certs.sh." >&2 | ||
| exit 1 | ||
| fi | ||
| cp "$AUTH_CONFIG" "$AUTH_CONFIG_BASE" | ||
| fi | ||
|
|
||
| # No groups mapping: Zitadel's roles claim is a map, which the API server can't | ||
| # turn into group names. RBAC binds on the username. | ||
| DESIRED="$(printf '%s\n' "$(<"$AUTH_CONFIG_BASE")" " - issuer: | ||
| url: $ISSUER | ||
| audiences: | ||
| - \"$CLIENT_ID\" | ||
| claimMappings: | ||
| username: | ||
| claim: email | ||
| prefix: \"\"")" | ||
|
|
||
| if [[ "$(cat "$AUTH_CONFIG")" == "$DESIRED" ]]; then | ||
| echo "$ISSUER already registered in $AUTH_CONFIG." | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "Registering $ISSUER in $AUTH_CONFIG..." | ||
| # Taken before the write: a reload logged earlier isn't evidence about ours. | ||
| SINCE="$(date -u +%Y-%m-%dT%H:%M:%SZ)" | ||
| printf '%s\n' "$DESIRED" > "$AUTH_CONFIG" | ||
|
|
||
| echo "Waiting for the API server to reload it..." | ||
| for _ in $(seq 1 45); do | ||
| sleep 2 | ||
| LOG="$($KUBECTL logs -n kube-system -l component=kube-apiserver --since-time="$SINCE" 2>/dev/null || true)" | ||
|
|
||
| ERRORS="$(grep -E "failed to (load|validate|update) authentication config" <<<"$LOG" || true)" | ||
| MINE="$(grep -F "\"$ISSUER\"" <<<"$ERRORS" || true)" | ||
| UNATTRIBUTED="$(grep -vF 'issuer "' <<<"$ERRORS" || true)" | ||
| if [[ -n "$MINE$UNATTRIBUTED" ]]; then | ||
| echo "The API server rejected the authentication config:" >&2 | ||
| printf '%s\n' "$MINE$UNATTRIBUTED" | tail -1 >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if grep -q "reloaded authentication config" <<<"$LOG"; then | ||
| echo "API server reloaded." | ||
| exit 0 | ||
| fi | ||
| done | ||
|
|
||
| # Changed on disk but identical to what's loaded — e.g. reverting a config the | ||
| # API server refused. Nothing to reload. | ||
| echo "No API-server reload was observed after changing $AUTH_CONFIG." >&2 | ||
| exit 1 | ||
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,72 @@ | ||
| // Copyright 2026 BWI GmbH and Solution Arsenal contributors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package auth | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "net/http/httptest" | ||
|
|
||
| "k8s.io/client-go/rest" | ||
|
|
||
| "go.opendefense.cloud/solar/pkg/ui/session" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| ) | ||
|
|
||
| var _ = Describe("NoopProvider", func() { | ||
| var ( | ||
| provider *NoopProvider | ||
| store *session.Store | ||
| ) | ||
|
|
||
| BeforeEach(func() { | ||
| provider = NewNoopProvider() | ||
| var err error | ||
| store, err = session.NewStore("") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| }) | ||
|
|
||
| It("establishes a synthetic session on login and redirects", func(ctx SpecContext) { | ||
| req := httptest.NewRequestWithContext(ctx, http.MethodGet, "/api/auth/login", nil) | ||
| rec := httptest.NewRecorder() | ||
|
|
||
| provider.HandleLogin(store)(rec, req) | ||
|
|
||
| Expect(rec.Code).To(Equal(http.StatusFound)) | ||
| Expect(rec.Header().Get("Location")).To(Equal("/")) | ||
|
|
||
| // The set cookie resolves to a noop session. | ||
| req2 := httptest.NewRequestWithContext(ctx, http.MethodGet, "/", nil) | ||
| req2.AddCookie(rec.Result().Cookies()[0]) | ||
| Expect(store.Get(req2).Username).To(Equal(noopUsername)) | ||
| }) | ||
|
|
||
| It("establishes a session on callback and redirects", func(ctx SpecContext) { | ||
| req := httptest.NewRequestWithContext(ctx, http.MethodGet, "/api/auth/callback", nil) | ||
| rec := httptest.NewRecorder() | ||
|
|
||
| provider.HandleCallback(store)(rec, req) | ||
|
|
||
| Expect(rec.Code).To(Equal(http.StatusFound)) | ||
|
|
||
| // The set cookie resolves to a noop session. | ||
| cookies := rec.Result().Cookies() | ||
| Expect(cookies).NotTo(BeEmpty()) | ||
| req2 := httptest.NewRequestWithContext(ctx, http.MethodGet, "/", nil) | ||
| req2.AddCookie(cookies[0]) | ||
| Expect(store.Get(req2).Username).To(Equal(noopUsername)) | ||
| }) | ||
|
rebEllieous marked this conversation as resolved.
|
||
|
|
||
| It("returns the base config unchanged", func() { | ||
| base := &rest.Config{Host: "https://example"} | ||
|
|
||
| before := *base | ||
| result := provider.WrapConfig(base, &session.Data{Username: "alice"}) | ||
|
|
||
| // Same pointer back, and its contents were not mutated in place. | ||
| Expect(result).To(BeIdenticalTo(base)) | ||
| Expect(*result).To(Equal(before)) | ||
| }) | ||
|
rebEllieous marked this conversation as resolved.
|
||
| }) | ||
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.