Add iptables rules to block requests to the supervisor API from all interfaces except vpn, docker and local

This commit is contained in:
Pablo Carranza Velez 2016-08-13 14:44:01 +00:00
parent 211560472a
commit c4ea2c77a0
7 changed files with 17 additions and 2 deletions

View File

@ -11,6 +11,7 @@ RUN apt-get -q update \
btrfs-tools \ btrfs-tools \
ca-certificates \ ca-certificates \
curl \ curl \
iptables \
rsync \ rsync \
supervisor \ supervisor \
--no-install-recommends \ --no-install-recommends \

View File

@ -11,6 +11,7 @@ RUN apt-get -q update \
btrfs-tools \ btrfs-tools \
ca-certificates \ ca-certificates \
curl \ curl \
iptables \
rsync \ rsync \
supervisor \ supervisor \
--no-install-recommends \ --no-install-recommends \

View File

@ -11,6 +11,7 @@ RUN apt-get -q update \
btrfs-tools \ btrfs-tools \
ca-certificates \ ca-certificates \
curl \ curl \
iptables \
rsync \ rsync \
supervisor \ supervisor \
--no-install-recommends \ --no-install-recommends \

View File

@ -11,6 +11,7 @@ RUN apt-get -q update \
btrfs-tools \ btrfs-tools \
ca-certificates \ ca-certificates \
curl \ curl \
iptables \
rsync \ rsync \
supervisor \ supervisor \
--no-install-recommends \ --no-install-recommends \

View File

@ -11,6 +11,7 @@ RUN apt-get -q update \
btrfs-tools \ btrfs-tools \
ca-certificates \ ca-certificates \
curl \ curl \
iptables \
rsync \ rsync \
supervisor \ supervisor \
--no-install-recommends \ --no-install-recommends \

View File

@ -24,8 +24,10 @@ knex.init.then ->
device = require './device' device = require './device'
console.log('Starting API server..') console.log('Starting API server..')
apiServer = api(application).listen(config.listenPort) utils.createIpTablesRules()
apiServer.timeout = config.apiTimeout .then ->
apiServer = api(application).listen(config.listenPort)
apiServer.timeout = config.apiTimeout
bootstrap.done bootstrap.done
.then -> .then ->

View File

@ -11,6 +11,7 @@ randomHexString = require './lib/random-hex-string'
request = Promise.promisifyAll require 'request' request = Promise.promisifyAll require 'request'
logger = require './lib/logger' logger = require './lib/logger'
TypedError = require 'typed-error' TypedError = require 'typed-error'
execAsync = Promise.promisify(require('child_process').exec)
# Parses package.json and returns resin-supervisor's version # Parses package.json and returns resin-supervisor's version
version = require('../package.json').version version = require('../package.json').version
@ -279,3 +280,10 @@ exports.validateKeys = (options, validSet) ->
return if !options? return if !options?
invalidKeys = _.keys(_.omit(options, validSet)) invalidKeys = _.keys(_.omit(options, validSet))
throw new Error("Using #{invalidKeys.join(', ')} is not allowed.") if !_.isEmpty(invalidKeys) throw new Error("Using #{invalidKeys.join(', ')} is not allowed.") if !_.isEmpty(invalidKeys)
exports.createIpTablesRules = ->
allowedInterfaces = ['tun0', 'docker0', 'lo']
Promise.each allowedInterfaces, (iface) ->
execAsync("iptables -A INPUT -p tcp --dport #{config.listenPort} -i #{iface} -j ACCEPT")
.then ->
execAsync("iptables -A INPUT -p tcp --dport #{config.listenPort} -j REJECT")