In SSH, there is an agent forwarding option to use local credentials, e.g. for working with services like GitHub or for chaining connections onward to log in to other servers, whereby the private key stays under the protection of the local OS keychain and no trusted private key material is ever present on the "jumpbox" or remote environment. Is anything analogous possible for AWS credentials?
For example, if connecting to an EC2 Instance with AWS SSM (or EC2 Instance Connect, or SSH via an SSM proxy tunnel, etc) is there any way to automatically transfer temporary AWS credentials to the remote session (or any way to proxy AWS SDK authentication calls back to the local system)?
I'm looking for an approach that can avoid needing to manually repeat the user authentication process twice (once locally and then again inside the remote session, potentially involving MFA each time). Ideally it would only provide temporary credentials to the remote session, and automate the temporary credential rotation to be transparent to applications (like how IRSA automatically rotates temporary AWS keys for AWS SDK based processes on EKS pods, except that IRSA uses k8s OIDC instead of depending on an active connection from an authenticated user). How could this be implemented?
You can give the ec2 an instance role with IAM permissions to access the required service and therefore do not use temporary AWS credentials. Then when you run aws cli commands or SDK programs in the ec2 instance it assumes the role and permissions of the instance role you setup. This is further secure over copying credentials from your local to the remote instance.
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html