NestJS cacheModule can't connect to Redis store with password - redis

I'm trying to connect to my redis store in NestJS using CacheModule, I updated my store to put a password but now it's impossible to connect from NestJS (work perfectly with redis-cli and it works on nestJS before putting the password).
I have tried this:
import * as redisStore from 'cache-manager-redis-store'; // v2.0
#Module({
imports: [
CacheModule.register({
store: redisStore,
url: 'redis://:azerty#localhost:6379/0', // 'redis://h:azerty#localhost:6379/0' and 'redis://default:azerty#localhost:6379/0'
}),
],
controllers: [],
providers: [],
})
The connection string is working with redis-cli but not in NestJS, it throws ReplyError: WRONGPASS invalid username-password pair or user is disabled. or ReplyError: Ready check failed: NOAUTH Authentication required. (depends on the connection string)
I also tried the "normal" way:
CacheModule.register({
store: redisStore,
host: 'localhost',
port: 6379,
auth_pass: 'azerty', // also tried password: 'azerty'
}),
I got the same errors as the connection string one ReplyError: Ready check failed: NOAUTH Authentication required..
How can I make it works ?

REMINDER: always check if there is multiple instance of CacheModule in your project, just lost 1 day of work because of that.

Related

Failed to save Express session with ioredis in AWS Lambda and Elasticache global redis cluster

I've encountered an error when developing an AWS Elasticache global Redis cluster (with cluster mode enabled) to store user sessions for an AWS Lambda Node 16 Express app as the backend for a website. The main region is us-west-2 and a replica exists in us-east-1. There is no Redis AUTH or TLS encryption currently.
I need to be able to use a cluster mode enabled global Redis cache to ensure users can be connected to the site if one AWS region or AZ fails. I've so far been unable to find a solution to this.
Does anyone know a solution??
The lambda function returns an error when attempting to sign in:
ERROR Error: Connection is closed. at EventEmitter.sendCommand
(/opt/nodejs/node_modules/ioredis/built/cluster/index.js:343:28) at EventEmitter.get
(/opt/nodejs/node_modules/ioredis/built/utils/Commander.js:90:25) at RedisStore.get
(/opt/nodejs/node_modules/connect-redis/lib/connect-redis.js:33:19) at session
(/opt/nodejs/node_modules/express-session/index.js:485:11) at Layer.handle [as handle_request]
(/opt/nodejs/node_modules/express/lib/router/layer.js:95:5) at trim_prefix
(/opt/nodejs/node_modules/express/lib/router/index.js:317:13) at
/opt/nodejs/node_modules/express/lib/router/index.js:284:7 at Function.process_params
(/opt/nodejs/node_modules/express/lib/router/index.js:335:12) at next
(/opt/nodejs/node_modules/express/lib/router/index.js:275:10) at cookieParser
(/opt/nodejs/node_modules/cookie-parser/index.js:71:5)
ioredis enables me to use the primary endpoint for the main cluster in us-west-2 with the following code. (The endpoint and secret are utilized correctly in code, below are placeholders)
import session from 'express-session';
import connectRedis from 'connect-redis';
import Redis from 'ioredis';
// ...
const redisClient = new Redis.Cluster([
{
host: 'redisPrimaryEndpoint',
port: 6379,
},
]);
// ...
const RedisStore = connectRedis(session);
app.use(
session({
store: new RedisStore({ client: redisClient }),
secret: 'a secret',
resave: false,
saveUninitialized: true,
})
);

NesJS RabbitMQ with #golevelup/nestjs-rabbitmq no connection when using new connectioninit

