diff --git a/docker-compose.yml b/docker-compose.yml index 849bb27f5f..463b986c72 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -94,9 +94,20 @@ services: redis: container_name: nr_node_redis - image: redis + image: bitnami/redis ports: - "6379:6379" + - "6380:6380" + environment: + - ALLOW_EMPTY_PASSWORD=yes + - REDIS_TLS_ENABLED=yes + - REDIS_TLS_PORT=6380 + - REDIS_TLS_CERT_FILE=/tls/redis.crt + - REDIS_TLS_KEY_FILE=/tls/redis.key + - REDIS_TLS_CA_FILE=/tls/ca.crt + - REDIS_TLS_AUTH_CLIENTS=no + volumes: + - "./docker/redis:/tls" healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 1s diff --git a/docker/redis/.gitignore b/docker/redis/.gitignore new file mode 100644 index 0000000000..56f124efd5 --- /dev/null +++ b/docker/redis/.gitignore @@ -0,0 +1,3 @@ +*.req +!*.key +!*.crt diff --git a/docker/redis/ca.crt b/docker/redis/ca.crt new file mode 100644 index 0000000000..d6137f2a8f --- /dev/null +++ b/docker/redis/ca.crt @@ -0,0 +1,31 @@ +-----BEGIN CERTIFICATE----- +MIIFQTCCAymgAwIBAgIUIkqwOT8o/3S7bbBCBiBlug41jY4wDQYJKoZIhvcNAQEL +BQAwMDEOMAwGA1UECgwFUmVkaXMxHjAcBgNVBAMMFUNlcnRpZmljYXRlIEF1dGhv +cml0eTAeFw0yNDA4MDgxNDI4MzNaFw0zNDA4MDYxNDI4MzNaMDAxDjAMBgNVBAoM +BVJlZGlzMR4wHAYDVQQDDBVDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwggIiMA0GCSqG +SIb3DQEBAQUAA4ICDwAwggIKAoICAQDeOcmk8R0d7R2/rFbfBgQFAsPolCSugUBT +FAnnpFCYAVvmadc+BpdUv7/tEHdvZOdOdZa9f9b1Xprq1AcZMeZsmZrKRHCkx6YW +bWtea0qWL73gEbkDnE2YbdOKZx0H1+nblpp10ywwtvCupL6off4Cdwy8wLXJiPth +K1MoOCgTL3I0elN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ktGH0W6FqChiqYCf +e9NlQhcz61exXa0Rn1vua5cHZLxZ/5n/1lHNTyfZi0Py+1cdmxn1XFRltrVWMm67 +wGsdVKU93y7Zh+/djPIShcB3Auful1aC4PeNya49cKracnoAx0kRx6SPmssCfhbu +JNqpAWbpP4tA/+r8ti/84l7pXFTL9n6OJi2vvUdndLXeK92K+T3+m+sl2u2x9NHk +C931gMu5/WEzP7fsC9WDXw3t2alG9BRvA2AUUiECVT1v/Ktb3QO1clozv9+pZupD +U0oITpQ= +-----END CERTIFICATE----- diff --git a/docker/redis/ca.key b/docker/redis/ca.key new file mode 100644 index 0000000000..23614cc550 --- /dev/null +++ b/docker/redis/ca.key @@ -0,0 +1,52 @@ +-----BEGIN PRIVATE KEY----- +MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQDeOcmk8R0d7R2/ +rFbfBgQFAsPolCSugUBTFAnnpFCYAVvmadc+BpdUv7/tEHdvZOdOdZa9f9b1Xprq +1AcZMeZsmZrKRHCkx6YWbWtea0qWL73gEbkDnE2YbdOKZx0H1+nblpp10ywwtvCu +pL6off4Cdwy8wLXJiPthK1MoOCgTL3I0elNl5AGv/ccnoz8BHQ59TY5+t25B9wO6 +7pm7LdppJXYgqx2LQ9QHJfw7KGAsfoo0ujZ6F9VnqvqU8oIJ8iqn/dF5YTzDvzB0 +M79dbdL863Rk+0J0wTzPFCZuuqwZYXMJf1tZnTNyRGCrcffF5qw1+wzvW0aGsyz6 +nQoA9CDSL8JTE3WqeFIHLtq6Naa60CpdDqxl19lYNjt4oVrfoK9bU87+z1GftVFl +7ljZIsWn9XZH+MscUobsOlhw2iVpYngC96xxDXwL/Q6gFiGhDdkdlbDq+TgTfjSa +XyW6Xqhz93dNDEXjNT9H7u8iWi13Z+w0C4KyPGioHb9Skvb85mfDiKz0c/gbPIkO +9FuXDPlLZBcBOnYFoTL3k+XLJ0I4eBXIfJXZ6PZkdWpw3fjpRxYSh43tKk3MoMGM ++R4pASMiE618fZ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JuVHZMXpjm+e61+Ep6n6PyQrWHj6h/Ke6dYpEQCinDa6UM +KQKCAQEA6KY+wqlt4lG9ghMYNUEFnk7DLtDMj4MFK9vI+KlfLYTyQNZM9uMkglIY +ufXeyOuKNWbTl/6q519uuv2dMLDOYX1TPaYZlElFyFPp6/o1/Ujh1BgQq1GS9q7+ +H3Y/xcSNOLmJF/igvhlsdnsu4i8X1MxeThbJ0H2DFPczkf0peG13ZAdAvW6ULMYb +Ze/b7siCsDQXw+SMT9DE61KFsf7jqouuxyri7+9e5BbB19ZpHibAC4FnzswlGzQ+ +aPFvku0Zer86umS6UcZawCQw1UqQMQ+2hVVFr/t7d99cN01VV2roBQBSCHsLcBCW +YpRxs9Qgfw04XTPN1t4fj6s1w6u0MQ== +-----END PRIVATE KEY----- diff --git a/docker/redis/ca.txt b/docker/redis/ca.txt new file mode 100644 index 0000000000..fba5063905 --- /dev/null +++ b/docker/redis/ca.txt @@ -0,0 +1 @@ +141E6AEEA165D992A53AEDBF732949EA4B278E51 diff --git a/docker/redis/gen-cert.sh b/docker/redis/gen-cert.sh new file mode 100755 index 0000000000..d8d680cbf3 --- /dev/null +++ b/docker/redis/gen-cert.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Based upon https://github.com/redis/redis/blob/3a08819f5169f9702cde680acb6bf0c75fa70ffb/utils/gen-test-certs.sh + +set -e + +openssl genrsa -out ca.key 4096 +openssl req \ + -x509 -new -nodes -sha256 \ + -key ca.key \ + -days 3650 \ + -subj '/O=Redis/CN=Certificate Authority'\ + -out ca.crt + +openssl genrsa -out redis.key 2048 +openssl req \ + -new -sha256 \ + -subj "/O=Redis/CN=redis" \ + -key redis.key | openssl x509 \ + -req \ + -sha256 \ + -CA ca.crt \ + -CAkey ca.key \ + -CAserial ca.txt \ + -CAcreateserial \ + -days 3650 \ + -out redis.crt diff --git a/docker/redis/redis.crt b/docker/redis/redis.crt new file mode 100644 index 0000000000..05881b647b --- /dev/null +++ b/docker/redis/redis.crt @@ -0,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JCZmpnsW+pv8pd6MCNdR4cV5b/wazR5PzGAQW2MAW7LCTy5WI6myC+EBdS +q46Var/mmDGh54sGreVMMGSvrsdcR3gFrUN+ZUbkZanjyI2EKl38M+WNlpm3UYLn +G0BlD6Ude8Ic7BbawS8Cx2Z+jvAcAr1KQs8nn1c4PpEvkdz+Lj1tzNWA3pjZu0Tf +x3XGj41iJLre9Deehe5akjWg6x8ho9sbvUasNIlh6F9JTZE+AZyis0WbhNIlh75/ +mnS1TufJ3uoJX2f1imLm2gJHeoYj8Ff16qnpvRvgxJT15Ut18CC2sn1n47bu/V6N +dgodOWEqBDxccP4K3e9TsI8WNoEThc2tXKGrzanN+4qxR7XXgW5jcdzoHGmdxTBZ +ll1Hx8gPQuEfOtU73CGCY6yvSjA8kHh2mnXJcHjZy3Kbxg5B +-----END CERTIFICATE----- diff --git a/docker/redis/redis.key b/docker/redis/redis.key new file mode 100644 index 0000000000..0c99652466 --- /dev/null +++ b/docker/redis/redis.key @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCQ9ppyY0HaCRxv +BLmQg53bpA51BRLRSLx6eI8MUA2tMBDZXO+DO+clppl9/fz8uo4EHLvAw9cLu0oU +gG3xFUS3CAXSLZKZ3C7rY288ygn9GbDHue/y4s5qM0JILVUFtDqrbiywuB+B6pMa +yaMjdc9+HNscJzMVigLolWe/oV4D+j8Y2KeMzFKfkoQUKpZw/woOvNLrERrbswgE +rID1KNn8PHnPLFZaCPSJuEZ7zj1MB4HESbsRiCJixvNtZcUJjT+bDHXnIR3EMxi7 +h8M3iI8H8e1iVzJCjKA84gQCZHm/2wANbedLBnsd5SvfX7nqlOJUEoxDKJspN/g9 +8yIpRT3BAgMBAAECggEAKsKLKU2s+Ycxe2/t2rpwIH9CgnMWK2SksA2KyIt+lUT1 +22AGCHRtiNYdNaRrcRMIXB8rpL8/2iaLQgPmKjRnWgQET4yAz2C6+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BaYl6 +cMzfUSR8HE5wnlAFOYsTCgj5ksjpk1mZ+obJGjA8c1PpA0ZGMxry1x20auGvlgd+ +AAYDp2njFzBuYeFbM/iJ18U= +-----END PRIVATE KEY----- diff --git a/lib/instrumentation/@node-redis/client.js b/lib/instrumentation/@node-redis/client.js index 7f2f76fccf..f51e5c6024 100644 --- a/lib/instrumentation/@node-redis/client.js +++ b/lib/instrumentation/@node-redis/client.js @@ -93,7 +93,7 @@ function getRedisParams(clientOpts) { // see: https://github.com/redis/node-redis/blob/5576a0db492cda2cd88e09881bc330aa956dd0f5/packages/client/lib/client/index.ts#L160 if (clientOpts?.url) { const parsedURL = new URL(clientOpts.url) - clientOpts.socket = { host: parsedURL.hostname } + clientOpts.socket = Object.assign({}, clientOpts.socket, { host: parsedURL.hostname }) if (parsedURL.port) { clientOpts.socket.port = parsedURL.port } diff --git a/test/lib/params.js b/test/lib/params.js index 22dffd2d3d..03095d0031 100644 --- a/test/lib/params.js +++ b/test/lib/params.js @@ -20,6 +20,8 @@ module.exports = { redis_host: process.env.NR_NODE_TEST_REDIS_HOST || 'localhost', redis_port: process.env.NR_NODE_TEST_REDIS_PORT || 6379, + redis_tls_host: process.env.NR_NODE_TEST_REDIS_TLS_HOST || '127.0.0.1', + redis_tls_port: process.env.NR_NODE_TEST_REDIS_TLS_PORT || 6380, cassandra_host: process.env.NR_NODE_TEST_CASSANDRA_HOST || 'localhost', cassandra_port: process.env.NR_NODE_TEST_CASSANDRA_PORT || 9042, diff --git a/test/versioned/redis/package.json b/test/versioned/redis/package.json index 589c9943fc..c82030c434 100644 --- a/test/versioned/redis/package.json +++ b/test/versioned/redis/package.json @@ -24,7 +24,8 @@ }, "files": [ "redis-v4.tap.js", - "redis-v4-legacy-mode.tap.js" + "redis-v4-legacy-mode.tap.js", + "tls.tap.js" ] } ] diff --git a/test/versioned/redis/tls.tap.js b/test/versioned/redis/tls.tap.js new file mode 100644 index 0000000000..95477d212f --- /dev/null +++ b/test/versioned/redis/tls.tap.js @@ -0,0 +1,91 @@ +/* + * Copyright 2024 New Relic Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +'use strict' + +const tap = require('tap') +const helper = require('../../lib/agent_helper') +const promiseResolvers = require('../../lib/promise-resolvers') +const { redis_tls_host: HOST, redis_tls_port: PORT } = require('../../lib/params') +const { removeModules } = require('../../lib/cache-buster') + +tap.test('redis over tls connection', (t) => { + t.afterEach(() => { + removeModules(['redis']) + }) + + t.test('should work with self-signed tls cert on server', async (t) => { + const { promise, resolve } = promiseResolvers() + const agent = helper.instrumentMockedAgent() + const redis = require('redis') + const client = await redis + .createClient({ + url: `rediss://${HOST}:${PORT}`, + socket: { + tls: true, + rejectUnauthorized: false + } + }) + .on('error', (error) => { + throw error + }) + .connect() + await client.flushAll() + + t.teardown(async () => { + await client.flushAll() + await client.disconnect() + helper.unloadAgent(agent) + }) + + helper.runInTransaction(agent, async function transactionInScope() { + const tx = agent.getTransaction() + await client.set('tls-test', 'foo') + const found = await client.get('tls-test') + t.equal(found, 'foo') + tx.end() + resolve() + }) + + await promise + }) + + t.test('url parsing should add tls true', async (t) => { + const { promise, resolve } = promiseResolvers() + const agent = helper.instrumentMockedAgent() + const redis = require('redis') + const client = await redis + .createClient({ + url: `rediss://${HOST}:${PORT}`, + socket: { + rejectUnauthorized: false + } + }) + .on('error', (error) => { + throw error + }) + .connect() + await client.flushAll() + + t.teardown(async () => { + await client.flushAll() + await client.disconnect() + helper.unloadAgent(agent) + }) + + helper.runInTransaction(agent, async function transactionInScope() { + const tx = agent.getTransaction() + await client.set('tls-test', 'foo') + const found = await client.get('tls-test') + t.equal(found, 'foo') + tx.end() + resolve() + }) + + await promise + }) + + t.end() +})