@@ -5,7 +5,14 @@ package osde2etests
55
66import (
77 "context"
8+ "crypto/rand"
9+ "crypto/rsa"
10+ "crypto/x509"
11+ "crypto/x509/pkix"
12+ "encoding/pem"
813 "fmt"
14+ "math/big"
15+ "time"
916
1017 securityv1 "github.com/openshift/api/security/v1"
1118 corev1 "k8s.io/api/core/v1"
@@ -19,11 +26,11 @@ import (
1926)
2027
2128// Create test splunkforwarder CR definition
22- func makeMinimalSplunkforwarder (name string ) sfv1alpha1.SplunkForwarder {
29+ func makeMinimalSplunkforwarder (name string , namespace string ) sfv1alpha1.SplunkForwarder {
2330 return sfv1alpha1.SplunkForwarder {
2431 ObjectMeta : metav1.ObjectMeta {
2532 Name : name ,
26- Namespace : operatorNamespace ,
33+ Namespace : namespace ,
2734 },
2835 Spec : sfv1alpha1.SplunkForwarderSpec {
2936 SplunkLicenseAccepted : true ,
@@ -38,11 +45,11 @@ func makeMinimalSplunkforwarder(name string) sfv1alpha1.SplunkForwarder {
3845}
3946
4047// makeSplunkforwarderWithIndex creates a test SplunkForwarder CR with custom index settings
41- func makeSplunkforwarderWithIndex (name , path , index , sourcetype string ) sfv1alpha1.SplunkForwarder {
48+ func makeSplunkforwarderWithIndex (name , namespace , path , index , sourcetype string ) sfv1alpha1.SplunkForwarder {
4249 return sfv1alpha1.SplunkForwarder {
4350 ObjectMeta : metav1.ObjectMeta {
4451 Name : name ,
45- Namespace : operatorNamespace ,
52+ Namespace : namespace ,
4653 },
4754 Spec : sfv1alpha1.SplunkForwarderSpec {
4855 SplunkLicenseAccepted : true ,
@@ -144,35 +151,90 @@ func cleanupTestSecrets(ctx context.Context, k8s *openshift.Client, namespace st
144151 k8s .Delete (ctx , hecSecret )
145152}
146153
147- // generateSelfSignedCACert returns a PEM-encoded self-signed CA cert for testing
148- // This is a minimal test certificate - sufficient for testing secret mounting
154+ // generateSelfSignedCACert dynamically generates a PEM-encoded self-signed CA certificate
155+ // using Go's crypto packages for realistic testing
149156func generateSelfSignedCACert () string {
150- return `-----BEGIN CERTIFICATE-----
151- MIIDXTCCAkWgAwIBAgIJAKJ0qJxKLhpOMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV
152- BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX
153- aWRnaXRzIFB0eSBMdGQwHhcNMjQwMTAxMDAwMDAwWhcNMjUwMTAxMDAwMDAwWjBF
154- MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50
155- ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
156- CgKCAQEAtIb8nPQXLq6F0mGxMz6pqGm6QC7hUdXQQEH+Vv8nqNGdF2P4IxHLqY3v
157- 8cTqvCXMQvJn4mGrDFVPZqXMtHxFHI+cKXkQ9BVJdUPxP6fqMq7TI4Cv3kMhz9M3
158- -----END CERTIFICATE-----`
157+ // Generate RSA private key
158+ privateKey , err := rsa .GenerateKey (rand .Reader , 2048 )
159+ if err != nil {
160+ panic (fmt .Sprintf ("failed to generate CA private key: %v" , err ))
161+ }
162+
163+ // Create certificate template
164+ template := x509.Certificate {
165+ SerialNumber : big .NewInt (1 ),
166+ Subject : pkix.Name {
167+ Organization : []string {"Splunk E2E Test CA" },
168+ Country : []string {"US" },
169+ CommonName : "Splunk Test CA" ,
170+ },
171+ NotBefore : time .Now (),
172+ NotAfter : time .Now ().Add (30 * 24 * time .Hour ), // Valid for 1 month
173+ KeyUsage : x509 .KeyUsageKeyEncipherment | x509 .KeyUsageDigitalSignature | x509 .KeyUsageCertSign ,
174+ ExtKeyUsage : []x509.ExtKeyUsage {x509 .ExtKeyUsageServerAuth , x509 .ExtKeyUsageClientAuth },
175+ BasicConstraintsValid : true ,
176+ IsCA : true ,
177+ }
178+
179+ // Create self-signed certificate
180+ certDER , err := x509 .CreateCertificate (rand .Reader , & template , & template , & privateKey .PublicKey , privateKey )
181+ if err != nil {
182+ panic (fmt .Sprintf ("failed to create CA certificate: %v" , err ))
183+ }
184+
185+ // Encode certificate to PEM
186+ certPEM := pem .EncodeToMemory (& pem.Block {
187+ Type : "CERTIFICATE" ,
188+ Bytes : certDER ,
189+ })
190+
191+ return string (certPEM )
159192}
160193
161- // generateSelfSignedServerCert returns a PEM-encoded server cert for testing
194+ // generateSelfSignedServerCert dynamically generates a PEM-encoded server certificate
195+ // with both certificate and private key for Splunk mTLS authentication
162196func generateSelfSignedServerCert () string {
163- return `-----BEGIN CERTIFICATE-----
164- MIIDXTCCAkWgAwIBAgIJAKJ0qJxKLhpPMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV
165- BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX
166- aWRnaXRzIFB0eSBMdGQwHhcNMjQwMTAxMDAwMDAwWhcNMjUwMTAxMDAwMDAwWjBF
167- MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50
168- ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
169- CgKCAQEAtIb8nPQXLq6F0mGxMz6pqGm6QC7hUdXQQEH+Vv8nqNGdF2P4IxHLqY3v
170- -----END CERTIFICATE-----
171- -----BEGIN PRIVATE KEY-----
172- MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC0hvy89Bcur4XS
173- YbEzPqmoabpALuFR1dBAQf5W/yeo0Z0XY/gjEcupje/xxOq8JcxC8mfiYasMVU9m
174- pcy0fEUcj5wpeRD0FUl1Q/E/p+oyrtMjgK/eQyHP0zc=
175- -----END PRIVATE KEY-----`
197+ // Generate RSA private key
198+ privateKey , err := rsa .GenerateKey (rand .Reader , 2048 )
199+ if err != nil {
200+ panic (fmt .Sprintf ("failed to generate server private key: %v" , err ))
201+ }
202+
203+ // Create certificate template
204+ template := x509.Certificate {
205+ SerialNumber : big .NewInt (2 ),
206+ Subject : pkix.Name {
207+ Organization : []string {"Splunk E2E Test Server" },
208+ Country : []string {"US" },
209+ CommonName : "splunk-forwarder-test.example.com" ,
210+ },
211+ NotBefore : time .Now (),
212+ NotAfter : time .Now ().Add (30 * 24 * time .Hour ), // Valid for 1 month
213+ KeyUsage : x509 .KeyUsageKeyEncipherment | x509 .KeyUsageDigitalSignature ,
214+ ExtKeyUsage : []x509.ExtKeyUsage {x509 .ExtKeyUsageServerAuth , x509 .ExtKeyUsageClientAuth },
215+ DNSNames : []string {"splunk-forwarder-test.example.com" , "localhost" },
216+ }
217+
218+ // Create self-signed certificate (in production, this would be signed by CA)
219+ certDER , err := x509 .CreateCertificate (rand .Reader , & template , & template , & privateKey .PublicKey , privateKey )
220+ if err != nil {
221+ panic (fmt .Sprintf ("failed to create server certificate: %v" , err ))
222+ }
223+
224+ // Encode certificate to PEM
225+ certPEM := pem .EncodeToMemory (& pem.Block {
226+ Type : "CERTIFICATE" ,
227+ Bytes : certDER ,
228+ })
229+
230+ // Encode private key to PEM
231+ privateKeyPEM := pem .EncodeToMemory (& pem.Block {
232+ Type : "RSA PRIVATE KEY" ,
233+ Bytes : x509 .MarshalPKCS1PrivateKey (privateKey ),
234+ })
235+
236+ // Return combined certificate and private key
237+ return string (certPEM ) + string (privateKeyPEM )
176238}
177239
178240// generateMTLSOutputsConf returns outputs.conf content for mTLS mode
@@ -181,7 +243,7 @@ func generateMTLSOutputsConf() string {
181243defaultGroup = default-autolb-group
182244
183245[tcpout:default-autolb-group]
184- server = splunk.example.com:9997
246+ server = splunk-forwarder-test .example.com:9997
185247clientCert = $SPLUNK_HOME/etc/apps/splunkauth/default/server.pem
186248sslCertPath = $SPLUNK_HOME/etc/apps/splunkauth/default/server.pem
187249sslRootCAPath = $SPLUNK_HOME/etc/apps/splunkauth/default/cacert.pem
@@ -190,11 +252,18 @@ sslVerifyServerCert = false`
190252}
191253
192254// generateHECOutputsConf returns outputs.conf content for HEC mode
255+ // with a realistic HEC token format (UUID) for testing
193256func generateHECOutputsConf () string {
194257 return `[http]
195- httpEventCollectorToken = test-hec-token-12345
196- uri = http://mock-hec-server:8088
197- disabled = 0`
258+ httpEventCollectorToken = 12345678-1234-5678-1234-567812345678
259+ uri = https://splunk-hec.example.com:8088/services/collector/event
260+ disabled = 0
261+ useACK = true
262+ token = 12345678-1234-5678-1234-567812345678
263+
264+ [tcpout]
265+ defaultGroup = nothing
266+ disabled = true`
198267}
199268
200269// generateLimitsConf returns limits.conf content for testing
0 commit comments