-
Notifications
You must be signed in to change notification settings - Fork 199
Fix AWS Region with Default region #478
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
base: main
Are you sure you want to change the base?
Fix AWS Region with Default region #478
Conversation
If you're new to commit signing, there are different ways to set it up: Sign commits with
|
c743f7f
to
2d45c84
Compare
Default region should only be used to fill in a region when awsConfig.Region doesn't exist (and set it accordingly, but not be the sole determinant on if there is a difference. It should defer to what is already does in the `else if` later, where it sets it if it isn't blank, but doesn't error. Right now, it will error if `default region` is set in the 1Password item, but in reality, it should only do that if `region` (aka: `hasRegularRegion`) is set. This updates this logic to reflect that.
Now not used by the error check below, so removing.
2d45c84
to
ec4ef7a
Compare
97aed46
to
f3cded3
Compare
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.
Thank you for your contribution.
I've left some comments concerning the backwards compatibility of these changes. Could you please take a look and adjust your changes accordingly?
Let me know if you have any questions or need additional guidance. 😄
@@ -643,14 +643,14 @@ func TestResolveLocalAnd1PasswordConfigurations(t *testing.T) { | |||
description: "has region both in 1Password and local config, but values differ", | |||
itemFields: map[sdk.FieldName]string{ | |||
fieldname.OneTimePassword: "515467", | |||
fieldname.DefaultRegion: "us-east-2", | |||
fieldname.Region: "us-east-2", |
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.
Instead of changing this test, can you add a new one in which the Region is configurerd? In this way, we ensure that this change is backwards compatible.
@@ -250,8 +248,8 @@ Learn how to add an OTP field to your item: | |||
https://developer.1password.com/docs/cli/shell-plugins/aws/#optional-set-up-multi-factor-authentication`, awsConfig.MfaSerial) | |||
} | |||
|
|||
if hasRegion && awsConfig.Region != "" && region != awsConfig.Region { | |||
return fmt.Errorf("your local AWS configuration (config file or environment variable) has a different default region than the one specified in 1Password") | |||
if hasRegularRegion && awsConfig.Region != "" && region != awsConfig.Region { |
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.
This change looks backwards incompatible to me.
What we're trying to achieve is the following:
- If the 1Password item doesn't have any region defined (
default region
norregion
), then look for the default region in the config - If the 1Password item contains
default region
, use that one - If the 1Password item contains
region
, use that one - If the 1Password item contains
default region
and we set the environment variableAWS_REGION
, then use the value fromAWS_REGION
Out of these the following scenario seems to fail now:
A user has a default region in
~/.aws/config
file and adefault region
defined in 1Password item. The shell plugin will now use the value in~/.aws/config
instead of the one in the 1Password item.
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.
Maybe this table explains it better in terms of the expected order of precedence:
AWS config file | 1P item default region field | 1P item region field | AWS_REGION env var |
Expected result |
---|---|---|---|---|
✅ | ❌ | ❌ | ❌ | AWS config file value |
✅ | ✅ | ❌ | ❌ | 1P item default region value |
✅ | ❌ | ✅ | ❌ | 1P item region value |
✅ | ✅ | ❌ | ✅ | AWS_REGION env var value |
Out of these 4 cases, the second one doesn't work as expected with the current changes.
Are there any other scenarios that you're thinking of that should be covered by this PR in terms of order of precendence?
Overview
When using the
aws
plugin, if theDEFAULT_REGION
is set in the 1Password item, it will override any usage ofAWS_REGION
, which should take president normally with theaws
cli, preventing the usage of being able to connect to other regions unless you regularly change theDEFAULT_REGION
value in the1Password
each time.Type of change
Related Issue(s)
How To Test
DEFAULT_REGION
value in your 1Password item you use for theaws
pluginaws s3 ls
(or something similar)DEFAULT_REGION
AWS_REGION=different-region aws s3 ls
, using adifferent-region
then the one you have configuredIn the previous version, this would return the same value for both commands, and this should fix that.
Other options is quering for something specific by ARN that exists in only in the
DEFAULT_REGION
, and with this patch, the second command will fail, where previously it would find it.Changelog
Fix
DEFAULT_REGION
logic foraws
plugin to allow for overrides usingAWS_REGION
.