Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Cache] Fix Redis TLS scheme rediss for Redis connection #39599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2021
Merged

[Cache] Fix Redis TLS scheme rediss for Redis connection #39599

merged 1 commit into from
Feb 22, 2021

Conversation

misaert
Copy link
Contributor

@misaert misaert commented Dec 21, 2020

Q A
Branch? 5.x
Bug fix? yes
New feature? no
Deprecations? no
Tickets
License MIT
Doc PR symfony/symfony-docs#14728

Like #35503 on Symfony Messenger, this will enable TLS support for Redis adapter.

The implementation just prefix the host with tls:// as described here: https://github.com/phpredis/phpredis#connect-open

I don't know how to test it because I guess I need a TLS Redis in src/Symfony/Component/Cache/Tests/Adapter/RedisAdapterTest.php.

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 5.x branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@njutn95
Copy link
Contributor

njutn95 commented Dec 22, 2020

Tested the code, and it's working.

Copy link
Member

@jderusse jderusse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be great to use the github action test suite and one of the running container to provide functional tests.

@jderusse
Copy link
Member

If we add a new parameter tls in query string, what is the purpose of rediss://? /cc @nicolas-grekas

@njutn95
Copy link
Contributor

njutn95 commented Dec 22, 2020

There really is no difference between redis and rediss at the moment, they're acting in exactly the same way. So you're right, using rediss:// would be a better option.

@jderusse
Copy link
Member

From the predis Readme:

Same set of parameters, but using an URI string:
$client = new Predis\Client('tls://127.0.0.1?ssl[cafile]=private.pem&ssl[verify_peer]=1');
The connection schemes redis (alias of tcp) and rediss (alias of tls) are also supported, with the difference that URI strings containing these schemes are parsed following the rules described on their respective IANA provisional registration documents.

IMHO the fix should be about keeping the scheme defined here:

if (0 === strpos($dsn, 'redis:')) {
$scheme = 'redis';
} elseif (0 === strpos($dsn, 'rediss:')) {
$scheme = 'rediss';
} else {

And use that scheme in the relevant places:

@njutn95
Copy link
Contributor

njutn95 commented Dec 22, 2020

For phpredis to work, it requires the use of tls://127.0.0.1. However, for predis, you can use tls:// or rediss:// (which is an alias for tls:// as it's said in the Predis README you mentioned). So we can't actually use the scheme for connecting with phpredis, but it can be used for predis though.

@misaert
Copy link
Contributor Author

misaert commented Dec 22, 2020

For phpredis to work, it requires the use of tls://127.0.0.1. However, for predis, you can use tls:// or rediss:// (which is an alias for tls:// as it's said in the Predis README you mentioned). So we can't actually use the scheme for connecting with phpredis, but it can be used for predis though.

And it doesn't work with the same DSN on Symfony Messenger because of https://github.com/symfony/messenger/blob/5.x/Transport/TransportFactory.php#L46:

  [Symfony\Component\Messenger\Exception\InvalidArgumentException]                                                                                                   
  No transport supports the given Messenger DSN "rediss://<...>"

@jderusse
Copy link
Member

I don't have strong opinion about rediss:// vs ?tls= but IMHO this should be consistent across all components:
I suggest to:

  • deprecates either ?tls in messenger or rediss:// in cache, lock, session
  • in all cases fix RedisTrait

Given The RedisTrait didn't work, maybe it's easier to deprecate the rediss:// scheme? @symfony/mergers

@njutn95
Copy link
Contributor

njutn95 commented Dec 22, 2020

I've created a PR to add rediss:// support to the Messenger (which is really going to be an alias to tls=1), without deprecating the tls option (yet). Either way, it should definitely be standardized one way or another (or to support both).

@derrabus
Copy link
Member

derrabus commented Dec 22, 2020

For reference, a codebase I took over recently uses this bundle to configure their redis connections: https://github.com/snc/SncRedisBundle

The developers told me that they in favor of that bundle mainly because it allowed them to configure TLS connections, which is a requirement when using the managed Redis services of our current hoster Digital Ocean. Our DSNs are all configured with the rediss scheme, but if I understood the bundle corectly, it mainly passes the DSN down to Predis. I got that wrong, thanks @njutn95 for the correction.

@njutn95
Copy link
Contributor

njutn95 commented Dec 22, 2020

SncRedisBundle is indeed reading the TLS configuration from the rediss:// scheme

@nicolas-grekas nicolas-grekas added this to the 5.x milestone Dec 23, 2020
@misaert
Copy link
Contributor Author

misaert commented Dec 24, 2020

I've created a PR to add rediss:// support to the Messenger (which is really going to be an alias to tls=1), without deprecating the tls option (yet). Either way, it should definitely be standardized one way or another (or to support both).

For now, I changed the code to support both. rediss DSN sheme changes Redis scheme by tls (for Predis particularly) and adds the prefix tls:// in host for Redis extension.

Copy link
Member

@jderusse jderusse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either tls option should not be added here, rediss scheme should be deprecated.

We should not support both.

@misaert
Copy link
Contributor Author

misaert commented Dec 25, 2020

Either tls option should not be added here, rediss scheme should be deprecated.

We should not support both.

To be consistent with #39607, I keep the rediss scheme for TLS and removed the option.

@misaert misaert changed the title [Cache] Add TLS option for Redis connection [Cache] Fix Redis TLS scheme rediss for Redis connection Dec 25, 2020
@stof
Copy link
Member

stof commented Feb 17, 2021

@nicolas-grekas I would vote for merging that in 4.4 as a bugfix, as symfony/cache claims to support rediss in 4.4 already. Supporting rediss without actually enabling TLS qualifies as a bug to me.

@nicolas-grekas nicolas-grekas changed the base branch from 5.x to 4.4 February 22, 2021 18:01
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I rebased on 4.4, cleaned up implementation a bit and fixed tests)

@nicolas-grekas nicolas-grekas merged commit 1688e5d into symfony:4.4 Feb 22, 2021
nicolas-grekas added a commit that referenced this pull request Feb 26, 2021
… to Redis transport (njutn95)

This PR was squashed before being merged into the 5.3-dev branch.

Discussion
----------

[Messenger] Add `rediss://` DSN scheme support for TLS to Redis transport

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | no
| Deprecations? | yes
| Tickets       |
| License       | MIT
| Doc PR        |

This adds a support for `rediss://` DSN (as discussed in #39599) and deprecates the use of `tls` parameter introduced in #35503 so it can be standardized to single format.

Commits
-------

28e7b74 [Messenger] Add `rediss://` DSN scheme support for TLS to Redis transport
This was referenced Mar 4, 2021
wouterj added a commit to symfony/symfony-docs that referenced this pull request Apr 7, 2021
This PR was merged into the 4.4 branch.

Discussion
----------

[Cache] Add TLS scheme for Redis connection

See symfony/symfony#39599.

Commits
-------

2d2f3b7 [Cache] Add TLS scheme for Redis connection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants