Skip to content
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

Add TLS on Keycloak server #3427

Merged
merged 16 commits into from Jul 3, 2023

Conversation

npalaska
Copy link
Member

@npalaska npalaska commented May 19, 2023

  • Run Keycloak containers with SSL support
  • Make necessary changes in the pbench-server to connect to the Keycloak running on SSL.
  • Note: run-pbench-in-a-can script creates self signed pbench-server certificate and the same certificate is used for Keycloak configuration.

PBENCH-1138

@npalaska npalaska self-assigned this May 19, 2023
@npalaska npalaska added Server Containerization Of and relating to the process of setting up and maintaining container images labels May 19, 2023
@npalaska npalaska added this to In progress in v0.72 via automation May 19, 2023
@npalaska npalaska added this to the v0.72 milestone May 19, 2023
@npalaska npalaska force-pushed the pbench-1138 branch 3 times, most recently from 406a8b8 to 366b6ae Compare May 23, 2023 15:27
@npalaska npalaska marked this pull request as ready for review May 23, 2023 16:12
Copy link
Member

@dbutenhof dbutenhof left a comment

Choose a reason for hiding this comment

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

Cool. My big concerns are:

  1. Do we support http urls or not? (Critically, do our intlab services support https, and do we have Opensearch credentials to use... i.e., can we actually stage this?)
  2. If not, I'd like some better diagnosis here when the new parameters are omitted. (And if we do support http backend services, we need some more conditionalized code, and additional testing.)

lib/pbench/server/api/resources/query_apis/__init__.py Outdated Show resolved Hide resolved
lib/pbench/server/api/resources/query_apis/__init__.py Outdated Show resolved Hide resolved
lib/pbench/server/indexer.py Outdated Show resolved Hide resolved
server/pbenchinacan/run-pbench-in-a-can Outdated Show resolved Hide resolved
server/pbenchinacan/run-pbench-in-a-can Outdated Show resolved Hide resolved
@npalaska
Copy link
Member Author

1. Do we support http urls or not? (Critically, do our intlab services support https, and do we have Opensearch credentials to use... i.e., can we actually stage this?)

True, with this change, we won't be able to support HTTP connections and we can not actually stage this until we have the required credentials to use in INTLAB. I am not sure if I know the answer to do our intlab services support https? That is something we have to get some more clarity on when we do a sit-down with Intlab. As far as I know, I don't think Intlab has to deploy certs for all the services until they move to DMZ, Right? but I may be wrong.

2. If not, I'd like some better diagnosis here when the new parameters are omitted. (And if we do support http backend services, we need some more conditionalized code, and additional testing.)

I agree if we do support HTTP then we need more conditionalized code in our source but as I said I don't know the answer and maybe we should hold off until we know the answer. I would like to think adding support for both HTTP and HTTPS and running tests with different scenarios would not be necessary if we know what is supported in the Intlab.

@dbutenhof
Copy link
Member

I agree if we do support HTTP then we need more conditionalized code in our source but as I said I don't know the answer and maybe we should hold off until we know the answer. I would like to think adding support for both HTTP and HTTPS and running tests with different scenarios would not be necessary if we know what is supported in the Intlab.

I think we need to find out the intent and timeframe of TLS within intlab. This is a great P.O.C., but I really don't want to get into a situation where main isn't deployable.

To make this more concrete, I think either:

  1. We require TLS backend, and we clearly diagnose missing configuration (certificates, credentials, a backend service specified as http instead of https, etc.), or
  2. We dynamically adapt to either https with credentials and certs or http without.

(In theory we can support credentials without TLS, as we do now for Postgresql, as well as TLS without credentials, as we expect for the relay server, but I'm less concerned about those twists as long as we end up with code that we can deploy in intlab. In theory I like the idea of being general; in practice I'm not sure we'll ever need to care about anything but our intlab service.)

Copy link
Member

@webbnh webbnh left a comment

Choose a reason for hiding this comment

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

I second Dave's comment: we should not merge a change which makes the main branch undeployable.

So, we either need code which supports both HTTPS and HTTP (and, then, we'll need to test both...), or we need to pick one. And, if we don't have support from the IntLab for HTTPS, then I think it's clear which one we need to pick.

In the meantime, I've found a number of things to consider, below.

lib/pbench/server/api/resources/query_apis/__init__.py Outdated Show resolved Hide resolved
lib/pbench/server/api/resources/query_apis/__init__.py Outdated Show resolved Hide resolved
server/lib/config/pbench-server-default.cfg Outdated Show resolved Hide resolved
server/pbenchinacan/deploy Outdated Show resolved Hide resolved
server/pbenchinacan/deploy Outdated Show resolved Hide resolved
server/pbenchinacan/etc/pbench-server/pbench-server.cfg Outdated Show resolved Hide resolved
server/pbenchinacan/load_keycloak.sh Outdated Show resolved Hide resolved
server/pbenchinacan/load_keycloak.sh Outdated Show resolved Hide resolved
server/pbenchinacan/load_keycloak.sh Outdated Show resolved Hide resolved
server/pbenchinacan/run-pbench-in-a-can Outdated Show resolved Hide resolved
v0.72 automation moved this from In progress to Review in progress May 30, 2023
Copy link
Member

@dbutenhof dbutenhof left a comment

Choose a reason for hiding this comment

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

The server's last words are "Waiting for OIDC server to become available."

lib/pbench/test/unit/server/auth/test_auth.py Outdated Show resolved Hide resolved
@dbutenhof dbutenhof changed the title Add TLS on all the dependency services Add TLS on Keycloak server Jun 27, 2023
@npalaska npalaska requested a review from webbnh June 27, 2023 14:38
Copy link
Member

@webbnh webbnh left a comment

Choose a reason for hiding this comment

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

This looks like a good update. However,

  • Please update the PR description to reflect the current scope of the work.
  • The OIDC client code around the cert validation and the CA location needs tweaking.
  • There are a number of places where we are supplying default values for environment variables; I think we should be consistent in the values of the defaults at each level, unless there is a good reason for them to diverge, otherwise someone is likely to fall into some serious confusion.
  • Since you've added localhost to the TLS certificate, we should use localhost to address the server(s) (assuming that it works) rather than the hostname -I value (which is likely to have a few challenges). (On the other hand, if using localhost doesn't work, why did you add it to the cert?)
  • Rather than using --cacert on the curl commands, consider using the CURL_CA_BUNDLE environment variable instead (which run-server-functional-tests already sets up). (The Pbench Client also uses it...you might want to do something similar in the ODIC client code.)

And, there are a bunch of nits and smaller things.

server/lib/config/pbench-server-default.cfg Outdated Show resolved Hide resolved
lib/pbench/server/auth/__init__.py Outdated Show resolved Hide resolved
lib/pbench/server/auth/__init__.py Outdated Show resolved Hide resolved
lib/pbench/test/unit/server/auth/test_auth.py Outdated Show resolved Hide resolved
lib/pbench/test/unit/server/auth/test_auth.py Show resolved Hide resolved
server/pbenchinacan/deploy-dependencies Outdated Show resolved Hide resolved
server/pbenchinacan/load_keycloak.sh Outdated Show resolved Hide resolved
server/pbenchinacan/load_keycloak.sh Outdated Show resolved Hide resolved
server/pbenchinacan/load_keycloak.sh Outdated Show resolved Hide resolved
server/pbenchinacan/load_keycloak.sh Outdated Show resolved Hide resolved
lib/pbench/server/auth/__init__.py Outdated Show resolved Hide resolved
server/lib/config/pbench-server-default.cfg Outdated Show resolved Hide resolved
dbutenhof
dbutenhof previously approved these changes Jun 27, 2023
Copy link
Member

@webbnh webbnh left a comment

Choose a reason for hiding this comment

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

Nikhil, this looks great, but there are a couple of details left to attend to:

  • The biggest item is how we make the Pbench CA cert available to inside the Server container: I think it should be copied in when the container is built, rather than mapped in when it is invoked, because this is workable and better reflects an actual deployment.
  • The default value for PB_DEPLOY_FILES in server/pbenchinacan/load_keycloak.sh isn't (quite) consistent with the default from run-pbench-in-a-can (prev).

In addition, I think these are a good idea:

  • The user should probably be able to override the value of CURL_CA_BUNDLE which is set in load_keycloak.sh.
  • The default for CURL_CA_BUNDLE in lib/pbench/client/oidc_admin.py should probably be True.
  • And, we might want a code comment.

lib/pbench/client/oidc_admin.py Outdated Show resolved Hide resolved
server/pbenchinacan/load_keycloak.sh Outdated Show resolved Hide resolved
lib/pbench/server/auth/__init__.py Show resolved Hide resolved
server/pbenchinacan/deploy Outdated Show resolved Hide resolved
server/pbenchinacan/load_keycloak.sh Outdated Show resolved Hide resolved
Comment on lines +66 to +69
# Add our Pbench Server CA certificate.
buildah copy --chown root:root --chmod 0444 $container \
${PBINC_INACAN}/etc/pki/tls/certs/pbench_CA.crt /etc/pki/tls/certs/pbench_CA.crt

Copy link
Member

Choose a reason for hiding this comment

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

Don't we user container-build.sh both for the functional tests and for the "real" containers we'll eventually deploy to staging/production? I'd really prefer not to be packaging our fake CA in staging much less production even though we need it for functional tests. This probably needs to be conditionalized somehow.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, Dave, we do (and I think should) use the same container image for functional testing and for deployment, but I concluded that adding the CA to the container image is the least of evils.

In the Staging/Production case, it's just another file, and a small one at that (1.3Kb). It's not a private key or anything, it's just a cert. We would give it away to anyone who wants to verify the TLS connection to a development server, so I'm not concerned about having it in the container.

And, I can't think of any way of conditionalizing this which doesn't impact Staging and Production.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, you have a point. I am not sure what is the best way forward, mounting it or copying it at the build time. @webbnh do you want to weigh in?

Copy link
Member

Choose a reason for hiding this comment

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

@webbnh do you want to weigh in?

Yes. 😁

Copy link
Member

Choose a reason for hiding this comment

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

I really don't like putting our development fake CA bundle into the product container. It may be expedient, but it's wrong and there's got to be a better way.

Copy link
Member

@webbnh webbnh Jun 29, 2023

Choose a reason for hiding this comment

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

We use the config file, which we map in already, to decide whether to use the private CA or not. (It's not fake....) If we map the CA in, then we cannot use the same command/script in both development and staging/production (or, at least, we have to add conditionalization such that the container invocation will be (slightly) different in the two cases...or we have to map in a dummy file....).

Instead, for the cost of a tiny increment in size, we avoid the need for conditionalization or divergence in the invocations.

jenkins/run Outdated Show resolved Hide resolved
jenkins/run Outdated Show resolved Hide resolved
tox.ini Outdated Show resolved Hide resolved
Copy link
Member

@webbnh webbnh left a comment

Choose a reason for hiding this comment

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

Looks great (assuming the tests pass this time...).

Just two nits.

Comment on lines 46 to +47
PB_SSL_KEY_FILE=${PB_SSL_KEY_FILE:-${PB_DEPLOY_FILES}/pbench-server.key}
PB_SSL_CA_FILE=${PB_SSL_CA_FILE:-${PWD}/server/pbenchinacan/etc/pki/tls/certs/pbench_CA.crt}
Copy link
Member

Choose a reason for hiding this comment

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

This definition doesn't seem to be needed anymore.

Comment on lines 245 to +246
# We use SQLALCHEMY_SILENCE_UBER_WARNING here ... (see above).
SQLALCHEMY_SILENCE_UBER_WARNING=1 PYTHONUNBUFFERED=True PBENCH_SERVER=${server_arg} KEEP_DATASETS="${keep_datasets}" pytest --tb=native -v -s -rs --pyargs ${posargs} pbench.test.functional.server
REQUESTS_CA_BUNDLE=${PWD}/server/pbenchinacan/etc/pki/tls/certs/pbench_CA.crt SQLALCHEMY_SILENCE_UBER_WARNING=1 PYTHONUNBUFFERED=True PBENCH_SERVER=${server_arg} KEEP_DATASETS="${keep_datasets}" pytest --tb=native -v -s -rs --pyargs ${posargs} pbench.test.functional.server
Copy link
Member

Choose a reason for hiding this comment

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

I would wrap this line:

        REQUESTS_CA_BUNDLE=${PWD}/server/pbenchinacan/etc/pki/tls/certs/pbench_CA.crt \
            SQLALCHEMY_SILENCE_UBER_WARNING=1 \
            PYTHONUNBUFFERED=True \
            PBENCH_SERVER=${server_arg} \
            KEEP_DATASETS="${keep_datasets}" \
                pytest --tb=native -v -s -rs --pyargs \
                    ${posargs} pbench.test.functional.server

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, but I don't think it's worth another commit though.

v0.72 automation moved this from Review in progress to Reviewer approved Jun 29, 2023
Copy link
Member

@dbutenhof dbutenhof left a comment

Choose a reason for hiding this comment

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

I dislike the container build hack, and it'll continue to bother me: but we also need to get Keycloak TLS into main and I'm going to hold my nose and approve just to move on for now.

Comment on lines +66 to +69
# Add our Pbench Server CA certificate.
buildah copy --chown root:root --chmod 0444 $container \
${PBINC_INACAN}/etc/pki/tls/certs/pbench_CA.crt /etc/pki/tls/certs/pbench_CA.crt

Copy link
Member

Choose a reason for hiding this comment

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

I really don't like putting our development fake CA bundle into the product container. It may be expedient, but it's wrong and there's got to be a better way.

@dbutenhof dbutenhof merged commit 3b8bf2f into distributed-system-analysis:main Jul 3, 2023
4 checks passed
v0.72 automation moved this from Reviewer approved to Done Jul 3, 2023
webbnh added a commit to webbnh/pbench that referenced this pull request Jul 3, 2023
webbnh added a commit to webbnh/pbench that referenced this pull request Jul 3, 2023
webbnh added a commit that referenced this pull request Jul 3, 2023
Also, removes an unused definition which was left over from PR #3427 and reformats a long line which it added.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Containerization Of and relating to the process of setting up and maintaining container images Server
Projects
v0.72
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants