Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

Patch release. No schema or API change. Upgrade from v3.9.1 is a Controller and image replace. The two fixes below apply to every release from v3.8.0 through v3.9.1.

### Added

- **External OIDC issuer CA** — `OIDC_ISSUER_TLS_PATH_CA` (`auth.issuer.tls.path.ca`) or `OIDC_ISSUER_TLS_BASE64_CA` (`auth.issuer.tls.base64.ca`) trusts an HTTPS issuer signed by a private CA. Path wins when both are set. The CA is added to the Mozilla roots for discovery, the token call, and JWKS only. Certificate checks stay on. Embedded mode ignores these keys.

### Changed

- Dockerfile base image digest pins refreshed for **`node:24-bookworm`** (console-builder and builder) and **`ubi9/nodejs-24-minimal`**.
Expand Down
4 changes: 4 additions & 0 deletions docs/controller-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ The auth block in the default file only activates `mode`, `insecureAllowHttp`, a
| `auth.bootstrap.username` | empty | `OIDC_BOOTSTRAP_ADMIN_USERNAME` |
| `auth.bootstrap.password` | empty | `OIDC_BOOTSTRAP_ADMIN_PASSWORD` |
| `auth.issuerUrl` | empty | `OIDC_ISSUER_URL` |
| `auth.issuer.tls.path.ca` | empty | `OIDC_ISSUER_TLS_PATH_CA` |
| `auth.issuer.tls.base64.ca` | empty | `OIDC_ISSUER_TLS_BASE64_CA` |
| `auth.client.id` | empty | `OIDC_CLIENT_ID` |
| `auth.client.secret` | empty | `OIDC_CLIENT_SECRET` |
| `auth.consoleClient` | empty | `OIDC_CONSOLE_CLIENT_ID` |
Expand All @@ -246,6 +248,8 @@ The auth block in the default file only activates `mode`, `insecureAllowHttp`, a

`auth.mode` is `embedded` or `external`. External mode uses `auth.issuerUrl`, `auth.client.id`, and `auth.client.secret`. Embedded mode runs the issuer inside Controller. The bootstrap username and password create the first admin. `auth.insecureAllowHttp` allows an `http` public URL in production. `auth.insecureAllowBootstrapLog` allows the bootstrap password path to be logged in production.

External mode can trust an HTTPS issuer signed by a private CA. Set `OIDC_ISSUER_TLS_PATH_CA` or `OIDC_ISSUER_TLS_BASE64_CA`. Path wins when both are set. The value is a PEM CA or a concatenated PEM bundle. Base64 is those PEM bytes. Controller adds that CA to the Mozilla roots for discovery, the token call, and JWKS. Certificate checks stay on. Embedded mode ignores these keys. `NODE_EXTRA_CA_CERTS` remains a process-wide alternative.

`OIDC_CONSOLE_CLIENT_ID` sets `auth.consoleClient` to the console client id string. The console client id is also read from `auth.consoleClient.id` when that key is an object. `AUTH_CONSOLE_CLIENT_ENABLED` sets `auth.consoleClient.enabled` and defaults to false when unset. Set the enabled flag when the console client should be registered. The id falls back to `ecn-viewer` when nothing is configured.

`auth.sessionStore.type` is `memory` or `database`. When it is unset, mysql and postgres use `database` and sqlite uses `memory`. An empty `auth.sessionStore.secret` is generated and stored. `auth.rateLimit.windowMs` is the per-IP window for auth endpoints.
Expand Down
4 changes: 4 additions & 0 deletions docs/external-oidc-client-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ In external mode:
| `TRUST_PROXY` | When TLS terminates at ingress | `true` |
| `AUTH_SESSION_STORE_TYPE` | HA + browser login | `database` (mysql/postgres) |
| `AUTH_INSECURE_ALLOW_HTTP` | Development only | `true` when using `http://localhost:*` |
| `OIDC_ISSUER_TLS_PATH_CA` | Private CA | PEM file for the issuer CA. Wins over base64 |
| `OIDC_ISSUER_TLS_BASE64_CA` | Private CA | Base64 of the issuer CA PEM (or PEM bundle) |

`OIDC_ISSUER_URL` must be the **issuer string**, not a generic IdP homepage. Discovery is:

