title: Using SASL EXTERNAL in Go using qpid-proton client library to connect to AMQP 1.0 RabbitMQ
body: <p>I am trying to make a TLS connection to RabbitMQ with authentication provided by self-signed certificates through the SASL EXTERNAL mechanism using the golang implementation provided by <a href="https://github.com/apache/qpid-proton" rel="nofollow noreferrer">https://github.com/apache/qpid-proton</a>. The goal is to be able to connect to RabbitMQ without specifying the username and password in the URI.</p>
  <p>RabbitMQ is running with the following configuration:</p>
  <pre><code>      auth_mechanisms.1 = EXTERNAL
        auth_mechanisms.2 = PLAIN
        auth_mechanisms.3 = AMQPLAIN
  </code></pre>
  <p>and plugins:</p>
  <ul>
  <li>rabbitmq_amqp1_0</li>
  <li>rabbitmq_auth_mechanism_ssl</li>
  </ul>
  <p>I have confirmed that I am able to connect with SASL EXTERNAL using a Node.js library (<a href="https://github.com/amqp/rhea" rel="nofollow noreferrer">https://github.com/amqp/rhea</a>) and I have confirmed that connecting with PLAIN and ANONYMOUS works with Go in the qpid-proton library but have been unable to connect with SASL EXTERNAL with Go.</p>
  <p>My client code does not return any errors, but the RabbitMQ error logs tell me that the client closed the TCP connection</p>
  <pre><code>2021-06-24 18:57:22.029 [info] &lt;0.16358.106&gt; accepting AMQP connection &lt;0.16358.106&gt; (127.0.0.1:50610 -&gt; 127.0.0.1:5671)
  2021-06-24 18:57:23.030 [warning] &lt;0.16358.106&gt; closing AMQP connection &lt;0.16358.106&gt; (127.0.0.1:50610 -&gt; 127.0.0.1:5671):
  client unexpectedly closed TCP connection
  </code></pre>
  <p>My client code is as follows:</p>
  <pre><code>package main
  
  import (
          &quot;fmt&quot;
          &quot;github.com/apache/qpid-proton/go/pkg/amqp&quot;
          &quot;github.com/apache/qpid-proton/go/pkg/electron&quot;
          &quot;os&quot;
          &quot;crypto/tls&quot;
          &quot;io/ioutil&quot;
          &quot;crypto/x509&quot;
          &quot;time&quot;
  )
  
  func main() {
          keyPair, err := tls.LoadX509KeyPair(&quot;client.crt&quot;, &quot;client.key&quot;)
  
          if err != nil {
                  fmt.Println(&quot;Failed to load certificate:&quot;, err)
                  os.Exit(1)
          }
  
          rootCa, err := ioutil.ReadFile(&quot;rootCA.crt&quot;)
          if err != nil {
                  fmt.Println(&quot;Failed to read root CA:&quot;, err)
                  os.Exit(1)
          }
          certPool := x509.NewCertPool()
          certPool.AppendCertsFromPEM(rootCa)
  
          tlsConfig := &amp;tls.Config{
                  RootCAs: certPool,
                  InsecureSkipVerify: true,
                  Certificates: []tls.Certificate{keyPair},
          }
  
          container := electron.NewContainer(&quot;myContainer&quot;)
  
          tlsConn, err := tls.Dial(&quot;tcp&quot;, &quot;rabbitmq.default.svc.cluster.local:5671&quot;, tlsConfig)
          if err != nil {
                  fmt.Println(&quot;Failed to open TLS connection:&quot;, err)
                  os.Exit(1)
          }
          defer tlsConn.Close()
  
          conn, err := container.Connection(
                  tlsConn,
                  electron.SASLEnable(),
                  electron.SASLAllowedMechs(&quot;EXTERNAL&quot;),
          )
          defer conn.Close(err)
  
          if err != nil {
                  fmt.Println(&quot;Failed to open AMQP connection&quot;, err)
                  os.Exit(1)
          }
  
          sess, err := conn.Session()
  
          sender, err := sess.Sender(electron.Target(&quot;demo-queue&quot;))
  
          if err != nil {
                  fmt.Println(&quot;Creating sender failed:&quot;, err)
                  os.Exit(1)
          }
  
          for i := int64(0); i &lt; 100000 ; i++ {
                  msg := amqp.NewMessage()
                  body := fmt.Sprintf(&quot;Test message %d&quot;, i)
                  msg.Marshal(body)
                  sender.SendSync(msg)
                  time.Sleep(1*time.Second)
          }
  }
  </code></pre>