-
Notifications
You must be signed in to change notification settings - Fork 26
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
Allows profiles to automatically assume a role #34
Conversation
Nice one! |
src/AWSCredentials.jl
Outdated
@@ -254,27 +254,62 @@ using IniFile | |||
dot_aws_credentials_file() = get(ENV, "AWS_CONFIG_FILE", | |||
joinpath(homedir(), ".aws", "credentials")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems based on the current doc that this should be changed to:
dot_aws_credentials_file() =
get(ENV, "AWS_SHARED_CREDENTIALS_FILE",
joinpath(homedir(), ".aws", "credentials"))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I forgot to change that. Thanks!
src/AWSCredentials.jl
Outdated
function dot_aws_credentials() | ||
|
||
@assert isfile(dot_aws_credentials_file()) | ||
@assert isfile(dot_aws_config_file()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to support systems with only one of these files. So the assert should probably be creds ||
conf.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Up in function AWSCredentials()
where dot_aws_credentials()
is called we'll need to apply the same test.
src/AWSCredentials.jl
Outdated
ini = read(Inifile(), dot_aws_credentials_file()) | ||
|
||
config_ini = read(Inifile(), dot_aws_config_file()) | ||
creds_ini = read(Inifile(), dot_aws_credentials_file()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One or the other of these files may not exist, so read(Inifile(), ...
will throw ERROR: SystemError: opening file food: No such file or directory
. Probably best to have an if isfile
around the block of code that uses that file.
The cli doc says that .credentials has precedence over .config for creds. So the logic should be something like:
- if there is a .config file:
- if there are credentials for
profile
in the config file load them - if there is a
role_arn
andsource_profile
forprofile, grab the
role_arnand overwrite the
profile` variable. - try to load credentials for
profile
in the config file again in case the source_profile refers to another profile in the config file.
- if there are credentials for
- if there is a .credentials file:
- if there are credentials for
profile
in the .credentials file load them (overwriting whatever was loaded from the .config file.
- if there are credentials for
- create the AWSCredentials object
- If there is a
role_arn
, call AssumeRole and create a new AWSCredentials object - return the AWSCredentials object
Thinking a bit more about how to test this... |
Note that the
|
src/AWSCredentials.jl
Outdated
|
||
profile = get(ENV, "AWS_DEFAULT_PROFILE", | ||
get(ENV, "AWS_PROFILE", "default")) | ||
|
||
region = get(ENV, "AWS_DEFAULT_REGION", "us-east-1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't be assuming a default region. If the profile doesn't have a region set or AWS_DEFAULT_REGION isn't set there should be an exception
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should that also be the case in aws_config()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe so. Maybe @samoconnor disagrees?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do :)
I have tried to include support for the env vars and config files that are uses by boto3 (and the AWS cli) as a convenience to end users. However, I'm not attempting to follow boto3's behaviour in every respect.
My intention is to try to make the Julia AWS interface as easy as possible for first time users. As such, I see having a default region as a feature that's good for people who don't know or care what a region is but just wan't to fetch some files from this thing called S3 where their collaborators keep their data.
Some examples:
-
The S3 interface automatically follows (and caches) bucket-region redirects so that bucket regions can be completely ignored.
-
The list objects interface handles pagination internally rather than requiring the user to deal with paginators as boto3 does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having said that, it doesn't seem quite right to duplicate the region env lookup and default (the other place is here: https://github.com/JuliaCloud/AWSCore.jl/blob/master/src/AWSCore.jl#L109)
There is a slight problem in that struct AWSCredentials
does not have a region
field so the region from the .config
or .credentials
file can't currently be accessed by the aws_config
function. I propose the following:
- Add a
default_region::String
field tostruct AWSCredentials
. - Set
default_region=get(ENV, "AWS_DEFAULT_REGION", "us-east-1")
in the default constructor - In
dot_aws_credentials
, setdefault_region
if specified by the config files. - In the
aws_config
function, change theregion=
kw parameter toregion=creds.default_region
.
I think this should preserve existing behaviour, keep the default in one place, and add support for reading the region from the config files.
Nested roles should work now. |
Thanks @morris25! I won't have time to review this immediately. Easter school holidays are about to begin... |
Is this still alive? |
src/AWSCredentials.jl
Outdated
|
||
profile = get(ENV, "AWS_DEFAULT_PROFILE", | ||
get(ENV, "AWS_PROFILE", "default")) | ||
|
||
region = get(ENV, "AWS_DEFAULT_REGION", "us-east-1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having said that, it doesn't seem quite right to duplicate the region env lookup and default (the other place is here: https://github.com/JuliaCloud/AWSCore.jl/blob/master/src/AWSCore.jl#L109)
There is a slight problem in that struct AWSCredentials
does not have a region
field so the region from the .config
or .credentials
file can't currently be accessed by the aws_config
function. I propose the following:
- Add a
default_region::String
field tostruct AWSCredentials
. - Set
default_region=get(ENV, "AWS_DEFAULT_REGION", "us-east-1")
in the default constructor - In
dot_aws_credentials
, setdefault_region
if specified by the config files. - In the
aws_config
function, change theregion=
kw parameter toregion=creds.default_region
.
I think this should preserve existing behaviour, keep the default in one place, and add support for reading the region from the config files.
@morris25 sorry about the delay, and thanks for your efforts! |
In response to #30