AWS-Lambda-Functions-Contain-Secrets
Severity : Medium
Description: This control ensures that Lambda function code does not contain the secrets like API keys, credentials for databases. Best security practice recommend that lambda function code must not use secrets like API keys, password etc in the code. Lambda code should access the secrets in stored in dedicated services like AWS Secret Manager or AWS system Manager Parameter store.
Remediation Steps:
Perform following to store secrets in Secret Manager and used by lambda :
Login to the AWS Management Console at https://console.aws.amazon.com.
Create the secret in the Secret Manager for instances :
Navigate to Secret Manager console.
Select Secrets and Store a new secret.
In navigation select Instances and the select the instance reported.
Under Secret Type, select other type secret and specify key value pair.
Select Next. Enter Name for secret and Description.
Create IAM role with secret access policy for instances:
Navigate to IAMÂ console.
Select Roles and select Create Role.
If EC2 instance role already created, Add Policy to get the secret as below. If role doesn’t exist Create Role for EC2 instances. The Policy in the role
{ "Version": "2012-10-17", "Statement": [ { "Action": [ "secretsmanager:GetSecretValue" ], "Resource": <Key ARN in Secrete Manager>, "Effect": "Allow" } ] }
Â
Update Lambda permission to use above role and remove secret from lambda function :
Navigate to Lambda function console.
In navigation, Select Functions.
Select the function reported from the list of functions.
If lambda function doesn’t have any role, Select Execution Role and select Edit. Under Basic Settings in existing Role, Select the role created above
In case lambda function have a role, Update the Existing role with the Policy in the above role to have lambda function access the secret key.
Choose Save to save changes.
In navigation, Select Environment variables. Select Edit and add name of secret key in the environment variable.
Update the Lambda function code to remove the secret and add code to fetch secret using Secret manager SDK.
Important:
Reference :
Â
Blue Hexagon Proprietary