-
Notifications
You must be signed in to change notification settings - Fork 95
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
THREESCALE-11020 Redis TLS certs and keys for porta and backend #1035
base: master
Are you sure you want to change the base?
Conversation
5414a05
to
2eea781
Compare
1347947
to
d661921
Compare
pkg/3scale/amp/component/system.go
Outdated
|
||
SystemSecretSystemRedisSslCa = "SSL_CA" | ||
SystemSecretSystemRedisSslCert = "SSL_CERT" | ||
SystemSecretSystemRedisSslKey = "SSL_KEY" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@valerymo think we need to agree on a naming scheme here as it may be possible that a customer has different certs for Redis and the System-db. Propose that we prefix with CACHE_
as may not be using redis going forward
SystemSecretSystemRedisSslKey = "SSL_KEY" | |
SystemSecretSystemRedisSslCa = "CACHE_SSL_CA" | |
SystemSecretSystemRedisSslCert = "CACHE_SSL_CERT" | |
SystemSecretSystemRedisSslKey = "CACHE_SSL_KEY" |
and I use the prefix SYSTEMDB_
SystemSecretSystemRedisSslKey = "SSL_KEY" | |
SystemSecretSslCa = "SYSTEMDB_SSL_CA" | |
SystemSecretSslCert = "SYSTEMDB_SSL_CERT" | |
SystemSecretSslKey = "SYSTEMDB_SSL_KEY" |
What do you think ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@austincunningham thanks for comment.
It's Done,
- "REDIS_" prefix was added to "SSL" names that appear in backend-redis and system-redis secrtes
- done in separate commit
- Tested locally
- Validation notes updated
Thanks
921879a
to
0ea718f
Compare
@@ -1535,3 +1537,26 @@ type APIManagerList struct { | |||
func init() { | |||
SchemeBuilder.Register(&APIManager{}, &APIManagerList{}) | |||
} | |||
|
|||
func (apimanager *APIManager) IsSystemRedisTLSEnabled() bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the RedisTLSEnabled is a global flag, why do we make a differentiation between system and backend redis here?
Can you have system redis TLS enabled but not worker TLS enabled? Doesn't system app connect to system redis and backend redis - which would to me mean, you can't have TLS on system and not on worker? Not sure about the other way around
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for comment @MStokluska . We can't have TLS on System if no TLS on Backend. But it can be vice-a-versa - TLS on Backend but not on System. This is what I see from Jira - System is depended to Backend (system has env vars from backend-redis secret), but Backend is not related to system-redis secret. Hope it's ok. But please tell me if I need check it from Joan. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So based on what you are saying:
Backend TLS - ON and System TLS - OFF is supported.
Backend TLS - OFF and System TLS - ON is not supported.
Based on the Jira description, it looks to me like they actually can be enabled independent of each other since backend is not reliant on system (meaning from backend pov, system SSL can be on or off). System is reliant on backend redis, but there seems to be individual flags for system/backend in system envs:
BACKEND_REDIS_SSL - REDIS_SSL.
Do you agree? Is this how it is currently working?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is how it's currently working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok thanks, do we have any indication (apim error or so) to let users know that tls on backend must be enabled if system tls is enabled?
pkg/3scale/amp/component/backend.go
Outdated
@@ -398,6 +437,9 @@ func (backend *Backend) buildBackendWorkerEnv() []v1.EnvVar { | |||
) | |||
} | |||
|
|||
if backend.Options.RedisTLSEnabled { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we already have these in buildBackendCommonEnv - common in my understanding applies to both, worker and listener - is this really required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Thank you
pkg/3scale/amp/component/backend.go
Outdated
@@ -422,6 +464,9 @@ func (backend *Backend) buildBackendListenerEnv() []v1.EnvVar { | |||
v1.EnvVar{Name: "CONFIG_LISTENER_PROMETHEUS_METRICS_ENABLED", Value: "true"}, | |||
) | |||
} | |||
if backend.Options.RedisTLSEnabled { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we already have these in buildBackendCommonEnv - common in my understanding applies to both, worker and listener - is this really required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Thank you
pkg/3scale/amp/component/backend.go
Outdated
func (backend *Backend) backendVolumes() []v1.Volume { | ||
res := []v1.Volume{} | ||
|
||
if backend.Options.RedisTLSEnabled { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just side note - so are we saying here that Redis TLS can be enabled on worker or listener IF system fails to have TLS enabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
System TLS certs are coming from both system-redis and backend-redis secrets. System TLS envs BACKEND_REDIS_CA_FILE, BACKEND_REDIS_PRIVATE_KEY - they are populated from Backend-redis secret. So System is depends on Backend TLS definitions.
But Backend TLS is not related to system - all certs are coming from backend-redis.
Hope I understand the quesion. Thank you Michal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I wrote before, as I understand - it can be TLS on backend, but not on system. Backend TLS is not dependent to system, but system TLS is dependent to backend. System is populating BACKEND_REDIS_CLIENT_CERT and BACKEND_REDIS_PRIVATE_KEY from backend-redis secret.
@@ -69,12 +70,14 @@ func (r *RedisOptionsProvider) GetRedisOptions() (*component.RedisOptions, error | |||
r.setPersistentVolumeClaimOptions() | |||
r.setPriorityClassNames() | |||
r.setTopologySpreadConstraints() | |||
//r.setTLSEnabled() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cleaned. Thank you
doc/apimanager-reference.md
Outdated
| REDIS_SSL_KEY | The private key for the Redis client certificate | Required to set TLS Redis connection. Only for TLS | | ||
| REDIS_SSL_QUEUES_CA | Redis Queues Certificate Authority (CA) certificate | Required to set TLS Redis connection. Only for TLS | | ||
| REDIS_SSL_QUEUES_CERT | Redis Queues client certificate | Required to set TLS Redis connection. Only for TLS | | ||
| REDIS_SSL_QUEUES_KEY | The private key for the Redis Queues client certificate | Required to set TLS Redis connection. Only for TLS | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you missing SSL_MODE ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @austincunningham ,
I'm not using SSL_MODE
but using REDIS_SSL and BACKEND_REDIS_SSL (for system), CONFIG_REDIS_SSL and CONFIG_QUEUES_SSL (for backend),
as it defined in Task.
These env vars are set in Pods, but not in secret.
They set to true if Any of related env vars defined in secret. This is how it's defined in Task/Requirements,
I rechecked it with Joan - thread https://app.slack.com/client/E030G10V24F/search).
These are also links to porta/backend:
System/porta:
- BACKEND_REDIS_SSL: https://github.com/3scale/porta/blob/master/config/examples/backend_redis.yml#L14
- REDIS_SS: https://github.com/3scale/porta/blob/master/config/examples/redis.yml#L13
Backend/apisonator:
- CONFIG_REDIS_SSL: https://github.com/3scale/apisonator/blob/master/openshift/3scale_backend.conf#L44
- CONFIG_QUEUES_SSL: https://github.com/3scale/apisonator/blob/master/openshift/3scale_backend.conf#L27
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure that is the same as ssl mode.
Although not sure if the same tls values are available for REDIS as are available for MySQL and Postgres
🤔
DATABASE_SSL_MODE. Values: Mysql ref., Postgres ref.
Don't see similar documented in redis docs so guess its ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@austincunningham , I'm not using SSL_MODE
but using REDIS_SSL and BACKEND_REDIS_SSL (for system), CONFIG_REDIS_SSL and CONFIG_QUEUES_SSL (for backend),
as it defined in Task.
These env vars are set in pods, but not in secret. And these env vars are used in Porta and apisonator (links below)
These env vars are set to true if Any of related env vars defined in secret.
I rechecked it with Joan - thread https://app.slack.com/client/E030G10V24F/search).
These are also links to porta/backend:
System/porta:
- BACKEND_REDIS_SSL: https://github.com/3scale/porta/blob/master/config/examples/backend_redis.yml#L14
- REDIS_SS: https://github.com/3scale/porta/blob/master/config/examples/redis.yml#L13
Backend/apisonator:
- CONFIG_REDIS_SSL: https://github.com/3scale/apisonator/blob/master/openshift/3scale_backend.conf#L44
- CONFIG_QUEUES_SSL: https://github.com/3scale/apisonator/blob/master/openshift/3scale_backend.conf#L27
Thank you
doc/apimanager-reference.md
Outdated
| AppLabel | `appLabel` | string | No | `3scale-api-management` | The value of the `app` label that will be applied to the API management solution | ||
| TenantName | `tenantName` | string | No | `3scale` | Tenant name under the root that Admin UI will be available with -admin suffix. | ||
| **Field** | **json/yaml field**| **Type** | **Required** | **Default value** | **Description** | | ||
| --- | --- | --- | --- | --- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
goland does this sort of auto edit, I usually edit md files in another ide to stop this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@austincunningham , Thanks a lot! I updated sections related to Redis TLS . I used now VSCodium.
Looks like there are more places where extra spaces added, but didn't touch them. Table of contents updated, as VSCodium required this, I checked, seems it's working fine.
- Client Private Key | ||
- TLS certificate files are populated from the **backend-redis** and **system-redis** secrets. | ||
|
||
- The tables below show the mapping between TLS certificate environment variables in the pods, their corresponding definitions in the related Redis backend and system secrets. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think we should only be documenting the ENV VAR the user has to set and not the ones set my the operator to avoid confusion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@austincunningham thank you for comment. It's User Guide. I thought it could help to User to understand how it's working, and investigate/debug if required. If you strongly disagree I will remove this, but seems to me it can be useful. Thanks
0ea718f
to
a686c2f
Compare
048f9bd
to
3aea74e
Compare
4809afc
to
e6a3851
Compare
There is a new functionality added to resync-routes when zync is enabled.
|
The secrets when TLS is enabled are annotated with: To enable watched-by you need |
In backend-redis, we have redis queues and redis storage entries - think we could maintain that? |
It's in requirements, as in Jira, if I understand the question : |
I think I would change that to be clear and follow what we have, alternatively, bring it up in jira please |
When enabling TLS with wrong certs (I've tried with storage) what happens is that although the authentication in backend listener fails, the products can be created and promoted to stage/prod. I guess, porta does some validation right, so maybe an idea here would be to restart system-app pod on every update of the TLS secrets to perform the validation (and hopefully catch the incorrect certs and block api access?) WDYT? |
@MStokluska It's working, I tested watched-by in my PR. The reason why it's working is here - checked only key of lable, not value. But Secret itself it's created by end-user, so actually nothing change in code, as I think. |
@MStokluska , all backend pods (listener, worker, cron) and system (app and sidekiq) are restarting if any change in secrets system-redis and backend-redis (that hold certificates), as whatched-by is available on backend-redis and system-redis |
@MStokluska , will discuss it. Thank you for comments |
In your current implementation, watched-by doesn't work correctly. When I've fixed it, watched-by on backend-redis doesn't restart system pod. |
@MStokluska are you suggest to open a Jir
@MStokluska , Current PR - Completed, tested, and confirmed to work exactly as specified in Jira/Requirements, as well as in alignment with our team prior meeting discussions and my prior conversation with System/Juan (see team chat for details). |
26c7670
to
7db7a23
Compare
ebfe2cd
to
17af0ea
Compare
17af0ea
to
1e0294b
Compare
Jira: https://issues.redhat.com/browse/THREESCALE-11020
Add a way for the user to provide Redis TLS certs and keys for porta and backend
This PR enables Porta and Apisonator to load TLS configuration details for connecting to Redis. It introduces environment variables to specify the locations of the certificate files and indicate whether TLS mode is enabled.
For additional information, please refer to the Jira ticket and the documentation files included as part of this PR.
NOTES PR includes also integration for Watched-by feature functionality for System and Backend deployments addressed in TLS feature.
Validation
1. Install Redis Server for Test
2. Certificates preparing
3. Update Redis Server with new server certificate
Update
redis-tls-secret
secret, using new created:Restart redis pod
4. Install 3scale
You may prepare the secrets in whichever way is most convenient for you.
Update Client Certificates in
system-redis
andbackedn-redis
secrets via UI. The following tables are for matching data field names with the certificate files created before:Secret: system-redis
Please note:
rediss
indicates a secure connection and port6380
is used for secure Redis connections. For example:4.2. Create s3-credentials secret
4.3. Run Install and Downloads commands
Please make sure you are in
3scale-operator
directory, and run following commands:4.4. Create APIManager CR and Run Operator
5 Check results and Troubleshooting
5.1 Check Environment Variables and Certificates in Pods
System pods: system-sidekiq and system-app
5.2. Troubleshooting
If you encounter issues with the Redis server, one approach is to test the connection using the
throwaway-redis
pod, which includesredis-cli
. This simplifies the process of checking TLS connections to Redis.5.2.1 Using the throwaway-redis Pod
In this example, we assume that the throwaway-redis pod is not yet present in the 3scale-test project. Since we used the export PREFLIGHT_CHECKS_BYPASS=true environment variable earlier, the pod needs to be created; follow the steps below:
throwaway-redis
pod:You can also check the Redis connection without TLS to verify basic connectivity. Run the following:
If the connection is successful, you should see:
PONG
If the non-TLS connection works, but the TLS connection does not, consider updating the server certificates. To do this:
- Update the Redis testing server's secret:
redis-tls-secret
.- Recreate the Redis testing server pod:
redis-5dc466fc8b-vxpbh 1/1 Running 0 4s
throwaway-redis
pod:After updating the server certificates and recreating the Redis pod, attempt the TLS connection again from the throwaway-redis pod. This time it looks good:
sh-5.1$ redis-cli -h 172.30.56.166 --tls -p 6380 --cert redis-client.crt --key redis-client.key --cacert ca.crt ping
The expected response should now be:
5.2.2 More things to check and useful commands
6 TLS - Test Cases, Documentation
6.1 Test Cases
In the previous sections, we provided details for testing scenarios where the APIManager CR options are as follows: redisTLSEnabled: true and both Redis external components are enabled (set to true), as shown in the following CR example:
However, we conducted additional tests, and below is a table listing all test cases and scenarios that were tested for the current PR
*Test 2. System-app, system-sidekiq are running in TLS mode even if Backend certificates are dummy ("replaceme")
6.2 TLS - Documentation
Please see documentation updated in this PR - operator-user-guide - Setting Redis TLS Environment variables
7. Check Watched-by Integration for Backend and System