This project secures the frontend using the OpenShift oauth-proxy sidecar. The proxy handles login against the cluster and forwards authenticated requests to the Next.js app.
You only need to do two one-time items per cluster: create an OAuthClient and provide its secret to the app. Also ensure the Route host uses your cluster apps domain.
Admin (one-time per cluster):
- Set the Route host to your cluster domain
ROUTE_DOMAIN=$(oc get ingresses.config cluster -o jsonpath='{.spec.domain}')
oc -n ambient-code patch route frontend-route --type=merge -p '{"spec":{"host":"ambient-code.'"$ROUTE_DOMAIN"'"}}'- Create OAuthClient and keep the secret
ROUTE_HOST=$(oc -n ambient-code get route frontend-route -o jsonpath='{.spec.host}')
SECRET="$(openssl rand -base64 32 | tr -d '\n=+/0OIl')"; echo "$SECRET"
cat <<EOF | oc apply -f -
apiVersion: oauth.openshift.io/v1
kind: OAuthClient
metadata:
name: ambient-frontend
secret: $SECRET
redirectURIs:
- https://$ROUTE_HOST/oauth/callback
grantMethod: auto
EOFDeployer (per install): 3. Put the client secret in the app Secret and restart
oc -n ambient-code create secret generic frontend-oauth-config \
--from-literal=client-secret="$SECRET" \
--from-literal=cookie_secret="$(LC_ALL=C tr -dc 'A-Za-z0-9' </dev/urandom | head -c 32)" \
--dry-run=client -o yaml | oc apply -f -
oc -n ambient-code rollout restart deployment/frontend- Open the app:
oc -n ambient-code get route frontend-route -o jsonpath='{.spec.host}' | sed 's#^#https://#'
- oc CLI configured to your cluster
- cluster-admin (to create
OAuthClient), or an admin to run those steps for you - Namespace:
ambient-code
- Deploy the frontend with an
oauth-proxysidecar (HTTPS on port 8443) - Expose
frontend-servicewith portshttp:3000anddashboard-ui:8443 - Create a Route to
frontend-service:dashboard-uiwith edge TLS termination
- Set the Route host to your real cluster apps domain (if not already)
- Create a cluster-scoped
OAuthClientnamedambient-frontendwith a strong secret and a redirect URI that matches your Route - Put that same secret into the namespaced Secret
frontend-oauth-config(keys:client-secret,cookie_secret)
- Get your Route host for the app:
ROUTE_HOST=$(oc -n ambient-code get route frontend -o jsonpath='{.spec.host}')
echo "$ROUTE_HOST"- Generate a strong client secret:
SECRET="$(openssl rand -base64 32 | tr -d '\n=+/0OIl')"
echo "$SECRET"- Create or update the OAuthClient:
cat <<EOF | oc apply -f -
apiVersion: oauth.openshift.io/v1
kind: OAuthClient
metadata:
name: ambient-frontend
secret: $SECRET
redirectURIs:
- https://$ROUTE_HOST/oauth/callback
grantMethod: auto
EOF- Verify:
oc get oauthclient ambient-frontend -o jsonpath='{.secret}{"\n"}{.redirectURIs[0]}{"\n"}'Notes:
- The OAuthClient name (ambient-frontend) must match the proxy arg
--client-id=ambient-frontendset infrontend-deployment.yaml. - The redirect URI must exactly match the app Route +
/oauth/callback.
Option A) Using the deploy script with .env:
cd components/manifests
cat >> ../.env <<EOF
OCP_OAUTH_CLIENT_SECRET=$SECRET
# Optional: provide your own cookie secret; otherwise the script will generate one
# OCP_OAUTH_COOKIE_SECRET=$(LC_ALL=C tr -dc 'A-Za-z0-9' </dev/urandom | head -c 32)
EOF
./deploy.sh secrets
oc -n ambient-code rollout restart deployment/frontendOption B) Manually create/update the Secret:
oc -n ambient-code create secret generic frontend-oauth-config \
--from-literal=client-secret="$SECRET" \
--from-literal=cookie_secret="$(LC_ALL=C tr -dc 'A-Za-z0-9' </dev/urandom | head -c 32)" \
--dry-run=client -o yaml | oc apply -f -
oc -n ambient-code rollout restart deployment/frontendThe Deployment mounts this Secret at /etc/oauth/config and reads:
--client-secret-file=/etc/oauth/config/client-secret--cookie-secret-file=/etc/oauth/config/cookie_secret
oc -n ambient-code get route frontend -o jsonpath='{.spec.host}' | sed 's#^#https://#'Visit the printed URL. You should be redirected to OpenShift login and returned to the app after authentication.
-
Pod fails: "secret "frontend-oauth-config" not found"
- Create the Secret (Step 2) and restart the Deployment.
-
Login redirects back to an error or a wrong host
- Ensure the OAuthClient redirect URI matches exactly
https://<route-host>/oauth/callback. - If you changed the Route host, update the OAuthClient accordingly.
- Ensure the OAuthClient redirect URI matches exactly
-
403 after login
- The proxy arg
--openshift-delegate-urlsshould include the backend API paths you need. Adjust based on your cluster policy.
- The proxy arg
-
Cookie secret errors
- Use an alphanumeric 32-char value for
cookie_secret(or let the script generate it).
- Use an alphanumeric 32-char value for
- You do NOT need ODH secret generators or a ServiceAccount OAuth redirect for this minimal setup.
- You do NOT need app-level env like
OAUTH_SERVER_URL; the sidecar handles the flow.
- ODH Dashboard uses a similar oauth-proxy sidecar pattern (with more bells and whistles): opendatahub-io/odh-dashboard