How do Lambda functions get security credentials?

So I was reading some case studies on the 2019 CapitalOne hack and read about how the attacker used a misconfigured firewall to exfiltrate credentials from EC2’s metadata service. The metadata service, which is accessible in any EC2 instance through the link local address 169.254.169.254, provides temporary credentials tied to the specific role attached to the instance. My question is, if Lambda functions don’t have an internal metadata service like EC2 instances do, how and where do they get temporary credentials?

When you set up a Lambda function, you must specify the IAM role you created as the corresponding execution role. The execution role provides the Lambda function with the credentials it needs to run and to invoke other web services. Lambda Service will use the AWS Security Token Service (AWS STS) to assume the Lambda execution role of your Lambda function.

Interesting. TIL that at least some tools get their credentials from the metadata server. I had always figured there was something analogous to a service account running behind the scenes.

I don’t see why a Lambda instance couldn’t query its own personal metadata server, but I have no idea if that’s a thing. I would really have assumed Lambda processes run as a service account.

I guess one could write a Lambda function to try hitting the metadata server and returning results. I can’t be bothered, though.

Lambda assumes the function’s role and then the Lambda runtime sets the resulting creds via environment variables the SDKs are configured to search.

This works well in a constrained environment like Lambda, as compared to something like EC2 where the service has no great way to configure env vars in the instance OS, so the metadata service is a much better approach.

Credentials are available in environment variables: https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime

This is the answer I was looking for, thanks.

This helps. Thanks, Mr. Lahey.

3+ years of using Lambda and I never thought to wonder how this works… lol. Good to know.

I don’t see why a Lambda instance couldn’t query its own personal metadata server

“magic” metadata service works in EC2 because there’s an opportunity for the hypervisor to intercept traffic from the virtual NIC, steer it wherever is appropriate.

Are the same abstraction layers (customer controlled kernel, customer admin access to “hardware”, opportunity for VM-edge network intercept) present in lambda? They’re not required by any other element of the operating model, so I doubt they exist.

About the same amount of years spent learning random auth and security things instead of, like, how to build a useful website. Gotta just live with what you prioritise :slight_smile: