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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ See [CONTRIBUTING.md](CONTRIBUTING.md).
The webhook secret that GitHub signs the POSTed payloads with. This is created when the webhook is defined. The default is `hush-hush`.
- **`TRAVIS_CI_TOKEN`**<br>
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
- **`JENKINS_WORKER_IPS`**<br>
List of valid Jenkins worker IPs allowed to push PR status updates, split by comma: `192.168.1.100,192.168.1.101`.
- **`JENKINS_API_CREDENTIALS`** (optional)<br>
For scripts that communicate with Jenkins on http://ci.nodejs.org. The Jenkins API token is visible on
your own profile page `https://ci.nodejs.org/user/<YOUR_GITHUB_USERNAME>/configure`, by clicking the
Expand Down
21 changes: 21 additions & 0 deletions scripts/jenkins-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
const pushJenkinsUpdate = require('../lib/push-jenkins-update')
const enabledRepos = ['citgm', 'node']

const jenkinsIpWhitelist = process.env.JENKINS_WORKER_IPS ? process.env.JENKINS_WORKER_IPS.split(',') : []

function isJenkinsIpWhitelisted (req) {
const ip = req.connection.remoteAddress

if (jenkinsIpWhitelist.length && !jenkinsIpWhitelist.includes(ip)) {
req.log.warn({ ip }, 'Ignoring, not allowed to push Jenkins updates')
return false
}

return true
}

module.exports = function (app) {
app.post('/:repo/jenkins/start', (req, res) => {
const isValid = pushJenkinsUpdate.validate(req.body)
Expand All @@ -16,6 +29,10 @@ module.exports = function (app) {
return res.status(400).end('Invalid repository')
}

if (!isJenkinsIpWhitelisted(req)) {
return res.status(401).end('Invalid Jenkins IP')
}

pushJenkinsUpdate.pushStarted({
owner: 'nodejs',
repo,
Expand All @@ -37,6 +54,10 @@ module.exports = function (app) {
return res.status(400).end('Invalid repository')
}

if (!isJenkinsIpWhitelisted(req)) {
return res.status(401).end('Invalid Jenkins IP')
}

pushJenkinsUpdate.pushEnded({
owner: 'nodejs',
repo,
Expand Down