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

Added support for cert-only login without user and password #121

Closed
wants to merge 1 commit into from
Closed

Added support for cert-only login without user and password #121

wants to merge 1 commit into from

Conversation

p-kraszewski
Copy link

Added new DialTLS_CertAuth function for RabbitMQ configured for EXTERNAL auth with ssl_cert_login plugin for userless/passwordless logons.

As of now, amqp just silently hangs, when server presents authentication metod not supported by amqp (when pickSASLMechanism finds no suitable match). I guess it should bail out with some sort of "No common SASL methods found" message.

Hope this helps,
best regards.

@streadway
Copy link
Owner

Thanks for this. Since the hang on unnegotiated SASL is serious, can you please include a regression test that exercises that behavior that this patch would fix?

Underscores aren't used in exported functions. Also we won't need a new Dial, given that DialConfig can be used in this case.

@p-kraszewski
Copy link
Author

Ah yes, regression test...

During weekend I'll prepare minimal example exhibiting unwanted behaviour (including RMQ config and all the necessary certs & keys).

From server's point of view it looks unverbose:

=INFO REPORT==== 16-Oct-2014::10:20:01 ===
accepting AMQP connection <0.509.0> (127.0.0.1:51305 -> 127.0.0.1:5671)

=ERROR REPORT==== 16-Oct-2014::10:20:11 ===
closing AMQP connection <0.509.0> (127.0.0.1:51305 -> 127.0.0.1:5671):
{handshake_timeout,handshake}

From client's point of view it hangs in amqp.DialTLS() never returning to calling process.

As to new DialTLS_CertAuth() I agree, you can manually prepare DialConfig - which makes Dial and DialTLS obsolete as well, according to the very rule.

Patching of auth.go can also be avoided by defining CertAuth mechanism in client code.

Still, userless logging-on via certificate is supported by RMQ natively and as such - it would be nice to have a DialXXX specific for this case. Non-native solutions with custom EXTERNAL methods per-definition need not be supported - but ssl_cert_login does not belong to this class (IMHO).

Thanks for response.

P.S. How should I provide test material? Commit to my fork?

@michaelklishin
Copy link
Collaborator

michaelklishin commented Nov 25, 2016

In a discussion with @streadway and @gerhard we agreed to make this an example/extend the API to make existing Dial* functions to support more "advanced" parameters. The idea is to avoid Dial* function explosion.

@michaelklishin
Copy link
Collaborator

Looks like CertAuth (or whatever we decide to name it) can be a part of this library because it won't change from user to user.

michaelklishin added a commit that referenced this pull request Dec 22, 2016
We'd like to add more TLS-related examples, e.g. for #121,
and duplicating the comments would be unfortunate.
@michaelklishin
Copy link
Collaborator

We agreed on ExternalAuth for struct name.

DmitriyMV pushed a commit to DmitriyMV/amqp that referenced this pull request Dec 23, 2016
We'd like to add more TLS-related examples, e.g. for streadway#121,
and duplicating the comments would be unfortunate.
@gerhard gerhard self-assigned this Feb 3, 2017
@troian
Copy link

troian commented Jan 22, 2020

@streadway @michaelklishin wouldn't usage of Options pattern help to not fall with different suffixes to Dial func. (it's not exactly topic of current issue but touches it in a little).

what do I mean

// Option callback for connection option
type Option func(*impl) error

// adding Options templates does not introduce compatibility issues
// as Dial(url) is still valid but adds flexibility in configuring AMQP connection as default
// configuration parameters still taking place
func Dial(url string, opts ...Option) (*Connection, error) {
	config := Config{
		Heartbeat: defaultHeartbeat,
		Locale:    defaultLocale,
	}

	return DialConfig(url, )
}

// SetOptions set amqp connection options
func (a *Config) SetOptions(opts ...Option) error {
	for _, opt := range opts {
		if err := opt(a); err != nil {
			return err
		}
	}

	return nil
}

func TLS(val *tls.Config) Option {
	return func(t * Config) error {
		t.TLSClientConfig = val
		return nil
	}
}

func Auth(val []amqp.Authentication) Option {
	return func(t *Config) error {
		t.SASL = val
		return nil
	}
}

// other parameters like connection timeout can be set through options too

from using prospective instead

