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

[v2] Add SSL support to RabbitMQ Scaler #1073

Closed
wants to merge 4 commits into from
Closed

Conversation

ansonauhk
Copy link

@ansonauhk ansonauhk commented Sep 3, 2020

Signed-off-by: Anson Au ansonau@gmail.com

Provide a description of what has been changed

Checklist

  • Commits are signed with Developer Certificate of Origin (DCO)
  • Tests have been added
  • A PR is opened to update the documentation on https://github.com/kedacore/keda-docs
  • Changelog has been updated

Fixes #967

Signed-off-by: Anson Au <ansonau@gmail.com>
@zroubalik zroubalik changed the title Add SSL support to RabbitMQ Scaler. This fix https://github.com/kedac… [v2] Add SSL support to RabbitMQ Scaler Sep 3, 2020
Copy link
Member

@zroubalik zroubalik left a comment

Choose a reason for hiding this comment

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

Looking good, could you please write a few tests? For the auth properties parsing. Feel free to look at the PR for an inspiration (Kafka) #1074

@zroubalik
Copy link
Member

Could you please update docs: kedacore/keda-docs#231

And add an entry to the Changelog please: https://github.com/kedacore/keda/blob/v2/CHANGELOG.md#v200

Comment on lines 125 to 138
if val, ok := authParams["ca"]; ok {
meta.ca = val
} else {
return nil, fmt.Errorf("no ca given")
}
if val, ok := authParams["cert"]; ok {
meta.cert = val
} else {
return nil, fmt.Errorf("no cert given")
}
if val, ok := authParams["key"]; ok {
meta.key = val
} else {
return nil, fmt.Errorf("no key given")
Copy link
Contributor

Choose a reason for hiding this comment

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

from the usage below, I'm assuming those are expected to have file paths, not actual certificate values, right? I think you would want to use metadata map instead of the authParams map, as the latter contains values resolved from a TriggerAuthentication CRD if present for a particular trigger.

Copy link
Contributor

Choose a reason for hiding this comment

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

also a bit of nitpicking, but perhaps rabbitmq host is using amqps://, but no key/cert/ca provided would be a bit more descriptive error message.

Copy link
Author

Choose a reason for hiding this comment

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

also a bit of nitpicking, but perhaps rabbitmq host is using amqps://, but no key/cert/ca provided would be a bit more descriptive error message.

Done

@ansonauhk
Copy link
Author

ansonauhk commented Sep 4, 2020 via email

Signed-off-by: Anson Au <ansonau@gmail.com>
Signed-off-by: Anson Au <ansonau@gmail.com>
ansonauhk added a commit to ansonauhk/keda that referenced this pull request Sep 6, 2020
Update change log for kedacore#1073
Signed-off-by: Anson Au ansonau@gmail.com
@ansonauhk ansonauhk mentioned this pull request Sep 6, 2020
4 tasks
@ansonauhk
Copy link
Author

Looking good, could you please write a few tests? For the auth properties parsing. Feel free to look at the PR for an inspiration (Kafka) #1074

Added, please review

@ansonauhk
Copy link
Author

Could you please update docs: kedacore/keda-docs#231

And add an entry to the Changelog please: https://github.com/kedacore/keda/blob/v2/CHANGELOG.md#v200

all done

@ahmelsayed
Copy link
Contributor

ahmelsayed commented Sep 9, 2020

No,not from a file. One has to upload the certificates content to the K8S secrets. I wonder how a file path works , as scaledObject is living in a keda namespace. In a enterprise environment, it's not flexible to have file contains secret stored in a shared namespace.

other scaler that use a cert take a certPath parameter in the metadata, and then KEDA users mount the cert as a file using kubernetes secret file volume.

In this PR it seems that you're reading the value from authParams. authParams is constructed here. However, authParams is a map[string]string.

so usually you'd have a secret defined in Kubernetes as

kind: Secret
apiVersion: v1
metadata:
  name: test-secret-name
data:
  key.pem: <base64 of key.pem file>

Other scalers assume that KEDA users will add something like this on the KEDA pod

    volumeMounts:
    - name: certs
      mountPath: "/etc/certs"
      readOnly: true
  volumes:
  - name: certs
    secret:
      secretName: test-secret-name

this will create a file under /etc/certs/key.pem that contains the key. Then the metadata of the scaler just contains:

metadata:
  keyPath: /etc/certs/key.pem

However, with this PR if the user is using TriggerAuthentication with RabbitMQ, then authParam will be a map[string]string

so doing this in parseRabbitMQMetadata()

if val, ok := authParams["key"]; ok {
	meta.key = val
}

then meta.key will contain an invalid string encoding of the key file content

In getConnectionAndChannel() however, it's calling

if ca, err := ioutil.ReadFile(caFile); err == nil {
	cfg.RootCAs.AppendCertsFromPEM(ca)
}

if cert, err := tls.LoadX509KeyPair(certFile, keyFile); err == nil {
	cfg.Certificates = append(cfg.Certificates, cert)
}

which assumes that meta.key and meta.ca are file paths mounted on the KEDA pod itself as mentioned above for the other scalers. You can check the Kafka scaler for an example, but I suspect you need to use tls apis that tabke a byte[] rather than a filePath and call it with []byte(meta.key), and []byte(meta.ca)

That's based on just reading the code of the PR but I could be wrong. Have you been able to test this change on your cluster?

@ansonauhk
Copy link
Author

ansonauhk commented Sep 11, 2020 via email

@ansonauhk
Copy link
Author

Hi,

Are you happy to accept this PR?

Thanks,
Anson

@zroubalik
Copy link
Member

zroubalik commented Sep 18, 2020

@ansonauhk there's a conflict that prevents a merge of this PR.
I am keeping this for @ahmelsayed for review

@@ -130,8 +155,27 @@ func parseRabbitMQMetadata(resolvedEnv, metadata, authParams map[string]string)
return &meta, nil
}