Using #golevelup/nestjs-rabbitmq I tried the connection manager to not wait for a connection. According to the readme it can handle reconnections and wait for a connection without crashing the app. However, when I use the connectionInitOptions as stated and set wait to false, I get a connection error. When I don't use it (default behavior setting wait to true) , it connects to the RabbitMQ server. Below are examples importing the RabbitMQModule in a NestJS module.
This works and connects to the RabbitMQ server
RabbitMQModule.forRoot(RabbitMQModule, {
exchanges: [{ type: 'topic', name: 'main' }],
uri: 'amqp://guest:guest#localhost:5672',
}
This doesn't work and won't connect
RabbitMQModule.forRoot(RabbitMQModule, {
exchanges: [{ type: 'topic', name: 'main' }],
uri: 'amqp://guest:guest#localhost:5672',
connectionInitOptions: {
wait: false,
},
With the second option I get the following error:
Error: AMQP connection is not available
at AmqpConnection.publish (/home/xxx/node_modules/#golevelup/nestjs-rabbitmq/src/amqp/connection.ts:424:13)
at BootstrapService.onApplicationBootstrap (/home/xxx/src/bootstrap/bootstrap.service.ts:20:25)
at MapIterator.iteratee (/home/xxx/node_modules/#nestjs/core/hooks/on-app-bootstrap.hook.js:22:43)
at MapIterator.next (/home/xxx/node_modules/iterare/src/map.ts:9:39)
at IteratorWithOperators.next (/home/xxx/node_modules/iterare/src/iterate.ts:19:28)
at Function.from (<anonymous>)
at IteratorWithOperators.toArray (/home/xxx/node_modules/iterare/src/iterate.ts:227:22)
at callOperator (/home/xxx/node_modules/#nestjs/core/hooks/on-app-bootstrap.hook.js:23:10)
at callModuleBootstrapHook (/home/xxx/node_modules/#nestjs/core/hooks/on-app-bootstrap.hook.js:43:23)
at NestApplication.callBootstrapHook (/home/xxx/node_modules/#nestjs/core/nest-application-context.js:199:55)
at NestApplication.init (/home/xxx/node_modules/#nestjs/core/nest-application.js:98:9)
at NestApplication.listen (/home/xxx/node_modules/#nestjs/core/nest-application.js:155:33)
at bootstrap (/home/xxx/src/main.ts:12:3)
The last line (main.ts:12:3) is the app.listen(3000) statement.
There are other options you can set with the connectionInitOptions (reject and timeout) and I've tried the combinations but still no connection.
RabbitMQ is running in a docker container on Linux but that should be no problem. I posted the same question on NestJS discord but got no reply, so hopefully someone on SO has an idea.
Any idea what could be the cause?
Found the problem, I was using the connection in a onApplicationBootstrap method and then the connection is apparently not present yet.
you can wait for connection asynchronously 'onApplicationBootstrap':
or on :
async onModuleInit() {
await this.amqpConnection.managedChannel.waitForConnect(async () => {
await this.assertQueueAndBindToExchange(
transferRequestQueueName,
transferRequestExchangeName,
createdRoutingKey
);

Infinispan java.lang.SecurityException: ISPN006017: Unauthorized 'PUT' operation

I am trying to put a value in Infinispan cache using Hotrod nodeJS client. The code runs fine if the server is installed locally. However, when I run the same code with Infinispan server hosted on docker container I get the following error
java.lang.SecurityException: ISPN006017: Unauthorized 'PUT' operation
try {
client = await infinispan.client({
port: 11222,
host: '127.0.0.1'
}, {
cacheName: 'testcache'
});
console.log(`Connected to cache`);
await client.put('test', 'hello 1');
await client.disconnect();
} catch (e) {
console.log(e);
await client.disconnect();
}
I have tried setting CORS Allow all option on the server as well
Need to provide custom config.yaml to docker with following configurations
endpoints:
hotrod:
auth: false
enabled: false
qop: auth
serverName: infinispan
Unfortunately the nodejs client doesn't support authentication yet. The issue to implement this is https://issues.redhat.com/projects/HRJS/issues/HRJS-36

Unrecognized WebSocket connection option(s) `agent`, `perMessageDeflate`, `pfx`, `key`, `passphrase`... Did you mean to put these under `headers`?

Have you ever met this message in a React Native application using a WebSocket ( SocketIOClient from 'socket.io-client') ?...
Unrecognized WebSocket connection option(s) `agent`, `perMessageDeflate`, `pfx`, `key`, `passphrase`, `cert`, `ca`, `ciphers`, `rejectUnauthorized`. Did you mean to put these under `headers`?
Yes, this is happening in the WebSocket class constructor in Socket.io. I think it happens when you specify your transport layer as 'websocket' in the constructor (which is necessary for React Native socket io use). It doesn't do anything bad, but is annoying.
You can get rid of it with the react-native YellowBox.ignoreWarnings:
When initiating your app:
console.ignoredYellowBox = ['Remote debugger'];
import { YellowBox } from 'react-native';
YellowBox.ignoreWarnings([
'Unrecognized WebSocket connection option(s) `agent`, `perMessageDeflate`, `pfx`, `key`, `passphrase`, `cert`, `ca`, `ciphers`, `rejectUnauthorized`. Did you mean to put these under `headers`?'
]);
The one way to remove the error:
let socket = io.connect(SOCKET_URL, {
timeout: 10000,
jsonp: false,
transports: [‘websocket’],
autoConnect: false,
agent: ‘-’,
path: ‘/’, // Whatever your path is
pfx: ‘-’,
key: token, // Using token-based auth.
passphrase: cookie, // Using cookie auth.
cert: ‘-’,
ca: ‘-’,
ciphers: ‘-’,
rejectUnauthorized: ‘-’,
perMessageDeflate: ‘-’
});

WebRTC Ice Servers Issue

Uncaught DOMException: Failed to construct 'RTCPeerConnection': Both username and credential are required when the URL scheme is "turn" or "turns".
i have getting this error her is my using ice servers:
var servers =
{'iceServers': [
{url:'turn:numb.viagenie.ca'},
{url:'stun:stun01.sipphone.com'},
{url:'stun:stun.ekiga.net'},
{url:'stun:stun.fwdnet.net'},
{url:'stun:stun.ideasip.com'},
{url:'stun:stun.iptel.org'},
{url:'stun:stun.rixtelecom.se'},
{url:'stun:stun.schlund.de'},
{url:'stun:stun.l.google.com:19302'},
{url:'stun:stun1.l.google.com:19302'},
{url:'stun:stun2.l.google.com:19302'},
{url:'stun:stun3.l.google.com:19302'},
{url:'stun:stun4.l.google.com:19302'},
{url:'stun:stunserver.org'},
{url:'stun:stun.softjoys.com'},
{url:'stun:stun.voiparound.com'},
{url:'stun:stun.voipbuster.com'},
{url:'stun:stun.voipstunt.com'},
{url:'stun:stun.voxgratia.org'},
{url:'stun:stun.xten.com'},
{
url: 'turn:numb.viagenie.ca',
credential: 'muazkh',
username: 'webrtc#live.com'
},
{
url: 'turn:192.158.29.39:3478?transport=udp',
credential: 'JZEOEt2V3Qb0y27GRntt2u2PAYA=',
username: '28224511:1379330808'
},
{
url: 'turn:192.158.29.39:3478?transport=tcp',
credential: 'JZEOEt2V3Qb0y27GRntt2u2PAYA=',
username: '28224511:1379330808'
}
]
};
where is my falt?What can i do?
What the error message says. The first server in your list specifies no username or credentials:
{url:'turn:numb.viagenie.ca'},
You also repeat the same server further down, this time with credentials.
These also look like non-working turn servers cut'n'pasted off the internet. Free turn servers is a lie.
Also waaaaay too many servers. One or two stun and/or turn will do. Too many slows down ICE.