if t.cfg.TLS {
	conn = amqp.DialTLS(url, t.cfg.TLS)
} else {
	conn = amqp.Dial(url)
}

can be as

conn = amqp.Dial(url, amqp.TLS(t.cfg.TLS), amqp.Auth(t.cfg.Auth))

All above is pseudo-code though we have done similar thing by making wrapper on top of amqp.DialConfig

@prateek2408
Copy link

prateek2408 commented Apr 6, 2020

When is this getting merged, I need this.

@michaelklishin
Copy link
Collaborator

@prateek2408 @troian I don't use Go enough to tell if this pattern the way to go today. It is truly unfortunate that this PR has been sitting there for years. I would welcome any reasonable solution that would allow the users to use the EXTERNAL auth mechanism. @streadway do you have a preference?

}

func (me *CertAuth) Response() string {
return fmt.Sprintf("\000*\000*")

Choose a reason for hiding this comment

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

Change to return "\000*\000*"

@@ -30,8 +30,21 @@ func (me *PlainAuth) Response() string {
return fmt.Sprintf("\000%s\000%s", me.Username, me.Password)
}

// CertAuth for RabbitMQ-auth-mechanism-ssl.
type CertAuth struct {

Choose a reason for hiding this comment

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

Can we rename this ExternalAuth to match the RabbitMQ Java library naming convention?

type CertAuth struct {
}

func (me *CertAuth) Mechanism() string {

Choose a reason for hiding this comment

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

And for naming convention again, @streadway seems to use auth instead of me.

// Finds the first mechanism preferred by the client that the server supports.
func pickSASLMechanism(client []Authentication, serverMechanisms []string) (auth Authentication, ok bool) {

Choose a reason for hiding this comment

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

Remove this unnecessary newline.

// DialTLS_CertAuth uses the provided tls.Config when encountering an amqps://
// scheme.
func DialTLS_CertAuth(url string, amqps *tls.Config) (*Connection, error) {

Choose a reason for hiding this comment

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

Unnecessary newline

@wolf-james
Copy link

@streadway Can we get this merged ASAP? I've been trying to get EXTERNAL to work for a few days now before finding this PR. @p-kraszewski's solution works perfectly for me, both with correct user:pass and user:incorrect_pass.

@michaelklishin
Copy link
Collaborator

Hey folks,

I'm posting this on behalf of the core team.

As you have noticed, this client hasn't seen a lot of activity recently.
Many users are unhappy about that and we fully recognize that it's a popular
library that should be maintained more actively. There are also many community
members who have contributed pull requests and haven't been merged for various reasons.

Because this client has a long tradition of "no breaking public API changes", certain
reasonable changes will likely never be accepted. This is frustrating to those who
have put in their time and effort into trying to improve this library.

We would like to thank @streadway
for developing this client and maintaining it for a decade — that's a remarkable contribution
to the RabbitMQ ecosystem. We this now is a good time to get more contributors
involved.

Team RabbitMQ has adopted a "hard fork" of this client
in order to give the community a place to evolve the API. Several RabbitMQ core team members
will participate but we think it very much should be a community-driven effort.

What do we mean by "hard fork" and what does it mean for you? The entire history of the project
is retained in the new repository but it is not a GitHub fork by design. The license remains the same
2-clause BSD. The contribution process won't change much (except that we hope to review and accept PRs
reasonably quickly).

What does change is that this new fork will accept reasonable breaking API changes according
to Semantic Versioning (or at least our understanding of it). At the moment the API is identical
to that of streadway/amqp but the package name is different. We will begin reviewing PRs
and merging them if they make sense in the upcoming weeks.

If your PR hasn't been accepted or reviewed, you are welcome to re-submit it for rabbitmq/amqp091-go.
RabbitMQ core team members will evaluate the PRs currently open for streadway/amqp as time allows,
and pull those that don't have any conflicts. We cannot promise that every PR would be accepted
but at least we are open to changing the API going forward.

Note that it is a high season for holidays in some parts of the world, so we may be slower
to respond in the next few weeks but otherwise, we are eager to review as many currently open PRs
as practically possible soon.

Thank you for using RabbitMQ and contributing to this client. On behalf of the RabbitMQ core team,
@ChunyiLyu and @michaelklishin.

@p-kraszewski p-kraszewski closed this by deleting the head repository Aug 15, 2023
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.

7 participants