func getConnectionAndChannel(host string) (*amqp.Connection, *amqp.Channel, error) {
conn, err := amqp.Dial(host)
func getConnectionAndChannel(host string, caFile string, certFile string, keyFile string) (*amqp.Connection, *amqp.Channel, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

With the recent change, we have added tls_config.go in pkg/util. That is supposed to be one-stop destination to enable tls encryption. Can you please move this to tls_config.go

cfg.RootCAs.AppendCertsFromPEM(ca)
}

if cert, err := tls.LoadX509KeyPair(certFile, keyFile); err == nil {
Copy link
Contributor

@aman-bansal aman-bansal Oct 16, 2020

Choose a reason for hiding this comment

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

In my opinion, this should not be the required parameter. client cert and the key are only required when client authentication at the server is set to REQUIREANDVERIFY. In other cases, it could be empty.

Until and unless I am missing something completely in regards to rabbitmq tls.

if cert, err := tls.LoadX509KeyPair(certFile, keyFile); err == nil {
cfg.Certificates = append(cfg.Certificates, cert)
}
conn, err = amqp.DialTLS(host, cfg)
Copy link
Contributor

Choose a reason for hiding this comment

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

This could fail in some cases. So DialTLS has this defined:
if config.TLSClientConfig.ServerName == "" { config.TLSClientConfig.ServerName = uri.Host }

Either specify InsecureSkipVerify or take servername as parameter. @ahmelsayed this is same what I have mentioned in this #1263

@zroubalik zroubalik changed the base branch from v2 to main October 30, 2020 13:22
@clarenceb
Copy link

Hi, is this PR still being worked on? It seems to be stalled for a few months now. We have a need for it and would appreciate any update on whether this is now abandoned or still in progress.

@jeffhollan
Copy link
Member

Looks like some open feedback / issues, as well as now some conflicts around the base that would need to be resolved. Thanks a ton for your help @ansonauhk and this looks pretty close to me. Any interest on clearing out the conflicts so we can ship some of this? Let us know if you have any questions or we can help

@ansonauhk
Copy link
Author

ansonauhk commented Feb 23, 2021 via email

@glennr8686
Copy link

glennr8686 commented Feb 24, 2021

@ansonauhk, thanks for picking this up. We are in the process of developing and testing Azure AKS scaling based on RabbitMQ queue. Our setup has TLS mandatory (actuallt mTLS), so this is blocking us from proceeding.
(part) RabbitMQ config below.
This is running RabbitMQ Cluster Kubernetes Operator.
https://www.rabbitmq.com/kubernetes/operator/using-operator.html

    additionalConfig: |
      ssl_options.fail_if_no_peer_cert = true
      management.ssl.port = 15671
      management.ssl.certfile = /etc/rabbitmq-tls/tls.crt
      management.ssl.keyfile = /etc/rabbitmq-tls/tls.key
      management.ssl.cacertfile = /etc/rabbitmq-tls/ca.crt```

@glennr8686
Copy link

@ansonauhk have you had any time to progress this?

@zroubalik
Copy link
Member

@ansonauhk any update on this PR please?

@ccolonri
Copy link

ccolonri commented Jun 7, 2021

Any updates on this PR?

@zroubalik
Copy link
Member

This PR is stale, I am closing this.

If anybody wants to follow up with this feature, please open another PR.

@zroubalik zroubalik closed this Jun 8, 2021
@mcmcghee
Copy link

mcmcghee commented Oct 1, 2021

This might have just killed our keda deployment. Surprised that this is not a feature already and that this PR died.

@zroubalik
Copy link
Member

@mcmcghee a PR with this feature is more then welcome :)

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.

RabbitMQ Scalers -issues in connecting with TLS enabled
9 participants