Assuming roles from php application running in Kubernetes cluster using IRSA #2706
-
Hey folks, We have been attempting to migrate a PHP application from Beanstalk to a Kubernetes cluster using IAM Roles for Service Accounts.
We were using the following code:
In Kubernetes we have the following setup
Problem is the Application isn't assuming IAM role 2 or if it is its failing past it silently and then erroring about the env provider not having AWS credentials. Has anyone Assume a role from a pod using IAM for Service Accounts? If so what did you have to do differently? Edit: Some more info Just to verify I assumed IAM role 2 from account 2 from the application pod by doing the following:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Hi @wesbrownfavor, here is some documentation for:
I know you have done already some of those steps, but can you confirm all of them were taken?
After all this is confirmed then it should work fine. Another thing to mention here is that if you use the default chain for credential resolution then, if there is any other credential provider defined and that could be resolved first then you should experience permission issues, but in this case you could just specify the correct credential provider for this situation as follow: <?php
require '../vendor/autoload.php';
use Aws\S3\S3Client;
use Aws\Credentials\CredentialProvider;
$client = new S3Client([
'version' => 'latest',
'region' => getenv('TEST_REGION'),
'credentials' => CredentialProvider::assumeRoleWithWebIdentityCredentialProvider()
]);
$command = $client->getCommand('getObject', [
'Bucket' => getenv('TEST_BUCKET'),
'Key' => getenv('TEST_KEY')
]);
$response = $client->execute($command);
var_dump($response); I hope this helps! Thanks! |
Beta Was this translation helpful? Give feedback.
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
Hi @wesbrownfavor, this behavior is expected. If we check the implementation here for assumeRoleWithWebIdentityCredentialProvider we will find that the parameter 'RoleArn' is never used, and that also the first role that is tried to be used is the one defined in AWS_ROLE_ARN. If you want to explicitly set which role you want to use when providing the credentials you could do the following: