Dynamically assign an IAM Role between an IAM user and and EC2 instance

0

I have an IAM Role created; currently assigned to an EC2 instance and works great. How do I dynamically assign the same IAM Role between an IAM user and an EC2 instance? Thanks!

gefragt vor 2 Jahren636 Aufrufe
2 Antworten
1

In short: Please don't!
Instances (systems) usually have a usage pattern that is totally different from humans. Mixing up their rights is a bound to conflict with the principle of "least privilege".

If somehow you have a use-case that requires this (please double-check!):

  • Write the policy into a managed policy
  • Attach it to the instance profile
  • Attach it to the user (or better, their group)
profile pictureAWS
Obijan
beantwortet vor 2 Jahren
1

Update the Trust Policy of the role to something like this:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Service": "ec2.amazonaws.com",
                "AWS": "arn:aws:iam::0123456789012:user/johnsmith"
            },
            "Action": "sts:AssumeRole"
        }
    ]
}
profile pictureAWS
EXPERTE
kentrad
beantwortet vor 2 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen