Conversation
Why are these changes being introduced: * Lambda needed role assumption capabilities * Clients were doing the same thing two different ways Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/TIMX-680 How does this address that need: * Normalized the configuration for Lambda and OpenSearch clients to use consistent role assumption and credential handling by implementing a common AWS authentication abstraction.
There was a problem hiding this comment.
Pull request overview
Normalizes AWS credential and role-assumption handling for Lambda and OpenSearch clients.
Changes:
- Adds shared AWS authentication and configuration validation.
- Updates Lambda and OpenSearch initialization.
- Renames AOSS role configuration to
AWS_ROLE_ARN. - Updates documentation and tests.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Summary |
|---|---|
test/initializers/lambda_config_test.rb |
Tests Lambda credential configuration. |
test/initializers/aws_config_validator_test.rb |
Updates shared configuration validation tests. |
README.md |
Documents AWS authentication settings; credential precedence requires clarification. |
lib/opensearch_config_validator.rb |
Removes the superseded validator. |
lib/aws_config_validator.rb |
Centralizes validation; migration support for AWS_AOSS_ROLE_ARN is required. |
lib/aws_auth.rb |
Provides shared credential and role-assumption helpers. |
config/initializers/opensearch.rb |
Uses shared OpenSearch authentication. |
config/initializers/lambda.rb |
Adds Lambda validation and role-based credentials. |
Suppressed comments (1)
config/initializers/lambda.rb:12
- When both
AWS_ROLE_ARNandAWS_SESSION_TOKENare set, Lambda takes this role-assumption branch, whileaws_aoss_clienttakes the session-token branch and uses the original credentials. The shared configuration can therefore make the two clients authenticate as different principals, contrary to the stated normalization (and the generic README text that a session token is used directly). Define one precedence rule—or reject the combination—and apply it consistently.
if AwsAuth.role_arn_present?
Rails.logger.debug 'Configuring Lambda client with assumed role credentials'
return AwsAuth.assume_role_credentials(role_session_name: 'timdex-lambda')
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| - `AWS_ROLE_ARN`: IAM role ARN to assume when using role-based AWS authentication. | ||
| Used by both OpenSearch (AOSS) and Lambda when `AWS_SESSION_TOKEN` is not set. | ||
| - `AWS_SESSION_TOKEN`: (Optional) AWS session token for temporary credentials when using expiring AWS credentials. | ||
| Use this with temporary AWS credentials for AWS-based OpenSearch access and Lambda. | ||
| For AOSS, when this is set, temporary credentials are used directly and `AWS_AOSS_ROLE_ARN` is not needed. | ||
| When this is set, temporary credentials are used directly and `AWS_ROLE_ARN` is not needed. |
There was a problem hiding this comment.
Normalized how the two clients work. This was a good call out.
❌ 1 blocking issue (1 total)
|
| require 'test_helper' | ||
|
|
||
| class LambdaConfigTest < ActiveSupport::TestCase | ||
| test 'configure_lambda_client uses assume role credentials when AWS_ROLE_ARN is set and no session token is present' do |
matt-bernhardt
left a comment
There was a problem hiding this comment.
This seems to work, so on that basis I'm happy to approve as-is if that's your preference on the question I'm asking.
My question is described more fully in the inline comment, but I wonder whether there's a dependency between the AwsAuth and AwsConfigValidator classes that isn't necessary, and could be cleaner / more maintainable if we moved the two validate_* methods out of AwsAuth and into AwsConfigValidator.
If I'm wrong about this, then go ahead and ![]()
| raise "#{error_prefix}: These required environment variables are not set: #{missing_vars.join(', ')}" | ||
| end | ||
|
|
||
| def validate_base_aws_config!(error_prefix:) |
There was a problem hiding this comment.
Would it be cleaner to move validate_base_aws_config! and validate_required_vars! to the AwsConfigValidator class?
My understanding of the functionality here is that, for each of the three validation pathways, we follow this logic:
- Create a Hash based on the current environment, using
nilas the default value each time. - Pass that hash through the
validate_required_vars!method, making sure that nonilvalues are present.
This feels pretty solid as an approach, could be extended to other configuration validation, and could also be applied to TIMDEX UI when that application integrates with all the services it consumes - so I really like it.
When I compare the three routes implemented in AwsConfigValidator, though, there is a difference between which class handles what - the lambda config gets passed to AwsAuth for building the hash, while the hash gets built directly in AwsConfigValidator for the AWS OS paths. Those two locations then each call the hash validation method in AwsAuth.
I wonder whether it would be self-contained if all three paths built the hash in AwsConfigValidator, and the hash validation method was part of the same class? That would leave AwsAuth to focus on interacting with the lambda and opensearch initializers as they are now, using the _credentials and _arn_present? methods.
There was a problem hiding this comment.
Good call out. I'm going to see if it is as clean as I think it should be to do this refactor now.
* Validation responsibility moved into AwsConfigValidator * Validation pathways are self-contained in AwsConfigValidator * AwsAuth is now focused on auth/credentials only * Lambda and AOSS role-ARN logic is aligned to be required when no session token present * AWS_REGION uses default and is no longer required
matt-bernhardt
left a comment
There was a problem hiding this comment.
This looks good to me - the layout of AwsConfigValidator and AwsAuth are much cleaner. I like the additional method documentation blocks as well. Thanks!
![]()
Why are these changes being introduced:
Relevant ticket(s):
How does this address that need:
Developer
our guide and
all issues introduced by these changes have been resolved or opened as new
issues (link to those issues in the Pull Request details above)
Code Reviewer
(not just this pull request message)
Requires database migrations?
NO
Includes new or updated dependencies?
NO