Skip to content

Commit 89bc9f2

Browse files
Merge pull request openstack-k8s-operators#1654 from stuggi/kuttl_custom_cert
tests: Refactor custom certificate management for kuttl tests
2 parents 7f5d32e + 97cfb4e commit 89bc9f2

14 files changed

+1108
-45
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ testbin/*
1111
bundle/*
1212
bundle.Dockerfile
1313
config/operator/deployment/kustomization.yaml
14+
# Generated certificate ConfigMaps for kustomize
15+
config/samples/tls/custom_route_cert/placement-cert-data.yaml
1416

1517
# Test binary, build with `go test -c`
1618
*.test
Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
resources:
22
- ../../base/openstackcontrolplane
3+
- placement-cert-data.yaml
34

45
patches:
56
- target:
@@ -9,6 +10,37 @@ patches:
910
- op: replace
1011
path: /metadata/name
1112
value: openstack
12-
- target:
13-
kind: OpenStackControlPlane
14-
path: patch.yaml
13+
14+
- path: patch.yaml
15+
16+
# Use replacements to inject cert data from ConfigMap
17+
replacements:
18+
- source:
19+
kind: ConfigMap
20+
name: placement-cert-data
21+
fieldPath: data.[tls.crt]
22+
targets:
23+
- select:
24+
kind: OpenStackControlPlane
25+
fieldPaths:
26+
- spec.placement.apiOverride.route.spec.tls.certificate
27+
28+
- source:
29+
kind: ConfigMap
30+
name: placement-cert-data
31+
fieldPath: data.[tls.key]
32+
targets:
33+
- select:
34+
kind: OpenStackControlPlane
35+
fieldPaths:
36+
- spec.placement.apiOverride.route.spec.tls.key
37+
38+
- source:
39+
kind: ConfigMap
40+
name: placement-cert-data
41+
fieldPath: data.[ca.crt]
42+
targets:
43+
- select:
44+
kind: OpenStackControlPlane
45+
fieldPaths:
46+
- spec.placement.apiOverride.route.spec.tls.caCertificate

config/samples/tls/custom_route_cert/patch.yaml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ spec:
1212
route:
1313
spec:
1414
tls:
15-
certificate: |
16-
CERT123
17-
key: |
18-
KEY123
19-
caCertificate: |
20-
CACERT123
15+
certificate: ""
16+
key: ""
17+
caCertificate: ""
2118
termination: reencrypt

tests/kuttl/common/README.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Common Certificate Management Utilities
2+
3+
This directory contains shared utilities for creating and managing custom TLS certificates using cert-manager in OpenStack operator kuttl tests.
4+
5+
## Files
6+
7+
- **`create_custom_cert.sh`** - Main script with bash functions for certificate creation
8+
- **`osp_check_route_cert.sh`** - Verification script for route certificates
9+
- **`verify_route_override_certs.sh`** - Verification script for OpenStackControlPlane overrides
10+
- **`prepare_placement_certs.sh`** - Helper script to create ConfigMap from certificates
11+
- **`custom-ingress-issuer.yaml`** - YAML template for custom ingress issuer
12+
- **`custom-internal-issuer.yaml`** - YAML template for custom internal issuer
13+
- **`custom-barbican-route.yaml`** - Pre-generated barbican route secret
14+
- **`custom-ca.yaml`** - Custom CA bundle for testing
15+
16+
## Quick Reference
17+
18+
### Create Certificates for Barbican and Placement
19+
20+
```bash
21+
source ../../common/create_custom_cert.sh
22+
INGRESS_DOMAIN=$(oc get ingresses.config.openshift.io cluster -o jsonpath='{.spec.domain}')
23+
create_barbican_placement_routes "${INGRESS_DOMAIN}" "${NAMESPACE}"
24+
```
25+
26+
### Main Functions
27+
28+
| Function | Usage | Description |
29+
|----------|-------|-------------|
30+
| `create_barbican_placement_routes` | `<ingress-domain> [namespace]` | One-command setup for barbican and placement |
31+
| `create_service_route_certificate` | `<service-name> <ingress-domain> [namespace]` | Create certificate for any service |
32+
| `create_custom_issuer` | `<issuer-name> [namespace]` | Create root CA and issuer |
33+
| `create_wildcard_certificate` | `<cert-name> <domain> [issuer-name] [namespace]` | Create wildcard certificate |
34+
| `setup_custom_certificate_infrastructure` | `[namespace]` | Setup complete cert infrastructure |
35+
| `cleanup_custom_certificates` | `[namespace]` | Remove all custom certificates |
36+
37+
### Verification Functions
38+
39+
```bash
40+
# Verify route certificate matches secret
41+
bash ../../common/osp_check_route_cert.sh <service-name>
42+
43+
# Verify OpenStackControlPlane override matches secret
44+
bash ../../common/verify_route_override_certs.sh <service-name>
45+
```
46+
47+
## Certificate Specifications
48+
49+
### Root CA Certificate
50+
- **Algorithm:** ECDSA P-256
51+
- **Duration:** 87600h (10 years)
52+
- **Usage:** Certificate Sign, CRL Sign
53+
- **IsCA:** true
54+
55+
### Service Certificates
56+
- **Algorithm:** ECDSA P-256
57+
- **Duration:** 8760h (1 year)
58+
- **Renewal:** 720h (30 days) before expiration
59+
- **Usage:** Server Auth, Client Auth
60+
- **DNS Names:** `*.domain.com`, `domain.com`
61+
62+
## Usage in Kuttl Tests
63+
64+
```yaml
65+
apiVersion: kuttl.dev/v1beta1
66+
kind: TestStep
67+
commands:
68+
- script: |
69+
source ../../common/create_custom_cert.sh
70+
INGRESS_DOMAIN=$(oc get ingresses.config.openshift.io cluster -o jsonpath='{.spec.domain}')
71+
create_barbican_placement_routes "${INGRESS_DOMAIN}" "${NAMESPACE}"
72+
```
73+
74+
## Examples
75+
76+
### Create Certificates for Any Service
77+
78+
```bash
79+
source ../../common/create_custom_cert.sh
80+
81+
# For keystone
82+
create_service_route_certificate "keystone" "apps-crc.testing" "openstack-kuttl-tests"
83+
84+
# For glance
85+
create_service_route_certificate "glance" "apps-crc.testing" "openstack-kuttl-tests"
86+
```
87+
88+
### Setup Complete Infrastructure
89+
90+
```bash
91+
# Creates both ingress and internal issuers
92+
setup_custom_certificate_infrastructure "openstack-kuttl-tests"
93+
```
94+
95+
### Cleanup
96+
97+
```bash
98+
# Remove all custom certificates and issuers
99+
cleanup_custom_certificates "openstack-kuttl-tests"
100+
```
101+
102+
## Security Considerations
103+
104+
⚠️ **Important:** These certificates are for **TESTING PURPOSES ONLY**
105+
106+
## Complete Documentation
107+
108+
For detailed documentation including test flow, architecture, troubleshooting, and implementation details, see:
109+
110+
**[tests/kuttl/tests/ctlplane-tls-custom-route/README.md](../tests/ctlplane-tls-custom-route/README.md)**
111+
112+
## Related Documentation
113+
114+
- [Cert-Manager Documentation](https://cert-manager.io/docs/)
115+
- [ctlplane-tls-custom-route Test](../tests/ctlplane-tls-custom-route/README.md)

0 commit comments

Comments
 (0)