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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
### Fixed

- **NATS operator rotation on Kubernetes** — resolver reconciliation writes the new operator JWT into `iofog-nats-config` when that line differs. The NATS image reloads `server.conf`. The `nats` StatefulSet is not rolled for this change.
- **Embedded OIDC token call** — the Controller's own authorization-code exchange dials `127.0.0.1` on the API port instead of the public issuer. The browser still uses the public HTTPS URL. When the listener is HTTPS, the loopback connection pins the listener certificate. When the listener is HTTP, including dev mode with TLS files set, the dial is plain HTTP. External issuers are unchanged.
- **WebSocket per-address limits behind a proxy** — the connection cap and the handshake cap use the same hop count as `TRUST_PROXY`. `true` is one hop, the address the closest proxy appended. A hop count, including `"2"`, trusts that many hops. With trust-proxy off, `X-Forwarded-For` is ignored. Closing the socket frees that same address.

### Changed

Expand All @@ -21,6 +23,7 @@
- **`@google-cloud/secret-manager` ^6.1.1 → ^7.2.0** — drop production `glob` 10.5.0 and nested `minimatch` 9.0.9 pulled in through `google-gax` 5 and `rimraf` 5 (GHSA-3g3m-2fjr-6pw4, GHSA-g3hv-75wg-m249). Secret Manager client calls are unchanged. The same advisories remain on dev-only `mocha`, `nyc`, and `sequelize-cli`. `better-npm-audit audit -p` is clean.
- Dockerfile base image digest pins refreshed for **`node:24-bookworm`** (console-builder and builder) and **`ubi9/nodejs-24-minimal`**.
- Embedded **EdgeOps Console** default **v1.1.3 → v1.1.4**
- **`node-forge` ^1.4.2 → ^1.4.3**.

### Unchanged

Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# ioFog overrides: EDGEOPS_CONSOLE_REPO=https://github.com/eclipse-iofog/edgeops-console
# EDGEOPS_CONSOLE_FLAVOR=iofog
# node:24-bookworm — pin manifest list digest for reproducible multi-arch builds
FROM node:24-bookworm@sha256:8fa96264f302f58bbb13aa7339c541547b56975766ce956c875da149452a3e40 AS console-builder
FROM node:24-bookworm@sha256:9d266751ca3d7fdbe651c878ffd5ad0a42fed49a18c283509267c97f025b7496 AS console-builder

ARG EDGEOPS_CONSOLE_REPO=https://github.com/Datasance/edgeops-console
ARG EDGEOPS_CONSOLE_VERSION=v1.1.4
Expand All @@ -28,7 +28,7 @@ RUN test -f build/index.html \
&& cp -a build /tmp/console/build


FROM node:24-bookworm@sha256:8fa96264f302f58bbb13aa7339c541547b56975766ce956c875da149452a3e40 AS builder
FROM node:24-bookworm@sha256:9d266751ca3d7fdbe651c878ffd5ad0a42fed49a18c283509267c97f025b7496 AS builder

ARG PKG_VERSION

Expand All @@ -48,7 +48,7 @@ RUN npm pack


# ubi9/nodejs-24-minimal:latest — pin manifest list digest for reproducible multi-arch builds
FROM registry.access.redhat.com/ubi9/nodejs-24-minimal@sha256:da724df0db4baceb0b89ebdc160dfe330fe3b215925742ee9e65efdfc6038850
FROM registry.access.redhat.com/ubi9/nodejs-24-minimal@sha256:94e1482b6fe50b5a99692d4cea62309b54201f405d12766f2ebe37ab49692f29

ARG EDGEOPS_CONSOLE_VERSION=v1.1.4
ARG IMAGE_REGISTRY
Expand Down
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,15 @@
"@nats-io/transport-node": "^3.4.0",
"nconf": "0.12.1",
"node-fetch-npm": "^2.0.4",
"node-forge": "^1.4.2",
"node-forge": "^1.4.3",
"oidc-provider": "^9.11.3",
"openid-client": "^6.8.4",
"otplib": "^13.4.1",
"pg": "8.12.0",
"pino": "9.13.1",
"pino-std-serializers": "7.0.0",
"portscanner": "2.2.0",
"proxy-addr": "2.0.8",
"qs": "6.16.1",
"rhea": "^3.0.4",
"sequelize": "6.37.8",
Expand Down
138 changes: 119 additions & 19 deletions src/config/oidc-fetch.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
const https = require('https')
const tls = require('tls')
const { Agent, fetch: undiciFetch } = require('undici')
const { X509Certificate } = require('crypto')
const { Agent, buildConnector, fetch: undiciFetch } = require('undici')
const config = require('./index')
const { getPublicUrl } = require('./auth-urls')
const { loadCertificate } = require('../utils/ssl-utils')
const { getListenerTlsMaterial, getListenerTrustCaBuffers } = require('../utils/tls-config')
const { getListenerTlsMaterial } = require('../utils/tls-config')

const LOOPBACK_HOST = '127.0.0.1'

let cachedFetch
let cachedExternalFetch
let cachedExternalCaKey
const loopbackAgents = new Map()

function resetEmbeddedOidcFetchForTests () {
cachedFetch = undefined
for (const agent of loopbackAgents.values()) {
try {
agent.destroy()
} catch {
// Agent cleanup is best-effort between tests.
}
}
loopbackAgents.clear()
}

function resetExternalOidcFetchForTests () {
Expand Down Expand Up @@ -83,32 +94,121 @@ function createExternalIssuerHttpsAgent (caBuffer) {
})
}

