mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-06-18 18:16:26 +00:00
Compare commits
42 Commits
v2.12.0
...
1a030a6ddd
Author | SHA1 | Date | |
---|---|---|---|
1a030a6ddd | |||
7ef52d8ed4 | |||
0b126ca546 | |||
7196dfa1ad | |||
25a26d6175 | |||
17246e418f | |||
f7d3ca0b07 | |||
a55de386e7 | |||
e9d4f5b827 | |||
1c1cee3836 | |||
eaf6335694 | |||
ffe05ebd41 | |||
2e9a4f1aed | |||
d17c85e4c8 | |||
dad8d0ca00 | |||
d7e0558a35 | |||
ee41bb5562 | |||
0cf6b9caa4 | |||
68a9baf206 | |||
d92421d098 | |||
96c58b203e | |||
d499e2bfef | |||
2f9e062718 | |||
edbed1af90 | |||
8497022e41 | |||
fa2c814fcb | |||
d96a3987c0 | |||
8b841176fa | |||
0b09f03f49 | |||
0f588baa3e | |||
6ed64153e7 | |||
d0d36a95ec | |||
fd49644f21 | |||
ef64edd943 | |||
df5ab361e3 | |||
6f98fa61e4 | |||
baee4641db | |||
bc0b466a8e | |||
8350271e6f | |||
457d1a75ba | |||
3e2a411dfb | |||
caeb2934f0 |
10
Jenkinsfile
vendored
10
Jenkinsfile
vendored
@ -43,7 +43,7 @@ pipeline {
|
||||
steps {
|
||||
script {
|
||||
// Defaults to the Branch name, which is applies to all branches AND pr's
|
||||
buildxPushTags = "-t docker.io/jc21/${IMAGE}:github-${BRANCH_LOWER}"
|
||||
buildxPushTags = "-t docker.io/nginxproxymanager/${IMAGE}-dev:${BRANCH_LOWER}"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -203,7 +203,13 @@ pipeline {
|
||||
}
|
||||
steps {
|
||||
script {
|
||||
npmGithubPrComment("Docker Image for build ${BUILD_NUMBER} is available on [DockerHub](https://cloud.docker.com/repository/docker/jc21/${IMAGE}) as `jc21/${IMAGE}:github-${BRANCH_LOWER}`\n\n**Note:** ensure you backup your NPM instance before testing this PR image! Especially if this PR contains database changes.", true)
|
||||
npmGithubPrComment("""Docker Image for build ${BUILD_NUMBER} is available on
|
||||
[DockerHub](https://cloud.docker.com/repository/docker/nginxproxymanager/${IMAGE}-dev)
|
||||
as `nginxproxymanager/${IMAGE}-dev:${BRANCH_LOWER}`
|
||||
|
||||
**Note:** ensure you backup your NPM instance before testing this image! Especially if there are database changes
|
||||
**Note:** this is a different docker image namespace than the official image
|
||||
""", true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
<p align="center">
|
||||
<img src="https://nginxproxymanager.com/github.png">
|
||||
<br><br>
|
||||
<img src="https://img.shields.io/badge/version-2.12.0-green.svg?style=for-the-badge">
|
||||
<img src="https://img.shields.io/badge/version-2.12.1-green.svg?style=for-the-badge">
|
||||
<a href="https://hub.docker.com/repository/docker/jc21/nginx-proxy-manager">
|
||||
<img src="https://img.shields.io/docker/stars/jc21/nginx-proxy-manager.svg?style=for-the-badge">
|
||||
</a>
|
||||
|
@ -181,7 +181,9 @@ const internalNginx = {
|
||||
* @param {Object} host
|
||||
* @returns {Promise}
|
||||
*/
|
||||
generateConfig: (host_type, host) => {
|
||||
generateConfig: (host_type, host_row) => {
|
||||
// Prevent modifying the original object:
|
||||
let host = JSON.parse(JSON.stringify(host_row));
|
||||
const nice_host_type = internalNginx.getFileFriendlyHostType(host_type);
|
||||
|
||||
if (config.debug()) {
|
||||
|
@ -82,6 +82,47 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} data
|
||||
* @param {String} data.identity
|
||||
* @param {String} [issuer]
|
||||
* @returns {Promise}
|
||||
*/
|
||||
getTokenFromOAuthClaim: (data) => {
|
||||
let Token = new TokenModel();
|
||||
|
||||
data.scope = 'user';
|
||||
data.expiry = '1d';
|
||||
|
||||
return userModel
|
||||
.query()
|
||||
.where('email', data.identity)
|
||||
.andWhere('is_deleted', 0)
|
||||
.andWhere('is_disabled', 0)
|
||||
.first()
|
||||
.then((user) => {
|
||||
if (!user) {
|
||||
throw new error.AuthError('No relevant user found');
|
||||
}
|
||||
|
||||
// Create a moment of the expiry expression
|
||||
let expiry = helpers.parseDatePeriod(data.expiry);
|
||||
if (expiry === null) {
|
||||
throw new error.AuthError('Invalid expiry time: ' + data.expiry);
|
||||
}
|
||||
|
||||
let iss = 'api',
|
||||
attrs = { id: user.id },
|
||||
scope = [ data.scope ],
|
||||
expiresIn = data.expiry;
|
||||
|
||||
return Token.create({ iss, attrs, scope, expiresIn })
|
||||
.then((signed) => {
|
||||
return { token: signed.token, expires: expiry.toISOString() };
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Access} access
|
||||
* @param {Object} [data]
|
||||
|
@ -4,7 +4,14 @@ module.exports = () => {
|
||||
return function (req, res, next) {
|
||||
res.locals.access = null;
|
||||
let access = new Access(res.locals.token || null);
|
||||
access.load()
|
||||
|
||||
// Allow unauthenticated access to get the oidc configuration
|
||||
let oidc_access =
|
||||
req.url === '/oidc-config' &&
|
||||
req.method === 'GET' &&
|
||||
!access.token.getUserId();
|
||||
|
||||
access.load(oidc_access)
|
||||
.then(() => {
|
||||
res.locals.access = access;
|
||||
next();
|
||||
|
@ -10,5 +10,6 @@ module.exports = {
|
||||
certbot: new Signale({scope: 'Certbot '}),
|
||||
import: new Signale({scope: 'Importer '}),
|
||||
setup: new Signale({scope: 'Setup '}),
|
||||
ip_ranges: new Signale({scope: 'IP Ranges'})
|
||||
ip_ranges: new Signale({scope: 'IP Ranges'}),
|
||||
oidc: new Signale({scope: 'OIDC '})
|
||||
};
|
||||
|
@ -21,6 +21,8 @@
|
||||
"moment": "^2.29.4",
|
||||
"mysql2": "^3.11.1",
|
||||
"node-rsa": "^1.0.8",
|
||||
"nodemon": "^2.0.2",
|
||||
"openid-client": "^5.4.0",
|
||||
"objection": "3.0.1",
|
||||
"path": "^0.12.7",
|
||||
"signale": "1.4.0",
|
||||
|
@ -27,6 +27,7 @@ router.get('/', (req, res/*, next*/) => {
|
||||
|
||||
router.use('/schema', require('./schema'));
|
||||
router.use('/tokens', require('./tokens'));
|
||||
router.use('/oidc', require('./oidc'));
|
||||
router.use('/users', require('./users'));
|
||||
router.use('/audit-log', require('./audit-log'));
|
||||
router.use('/reports', require('./reports'));
|
||||
|
168
backend/routes/oidc.js
Normal file
168
backend/routes/oidc.js
Normal file
@ -0,0 +1,168 @@
|
||||
const crypto = require('crypto');
|
||||
const error = require('../lib/error');
|
||||
const express = require('express');
|
||||
const jwtdecode = require('../lib/express/jwt-decode');
|
||||
const logger = require('../logger').oidc;
|
||||
const oidc = require('openid-client');
|
||||
const settingModel = require('../models/setting');
|
||||
const internalToken = require('../internal/token');
|
||||
|
||||
let router = express.Router({
|
||||
caseSensitive: true,
|
||||
strict: true,
|
||||
mergeParams: true
|
||||
});
|
||||
|
||||
router
|
||||
.route('/')
|
||||
.options((req, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
|
||||
/**
|
||||
* GET /api/oidc
|
||||
*
|
||||
* OAuth Authorization Code flow initialisation
|
||||
*/
|
||||
.get(jwtdecode(), async (req, res) => {
|
||||
logger.info('Initializing OAuth flow');
|
||||
settingModel
|
||||
.query()
|
||||
.where({id: 'oidc-config'})
|
||||
.first()
|
||||
.then((row) => getInitParams(req, row))
|
||||
.then((params) => redirectToAuthorizationURL(res, params))
|
||||
.catch((err) => redirectWithError(res, err));
|
||||
});
|
||||
|
||||
|
||||
router
|
||||
.route('/callback')
|
||||
.options((req, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
|
||||
/**
|
||||
* GET /api/oidc/callback
|
||||
*
|
||||
* Oauth Authorization Code flow callback
|
||||
*/
|
||||
.get(jwtdecode(), async (req, res) => {
|
||||
logger.info('Processing callback');
|
||||
settingModel
|
||||
.query()
|
||||
.where({id: 'oidc-config'})
|
||||
.first()
|
||||
.then((settings) => validateCallback(req, settings))
|
||||
.then((token) => redirectWithJwtToken(res, token))
|
||||
.catch((err) => redirectWithError(res, err));
|
||||
});
|
||||
|
||||
/**
|
||||
* Executes discovery and returns the configured `openid-client` client
|
||||
*
|
||||
* @param {Setting} row
|
||||
* */
|
||||
let getClient = async (row) => {
|
||||
let issuer;
|
||||
try {
|
||||
issuer = await oidc.Issuer.discover(row.meta.issuerURL);
|
||||
} catch (err) {
|
||||
throw new error.AuthError(`Discovery failed for the specified URL with message: ${err.message}`);
|
||||
}
|
||||
|
||||
return new issuer.Client({
|
||||
client_id: row.meta.clientID,
|
||||
client_secret: row.meta.clientSecret,
|
||||
redirect_uris: [row.meta.redirectURL],
|
||||
response_types: ['code'],
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Generates state, nonce and authorization url.
|
||||
*
|
||||
* @param {Request} req
|
||||
* @param {Setting} row
|
||||
* @return { {String}, {String}, {String} } state, nonce and url
|
||||
* */
|
||||
let getInitParams = async (req, row) => {
|
||||
let client = await getClient(row),
|
||||
state = crypto.randomUUID(),
|
||||
nonce = crypto.randomUUID(),
|
||||
url = client.authorizationUrl({
|
||||
scope: 'openid email profile',
|
||||
resource: `${req.protocol}://${req.get('host')}${req.originalUrl}`,
|
||||
state,
|
||||
nonce,
|
||||
});
|
||||
|
||||
return { state, nonce, url };
|
||||
};
|
||||
|
||||
/**
|
||||
* Parses state and nonce from cookie during the callback phase.
|
||||
*
|
||||
* @param {Request} req
|
||||
* @return { {String}, {String} } state and nonce
|
||||
* */
|
||||
let parseStateFromCookie = (req) => {
|
||||
let state, nonce;
|
||||
let cookies = req.headers.cookie.split(';');
|
||||
for (let cookie of cookies) {
|
||||
if (cookie.split('=')[0].trim() === 'npm_oidc') {
|
||||
let raw = cookie.split('=')[1],
|
||||
val = raw.split('--');
|
||||
state = val[0].trim();
|
||||
nonce = val[1].trim();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return { state, nonce };
|
||||
};
|
||||
|
||||
/**
|
||||
* Executes validation of callback parameters.
|
||||
*
|
||||
* @param {Request} req
|
||||
* @param {Setting} settings
|
||||
* @return {Promise} a promise resolving to a jwt token
|
||||
* */
|
||||
let validateCallback = async (req, settings) => {
|
||||
let client = await getClient(settings);
|
||||
let { state, nonce } = parseStateFromCookie(req);
|
||||
|
||||
const params = client.callbackParams(req);
|
||||
const tokenSet = await client.callback(settings.meta.redirectURL, params, { state, nonce });
|
||||
let claims = tokenSet.claims();
|
||||
|
||||
if (!claims.email) {
|
||||
throw new error.AuthError('The Identity Provider didn\'t send the \'email\' claim');
|
||||
} else {
|
||||
logger.info('Successful authentication for email ' + claims.email);
|
||||
}
|
||||
|
||||
return internalToken.getTokenFromOAuthClaim({ identity: claims.email });
|
||||
};
|
||||
|
||||
let redirectToAuthorizationURL = (res, params) => {
|
||||
logger.info('Authorization URL: ' + params.url);
|
||||
res.cookie('npm_oidc', params.state + '--' + params.nonce);
|
||||
res.redirect(params.url);
|
||||
};
|
||||
|
||||
let redirectWithJwtToken = (res, token) => {
|
||||
res.cookie('npm_oidc', token.token + '---' + token.expires);
|
||||
res.redirect('/login');
|
||||
};
|
||||
|
||||
let redirectWithError = (res, error) => {
|
||||
logger.error('Callback error: ' + error.message);
|
||||
res.cookie('npm_oidc_error', error.message);
|
||||
res.redirect('/login');
|
||||
};
|
||||
|
||||
module.exports = router;
|
@ -71,6 +71,18 @@ router
|
||||
});
|
||||
})
|
||||
.then((row) => {
|
||||
if (row.id === 'oidc-config') {
|
||||
// Redact oidc configuration via api (unauthenticated get call)
|
||||
let m = row.meta;
|
||||
row.meta = {
|
||||
name: m.name,
|
||||
enabled: m.enabled === true && !!(m.clientID && m.clientSecret && m.issuerURL && m.redirectURL && m.name)
|
||||
};
|
||||
|
||||
// Remove these temporary cookies used during oidc authentication
|
||||
res.clearCookie('npm_oidc');
|
||||
res.clearCookie('npm_oidc_error');
|
||||
}
|
||||
res.status(200)
|
||||
.send(row);
|
||||
})
|
||||
|
@ -29,6 +29,8 @@ router
|
||||
scope: (typeof req.query.scope !== 'undefined' ? req.query.scope : null)
|
||||
})
|
||||
.then((data) => {
|
||||
// clear this temporary cookie following a successful oidc authentication
|
||||
res.clearCookie('npm_oidc');
|
||||
res.status(200)
|
||||
.send(data);
|
||||
})
|
||||
|
@ -23,9 +23,7 @@
|
||||
"locations",
|
||||
"hsts_enabled",
|
||||
"hsts_subdomains",
|
||||
"certificate",
|
||||
"use_default_location",
|
||||
"ipv6"
|
||||
"certificate"
|
||||
],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
@ -151,12 +149,6 @@
|
||||
"$ref": "./access-list-object.json"
|
||||
}
|
||||
]
|
||||
},
|
||||
"use_default_location": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"ipv6": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@
|
||||
},
|
||||
"forward_scheme": {
|
||||
"type": "string",
|
||||
"enum": ["http", "https"]
|
||||
"enum": ["auto", "http", "https"]
|
||||
},
|
||||
"forward_domain_name": {
|
||||
"description": "Domain Name",
|
||||
|
@ -25,7 +25,7 @@
|
||||
"value": {
|
||||
"description": "Value in almost any form",
|
||||
"example": "congratulations",
|
||||
"oneOf": [
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
@ -46,7 +46,10 @@
|
||||
},
|
||||
"meta": {
|
||||
"description": "Extra metadata",
|
||||
"example": {},
|
||||
"example": {
|
||||
"redirect": "http://example.com",
|
||||
"html": "<h1>404</h1>"
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
|
@ -49,8 +49,7 @@
|
||||
"minLength": 1
|
||||
},
|
||||
"password": {
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -94,9 +94,7 @@
|
||||
"avatar": "",
|
||||
"roles": ["admin"]
|
||||
},
|
||||
"certificate": null,
|
||||
"use_default_location": true,
|
||||
"ipv6": true
|
||||
"certificate": null
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -79,9 +79,7 @@
|
||||
"nickname": "Admin",
|
||||
"avatar": "",
|
||||
"roles": ["admin"]
|
||||
},
|
||||
"use_default_location": true,
|
||||
"ipv6": true
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -129,9 +129,7 @@
|
||||
"roles": ["admin"]
|
||||
},
|
||||
"certificate": null,
|
||||
"access_list": null,
|
||||
"use_default_location": true,
|
||||
"ipv6": true
|
||||
"access_list": null
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -114,9 +114,7 @@
|
||||
"avatar": "//www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?default=mm",
|
||||
"roles": ["admin"]
|
||||
},
|
||||
"access_list": null,
|
||||
"use_default_location": true,
|
||||
"ipv6": true
|
||||
"access_list": null
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -114,9 +114,7 @@
|
||||
"avatar": "",
|
||||
"roles": ["admin"]
|
||||
},
|
||||
"certificate": null,
|
||||
"use_default_location": true,
|
||||
"ipv6": true
|
||||
"certificate": null
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -99,9 +99,7 @@
|
||||
"nickname": "Admin",
|
||||
"avatar": "",
|
||||
"roles": ["admin"]
|
||||
},
|
||||
"use_default_location": true,
|
||||
"ipv6": true
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -129,9 +129,7 @@
|
||||
"roles": ["admin"]
|
||||
},
|
||||
"certificate": null,
|
||||
"access_list": null,
|
||||
"use_default_location": true,
|
||||
"ipv6": true
|
||||
"access_list": null
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -13,7 +13,8 @@
|
||||
"name": "settingID",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
"minLength": 1,
|
||||
"enum": ["default-site", "oidc-config"]
|
||||
},
|
||||
"required": true,
|
||||
"description": "Setting ID",
|
||||
@ -26,19 +27,71 @@
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"minProperties": 1,
|
||||
"properties": {
|
||||
"value": {
|
||||
"$ref": "../../../components/setting-object.json#/properties/value"
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"enum": [
|
||||
"congratulations",
|
||||
"404",
|
||||
"444",
|
||||
"redirect",
|
||||
"html"
|
||||
]
|
||||
},
|
||||
"meta": {
|
||||
"$ref": "../../../components/setting-object.json#/properties/meta"
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"redirect": {
|
||||
"type": "string"
|
||||
},
|
||||
"html": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"minProperties": 1,
|
||||
"properties": {
|
||||
"meta": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"clientID": {
|
||||
"type": "string"
|
||||
},
|
||||
"clientSecret": {
|
||||
"type": "string"
|
||||
},
|
||||
"enabled": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"issuerURL": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"redirectURL": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"responses": {
|
||||
|
@ -75,7 +75,8 @@ const setupDefaultUser = () => {
|
||||
* @returns {Promise}
|
||||
*/
|
||||
const setupDefaultSettings = () => {
|
||||
return settingModel
|
||||
return Promise.all([
|
||||
settingModel
|
||||
.query()
|
||||
.select(settingModel.raw('COUNT(`id`) as `count`'))
|
||||
.where({id: 'default-site'})
|
||||
@ -92,13 +93,38 @@ const setupDefaultSettings = () => {
|
||||
meta: {},
|
||||
})
|
||||
.then(() => {
|
||||
logger.info('Default settings added');
|
||||
logger.info('Added default-site setting');
|
||||
});
|
||||
}
|
||||
if (config.debug()) {
|
||||
logger.info('Default setting setup not required');
|
||||
}
|
||||
}),
|
||||
settingModel
|
||||
.query()
|
||||
.select(settingModel.raw('COUNT(`id`) as `count`'))
|
||||
.where({id: 'oidc-config'})
|
||||
.first()
|
||||
.then((row) => {
|
||||
if (!row.count) {
|
||||
settingModel
|
||||
.query()
|
||||
.insert({
|
||||
id: 'oidc-config',
|
||||
name: 'Open ID Connect',
|
||||
description: 'Sign in to Nginx Proxy Manager with an external Identity Provider',
|
||||
value: 'metadata',
|
||||
meta: {},
|
||||
})
|
||||
.then(() => {
|
||||
logger.info('Added oidc-config setting');
|
||||
});
|
||||
}
|
||||
if (config.debug()) {
|
||||
logger.info('Default setting setup not required');
|
||||
}
|
||||
})
|
||||
]);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -4,7 +4,7 @@
|
||||
auth_basic "Authorization required";
|
||||
auth_basic_user_file /data/access/{{ access_list_id }};
|
||||
|
||||
{% if access_list.pass_auth == 0 %}
|
||||
{% if access_list.pass_auth == 0 or access_list.pass_auth == true %}
|
||||
proxy_set_header Authorization "";
|
||||
{% endif %}
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
deny all;
|
||||
|
||||
# Access checks must...
|
||||
{% if access_list.satisfy_any == 1 %}
|
||||
{% if access_list.satisfy_any == 1 or access_list.satisfy_any == true %}
|
||||
satisfy any;
|
||||
{% else %}
|
||||
satisfy all;
|
||||
|
@ -5,11 +5,16 @@
|
||||
#listen [::]:80;
|
||||
{% endif %}
|
||||
{% if certificate -%}
|
||||
listen 443 ssl{% if http2_support == 1 or http2_support == true %} http2{% endif %};
|
||||
listen 443 ssl;
|
||||
{% if ipv6 -%}
|
||||
listen [::]:443 ssl{% if http2_support == 1 or http2_support == true %} http2{% endif %};
|
||||
listen [::]:443 ssl;
|
||||
{% else -%}
|
||||
#listen [::]:443;
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
server_name {{ domain_names | join: " " }};
|
||||
{% if http2_support == 1 or http2_support == true %}
|
||||
http2 on;
|
||||
{% else -%}
|
||||
http2 off;
|
||||
{% endif %}
|
@ -7,11 +7,7 @@
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
|
||||
set $proxy_forward_scheme {{ forward_scheme }};
|
||||
set $proxy_server "{{ forward_host }}";
|
||||
set $proxy_port {{ forward_port }};
|
||||
|
||||
proxy_pass $proxy_forward_scheme://$proxy_server:$proxy_port{{ forward_path }};
|
||||
proxy_pass {{ forward_scheme }}://{{ forward_host }}:{{ forward_port }}{{ forward_path }};
|
||||
|
||||
{% include "_access.conf" %}
|
||||
{% include "_assets.conf" %}
|
||||
|
1794
backend/yarn.lock
1794
backend/yarn.lock
File diff suppressed because it is too large
Load Diff
@ -137,5 +137,13 @@ Email: admin@example.com
|
||||
Password: changeme
|
||||
```
|
||||
|
||||
Immediately after logging in with this default user you will be asked to modify your details and change your password.
|
||||
Immediately after logging in with this default user you will be asked to modify your details and change your password. You can change defaults with:
|
||||
|
||||
|
||||
```
|
||||
environment:
|
||||
INITIAL_ADMIN_EMAIL: my@example.com
|
||||
INITIAL_ADMIN_PASSWORD: mypassword1
|
||||
```
|
||||
|
||||
|
||||
|
@ -59,6 +59,11 @@ function fetch(verb, path, data, options) {
|
||||
},
|
||||
|
||||
beforeSend: function (xhr) {
|
||||
// Allow unauthenticated access to get the oidc configuration
|
||||
if (path === 'settings/oidc-config' && verb === "get") {
|
||||
return;
|
||||
}
|
||||
|
||||
xhr.setRequestHeader('Authorization', 'Bearer ' + (token ? token.t : null));
|
||||
},
|
||||
|
||||
|
@ -434,6 +434,11 @@ module.exports = {
|
||||
App.UI.showModalDialog(new View({model: model}));
|
||||
});
|
||||
}
|
||||
if (model.get('id') === 'oidc-config') {
|
||||
require(['./main', './settings/oidc-config/main'], function (App, View) {
|
||||
App.UI.showModalDialog(new View({model: model}));
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -1,7 +1,19 @@
|
||||
<td>
|
||||
<div><%- i18n('settings', 'default-site') %></div>
|
||||
<div>
|
||||
<% if (id === 'default-site') { %>
|
||||
<%- i18n('settings', 'default-site') %>
|
||||
<% } %>
|
||||
<% if (id === 'oidc-config') { %>
|
||||
<%- i18n('settings', 'oidc-config') %>
|
||||
<% } %>
|
||||
</div>
|
||||
<div class="small text-muted">
|
||||
<% if (id === 'default-site') { %>
|
||||
<%- i18n('settings', 'default-site-description') %>
|
||||
<% } %>
|
||||
<% if (id === 'oidc-config') { %>
|
||||
<%- i18n('settings', 'oidc-config-description') %>
|
||||
<% } %>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
@ -9,6 +21,14 @@
|
||||
<% if (id === 'default-site') { %>
|
||||
<%- i18n('settings', 'default-site-' + value) %>
|
||||
<% } %>
|
||||
<% if (id === 'oidc-config' && meta && meta.name && meta.clientID && meta.clientSecret && meta.issuerURL && meta.redirectURL) { %>
|
||||
<%- meta.name %>
|
||||
<% if (!meta.enabled) { %>
|
||||
(<%- i18n('str', 'disabled') %>)
|
||||
<% } %>
|
||||
<% } else if (id === 'oidc-config') { %>
|
||||
<%- i18n('settings', 'oidc-not-configured') %>
|
||||
<% } %>
|
||||
</div>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
|
56
frontend/js/app/settings/oidc-config/main.ejs
Normal file
56
frontend/js/app/settings/oidc-config/main.ejs
Normal file
@ -0,0 +1,56 @@
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><%- i18n('settings', id) %></h5>
|
||||
<button type="button" class="close cancel" aria-label="Close" data-dismiss="modal"> </button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form>
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-12">
|
||||
<div class="form-group">
|
||||
<div class="form-label"><%- description %></div>
|
||||
<div>
|
||||
<p><%- i18n('settings', 'oidc-config-hint-1') %></p>
|
||||
<p><%- i18n('settings', 'oidc-config-hint-2') %></p>
|
||||
</div>
|
||||
<div class="custom-controls-stacked">
|
||||
<div class="form-group">
|
||||
<label class="form-label"><%- i18n('str', 'name') %> <span class="form-required">*</span>
|
||||
<input class="form-control name-input" name="meta[name]" required type="text" value="<%- meta && typeof meta.name !== 'undefined' ? meta.name : '' %>">
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Client ID <span class="form-required">*</span>
|
||||
<input class="form-control id-input" name="meta[clientID]" required type="text" value="<%- meta && typeof meta.clientID !== 'undefined' ? meta.clientID : '' %>">
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Client Secret <span class="form-required">*</span>
|
||||
<input class="form-control secret-input" name="meta[clientSecret]" required type="text" value="<%- meta && typeof meta.clientSecret !== 'undefined' ? meta.clientSecret : '' %>">
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Issuer URL <span class="form-required">*</span>
|
||||
<input class="form-control issuer-input" name="meta[issuerURL]" required placeholder="https://" type="url" value="<%- meta && typeof meta.issuerURL !== 'undefined' ? meta.issuerURL : '' %>">
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Redirect URL <span class="form-required">*</span>
|
||||
<input class="form-control redirect-url-input" name="meta[redirectURL]" required placeholder="https://" type="url" value="<%- meta && typeof meta.redirectURL !== 'undefined' ? meta.redirectURL : document.location.origin + '/api/oidc/callback' %>">
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="form-label"><%- i18n('str', 'enable') %></div>
|
||||
<input class="form-check enabled-input" name="meta[enabled]" placeholder="" type="checkbox" <%- meta && (typeof meta.enabled !== 'undefined' && meta.enabled === true) || (JSON.stringify(meta) === '{}') ? 'checked="checked"' : '' %> >
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary cancel" data-dismiss="modal"><%- i18n('str', 'cancel') %></button>
|
||||
<button type="button" class="btn btn-teal save"><%- i18n('str', 'save') %></button>
|
||||
</div>
|
||||
</div>
|
46
frontend/js/app/settings/oidc-config/main.js
Normal file
46
frontend/js/app/settings/oidc-config/main.js
Normal file
@ -0,0 +1,46 @@
|
||||
const Mn = require('backbone.marionette');
|
||||
const App = require('../../main');
|
||||
const template = require('./main.ejs');
|
||||
|
||||
require('jquery-serializejson');
|
||||
|
||||
module.exports = Mn.View.extend({
|
||||
template: template,
|
||||
className: 'modal-dialog wide',
|
||||
|
||||
ui: {
|
||||
form: 'form',
|
||||
buttons: '.modal-footer button',
|
||||
cancel: 'button.cancel',
|
||||
save: 'button.save',
|
||||
},
|
||||
|
||||
events: {
|
||||
'click @ui.save': function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
if (!this.ui.form[0].checkValidity()) {
|
||||
$('<input type="submit">').hide().appendTo(this.ui.form).click().remove();
|
||||
return;
|
||||
}
|
||||
|
||||
let view = this;
|
||||
let data = this.ui.form.serializeJSON();
|
||||
data.id = this.model.get('id');
|
||||
if (data.meta.enabled) {
|
||||
data.meta.enabled = data.meta.enabled === 'on' || data.meta.enabled === 'true';
|
||||
}
|
||||
|
||||
this.ui.buttons.prop('disabled', true).addClass('btn-disabled');
|
||||
App.Api.Settings.update(data)
|
||||
.then((result) => {
|
||||
view.model.set(result);
|
||||
App.UI.closeModal();
|
||||
})
|
||||
.catch((err) => {
|
||||
alert(err.message);
|
||||
this.ui.buttons.prop('disabled', false).removeClass('btn-disabled');
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
@ -5,6 +5,7 @@
|
||||
"username": "Username",
|
||||
"password": "Password",
|
||||
"sign-in": "Sign in",
|
||||
"sign-in-with": "Sign in with",
|
||||
"sign-out": "Sign out",
|
||||
"try-again": "Try again",
|
||||
"name": "Name",
|
||||
@ -290,7 +291,12 @@
|
||||
"default-site-404": "404 Page",
|
||||
"default-site-444": "No Response (444)",
|
||||
"default-site-html": "Custom Page",
|
||||
"default-site-redirect": "Redirect"
|
||||
"default-site-redirect": "Redirect",
|
||||
"oidc-config": "Open ID Conncect Configuration",
|
||||
"oidc-config-description": "Sign in to Nginx Proxy Manager with an external Identity Provider",
|
||||
"oidc-not-configured": "Not configured",
|
||||
"oidc-config-hint-1": "Provide configuration for an IdP that supports Open ID Connect Discovery.",
|
||||
"oidc-config-hint-2": "The 'RedirectURL' must be set to '[base URL]/api/oidc/callback', the IdP must send the 'email' claim and a user with matching email address must exist in Nginx Proxy Manager."
|
||||
}
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
<div class="card-body p-6">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-6">
|
||||
<div class="col-sm-12 col-md-6 margin-auto">
|
||||
<div class="text-center p-6">
|
||||
<img src="/images/logo-text-vertical-grey.png" alt="Logo" />
|
||||
<div class="text-center text-muted mt-5">
|
||||
@ -27,6 +27,13 @@
|
||||
<div class="form-footer">
|
||||
<button type="submit" class="btn btn-teal btn-block"><%- i18n('str', 'sign-in') %></button>
|
||||
</div>
|
||||
<div class="form-footer login-oidc">
|
||||
<div class="separator"><slot>OR</slot></div>
|
||||
<button type="button" id="login-oidc" class="btn btn-teal btn-block">
|
||||
<%- i18n('str', 'sign-in-with') %> <span class="oidc-provider"></span>
|
||||
</button>
|
||||
<div class="invalid-feedback oidc-error"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -3,6 +3,7 @@ const Mn = require('backbone.marionette');
|
||||
const template = require('./login.ejs');
|
||||
const Api = require('../../app/api');
|
||||
const i18n = require('../../app/i18n');
|
||||
const Tokens = require('../../app/tokens');
|
||||
|
||||
module.exports = Mn.View.extend({
|
||||
template: template,
|
||||
@ -13,7 +14,11 @@ module.exports = Mn.View.extend({
|
||||
identity: 'input[name="identity"]',
|
||||
secret: 'input[name="secret"]',
|
||||
error: '.secret-error',
|
||||
button: 'button'
|
||||
button: 'button[type=submit]',
|
||||
oidcLogin: 'div.login-oidc',
|
||||
oidcButton: 'button#login-oidc',
|
||||
oidcError: '.oidc-error',
|
||||
oidcProvider: 'span.oidc-provider'
|
||||
},
|
||||
|
||||
events: {
|
||||
@ -26,10 +31,56 @@ module.exports = Mn.View.extend({
|
||||
.then(() => {
|
||||
window.location = '/';
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err) => {
|
||||
this.ui.error.text(err.message).show();
|
||||
this.ui.button.removeClass('btn-loading').prop('disabled', false);
|
||||
});
|
||||
},
|
||||
'click @ui.oidcButton': function() {
|
||||
this.ui.identity.prop('disabled', true);
|
||||
this.ui.secret.prop('disabled', true);
|
||||
this.ui.button.prop('disabled', true);
|
||||
this.ui.oidcButton.addClass('btn-loading').prop('disabled', true);
|
||||
// redirect to initiate oauth flow
|
||||
document.location.replace('/api/oidc/');
|
||||
},
|
||||
},
|
||||
|
||||
async onRender() {
|
||||
// read oauth callback state cookies
|
||||
let cookies = document.cookie.split(';'),
|
||||
token, expiry, error;
|
||||
for (cookie of cookies) {
|
||||
let raw = cookie.split('='),
|
||||
name = raw[0].trim(),
|
||||
value = raw[1];
|
||||
if (name === 'npm_oidc') {
|
||||
let v = value.split('---');
|
||||
token = v[0];
|
||||
expiry = v[1];
|
||||
}
|
||||
if (name === 'npm_oidc_error') {
|
||||
error = decodeURIComponent(value);
|
||||
}
|
||||
}
|
||||
|
||||
// register a newly acquired jwt token following successful oidc authentication
|
||||
if (token && expiry && (new Date(Date.parse(decodeURIComponent(expiry)))) > new Date() ) {
|
||||
Tokens.addToken(token);
|
||||
document.location.replace('/');
|
||||
}
|
||||
|
||||
// show error message following a failed oidc authentication
|
||||
if (error) {
|
||||
this.ui.oidcError.html(error);
|
||||
}
|
||||
|
||||
// fetch oidc configuration and show alternative action button if enabled
|
||||
let response = await Api.Settings.getById('oidc-config');
|
||||
if (response && response.meta && response.meta.enabled === true) {
|
||||
this.ui.oidcProvider.html(response.meta.name);
|
||||
this.ui.oidcLogin.show();
|
||||
this.ui.oidcError.show();
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -40,3 +40,33 @@ a:hover {
|
||||
.col-login {
|
||||
max-width: 48rem;
|
||||
}
|
||||
|
||||
.margin-auto {
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
.separator {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
.separator::before, .separator::after {
|
||||
content: "";
|
||||
flex: 1 1 0%;
|
||||
border-bottom: 1px solid #ccc;
|
||||
}
|
||||
|
||||
.separator:not(:empty)::before {
|
||||
margin-right: 0.5em;
|
||||
}
|
||||
|
||||
.separator:not(:empty)::after {
|
||||
margin-left: 0.5em;
|
||||
}
|
||||
|
||||
.login-oidc {
|
||||
display: none;
|
||||
margin-top: 1em;
|
||||
}
|
@ -303,6 +303,14 @@
|
||||
"credentials": "dns_joker_username = <Dynamic DNS Authentication Username>\ndns_joker_password = <Dynamic DNS Authentication Password>\ndns_joker_domain = <Dynamic DNS Domain>",
|
||||
"full_plugin_name": "dns-joker"
|
||||
},
|
||||
"leaseweb": {
|
||||
"name": "LeaseWeb",
|
||||
"package_name": "certbot-dns-leaseweb",
|
||||
"version": "~=1.0.1",
|
||||
"dependencies": "",
|
||||
"credentials": "dns_leaseweb_api_token = 01234556789",
|
||||
"full_plugin_name": "dns-leaseweb"
|
||||
},
|
||||
"linode": {
|
||||
"name": "Linode",
|
||||
"package_name": "certbot-dns-linode",
|
||||
|
@ -9,7 +9,7 @@ describe('Full Certificate Provisions', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it.only('Should be able to create new http certificate', function() {
|
||||
it('Should be able to create new http certificate', function() {
|
||||
cy.task('backendApiPost', {
|
||||
token: token,
|
||||
path: '/api/nginx/certificates',
|
||||
@ -35,7 +35,7 @@ describe('Full Certificate Provisions', () => {
|
||||
it('Should be able to create new DNS certificate with Powerdns', function() {
|
||||
cy.task('backendApiPost', {
|
||||
token: token,
|
||||
path: '/api/certificates',
|
||||
path: '/api/nginx/certificates',
|
||||
data: {
|
||||
domain_names: [
|
||||
'website2.example.com'
|
||||
@ -45,7 +45,8 @@ describe('Full Certificate Provisions', () => {
|
||||
dns_challenge: true,
|
||||
dns_provider: 'powerdns',
|
||||
dns_provider_credentials: 'dns_powerdns_api_url = http://ns1.pdns:8081\r\ndns_powerdns_api_key = npm',
|
||||
letsencrypt_agree: true
|
||||
letsencrypt_agree: true,
|
||||
propagation_seconds: 5,
|
||||
},
|
||||
provider: 'letsencrypt'
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/// <reference types="cypress" />
|
||||
|
||||
describe('Hosts endpoints', () => {
|
||||
describe('Proxy Hosts endpoints', () => {
|
||||
let token;
|
||||
|
||||
before(() => {
|
124
test/cypress/e2e/api/Settings.cy.js
Normal file
124
test/cypress/e2e/api/Settings.cy.js
Normal file
@ -0,0 +1,124 @@
|
||||
/// <reference types="cypress" />
|
||||
|
||||
describe('Settings endpoints', () => {
|
||||
let token;
|
||||
|
||||
before(() => {
|
||||
cy.getToken().then((tok) => {
|
||||
token = tok;
|
||||
});
|
||||
});
|
||||
|
||||
it('Get all settings', function() {
|
||||
cy.task('backendApiGet', {
|
||||
token: token,
|
||||
path: '/api/settings',
|
||||
}).then((data) => {
|
||||
cy.validateSwaggerSchema('get', 200, '/settings', data);
|
||||
expect(data.length).to.be.greaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
it('Get default-site setting', function() {
|
||||
cy.task('backendApiGet', {
|
||||
token: token,
|
||||
path: '/api/settings/default-site',
|
||||
}).then((data) => {
|
||||
cy.validateSwaggerSchema('get', 200, '/settings/{settingID}', data);
|
||||
expect(data).to.have.property('id');
|
||||
expect(data.id).to.be.equal('default-site');
|
||||
});
|
||||
});
|
||||
|
||||
it('Default Site congratulations', function() {
|
||||
cy.task('backendApiPut', {
|
||||
token: token,
|
||||
path: '/api/settings/default-site',
|
||||
data: {
|
||||
value: 'congratulations',
|
||||
},
|
||||
}).then((data) => {
|
||||
cy.validateSwaggerSchema('put', 200, '/settings/{settingID}', data);
|
||||
expect(data).to.have.property('id');
|
||||
expect(data.id).to.be.equal('default-site');
|
||||
expect(data).to.have.property('value');
|
||||
expect(data.value).to.be.equal('congratulations');
|
||||
});
|
||||
});
|
||||
|
||||
it('Default Site 404', function() {
|
||||
cy.task('backendApiPut', {
|
||||
token: token,
|
||||
path: '/api/settings/default-site',
|
||||
data: {
|
||||
value: '404',
|
||||
},
|
||||
}).then((data) => {
|
||||
cy.validateSwaggerSchema('put', 200, '/settings/{settingID}', data);
|
||||
expect(data).to.have.property('id');
|
||||
expect(data.id).to.be.equal('default-site');
|
||||
expect(data).to.have.property('value');
|
||||
expect(data.value).to.be.equal('404');
|
||||
});
|
||||
});
|
||||
|
||||
it('Default Site 444', function() {
|
||||
cy.task('backendApiPut', {
|
||||
token: token,
|
||||
path: '/api/settings/default-site',
|
||||
data: {
|
||||
value: '444',
|
||||
},
|
||||
}).then((data) => {
|
||||
cy.validateSwaggerSchema('put', 200, '/settings/{settingID}', data);
|
||||
expect(data).to.have.property('id');
|
||||
expect(data.id).to.be.equal('default-site');
|
||||
expect(data).to.have.property('value');
|
||||
expect(data.value).to.be.equal('444');
|
||||
});
|
||||
});
|
||||
|
||||
it('Default Site redirect', function() {
|
||||
cy.task('backendApiPut', {
|
||||
token: token,
|
||||
path: '/api/settings/default-site',
|
||||
data: {
|
||||
value: 'redirect',
|
||||
meta: {
|
||||
redirect: 'https://www.google.com',
|
||||
},
|
||||
},
|
||||
}).then((data) => {
|
||||
cy.validateSwaggerSchema('put', 200, '/settings/{settingID}', data);
|
||||
expect(data).to.have.property('id');
|
||||
expect(data.id).to.be.equal('default-site');
|
||||
expect(data).to.have.property('value');
|
||||
expect(data.value).to.be.equal('redirect');
|
||||
expect(data).to.have.property('meta');
|
||||
expect(data.meta).to.have.property('redirect');
|
||||
expect(data.meta.redirect).to.be.equal('https://www.google.com');
|
||||
});
|
||||
});
|
||||
|
||||
it('Default Site html', function() {
|
||||
cy.task('backendApiPut', {
|
||||
token: token,
|
||||
path: '/api/settings/default-site',
|
||||
data: {
|
||||
value: 'html',
|
||||
meta: {
|
||||
html: '<p>hello world</p>'
|
||||
},
|
||||
},
|
||||
}).then((data) => {
|
||||
cy.validateSwaggerSchema('put', 200, '/settings/{settingID}', data);
|
||||
expect(data).to.have.property('id');
|
||||
expect(data.id).to.be.equal('default-site');
|
||||
expect(data).to.have.property('value');
|
||||
expect(data.value).to.be.equal('html');
|
||||
expect(data).to.have.property('meta');
|
||||
expect(data.meta).to.have.property('html');
|
||||
expect(data.meta.html).to.be.equal('<p>hello world</p>');
|
||||
});
|
||||
});
|
||||
});
|
@ -7,7 +7,7 @@ const BackendApi = function(config, token) {
|
||||
|
||||
this.axios = axios.create({
|
||||
baseURL: config.baseUrl,
|
||||
timeout: 60000,
|
||||
timeout: 90000,
|
||||
});
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user