-
Notifications
You must be signed in to change notification settings - Fork 146
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
K8SPSMDB-956: fix problems with TLS certificate renewal #1287
Merged
Merged
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
39d3cd1
K8SPSMDB-956: fix problems with TLS certificate renewal
pooknull 6fc9ed7
refactor
pooknull 3325b5e
Merge branch 'main' into dev/K8SPSMDB-956
pooknull b889932
add `tls-issue-cert-manager` test to `csv` files
pooknull fc1c9f7
wait for ca certs
pooknull 422dd5f
update `cert-manager`
pooknull 7a6e8ce
fix cert-manager test
pooknull 933dda7
Merge branch 'main' into dev/K8SPSMDB-956
hors 72729c2
Merge branch 'main' into dev/K8SPSMDB-956
inelpandzic 8b3af4a
increase sleep in `deploy_cert_manager`
pooknull 032c660
Merge remote-tracking branch 'origin/main' into dev/K8SPSMDB-956
pooknull 906706d
add more sleep
pooknull 8a2524b
Merge branch 'main' into dev/K8SPSMDB-956
hors b0c4123
fix deploy/bundle.yaml
hors 6958601
fix `tls-issue-cert-manager` for cluster wide
pooknull 9d7d0c6
update `cert-manager` url
pooknull 021f368
Merge branch 'main' into dev/K8SPSMDB-956
inelpandzic e961e29
Merge branch 'main' into dev/K8SPSMDB-956
hors 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,7 @@ rules: | |
resources: | ||
- issuers | ||
- certificates | ||
- certificates/status | ||
verbs: | ||
- get | ||
- list | ||
|
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,28 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: cmctl | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
name: cmctl | ||
template: | ||
metadata: | ||
labels: | ||
name: cmctl | ||
spec: | ||
serviceAccountName: percona-server-mongodb-operator | ||
containers: | ||
- name: cmctl | ||
image: debian | ||
imagePullPolicy: Always | ||
command: | ||
- /bin/bash | ||
- -c | ||
- | | ||
apt-get update && apt-get install -y curl \ | ||
&& curl -fsSL -o cmctl.tar.gz https://github.com/cert-manager/cert-manager/releases/latest/download/cmctl-linux-amd64.tar.gz \ | ||
&& tar xzf cmctl.tar.gz \ | ||
&& sleep 100500 | ||
restartPolicy: Always |
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 |
---|---|---|
|
@@ -17,6 +17,7 @@ pitr-sharded | |
recover-no-primary | ||
rs-shard-migration | ||
scaling | ||
tls-issue-cert-manager | ||
upgrade | ||
upgrade-sharded | ||
users |
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
47 changes: 47 additions & 0 deletions
47
e2e-tests/tls-issue-cert-manager/compare/certificate_some-name-ssl-internal.yml
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,47 @@ | ||
apiVersion: cert-manager.io/v1 | ||
kind: Certificate | ||
metadata: | ||
generation: 1 | ||
name: some-name-ssl-internal | ||
ownerReferences: | ||
- blockOwnerDeletion: true | ||
controller: true | ||
kind: PerconaServerMongoDB | ||
name: some-name | ||
spec: | ||
commonName: some-name | ||
dnsNames: | ||
- localhost | ||
- some-name-rs0 | ||
- some-name-rs0.NAME_SPACE | ||
- some-name-rs0.NAME_SPACE.svc.cluster.local | ||
- '*.some-name-rs0' | ||
- '*.some-name-rs0.NAME_SPACE' | ||
- '*.some-name-rs0.NAME_SPACE.svc.cluster.local' | ||
- some-name-rs0.NAME_SPACE.svc.clusterset.local | ||
- '*.some-name-rs0.NAME_SPACE.svc.clusterset.local' | ||
- '*.NAME_SPACE.svc.clusterset.local' | ||
- some-name-mongos | ||
- some-name-mongos.NAME_SPACE | ||
- some-name-mongos.NAME_SPACE.svc.cluster.local | ||
- '*.some-name-mongos' | ||
- '*.some-name-mongos.NAME_SPACE' | ||
- '*.some-name-mongos.NAME_SPACE.svc.cluster.local' | ||
- some-name-cfg | ||
- some-name-cfg.NAME_SPACE | ||
- some-name-cfg.NAME_SPACE.svc.cluster.local | ||
- '*.some-name-cfg' | ||
- '*.some-name-cfg.NAME_SPACE' | ||
- '*.some-name-cfg.NAME_SPACE.svc.cluster.local' | ||
- some-name-mongos.NAME_SPACE.svc.clusterset.local | ||
- '*.some-name-mongos.NAME_SPACE.svc.clusterset.local' | ||
- some-name-cfg.NAME_SPACE.svc.clusterset.local | ||
- '*.some-name-cfg.NAME_SPACE.svc.clusterset.local' | ||
duration: 2160h0m0s | ||
issuerRef: | ||
kind: Issuer | ||
name: some-name-psmdb-issuer | ||
secretName: some-name-ssl-internal | ||
subject: | ||
organizations: | ||
- PSMDB |
47 changes: 47 additions & 0 deletions
47
e2e-tests/tls-issue-cert-manager/compare/certificate_some-name-ssl.yml
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,47 @@ | ||
apiVersion: cert-manager.io/v1 | ||
kind: Certificate | ||
metadata: | ||
generation: 1 | ||
name: some-name-ssl | ||
ownerReferences: | ||
- blockOwnerDeletion: true | ||
controller: true | ||
kind: PerconaServerMongoDB | ||
name: some-name | ||
spec: | ||
commonName: some-name | ||
dnsNames: | ||
- localhost | ||
- some-name-rs0 | ||
- some-name-rs0.NAME_SPACE | ||
- some-name-rs0.NAME_SPACE.svc.cluster.local | ||
- '*.some-name-rs0' | ||
- '*.some-name-rs0.NAME_SPACE' | ||
- '*.some-name-rs0.NAME_SPACE.svc.cluster.local' | ||
- some-name-rs0.NAME_SPACE.svc.clusterset.local | ||
- '*.some-name-rs0.NAME_SPACE.svc.clusterset.local' | ||
- '*.NAME_SPACE.svc.clusterset.local' | ||
- some-name-mongos | ||
- some-name-mongos.NAME_SPACE | ||
- some-name-mongos.NAME_SPACE.svc.cluster.local | ||
- '*.some-name-mongos' | ||
- '*.some-name-mongos.NAME_SPACE' | ||
- '*.some-name-mongos.NAME_SPACE.svc.cluster.local' | ||
- some-name-cfg | ||
- some-name-cfg.NAME_SPACE | ||
- some-name-cfg.NAME_SPACE.svc.cluster.local | ||
- '*.some-name-cfg' | ||
- '*.some-name-cfg.NAME_SPACE' | ||
- '*.some-name-cfg.NAME_SPACE.svc.cluster.local' | ||
- some-name-mongos.NAME_SPACE.svc.clusterset.local | ||
- '*.some-name-mongos.NAME_SPACE.svc.clusterset.local' | ||
- some-name-cfg.NAME_SPACE.svc.clusterset.local | ||
- '*.some-name-cfg.NAME_SPACE.svc.clusterset.local' | ||
duration: 2160h0m0s | ||
issuerRef: | ||
kind: Issuer | ||
name: some-name-psmdb-issuer | ||
secretName: some-name-ssl | ||
subject: | ||
organizations: | ||
- PSMDB |
12 changes: 12 additions & 0 deletions
12
e2e-tests/tls-issue-cert-manager/compare/issuer_some-name-psmdb-ca-issuer.yml
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,12 @@ | ||
apiVersion: cert-manager.io/v1 | ||
kind: Issuer | ||
metadata: | ||
generation: 1 | ||
name: some-name-psmdb-ca-issuer | ||
ownerReferences: | ||
- blockOwnerDeletion: true | ||
controller: true | ||
kind: PerconaServerMongoDB | ||
name: some-name | ||
spec: | ||
selfSigned: {} |
13 changes: 13 additions & 0 deletions
13
e2e-tests/tls-issue-cert-manager/compare/issuer_some-name-psmdb-issuer.yml
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,13 @@ | ||
apiVersion: cert-manager.io/v1 | ||
kind: Issuer | ||
metadata: | ||
generation: 1 | ||
name: some-name-psmdb-issuer | ||
ownerReferences: | ||
- blockOwnerDeletion: true | ||
controller: true | ||
kind: PerconaServerMongoDB | ||
name: some-name | ||
spec: | ||
ca: | ||
secretName: some-name-ca-cert |
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,45 @@ | ||
apiVersion: psmdb.percona.com/v1 | ||
kind: PerconaServerMongoDB | ||
metadata: | ||
name: some-name | ||
spec: | ||
#platform: openshift | ||
image: | ||
imagePullPolicy: Always | ||
backup: | ||
enabled: false | ||
replsets: | ||
- name: rs0 | ||
affinity: | ||
antiAffinityTopologyKey: none | ||
resources: | ||
limits: | ||
cpu: 500m | ||
memory: 1G | ||
requests: | ||
cpu: 100m | ||
memory: 0.1G | ||
volumeSpec: | ||
persistentVolumeClaim: | ||
resources: | ||
requests: | ||
storage: 1Gi | ||
expose: | ||
enabled: false | ||
exposeType: ClusterIP | ||
size: 3 | ||
sharding: | ||
enabled: true | ||
configsvrReplSet: | ||
size: 3 | ||
volumeSpec: | ||
persistentVolumeClaim: | ||
resources: | ||
requests: | ||
storage: 3Gi | ||
expose: | ||
enabled: false | ||
mongos: | ||
size: 3 | ||
secrets: | ||
users: some-users |
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,112 @@ | ||
#!/bin/bash | ||
|
||
set -o errexit | ||
|
||
test_dir=$(realpath $(dirname $0)) | ||
. "${test_dir}/../functions" | ||
set_debug | ||
|
||
renew-certificate() { | ||
certificate="$1" | ||
|
||
desc "renew $certificate" | ||
|
||
local pod_name | ||
pod_name=$(kubectl_bin get pods --selector=name=cmctl -o 'jsonpath={.items[].metadata.name}') | ||
|
||
local revision | ||
revision=$(kubectl_bin get certificate "$certificate" -o 'jsonpath={.status.revision}') | ||
|
||
kubectl_bin exec "$pod_name" -- ./cmctl renew "$certificate" | ||
|
||
# wait for new revision | ||
for i in {1..10}; do | ||
local new_revision | ||
new_revision=$(kubectl_bin get certificate "$certificate" -o 'jsonpath={.status.revision}') | ||
if [ "$((revision + 1))" == "$new_revision" ]; then | ||
break | ||
fi | ||
sleep 1 | ||
done | ||
} | ||
|
||
check_tls_secret() { | ||
local secret_name=$1 | ||
check_secret_data_key "$secret_name" 'ca.crt' | ||
check_secret_data_key "$secret_name" 'tls.crt' | ||
check_secret_data_key "$secret_name" 'tls.key' | ||
} | ||
|
||
check_secret_data_key() { | ||
local secret_name=$1 | ||
local data_key=$2 | ||
local secret_data | ||
|
||
secret_data=$(kubectl_bin get "secrets/${secret_name}" -o json | jq ".data[\"${data_key}\"]") | ||
if [ -z "$secret_data" ]; then | ||
exit 1 | ||
fi | ||
} | ||
|
||
main() { | ||
deploy_cert_manager | ||
create_infra "$namespace" | ||
|
||
desc 'create secrets and start client' | ||
kubectl_bin apply -f "$conf_dir/secrets.yml" | ||
kubectl_bin apply -f "$conf_dir/client_with_tls.yml" | ||
kubectl_bin apply -f "$conf_dir/cmctl.yml" | ||
|
||
cluster="some-name" | ||
desc "create first PSMDB cluster $cluster" | ||
apply_cluster "$test_dir/conf/$cluster.yml" | ||
|
||
desc 'check if all Pods started' | ||
wait_for_running $cluster-rs0 3 | ||
wait_for_running $cluster-cfg 3 "false" | ||
wait_for_running $cluster-mongos 3 | ||
|
||
desc 'check if certificates issued with certmanager' | ||
check_tls_secret "$cluster-ssl" | ||
|
||
desc 'check if CA issuer created' | ||
compare_kubectl issuer/$cluster-psmdb-ca-issuer | ||
|
||
desc 'check if issuer created' | ||
compare_kubectl issuer/$cluster-psmdb-issuer | ||
|
||
desc 'check if certificate issued' | ||
compare_kubectl certificate/$cluster-ssl | ||
|
||
desc 'check if internal certificate issued' | ||
compare_kubectl certificate/$cluster-ssl-internal | ||
|
||
renew-certificate "some-name-ssl" | ||
sleep 10 | ||
wait_for_running $cluster-rs0 3 | ||
wait_for_running $cluster-cfg 3 "false" | ||
wait_for_running $cluster-mongos 3 | ||
|
||
renew-certificate "some-name-ssl-internal" | ||
sleep 10 | ||
wait_for_running $cluster-rs0 3 | ||
wait_for_running $cluster-cfg 3 "false" | ||
wait_for_running $cluster-mongos 3 | ||
|
||
desc 'check if CA issuer created' | ||
compare_kubectl issuer/$cluster-psmdb-ca-issuer | ||
|
||
desc 'check if issuer created' | ||
compare_kubectl issuer/$cluster-psmdb-issuer | ||
|
||
desc 'check if certificate issued' | ||
compare_kubectl certificate/$cluster-ssl | ||
|
||
desc 'check if internal certificate issued' | ||
compare_kubectl certificate/$cluster-ssl-internal | ||
|
||
destroy "$namespace" | ||
desc 'test passed' | ||
} | ||
|
||
main |
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.
please also update the bundle.yaml
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 should not have it at all. It is needed only for test.