Skip to content

Commit e2d989e

Browse files
authored
jenkins: whitelist IPs allowed to push status changes (#142)
This is needed to ensure not everyone on the internet can push an inline status to any PR if they know the bot URL.
1 parent bdfd21e commit e2d989e

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ See [CONTRIBUTING.md](CONTRIBUTING.md).
1818
The webhook secret that GitHub signs the POSTed payloads with. This is created when the webhook is defined. The default is `hush-hush`.
1919
- **`TRAVIS_CI_TOKEN`**<br>
2020
For scripts that communicate with Travis CI. Your Travis token is visible on [yourprofile](https://travis-ci.org/profile) page, by clicking the "show token" link. Also See: https://blog.travis-ci.com/2013-01-28-token-token-token
21+
- **`JENKINS_WORKER_IPS`**<br>
22+
List of valid Jenkins worker IPs allowed to push PR status updates, split by comma: `192.168.1.100,192.168.1.101`.
2123
- **`JENKINS_API_CREDENTIALS`** (optional)<br>
2224
For scripts that communicate with Jenkins on http://ci.nodejs.org. The Jenkins API token is visible on
2325
your own profile page `https://ci.nodejs.org/user/<YOUR_GITHUB_USERNAME>/configure`, by clicking the

scripts/jenkins-status.js

+21
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33
const pushJenkinsUpdate = require('../lib/push-jenkins-update')
44
const enabledRepos = ['citgm', 'node']
55

6+
const jenkinsIpWhitelist = process.env.JENKINS_WORKER_IPS ? process.env.JENKINS_WORKER_IPS.split(',') : []
7+
8+
function isJenkinsIpWhitelisted (req) {
9+
const ip = req.connection.remoteAddress
10+
11+
if (jenkinsIpWhitelist.length && !jenkinsIpWhitelist.includes(ip)) {
12+
req.log.warn({ ip }, 'Ignoring, not allowed to push Jenkins updates')
13+
return false
14+
}
15+
16+
return true
17+
}
18+
619
module.exports = function (app) {
720
app.post('/:repo/jenkins/start', (req, res) => {
821
const isValid = pushJenkinsUpdate.validate(req.body)
@@ -16,6 +29,10 @@ module.exports = function (app) {
1629
return res.status(400).end('Invalid repository')
1730
}
1831

32+
if (!isJenkinsIpWhitelisted(req)) {
33+
return res.status(401).end('Invalid Jenkins IP')
34+
}
35+
1936
pushJenkinsUpdate.pushStarted({
2037
owner: 'nodejs',
2138
repo,
@@ -37,6 +54,10 @@ module.exports = function (app) {
3754
return res.status(400).end('Invalid repository')
3855
}
3956

57+
if (!isJenkinsIpWhitelisted(req)) {
58+
return res.status(401).end('Invalid Jenkins IP')
59+
}
60+
4061
pushJenkinsUpdate.pushEnded({
4162
owner: 'nodejs',
4263
repo,

0 commit comments

Comments
 (0)