Skip to content

https connection with container doesn't work #540

@rafakaiber

Description

@rafakaiber

I have created a node api that publish messages using a faye client and would like to use the https connection.
In local environment it is working just fine in my faye client I have the certificate and key in place, and it is coming up as https://localhost:4001 and in node api side I have the config pointing to the correct url and using the tls: {ca: certificate.pem}.

It works like a charm, but when I create each service on a container the node api is not able to connect with the faye client.

NODE API
`

export class FayeUtil {
  private static fayeClient;
  static init(appConfig: ApplicationConfig) {
  const tlsConfig = {
    retry: 5,
    timeout: 30,
    tls: {
      rejectUnauthorized: true,
      ca: Environment.getCerficate()
    }
  }
  this.fayeClient = new Faye.Client("https://localhost:4001/prism-faye", tlsConfig);

  this.fayeClient.addExtension({
    outgoing: function (message, callback) {
      AppLogger.debug("Faye Channel Outgoing Message :: " + JSON.stringify(message));
      message.ext = message.ext || {};
      message.ext.password = appConfig["faye"]["secret"];
      message.ext.user = appConfig["faye"]["user"];
      callback(message);
    },
  });

  this.fayeClient.on("transport:down", () => {
    AppLogger.error("Faye Client Down");
  });

  this.fayeClient.on("transport:up", () => {
    AppLogger.info("Faye Client Up");
  });
}

static publish(channel, message) {
  this.fayeClient.publish(channel, message);
}

static subscribe(channel, onMessage) {
  this.fayeClient.subscribe(channel, onMessage);
}

static sendHeartBeat(serverName) {
  this.fayeClient
    .publish("/heartbeat", {
      server: serverName,
      time: Date.now(),
    })
    .then(() => {
      AppLogger.info("HeartBeat published successfully");
    });
  }
}

`

FAYE-PUBSUB

`

  async function start() {
  // load config
  await ConfigService.init("/conf/config.local.json");

  // Create a https server instance 
 const sslOptions = {
   key: fs.readFileSync("/certificate.key", "utf8"),
   cert: fs.readFileSync("/certificate.crt", "utf8")
 }
const httpServerInstance = https.createServer(sslOptions, nonBayeuxHandler);

 // Create a Faye instance
const bayeux = new Faye.NodeAdapter({
   mount: "/prism-faye", // this is the prefix on which faye will be mounted
   timeout: 30
 });

 // attach faye to http server
bayeux.attach(httpServerInstance);

 // Add authentication to restrict publish only to servers
authHandler(bayeux, ConfigService.config());

 // Start Server
httpServerInstance.listen(Environment.getPort(DEFAULT_PORT), Environment.getHost(DEFAULT_HOST), () => {
   AppLogger.info(
     "FAYE HTTP Server Started Successfully: Host = " + Environment.getHost(DEFAULT_HOST) + ", Port = " + 
     Environment.getPort(DEFAULT_PORT)
   );
  });
}

/* Common Code */
start()
  .then(() => {
    AppLogger.info("Faye server started successfully.");
  })
  .catch((err) => {
    AppLogger.error("Error starting Faye server. Send notification.", err);
  });

`

I spent sometime looking for a solution but not able to identify where is the issue, as it works locally, but doesn't work when I bring the code to the container.

the only difference I see in console logs is in the node api
LOCAL -> Faye Client Up
CONTAINER of NODE API -> Faye Client Down

Just as more info: I'm using mac and podman to create the containers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions