Automattic / hostmgr

A tool for managing macOS VM hosts
Mozilla Public License 2.0
9 stars 3 forks source link

AWS Region should be read from config, not credentials #83

Closed AliSoftware closed 5 months ago

AliSoftware commented 7 months ago

What

When running hostmgr vm list, I get the No region set in your credentials file – please specify the region error (.noRegionFound case, because my AWS region is defined in ~/.aws/config, not in ~/.aws/credentials.

$ cat ~/.aws/config 
[default]
region = us-east-2
output = json
$ cat ~/.aws/credentials 
# a8c-apps Account, where we store CI-related artefacts and secrets
#   This is the one that contains most of our apps-related buckets,
#   except for `a8c-libs` bucket which lives in the `a8c` account for legacy reasons
[default]
aws_access_key_id = **REDACTED**
aws_secret_access_key = **REDACTED**

# The main a8c Account (where we publish our Android artefacts in the `a8c-libs` bucket, amongst other things)
#   Note: My access seems to be limited on this one, might need to ask Systems for additional permissions
#   e.g. `aws --profile a8c s3 ls` returns `AccessDenied` (but _not_ `InvalidAccessKeyId`, so key is still valid)
[a8c]
aws_access_key_id = **REDACTED**
aws_secret_access_key = **REDACTED**

How

We should update tinyS3 so that it supports reading the region from the ~/.aws/config file, not the ~/.aws/credentials file.

This might mean making AWSCredentialsFileParser.swift more versatile, e.g. renaming it IniConfigFileParser.swift or similar, and make it be able to parse an arbitrary .ini-formated config file (i.e. storing the results as [String: [String: String]] for storing arbitrary key-value-pairs for each detected profile, so that we can allow values like region missing in credentials but only present in config), and then merge the config data coming from both parsed files into a single AWSCredential model object—only doing the nil-check of the expected fields after/during the merge of the parsed data.

AliSoftware commented 6 months ago

Implementation to support this feature is ready for review in https://github.com/Automattic/hostmgr/pull/93