-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FR: support credential_source = Ec2InstanceMetadata
in ~/.aws/config
#287
Comments
I think is would be a good feature to have. Looking at the documentation there are three parameters which
We would just need a mapping the values to their functions, and then if credential_source_mapping = Dict(
"Environment" => env_var_credentials,
"Ec2InstanceMetadata" => ec2_instance_credentials,
"EcsContainer" => ecs_instance_credentials
) |
Cool, thanks for taking a look! I think that's not quite enough here, because for me In case that doesn't make sense, going back to the config,
here |
Ah okay, I think I understand now. You want to use the This is probably a bit more of a complex assumption process. It's definitely do-able, but would require some more time spent thinking of a solution. Supporting more use cases for various configurations would be great to have, currently I don't have too much time to dive into this and would be a lower priority for me. If you'd like to make the propose changes for it, I can dedicate some time for code review on it. A quick work-around for this if possible is to give the default credentials on the instance the ability to assume the role you want and then use:
To create an AWSConfig object with those credentials. |
Thanks for the workaround! That worked for me. In the language of my example, I think it's this: using AWS: @service
@service STS
function config_by_assuming_role_from_profile(profile::String, role_session_name; config = global_aws_config())
config_file = AWS.dot_aws_config_file()
isfile(config_file) || error("`config` file not found at $(config_file)")
ini = read(AWS.Inifile(), config_file)
role_arn = AWS._get_ini_value(ini, profile, "role_arn")
role_arn === nothing && error("`role_arn` not found in profile $profile in config file $(config_file)")
assume_role_results = STS.assume_role(role_arn, role_session_name)
role_creds = AWS.AWSCredentials(
assume_role_results["AssumeRoleResult"]["Credentials"]["AccessKeyId"], # access_key_id
assume_role_results["AssumeRoleResult"]["Credentials"]["SecretAccessKey"], # secret_key
assume_role_results["AssumeRoleResult"]["Credentials"]["SessionToken"], # token,
assume_role_results["AssumeRoleResult"]["AssumedRoleUser"]["Arn"], # user_arn
config.credentials.account_number #= account_number =#)
return AWSConfig(role_creds, config.region, config.output)
end
role_Y_config = config_by_assuming_role_from_profile("role-Y", "using_role_Y_for_reasons")
and then path = S3Path("s3://my-bucket/role-Y-path/test"; config = role_Y_config)
open(path, write=true) do io
write(io, "abc")
end # no errors! if that role now gives you write permissions for |
Note: the |
383: Assume role from profile via instance metadata r=mattBrzezinski a=christopher-dG Closes #287 ```ini [default] region = us-east-2 [profile role-to-assume] region = us-east-2 role_arn = arn:aws:iam::account:role/role-to-assume credential_source = Ec2InstanceMetadata ``` ```julia julia> using AWS julia> global_aws_config(; profile="default") AWSConfig(arn:aws:iam::account:instance-profile/role-from-instance-profile (ASIASWQI5NDNRIZLJ3WJ, pAk..., IQo..., 2021-06-18T21:11:05), "us-east-2", "json") julia> global_aws_config(; profile="role-to-assume") AWSConfig(arn:aws:sts::account:assumed-role/role-to-assume/AWS.jl-role-role-to-assume-20210618T152950Z (ASIASWQI5NDNRFEK2HJS, AYR..., IQo..., 2021-06-18T15:44:53), "us-east-2", "json") ``` Needs some tests of course. Co-authored-by: Chris de Graaf <me@cdg.dev> Co-authored-by: mattBrzezinski <matt.brzezinski@invenia.ca>
383: Assume role from profile via instance metadata r=mattBrzezinski a=christopher-dG Closes #287 ```ini [default] region = us-east-2 [profile role-to-assume] region = us-east-2 role_arn = arn:aws:iam::account:role/role-to-assume credential_source = Ec2InstanceMetadata ``` ```julia julia> using AWS julia> global_aws_config(; profile="default") AWSConfig(arn:aws:iam::account:instance-profile/role-from-instance-profile (ASIASWQI5NDNRIZLJ3WJ, pAk..., IQo..., 2021-06-18T21:11:05), "us-east-2", "json") julia> global_aws_config(; profile="role-to-assume") AWSConfig(arn:aws:sts::account:assumed-role/role-to-assume/AWS.jl-role-role-to-assume-20210618T152950Z (ASIASWQI5NDNRFEK2HJS, AYR..., IQo..., 2021-06-18T15:44:53), "us-east-2", "json") ``` Needs some tests of course. Co-authored-by: Chris de Graaf <me@cdg.dev> Co-authored-by: mattBrzezinski <matt.brzezinski@invenia.ca>
I've an EC2 instance with a role (say role X), which is allowed to assume a role Y. I have a
~/.aws/config
that looks likeI can run commands using the AWS CLI within the EC2 instance like
that work fine (and correctly give access denied without the
--profile
flag). However, if I dothen I get access denied. The issue seems to be that AWSConfig does not detect the credentials in the profile in
~/.aws/config
and instead falls back to the overall EC2 creds; in particular, I suspect if I had the creds in that~/.aws/config
directly instead ofcredential_source = Ec2InstanceMetadata
it might work.The text was updated successfully, but these errors were encountered: