Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

willwill96
Copy link

@willwill96 willwill96 commented Apr 12, 2025

Description

Adds configuration which allows Oauth2 Proxy to connect to AWS redis services using IAM auth.

Motivation and Context

This should be useful for organizations who use AWS IAM auth for redis connections.

Resolves #2950

How Has This Been Tested?

I primarily tested this in my organization's infrastructure. I may be able to get permission to screen share the before/after of these changes, if that's useful. Otherwise, I can try to get a setup working in my AWS cluster.

Checklist:

  • My change requires a change to the documentation or CHANGELOG.
  • I have updated the documentation/CHANGELOG accordingly.
  • I have created a feature (non-master) branch for my PR.
  • I have written tests for my code changes.

@willwill96 willwill96 requested a review from a team as a code owner April 12, 2025 00:11
@github-actions github-actions bot added dependencies Pull requests that update a dependency file go labels Apr 12, 2025
Comment on lines 159 to 162
flagSet.Bool("redis-aws-use-iam-auth", false, "Use AWS IAM authentication for Redis. Must set --redis-aws-service-name, --redis-aws-cluster-name, & --redis-aws-username to use this feature")
flagSet.String("redis-aws-service-name", "", "AWS service name for Redis IAM authentication - `elasticache` or `memorydb`")
flagSet.String("redis-aws-cluster-name", "", "AWS cluster name for Redis IAM authentication")
flagSet.String("redis-aws-username", "", "AWS username for Redis IAM authentication")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code climate is complaining that this function is too long now. Should the redis flags be extracted to their own flagSet?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need these as flags/could they be added only to the alpha/structured configuration?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need for them to be flags specifically. There is no session/redis config for the alpha config from what I can tell, but I can take a stab at adding that.

Copy link
Member

@tuunit tuunit Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JoelSpeed this was probably not the best call as session settings are only being introduced to the alpha config with one of my PRs

structured config #4: support for session and probes #2632

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue now would be that we would introduce the AWS Redis support at the toplevel of the alpha config just to refactor / break the config API in a couple months again

@willwill96
Copy link
Author

Is there any possibility of this being reviewed/merged?

@willwill96 willwill96 closed this Jun 10, 2025
@willwill96 willwill96 reopened this Jun 10, 2025
@rfahsel3
Copy link

rfahsel3 commented Jul 8, 2025

@JoelSpeed , I see you have a lot of contributions to this project. Is there any chance you could review this or explain what steps we would need to take to get a review? Without this, we will be forced to fork this repo for our organization. I know @willwill96 is amenable to make any changes that would make this MR any easier for you guys to review. Thank you for reading.

@rfahsel3
Copy link

@tuunit is there any expectation on when something like this could be reviewed? Is there anything we can do to make it easier or more straightforward on the maintainers? It seems like we are following the process, but we are open to whatever changes we might need to make. We are really really hoping to not have to fork it.

@tuunit
Copy link
Member

tuunit commented Jul 22, 2025

Hi @willwill96 / @rfahsel3, we are only one or two maintainers checking the PRs in our free time. Therefore it often takes quite some time before get around to these things and priorities bugfixes and generic changes over provider specific.

In the case of your change, we don't have an AWS account to validate the changes in your PR. I'll try to make some time for it :)

@rfahsel3
Copy link

Thank you very much @tuunit . Your message makes a lot of sense.

Copy link
Member

@JoelSpeed JoelSpeed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way we can add testing locally to prove this is working? Is there a service that we could use to mock the AWS auth?

Comment on lines 159 to 162
flagSet.Bool("redis-aws-use-iam-auth", false, "Use AWS IAM authentication for Redis. Must set --redis-aws-service-name, --redis-aws-cluster-name, & --redis-aws-username to use this feature")
flagSet.String("redis-aws-service-name", "", "AWS service name for Redis IAM authentication - `elasticache` or `memorydb`")
flagSet.String("redis-aws-cluster-name", "", "AWS cluster name for Redis IAM authentication")
flagSet.String("redis-aws-username", "", "AWS username for Redis IAM authentication")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need these as flags/could they be added only to the alpha/structured configuration?

hexEncodedSHA256EmptyString = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
)

type IAMTokenGenerator struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit missing comment on exported struct

Does it actually need to be exported? Could be behind an interface?

signer *v4.Signer
}

func New(serviceName, clusterName, userName string) (*IAMTokenGenerator, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comment on exported function

return "", fmt.Errorf("AWS IAM request signing failed - %v", err)
}

signedURL = strings.Replace(signedURL, "http://", "", 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment explaining why we do this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find any docs explaining why this is recommended, but it is in many of the aws iam examples. For example here: https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/auth-iam.html#auth-iam-Connecting

This value is used as a bearer token so my best guess is that the http:// breaks the validation of that header in some way.

I will add a comment with a link to the aws docs

}
return opts.AWSUsername, token
}
// AWS services has a max connection lifetime of 12 hours. This is set to 11 hours to give some buffer time
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume there's no action needed and the connection refreshes itself automatically after this period?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, once the connection expires, the redis client will reconnect on the next request, using a regenerated auth token.

@willwill96
Copy link
Author

Is there any way we can add testing locally to prove this is working? Is there a service that we could use to mock the AWS auth?

I haven't been able to find a way to test this locally. I investigated localstack, which does support a mock service for Elasticache here, but:

  1. The feature does not actually validate the iam auth token - it ignores the authorization and accepts all connections.
  2. The feature is behind a pay wall for the pro accounts.

I'll take a look at adding some unit tests to at least validate what we can.

We are also going to try to put together a screen recording of the important parts working so that we can share here.

"github.com/stretchr/testify/require"
)

func TestAWSIAMTokenGenerator(t *testing.T) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw another OSS project add a similar unit test when they added IAM auth for postgres:
https://github.com/authzed/spicedb/pull/1858/files

@willwill96
Copy link
Author

Hi @JoelSpeed,

Thank you for taking a look at our changes. I think that I have addressed your comments to the best of my ability, but happy to make additional changes if necessary.

Additionally, I have sent an email to you & @tuunit containing a demo of the IAM auth changes, which I hope will inspire a bit more confidence in these changes.

If you have any additional feedback or questions on these changes, I'm happy to help where I can.

Best regards.

Signed-off-by: Jan Larwig <[email protected]>
@willwill96
Copy link
Author

@tuunit Thank you for pushing some updates to this MR. I've resolved the linting issues that were causing a build issue before and updated the changelog entry to reflect the latest minor version. Please let me know if there's anything else I can to do help.

@rfahsel3
Copy link

Hi @tuunit ! I saw you made some contributions to this MR. Is this ready to merge?

@rfahsel3
Copy link

rfahsel3 commented Sep 9, 2025

@tuunit and @JoelSpeed , I'm sorry to be annoying, but we are really trying to figure out if we are going to fork this or not. We have a pretty hard deadline at the end of the month. I feel like we were making good progress by sending the video and working through the comments. Do we foresee this being merged in the next week, or should we plan on forking the repo? We just need to know for our planning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file docs go tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: AWS IRSA Redis Authentication
4 participants