function createEmbeddedOidcFetch () {
const material = getListenerTlsMaterial()
if (!material.enabled) {
return undefined
function getApiListenPort () {
return String(process.env.API_PORT || config.get('server.port'))
}

function embeddedIssuerUrl () {
const publicUrl = getPublicUrl()
if (!publicUrl) {
return null
}
try {
return new URL(`${publicUrl}/oidc`)
} catch {
return null
}
}

const caBuffers = getListenerTrustCaBuffers(material)
if (!caBuffers?.length) {
return undefined
function isEmbeddedIssuerUrl (target, issuer) {
const issuerPath = issuer.pathname.replace(/\/$/, '')
return target.origin === issuer.origin &&
(target.pathname === issuerPath || target.pathname.startsWith(`${issuerPath}/`))
}

// Browser and discovery URLs stay on CONTROLLER_PUBLIC_URL. This process dials
// its own listener instead, so embedded token and JWKS calls do not hairpin
// through ingress TLS.
function rewriteEmbeddedBackchannelUrl (input) {
const target = new URL(typeof input === 'string' ? input : String(input))
const issuer = embeddedIssuerUrl()
if (!issuer || !isEmbeddedIssuerUrl(target, issuer)) {
return { href: target.href, local: false, tls: false }
}

if (!cachedFetch) {
const agent = new Agent({
connect: {
ca: caBuffers,
rejectUnauthorized: true
const material = getListenerTlsMaterial()
target.protocol = material.enabled ? 'https:' : 'http:'
target.hostname = LOOPBACK_HOST
target.port = getApiListenPort()
return { href: target.href, local: true, tls: material.enabled === true }
}

function readListenerLeafFingerprint (material) {
const leaf = loadCertificate(material.cert, material.isBase64)
return new X509Certificate(leaf).fingerprint256
}

function createLoopbackTlsAgent (expectedFingerprint) {
const connector = buildConnector({ rejectUnauthorized: false })
return new Agent({
connect (opts, callback) {
const hostname = opts.hostname || opts.host
if (hostname !== LOOPBACK_HOST) {
callback(new Error('embedded loopback agent refused a non-local connection'))
return
}
})
cachedFetch = (url, init) => undiciFetch(url, { ...init, dispatcher: agent })

connector({ ...opts, rejectUnauthorized: false }, (err, socket) => {
if (err) {
callback(err)
return
}

let peerFingerprint = ''
try {
peerFingerprint = socket.getPeerCertificate().fingerprint256 || ''
} catch (error) {
socket.destroy()
callback(error)
return
}

if (!peerFingerprint || peerFingerprint !== expectedFingerprint) {
socket.destroy()
callback(new Error('loopback certificate does not match the listener certificate'))
return
}

callback(null, socket)
})
}
})
}

function getLoopbackAgent (fingerprint) {
let agent = loopbackAgents.get(fingerprint)
if (!agent) {
agent = createLoopbackTlsAgent(fingerprint)
loopbackAgents.set(fingerprint, agent)
}
return agent
}

function createEmbeddedOidcFetch () {
return function embeddedOidcFetch (url, init) {
const rewritten = rewriteEmbeddedBackchannelUrl(url)
if (!rewritten.local || !rewritten.tls) {
return undiciFetch(rewritten.href, init)
}

return cachedFetch
const material = getListenerTlsMaterial()
let fingerprint
try {
fingerprint = readListenerLeafFingerprint(material)
} catch (error) {
return Promise.reject(error)
}

return undiciFetch(rewritten.href, {
...init,
dispatcher: getLoopbackAgent(fingerprint)
})
}
}

module.exports = {
createEmbeddedOidcFetch,
rewriteEmbeddedBackchannelUrl,
resetEmbeddedOidcFetchForTests,
hasExternalIssuerCaConfig,
getExternalIssuerCaBuffer,
Expand Down
30 changes: 30 additions & 0 deletions src/websocket/client-ip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict'

const proxyaddr = require('proxy-addr')
const { getTrustProxySetting } = require('../config/trust-proxy')

function normalizeIp (ip) {
if (ip && ip.startsWith('::ffff:')) return ip.slice(7)
return ip || 'unknown'
}

function hopCount (trust) {
if (!trust) return 0
if (trust === true) return 1
const hops = Number(trust)
if (!Number.isInteger(hops) || hops < 1) return 0
return hops
}

function websocketClientIp (req) {
const socketIp = req && req.socket && req.socket.remoteAddress
const hops = hopCount(getTrustProxySetting())
if (!hops) return normalizeIp(socketIp)
return normalizeIp(proxyaddr(req, function (address, index) {
return index < hops
}))
}

module.exports = {
websocketClientIp
}
8 changes: 5 additions & 3 deletions src/websocket/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const FogManager = require('../data/managers/iofog-manager')
const FogStates = require('../enums/fog-state')
const Sequelize = require('sequelize')
const Op = Sequelize.Op
const { websocketClientIp } = require('./client-ip')

const MESSAGE_TYPES = {
STDIN: 0,
Expand Down Expand Up @@ -1498,8 +1499,9 @@ class WebSocketServer {
return
}

// Check connection limits
const clientIp = info.req.socket.remoteAddress
// Check connection limits. Behind a trusted proxy this is the forwarded
// client, using the same hop count Express uses for req.ip.
const clientIp = websocketClientIp(info.req)
const currentConnections = this.connectionLimits.get(clientIp) || 0
if (currentConnections >= (process.env.WS_SECURITY_MAX_CONNECTIONS_PER_IP || config.get('server.webSocket.security.maxConnectionsPerIp'))) {
callback(new Error('Too many connections'), false)
Expand Down Expand Up @@ -1540,7 +1542,7 @@ class WebSocketServer {
}

trackConnectionLimit (ws, req) {
const clientIp = req.socket.remoteAddress
const clientIp = websocketClientIp(req)
let released = false
const release = () => {
if (released) return
Expand Down
Loading