Skip to content
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

feat: signer using default creds #1

Merged
merged 63 commits into from
Feb 29, 2024
Merged

feat: signer using default creds #1

merged 63 commits into from
Feb 29, 2024

Conversation

bruce-szalwinski-he
Copy link
Owner

@bruce-szalwinski-he bruce-szalwinski-he commented Feb 21, 2024

The msk iam sasl signer in Ruby, joining the family of msk iam sasl signers.

Waiting on OAuth support to be added to rdkafka-ruby

@@ -73,6 +73,9 @@ Metrics/ParameterLists:
Minitest/EmptyLineBeforeAssertionMethods:
Enabled: false

Minitest/MultipleAssertions:
Copy link
Owner Author

Choose a reason for hiding this comment

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

I split up credential tests into groups and moved creation of token into setup. Increased MultipleAssertions from default of 3 to 20. With the increase, could also just put all of the assertions back together.


Naming/MethodParameterName:
AllowedNames:
- a
Copy link
Owner Author

Choose a reason for hiding this comment

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

chose to add comparison helpers and needed to allow short names.

module Sasl
module Signer
class Credentials
def load_default_credentials
Copy link
Owner Author

Choose a reason for hiding this comment

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

put this here so that it could be stubbed with fake creds.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It makes better sense to have the client created in the presigner module. You can use the stub responses feature of the client for testing:

stubbed_client = Aws::Kafka::Client.new(stub_responses: true)

which gives stubbed credentials. You can do something like:

expect(Aws::Kafka::Client).to receive(:new).and_return(stubbed_client)

Copy link
Collaborator

@mullermp mullermp left a comment

Choose a reason for hiding this comment

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

Nice! Just some general comments and improvements - I didn't want to be a blocker to your progress.

module Sasl
module Signer
class Credentials
def load_default_credentials
Copy link
Collaborator

Choose a reason for hiding this comment

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

It makes better sense to have the client created in the presigner module. You can use the stub responses feature of the client for testing:

stubbed_client = Aws::Kafka::Client.new(stub_responses: true)

which gives stubbed credentials. You can do something like:

expect(Aws::Kafka::Client).to receive(:new).and_return(stubbed_client)

end

def endpoint_url
host = ENDPOINT_URL_TEMPLATE.gsub("{}", @region)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of using the template here, use endpoint resolution pieces:

endpoint_params = Aws::Kafka::EndpointParameters.new(
  region: region,
  use_dual_stack: true/false # can be options
  use_fips: true/false # can be options
)
endpoint = client.config.endpoint_provider.resolve_endpoint(endpoint_params)

Copy link
Owner Author

Choose a reason for hiding this comment

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

I was following the pattern that the go and python signers use. Will look at EndpointParameters.

def endpoint_url
host = ENDPOINT_URL_TEMPLATE.gsub("{}", @region)
query_params = {
Action: "kafka-cluster:Connect"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this the only query param ever supported for this to work?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yes. Once you connect, then MSK Cluster policy along with your IAM Policy governs what you can do in the cluster.

ENDPOINT_URL_TEMPLATE = "kafka.{}.amazonaws.com".freeze
DEFAULT_TOKEN_EXPIRY_SECONDS = 900
ACTION_TYPE = "Action".freeze
ACTION_NAME = "kafka-cluster:Connect".freeze
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some of these aren't used

spec.require_paths = ["lib"]

# Runtime dependencies
# spec.add_dependency "thor", "~> 1.2"
Copy link
Collaborator

Choose a reason for hiding this comment

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

You'll want a dependency on aws-sdk-kafka.

@bruce-szalwinski-he bruce-szalwinski-he marked this pull request as ready for review February 23, 2024 21:47
Copy link
Collaborator

@HarlemSquirrel HarlemSquirrel left a comment

Choose a reason for hiding this comment

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

I definitely like the single module name AwsMskIamSaslSigner better 👍

Got a few comments

Gemfile Outdated
@@ -1,11 +1,16 @@
source "https://rubygems.org"
gemspec

gem "aws-sdk-kafka", "~> 1.68"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't put this here since it will be read from gemspec above

Copy link
Owner Author

Choose a reason for hiding this comment

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

fixed

Gemfile Outdated
gem "rake", "~> 13.0"
gem "rubocop", "1.60.2"
gem "rubocop-minitest", "0.34.5"
gem "rubocop-packaging", "0.5.2"
gem "rubocop-performance", "1.20.2"
gem "rubocop-rake", "0.6.0"
gem "simplecov", require: false, group: :test
gem "thor", "~> 1.3"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't put this here since it will be read from gemspec above

Copy link
Owner Author

Choose a reason for hiding this comment

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

fixed

sts.get_caller_identity.arn
)

puts "Credentials Identity: #{caller_identity.to_h.to_json}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would avoid puts in the lib since it's not good practice with Rails apps. If we need to output something, we should look for Rails.logger to be defined, allow overriding it in a config, and have a default logger for non-Rails apps

Copy link
Owner Author

Choose a reason for hiding this comment

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

fixed

Copy link
Collaborator

@HarlemSquirrel HarlemSquirrel left a comment

Choose a reason for hiding this comment

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

bin/console Outdated
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "example"
require "aws/msk/iam/sasl/signer"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs to point to the flattened file now, right?

@bruce-szalwinski-he bruce-szalwinski-he merged commit bef3893 into main Feb 29, 2024
7 checks passed
@bruce-szalwinski-he bruce-szalwinski-he deleted the sasl-signer branch February 29, 2024 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants