Possible secret key in a Lambda task's aws_access_key field

Keep real secret keys out of Lambda deployment playbooks and manage deployment authentication separately from the function's execution role.

Description

Ansible’s aws_access_key takes the access key ID for deployment requests. Putting a real secret access key there can break authentication and leave the secret in the playbook and deployment records.

Potential impact

Anyone with the valid ID and its secret may use the key’s permissions. Other workloads that share an exposed key are affected too.

Remediation

Use temporary credentials or a supported authentication source in the Ansible module’s execution environment. Grant the deployer only deployment permissions and the Lambda execution role only the permissions the function needs. If a real key was exposed, deactivate it promptly and update its consumers. Review repository history, deployment records, and access logs, then test deployment and function execution separately.

Examples

Each lambda_functions entry needs name and zip_file. Supply the execution role ARN, deployment files, and a supported lambda_runtime compatible with the code.

Before

yaml
- name: looped creation
  amazon.aws.lambda:
    aws_access_key: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
    name: "{{ item.name }}"
    state: present
    zip_file: "{{ item.zip_file }}"
    runtime: "{{ lambda_runtime }}"
    role: "{{ lambda_execution_role_arn }}"
    handler: "hello_python.my_handler"
  loop: "{{ lambda_functions }}"

The ID field contains a public example secret from the AWS documentation.

After

yaml
- name: looped creation
  amazon.aws.lambda:
    name: "{{ item.name }}"
    state: present
    zip_file: "{{ item.zip_file }}"
    runtime: "{{ lambda_runtime }}"
    role: "{{ lambda_execution_role_arn }}"
    handler: hello_python.my_handler
  loop: "{{ lambda_functions }}"

With the ID field removed, Ansible uses credentials from its execution environment. role applies to the running Lambda function.

References