Skip to content

NODE_TLS_REJECT_UNAUTHORIZED environment variable not respected in applyToFetchOptions #2601

Closed

Description

@0x5457

Describe the bug
I'm using @kubernetes/client-node to send HTTP requests to an apiserver with a self-signed certificate. I can't provide the CA, so I'm trying to use NODE_TLS_REJECT_UNAUTHORIZED=0 to skip the tls verification. However, this doesn't work.

Client Version
1.3.0

Server Version
N/A

To Reproduce
Steps to reproduce the behavior:

import * as k8s from '@kubernetes/client-node';
import fetch from 'node-fetch';

const url = "https://localhost:443";  // server with self-signed certificate
const kc = new k8s.KubeConfig();

const res = await fetch(url, await kc.applyToFetchOptions({}));
console.log(res.status);
NODE_TLS_REJECT_UNAUTHORIZED=0 node test.js
(node:211892) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
(Use `node --trace-warnings ...` to show where the warning was created)

/home/tw/code/javascript/node_modules/node-fetch/lib/index.js:1501
                        reject(new FetchError(`request to ${request.url} failed, reason: ${err.message}`, 'system', err));
                               ^
FetchError: request to https://localhost:8443/ failed, reason: self-signed certificate; if the root CA is installed locally, try running Node.js with --use-system-ca
    at ClientRequest.<anonymous> (/home/0x5457/code/test/node_modules/node-fetch/lib/index.js:1501:11)
    at ClientRequest.emit (node:events:507:28)
    at emitErrorEvent (node:_http_client:104:11)
    at TLSSocket.socketErrorListener (node:_http_client:518:5)
    at TLSSocket.emit (node:events:507:28)
    at emitErrorNT (node:internal/streams/destroy:170:8)
    at emitErrorCloseNT (node:internal/streams/destroy:129:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {
  type: 'system',
  errno: 'DEPTH_ZERO_SELF_SIGNED_CERT',
  code: 'DEPTH_ZERO_SELF_SIGNED_CERT'
}

Expected behavior
Print status code 200

Environment (please complete the following information):

  • OS: Ubuntu 24.04
  • Node.js version v24.4.1

Activity

  1. abdulfarid-dev commented on Sep 5, 2025

    @abdulfarid-dev

    Hi, I was able to reproduce this issue on my local setup (Node.js v24.4.1, Ubuntu 24.04).
    I’d like to work on fixing this . Could you please assign it to me?

    Thanks!

  2. abdulfarid-dev commented on Sep 6, 2025

    @abdulfarid-dev

    “Hi 👋 I commented a f
    One day ago and I’m still interested in contributing to this issue. Could you please let me know if it’s okay for me to work on it? Thanks!”

  3. 0x5457 commented on Sep 7, 2025

    @0x5457
    ContributorAuthor

    Hi @abdulfarid-dev ,

    I'm already working on fixing this issue in PR #2602. I'll continue handling it until the fix is complete.

    Thanks for your willingness to help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions