-
Notifications
You must be signed in to change notification settings - Fork 59
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
Support user configs, user secrets and separate environments for cassandra and sidecar #218
Merged
benbromhead
merged 9 commits into
instaclustr:superdupertopsecretrewrite
from
alourie:keystore_178
Aug 21, 2019
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c8cdba9
Initial work for clouds secrets and user-defined configmap
alourie 9f8b223
PR comments fixes
alourie e7109f6
Support TLS certificates for internal communication
alourie f3f49bb
PR comments, docs updates
alourie a38eb32
Cleanups
alourie 1af32c3
Path naming update
alourie fa47f90
Cleanups
alourie a860bbe
Merge branch 'superdupertopsecretrewrite' of github.com:instaclustr/c…
alourie aff1123
go fmt
alourie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
### SSL encryption | ||
|
||
This is an example for running cassandra with ssl encryption using the operator. | ||
Assuming you already have [generated keys](https://docs.datastax.com/en/cassandra/3.0/cassandra/configuration/secureSSLCertWithCA.html) : | ||
* keystore.jks | ||
* trustore.jks | ||
* cacert.pem (containing the root certificate) | ||
|
||
Create a secret with those files : | ||
```bash | ||
kubectl create secret generic dc1-user-secret \ | ||
--from-file=keystore.jks \ | ||
--from-file=truststore.jks \ | ||
--from-file=cacert.pem | ||
``` | ||
|
||
Create a config map with 2 entries: | ||
* a cassandra yaml fragment for configuring node-to-node and client-to-node encryption | ||
* `cqlshrc` to make cqlsh work with ssl | ||
|
||
For instance : | ||
```bash | ||
kubectl apply -f - <<EOF | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: dc1-user-config | ||
data: | ||
cassandra_ssl: | | ||
server_encryption_options: | ||
internode_encryption: all | ||
keystore: /tmp/user-secret-config/keystore.jks | ||
# keystore_password: myKeyPass | ||
truststore: /tmp/user-secret-config/truststore.jks | ||
#truststore_password: truststorePass | ||
# More advanced defaults below: | ||
protocol: TLSv1.2 | ||
algorithm: SunX509 | ||
store_type: JKS | ||
cipher_suites: [TLS_RSA_WITH_AES_256_CBC_SHA] | ||
require_client_auth: true | ||
client_encryption_options: | ||
enabled: true | ||
keystore: /tmp/user-secret-config/keystore.jks ## Path to your .keystore file | ||
# keystore_password: keystore password ## Password that you used to generate the keystore | ||
truststore: /tmp/user-secret-config/truststore.jks ## Path to your .truststore | ||
#truststore_password: truststore password ## Password that you used to generate the truststore | ||
protocol: TLSv1.2 | ||
store_type: JKS | ||
algorithm: SunX509 | ||
require_client_auth: false | ||
cipher_suites: [TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA] | ||
cqlshrc: | | ||
[connection] | ||
factory = cqlshlib.ssl.ssl_transport_factory | ||
ssl = true | ||
|
||
[ssl] | ||
certfile = /tmp/user-secret-config/cacert.pem | ||
validate = true | ||
|
||
[authentication] | ||
# username = cassandra // use the one provided during certificate generation | ||
# password = cassandra // use the one provided during certificate generation | ||
EOF | ||
``` | ||
|
||
## Deploying the cluster with TLS | ||
The credentials will be added to the cassandra container at the `/tmp/user-secret-config` location, so we use that in the | ||
`cqlshrc` configuration in the configMap example above. | ||
The yaml fragment and the cqlshrc are going to be added to the `/etc/cassandra/` inside the container. | ||
|
||
We also use an environment variable **CQLSHRC** to let operator move the `cqlshrc` file | ||
to the default folder where cqlsh will expect to find it (~/.cassandra) | ||
|
||
Create a `CassandraDataCenter` CRD that injects the secret, configuration and the environment variable | ||
into the cassandra container: | ||
|
||
```yaml | ||
apiVersion: stable.instaclustr.com/v1 | ||
kind: CassandraDataCenter | ||
metadata: | ||
name: foo-cassandra | ||
labels: | ||
app: cassandra | ||
chart: cassandra-0.1.0 | ||
release: foo | ||
spec: | ||
replicas: 3 | ||
cassandraImage: "gcr.io/cassandra-operator/cassandra:latest" | ||
sidecarImage: "gcr.io/cassandra-operator/cassandra-sidecar:latest" | ||
imagePullPolicy: IfNotPresent | ||
resources: | ||
limits: | ||
memory: 512Mi | ||
requests: | ||
memory: 512Mi | ||
dataVolumeClaim: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 100Mi | ||
userSecretVolumeSource: | ||
secretName: dc1-user-secret | ||
userConfigMapVolumeSource: | ||
name: dc1-user-config | ||
# type is a workaround for https://github.com/kubernetes/kubernetes/issues/68466 | ||
type: array | ||
items: | ||
- key: cassandra_ssl | ||
path: cassandra.yaml.d/003-ssl.yaml | ||
- key: cqlshrc | ||
path: cqlshrc | ||
cassandraEnv: | ||
- name: CQLSHRC | ||
value: "/etc/cassandra/cqlshrc" | ||
prometheusEnabled: false | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 24 additions & 5 deletions
29
pkg/apis/cassandraoperator/v1alpha1/zz_generated.deepcopy.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
18 changes: 15 additions & 3 deletions
18
pkg/apis/cassandraoperator/v1alpha1/zz_generated.openapi.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think we can make this nicer. It IMO shouldn't be a requirement that users have to define an environment variable and add a file to a config map to get cqlsh to function.
Instead I suggest that we write our own wrapper for
cqlsh
that detects if SSL is enabled, and fetches the CA cert (or just disables trust checking). This will also be necessary once we support authn/authz, since we need to implement shared-secret support.As a side question, should
cqlsh
be installed the C* container at all? If people want to connect to the cluster, should they instead start a new pod/container that just contains cqlsh?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.
@zegelin we currently use cqlsh now in
cql-readiness-probe
, and this is easily replaceable with either python script or, say, a statically compiled gocql simple program. So we don't have an inherent requirement to have it in the container at all.Also, if people want to use cqlsh to connect to the cluster, they can either spin a new container with all the certificates and custom configs as they need to, or have it installed locally if they have the network access to the cluster. So, if you think that's a good path to follow, I can replace the readiness script with something else pretty quickly and stop the dependency on
cqlsh
.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.
I did rush it a bit. Clearly, any "script" we use will have to know about SSL configuration to be able to connect to the node. So having a wrapper around cqlsh might be a useful and simpler solution.
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.
In order to get the PR closed, I think we should create a new issue/PR for the wrapper script and solve that one separately.
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.
yea, I'm going to remove this part and deal with that in #241