-
Notifications
You must be signed in to change notification settings - Fork 672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
aws lambda func url not in use #1970
base: master
Are you sure you want to change the base?
Changes from all commits
541e2a9
e805cbf
a8b262f
de89b84
5caaf9d
41564dc
a0fee64
37c5bb6
af25ad4
c02ec4a
5779c4e
6029db2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,65 @@ | ||||||
var async = require('async'); | ||||||
var helpers = require('../../../helpers/aws'); | ||||||
|
||||||
module.exports = { | ||||||
title: 'Lambda Function URL Not In Use', | ||||||
category: 'Lambda', | ||||||
domain: 'Serverless', | ||||||
severity: 'Medium', | ||||||
description: 'Ensure that AWS Lambda functions are not configured with function URLs for HTTP(S) endpoints.', | ||||||
more_info: 'A function URL is a dedicated HTTP(S) endpoint created for your Amazon Lambda function. You can use a function URL to invoke your Lambda function. But it can lead to some security risks depending on the security configuration and intention of the function.', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
link: 'https://docs.aws.amazon.com/lambda/latest/dg/urls-configuration.html', | ||||||
recommended_action: 'Modify Lambda function configurations and delete function url.', | ||||||
apis: ['Lambda:listFunctions','Lambda:listFunctionUrlConfigs'], | ||||||
realtime_triggers: ['lambda:CreateFunction','lambda:UpdateFunctionConfiguration','lambda:DeleteFunction'], | ||||||
|
||||||
run: function(cache, settings, callback) { | ||||||
var results = []; | ||||||
var source = {}; | ||||||
var regions = helpers.regions(settings); | ||||||
|
||||||
async.each(regions.lambda, function(region, rcb){ | ||||||
var listFunctions = helpers.addSource(cache, source, | ||||||
['lambda', 'listFunctions', region]); | ||||||
|
||||||
if (!listFunctions) return rcb(); | ||||||
|
||||||
if (listFunctions.err || !listFunctions.data) { | ||||||
helpers.addResult(results, 3, | ||||||
`Unable to query for Lambda functions: ${helpers.addError(listFunctions)}`, region); | ||||||
return rcb(); | ||||||
} | ||||||
|
||||||
if (!listFunctions.data.length) { | ||||||
helpers.addResult(results, 0, 'No Lambda functions found', region); | ||||||
return rcb(); | ||||||
} | ||||||
|
||||||
for (var lambdaFunc of listFunctions.data) { | ||||||
|
||||||
if (!lambdaFunc.FunctionArn || !lambdaFunc.FunctionName) continue; | ||||||
var resource = lambdaFunc.FunctionArn; | ||||||
|
||||||
var urlConfigs = helpers.addSource(cache, source, | ||||||
['lambda', 'listFunctionUrlConfigs', region, lambdaFunc.FunctionName]); | ||||||
|
||||||
if (!urlConfigs || urlConfigs.err || !urlConfigs.data) { | ||||||
helpers.addResult(results, 3, | ||||||
`Unable to query for Lambda function URL configs: ${helpers.addError(urlConfigs)}`, region, resource); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
continue; | ||||||
} | ||||||
|
||||||
if (urlConfigs.data.FunctionUrlConfigs && | ||||||
urlConfigs.data.FunctionUrlConfigs.length){ | ||||||
helpers.addResult(results, 2, 'Lambda function Url is configured', region, resource); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} else { | ||||||
helpers.addResult(results, 0, 'Lambda function Url is not configured', region, resource); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
} | ||||||
|
||||||
rcb(); | ||||||
}, function(){ | ||||||
callback(null, results, source); | ||||||
}); | ||||||
} | ||||||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
var expect = require('chai').expect; | ||
var lambdaFunctionURLNotInUse = require('./lambdaFuncUrlNotInUse'); | ||
|
||
const createCache = (lambdaData, functionUrlConfigs) => { | ||
return { | ||
lambda: { | ||
listFunctions: { | ||
'us-east-1': { | ||
err: null, | ||
data: lambdaData | ||
} | ||
}, | ||
listFunctionUrlConfigs: functionUrlConfigs | ||
} | ||
}; | ||
}; | ||
|
||
describe('Lambda Function URL Not in Use', function () { | ||
alphadev4 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
describe('run', function () { | ||
it('should return unknown result if unable to list the lambda functions', function (done) { | ||
const callback = (err, results) => { | ||
expect(results.length).to.equal(1); | ||
expect(results[0].status).to.equal(3); | ||
expect(results[0].region).to.equal('us-east-1'); | ||
expect(results[0].message).to.include('Unable to query for Lambda functions'); | ||
done(); | ||
}; | ||
|
||
const cache = createCache(null, {}); | ||
|
||
lambdaFunctionURLNotInUse.run(cache, {}, callback); | ||
}); | ||
|
||
it('should return passing result if no lambda function found in region', function (done) { | ||
const callback = (err, results) => { | ||
expect(results.length).to.equal(1); | ||
expect(results[0].status).to.equal(0); | ||
expect(results[0].region).to.equal('us-east-1'); | ||
expect(results[0].message).to.include('No Lambda functions found'); | ||
done(); | ||
}; | ||
|
||
const cache = createCache([], {}); | ||
|
||
lambdaFunctionURLNotInUse.run(cache, {}, callback); | ||
}); | ||
|
||
it('should return passing result if lambda function URL is not configured', function (done) { | ||
const lambdaData = [ | ||
{ | ||
"FunctionName": "test-lambda", | ||
"FunctionArn": "arn:aws:lambda:us-east-1:000011112222:function:test-lambda" | ||
} | ||
]; | ||
|
||
const functionUrlConfigs = { | ||
'us-east-1': { | ||
'test-lambda': { | ||
'err': null, | ||
'data': { | ||
'FunctionUrlConfigs': [] | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const callback = (err, results) => { | ||
expect(results.length).to.equal(1); | ||
expect(results[0].status).to.equal(0); | ||
expect(results[0].region).to.equal('us-east-1'); | ||
expect(results[0].message).to.include('Lambda function Url is not configured'); | ||
done(); | ||
}; | ||
|
||
const cache = createCache(lambdaData, functionUrlConfigs); | ||
|
||
lambdaFunctionURLNotInUse.run(cache, {}, callback); | ||
}); | ||
|
||
it('should return failing result if lambda function URL is configured', function (done) { | ||
const lambdaData = [ | ||
{ | ||
"FunctionName": "test-lambda", | ||
"FunctionArn": "arn:aws:lambda:us-east-1:000011112222:function:test-lambda" | ||
} | ||
]; | ||
|
||
const functionUrlConfigs = { | ||
'us-east-1': { | ||
'test-lambda': { | ||
'err': null, | ||
'data': { | ||
'FunctionUrlConfigs': [{ | ||
FunctionUrl: "https://tetsuewfebwfweffesvvs.lambda-url.us-east-1.on.aws/", | ||
}] | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const callback = (err, results) => { | ||
expect(results.length).to.equal(1); | ||
expect(results[0].status).to.equal(2); | ||
expect(results[0].region).to.equal('us-east-1'); | ||
expect(results[0].message).to.include('Lambda function Url is configured'); | ||
done(); | ||
}; | ||
|
||
const cache = createCache(lambdaData, functionUrlConfigs); | ||
|
||
lambdaFunctionURLNotInUse.run(cache, {}, callback); | ||
}); | ||
|
||
it('should return unknown result if unable to list the lambda function url config', function (done) { | ||
const lambdaData = [ | ||
{ | ||
"FunctionName": "test-lambda", | ||
"FunctionArn": "arn:aws:lambda:us-east-1:000011112222:function:test-lambda" | ||
} | ||
]; | ||
|
||
const callback = (err, results) => { | ||
expect(results.length).to.equal(1); | ||
expect(results[0].status).to.equal(3); | ||
expect(results[0].region).to.equal('us-east-1'); | ||
expect(results[0].message).to.include('Unable to query for Lambda function URL configs: Unable to obtain data'); | ||
done(); | ||
}; | ||
|
||
const cache = createCache(lambdaData, null); | ||
|
||
lambdaFunctionURLNotInUse.run(cache, {}, callback); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.