Expand All @@ -48,6 +50,8 @@ GET {OIDC_ISSUER_URL}/.well-known/openid-configuration

Do **not** set legacy `KC_*`, `auth.realm`, or `auth.realmKey`.

When the issuer certificate is signed by a private CA, set `OIDC_ISSUER_TLS_PATH_CA` or `OIDC_ISSUER_TLS_BASE64_CA`. Path wins when both are set. Controller adds that CA to the Mozilla roots for discovery, the token call, and JWKS, and does not turn certificate checks off. These keys apply only when `AUTH_MODE=external`. `NODE_EXTRA_CA_CERTS` remains a process-wide alternative.

Optional `OIDC_CONSOLE_CLIENT_ID` / `AUTH_CONSOLE_CLIENT_ENABLED` registers a **future SPA-direct** public client. Default is **off**. Primary Console login uses this confidential Controller client via the BFF. Do not point Console at a second public client unless you intend to enable that path.

## IdP client — required settings
Expand Down
4 changes: 4 additions & 0 deletions docs/oidc-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Set **`CONTROLLER_PUBLIC_URL`** to the URL clients use to reach Controller (HTTP

Development with `http://localhost:*` requires **`AUTH_INSECURE_ALLOW_HTTP=true`**.

An external HTTPS issuer signed by a private CA needs **`OIDC_ISSUER_TLS_PATH_CA`** (PEM file) or **`OIDC_ISSUER_TLS_BASE64_CA`** (base64 of that PEM). Path wins when both are set. The file may be one CA or a concatenated PEM bundle. Controller adds it to the Mozilla roots for discovery, the token call, and JWKS, and keeps certificate checks on. Embedded mode ignores these keys. **`NODE_EXTRA_CA_CERTS`** still works and applies to every HTTPS call in the process.

---

## Environment variables
Expand All @@ -32,6 +34,8 @@ Canonical names map to `config.yaml` under `auth.*` (see `src/config/env-mapping
| `CONTROLLER_PUBLIC_URL` | both | Yes | External URL; embedded issuer base |
| `TRUST_PROXY` | both | When proxied | Honor forwarded headers |
| `OIDC_ISSUER_URL` | external | Yes | Full issuer URL (e.g. `https://auth.example.com/realms/myrealm`) |
| `OIDC_ISSUER_TLS_PATH_CA` | external | Private CA | PEM file for the issuer CA. Wins over the base64 key |
| `OIDC_ISSUER_TLS_BASE64_CA` | external | Private CA | Base64 of the issuer CA PEM (or PEM bundle) |
| `OIDC_CLIENT_ID` | both | Yes | Confidential API client (default embedded: `controller`) |
| `OIDC_CLIENT_SECRET` | both | external required; embedded optional | Client secret for token exchange |
| `CONSOLE_URL` | both | Recommended | EdgeOps Console browser origin (defaults to public URL) |
Expand Down
6 changes: 6 additions & 0 deletions src/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ auth:
# password: "" # Bootstrap admin password (OIDC_BOOTSTRAP_ADMIN_PASSWORD)
insecureAllowBootstrapLog: false # Allow bootstrap log in prod (AUTH_INSECURE_ALLOW_BOOTSTRAP_LOG)
# issuerUrl: # OIDC issuer URL (OIDC_ISSUER_URL); external mode only
# issuer: # External issuer TLS trust; ignored when auth.mode is embedded
# tls:
# path:
# ca: "" # CA PEM file path (OIDC_ISSUER_TLS_PATH_CA); path wins over base64
# base64:
# ca: "" # CA PEM bytes, base64 (OIDC_ISSUER_TLS_BASE64_CA)
# client:
# id: # Controller API client ID (OIDC_CLIENT_ID)
# secret: # Controller API client secret (OIDC_CLIENT_SECRET)
Expand Down
2 changes: 2 additions & 0 deletions src/config/env-mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ module.exports = {
// Auth Configuration (OIDC — k8s-style; naming-map §13)
AUTH_MODE: 'auth.mode',
OIDC_ISSUER_URL: 'auth.issuerUrl',
OIDC_ISSUER_TLS_PATH_CA: 'auth.issuer.tls.path.ca',
OIDC_ISSUER_TLS_BASE64_CA: 'auth.issuer.tls.base64.ca',
OIDC_CLIENT_ID: 'auth.client.id',
OIDC_CLIENT_SECRET: 'auth.client.secret',
OIDC_CONSOLE_CLIENT_ID: 'auth.consoleClient',
Expand Down
83 changes: 82 additions & 1 deletion src/config/oidc-fetch.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,88 @@
const https = require('https')
const tls = require('tls')
const { Agent, fetch: undiciFetch } = require('undici')
const config = require('./index')
const { loadCertificate } = require('../utils/ssl-utils')
const { getListenerTlsMaterial, getListenerTrustCaBuffers } = require('../utils/tls-config')

let cachedFetch
let cachedExternalFetch
let cachedExternalCaKey

function resetEmbeddedOidcFetchForTests () {
cachedFetch = undefined
}

function resetExternalOidcFetchForTests () {
cachedExternalFetch = undefined
cachedExternalCaKey = undefined
}

function trimConfigValue (value) {
if (typeof value !== 'string') {
return ''
}
return value.trim()
}

function readExternalIssuerCaSource () {
const pathValue = trimConfigValue(
process.env.OIDC_ISSUER_TLS_PATH_CA || config.get('auth.issuer.tls.path.ca')
)
if (pathValue) {
return { source: pathValue, isBase64: false }
}

const base64Value = trimConfigValue(
process.env.OIDC_ISSUER_TLS_BASE64_CA || config.get('auth.issuer.tls.base64.ca')
)
if (base64Value) {
return { source: base64Value, isBase64: true }
}

return undefined
}

function hasExternalIssuerCaConfig () {
return readExternalIssuerCaSource() !== undefined
}

function getExternalIssuerCaBuffer () {
const material = readExternalIssuerCaSource()
if (!material) {
return undefined
}
return loadCertificate(material.source, material.isBase64)
}

function buildIssuerTrustCaList (privateCa) {
return [privateCa, ...tls.rootCertificates]
}

function createExternalOidcFetch (caBuffer) {
const cacheKey = caBuffer.toString('base64')
if (cachedExternalFetch && cachedExternalCaKey === cacheKey) {
return cachedExternalFetch
}

const agent = new Agent({
connect: {
ca: buildIssuerTrustCaList(caBuffer),
rejectUnauthorized: true
}
})
cachedExternalCaKey = cacheKey
cachedExternalFetch = (url, init) => undiciFetch(url, { ...init, dispatcher: agent })
return cachedExternalFetch
}

function createExternalIssuerHttpsAgent (caBuffer) {
return new https.Agent({
ca: buildIssuerTrustCaList(caBuffer),
rejectUnauthorized: true
})
}

function createEmbeddedOidcFetch () {
const material = getListenerTlsMaterial()
if (!material.enabled) {
Expand All @@ -33,5 +109,10 @@ function createEmbeddedOidcFetch () {

module.exports = {
createEmbeddedOidcFetch,
resetEmbeddedOidcFetchForTests
resetEmbeddedOidcFetchForTests,
hasExternalIssuerCaConfig,
getExternalIssuerCaBuffer,
createExternalOidcFetch,
createExternalIssuerHttpsAgent,
resetExternalOidcFetchForTests
}
71 changes: 64 additions & 7 deletions src/config/oidc.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ let embeddedOauthClientPromise = null
let jwks = null
let issuerString = null
let configuredClientId = null
let embeddedIssuerCaWarned = false

const AUTH_MODES = ['embedded', 'external']

Expand Down Expand Up @@ -156,17 +157,48 @@ async function verifyUserAccessToken (token) {
return payload
}

function warnIfEmbeddedIssuerCaIgnored () {
if (getAuthMode() !== 'embedded' || embeddedIssuerCaWarned) {
return
}

const { hasExternalIssuerCaConfig } = require('./oidc-fetch')
if (!hasExternalIssuerCaConfig()) {
return
}

embeddedIssuerCaWarned = true
logger.warn('OIDC issuer CA is ignored when auth.mode is embedded')
}

function getDiscoveryOptions () {
const options = {}
const allowHttp = config.getBoolean('auth.insecureAllowHttp', false)
if (!allowHttp) {
if (allowHttp) {
// openid-client marks allowInsecureRequests @deprecated to discourage prod use;
// required for local http:// when AUTH_INSECURE_ALLOW_HTTP=true.
options.execute = [oidcClient.allowInsecureRequests]
}

if (getAuthMode() === 'external') {
const {
getExternalIssuerCaBuffer,
createExternalOidcFetch
} = require('./oidc-fetch')
const caBuffer = getExternalIssuerCaBuffer()
if (caBuffer) {
options[oidcClient.customFetch] = createExternalOidcFetch(caBuffer)
}
}

if (!options.execute && options[oidcClient.customFetch] === undefined) {
return undefined
}
// openid-client marks allowInsecureRequests @deprecated to discourage prod use;
// required for local http:// when AUTH_INSECURE_ALLOW_HTTP=true.
return { execute: [oidcClient.allowInsecureRequests] }
return options
}

async function ensureEmbeddedJwks () {
warnIfEmbeddedIssuerCaIgnored()
const { privateJwk } = await AuthJwks.getActiveSigningMaterial()
jwks = createLocalJWKSet({ keys: [AuthJwks.getPublicJwk(privateJwk)] })
issuerString = getEmbeddedIssuerUrl()
Expand All @@ -192,20 +224,30 @@ async function ensureDiscovery () {

discoveryPromise = (async () => {
const issuer = new URL(issuerUrl)
const discoveryOptions = getDiscoveryOptions()
const configuration = await oidcClient.discovery(
issuer,
clientId,
clientSecret,
undefined,
getDiscoveryOptions()
discoveryOptions
)
if (discoveryOptions?.[oidcClient.customFetch]) {
configuration[oidcClient.customFetch] = discoveryOptions[oidcClient.customFetch]
}
const metadata = configuration.serverMetadata()

if (!metadata.jwks_uri) {
throw new Error('OIDC issuer discovery did not return jwks_uri')
}

jwks = createRemoteJWKSet(new URL(metadata.jwks_uri))
const { getExternalIssuerCaBuffer } = require('./oidc-fetch')
const caBuffer = getExternalIssuerCaBuffer()
const verifyOptions = getRemoteJwksVerifyOptions(caBuffer)
const jwksUrl = new URL(metadata.jwks_uri)
jwks = verifyOptions
? createRemoteJWKSet(jwksUrl, verifyOptions)
: createRemoteJWKSet(jwksUrl)
issuerString = metadata.issuer
return configuration
})().catch((error) => {
Expand Down Expand Up @@ -243,6 +285,7 @@ function initOidc () {
}

validateAuthConfig()
warnIfEmbeddedIssuerCaIgnored()
oidcInstance = createOidcFacade()
logger.info(`OIDC initialized successfully (${getAuthMode()} mode)`)
return oidcInstance
Expand Down Expand Up @@ -294,6 +337,16 @@ function getOidcMiddleware () {
}
}

function getRemoteJwksVerifyOptions (caBuffer) {
if (!caBuffer) {
return undefined
}
const { createExternalIssuerHttpsAgent } = require('./oidc-fetch')
return {
agent: createExternalIssuerHttpsAgent(caBuffer)
}
}

function getMemoryStore () {
const { getAuthSessionStore } = require('./auth-session-store')
return getAuthSessionStore()
Expand Down Expand Up @@ -356,8 +409,10 @@ function resetDiscoveryForTests () {
issuerString = null
configuredClientId = null
oidcInstance = null
const { resetEmbeddedOidcFetchForTests } = require('./oidc-fetch')
embeddedIssuerCaWarned = false
const { resetEmbeddedOidcFetchForTests, resetExternalOidcFetchForTests } = require('./oidc-fetch')
resetEmbeddedOidcFetchForTests()
resetExternalOidcFetchForTests()
const { resetAuthSessionStoreForTests } = require('./auth-session-store')
resetAuthSessionStoreForTests()
}
Expand All @@ -373,6 +428,8 @@ module.exports = {
getOidcSettings,
getOidcConfiguration: ensureDiscovery,
getOauthClientConfiguration,
getDiscoveryOptions,
getRemoteJwksVerifyOptions,
resetDiscoveryForTests,
buildKauthGrant,
verifyUserAccessToken
Expand Down
Loading