RMko
RMko•7mo ago

PermissionDenied while using ioredis npm package

Hello, I'm facing an issue with an npm library ioredis (https://github.com/redis/ioredis). For some reason, when I tried to initialize a new Redis client using this package, I received an error: error: Uncaught PermissionDenied: Requires env access, run again with the --allow-env flag. No exact env variable is specified in the log. Yes, it works when I allow env globally, but for my system, I would like to avoid allowing all env variables. So, the question is, how can I check which env variables are accessed by this package, if any? How can I debug this issue and what should i put as allow env ?
6 Replies
marvinh.
marvinh.•7mo ago
These are all the environment variables the ioredis package reads from (including intests and other files not published to npm) https://github.com/search?q=repo%3Aredis%2Fioredis%20process.env&type=code
RMko
RMko•7mo ago
@marvinh. Thank you for your suggestion. After trying list all env variables into --allow-env, it didn't resolve the issue. Adding stacktrace maybe can help: at Object.toObject (ext:runtime/30_os.js:97:16) at Object.ownKeys (ext:deno_node/_process/process.ts:59:41) at Function.keys (<anonymous>) at Object.<anonymous> (file:///deno-dir/npm/registry.npmjs.org/debug/4.3.4/src/node.js:124:30) at Object.<anonymous> (file:///deno-dir/npm/registry.npmjs.org/debug/4.3.4/src/node.js:265:4) at Module._compile (node:module:733:34) at Object.Module._extensions..js (node:module:747:10) at Module.load (node:module:658:32) at Function.Module._load (node:module:539:12) at Module.require (node:module:677:19) Error 1
marvinh.
marvinh.•7mo ago
Can you share the full command including the --allow-env bit?
RMko
RMko•7mo ago
Sure, here is the command:
deno run \
--allow-env=REDIS_PORT,NODES,PORT,KEYS,NODES,redisPort,redisEndpoint,redisUsername,redisPW,ITERATIONS,BATCH_SIZE,DEBUG,DENOAPP_PORT \
--allow-net \
denoapp/app.ts
deno run \
--allow-env=REDIS_PORT,NODES,PORT,KEYS,NODES,redisPort,redisEndpoint,redisUsername,redisPW,ITERATIONS,BATCH_SIZE,DEBUG,DENOAPP_PORT \
--allow-net \
denoapp/app.ts
marvinh.
marvinh.•7mo ago
The command looks correct, even if that list of environment variables seems a bit excessive if I may say so 😄 Is there an error message thrown or is Error 1 all there is? Do you have a code snippet that reproduces the error? I'm not entirely sure why it's failing yet. I would've assumed there to be an error message as well
RMko
RMko•7mo ago
When it comes to the code: I have simple Singleton redis client:
import { Redis } from "npm:ioredis@5.3.2";

export class RedisClient {
private static instance: RedisClient;
private readonly client: Redis;

private constructor() {
// this client initialization is causing the issue
this.client = new Redis({
port: 6379,
host: "172.17.0.1",
db: 0,
});
}

public static getInstance(): RedisClient {
if (!RedisClient.instance) {
RedisClient.instance = new RedisClient();
}
return RedisClient.instance;
}
}
import { Redis } from "npm:ioredis@5.3.2";

export class RedisClient {
private static instance: RedisClient;
private readonly client: Redis;

private constructor() {
// this client initialization is causing the issue
this.client = new Redis({
port: 6379,
host: "172.17.0.1",
db: 0,
});
}

public static getInstance(): RedisClient {
if (!RedisClient.instance) {
RedisClient.instance = new RedisClient();
}
return RedisClient.instance;
}
}
Regarding the error, there is only the i'm executiing line in the Makefile I'm using for my project: make: *** [Makefile:42: dev-denoapp] Error 1