@@ -4,6 +4,7 @@ package proxy
4
4
5
5
import (
6
6
"context"
7
+ "crypto/x509"
7
8
"fmt"
8
9
"path"
9
10
"path/filepath"
@@ -12,6 +13,8 @@ import (
12
13
"github.com/Dynatrace/dynatrace-operator/pkg/api/shared/value"
13
14
"github.com/Dynatrace/dynatrace-operator/pkg/api/v1beta4/dynakube"
14
15
"github.com/Dynatrace/dynatrace-operator/pkg/injection/codemodule/installer/common"
16
+ "github.com/Dynatrace/dynatrace-operator/pkg/util/certificates"
17
+ "github.com/Dynatrace/dynatrace-operator/pkg/util/timeprovider"
15
18
"github.com/Dynatrace/dynatrace-operator/pkg/webhook"
16
19
oamutation "github.com/Dynatrace/dynatrace-operator/pkg/webhook/mutation/pod/v1/oneagent"
17
20
"github.com/Dynatrace/dynatrace-operator/test/helpers"
@@ -20,6 +23,7 @@ import (
20
23
"github.com/Dynatrace/dynatrace-operator/test/helpers/kubeobjects/manifests"
21
24
"github.com/Dynatrace/dynatrace-operator/test/helpers/kubeobjects/namespace"
22
25
"github.com/Dynatrace/dynatrace-operator/test/helpers/kubeobjects/pod"
26
+ "github.com/Dynatrace/dynatrace-operator/test/helpers/kubeobjects/secret"
23
27
"github.com/Dynatrace/dynatrace-operator/test/helpers/platform"
24
28
"github.com/Dynatrace/dynatrace-operator/test/helpers/sample"
25
29
"github.com/Dynatrace/dynatrace-operator/test/helpers/shell"
@@ -45,9 +49,10 @@ const (
45
49
var (
46
50
dynatraceNetworkPolicy = path .Join (project .TestDataDir (), "network/dynatrace-denial.yaml" )
47
51
48
- proxyDeploymentPath = path .Join (project .TestDataDir (), "network/proxy.yaml" )
49
- proxyWithCustomCADeploymentPath = path .Join (project .TestDataDir (), "network/proxy-ssl.yaml" )
50
- proxySCCPath = path .Join (project .TestDataDir (), "network/proxy-scc.yaml" )
52
+ proxyDeploymentPath = path .Join (project .TestDataDir (), "network/proxy.yaml" )
53
+ proxyWithCustomCADeploymentPath = path .Join (project .TestDataDir (), "network/proxy-ssl.yaml" )
54
+ proxyNamespaceWithCustomCADeploymentPath = path .Join (project .TestDataDir (), "network/proxy-ssl-namespace.yaml" )
55
+ proxySCCPath = path .Join (project .TestDataDir (), "network/proxy-scc.yaml" )
51
56
52
57
ProxySpec = & value.Source {
53
58
Value : "http://squid.proxy.svc.cluster.local:3128" ,
@@ -67,8 +72,11 @@ func SetupProxyWithTeardown(t *testing.T, builder *features.FeatureBuilder, test
67
72
}
68
73
}
69
74
70
- func SetupProxyWithCustomCAandTeardown (t * testing.T , builder * features.FeatureBuilder , testDynakube dynakube.DynaKube ) {
75
+ func SetupProxyWithCustomCAandTeardown (t * testing.T , builder * features.FeatureBuilder , testDynakube dynakube.DynaKube , pemCert [] byte , pemPk [] byte ) {
71
76
if testDynakube .Spec .Proxy != nil {
77
+ builder .Assess ("create proxy namespace" , helpers .ToFeatureFunc (manifests .InstallFromFile (proxyNamespaceWithCustomCADeploymentPath ), true ))
78
+ proxySecret := createProxyTLSSecret (pemCert , pemPk )
79
+ builder .Assess ("create proxy TLS secret" , secret .Create (proxySecret ))
72
80
installProxySCC (builder , t )
73
81
builder .Assess ("install proxy" , helpers .ToFeatureFunc (manifests .InstallFromFile (proxyWithCustomCADeploymentPath ), true ))
74
82
builder .Assess ("proxy started" , helpers .ToFeatureFunc (deployment .WaitFor (proxyDeploymentName , proxyNamespaceName ), true ))
@@ -141,3 +149,43 @@ func CheckRuxitAgentProcFileHasProxySetting(sampleApp sample.App, proxySpec *val
141
149
func getWebhookServiceUrl (dk dynakube.DynaKube ) string {
142
150
return fmt .Sprintf ("%s.%s.svc.cluster.local" , webhook .DeploymentName , dk .Namespace )
143
151
}
152
+
153
+ func createProxyTLSSecret (pemCert []byte , pemPK []byte ) corev1.Secret {
154
+ pem := pemCert
155
+ pem = append (pem , byte ('\n' ))
156
+ pem = append (pem , pemPK ... )
157
+
158
+ secretData := map [string ][]byte {
159
+ "squid-ca-cert.pem" : pem ,
160
+ }
161
+
162
+ proxySecret := secret .New ("proxy-ca" , "proxy" , secretData )
163
+ proxySecret .Type = corev1 .SecretTypeOpaque
164
+
165
+ return proxySecret
166
+ }
167
+
168
+ func CreateProxyTLSCertAndKey () (pemCert []byte , pemKey []byte , err error ) {
169
+ cert , err := certificates .New (timeprovider .New ())
170
+ if err != nil {
171
+ return nil , nil , err
172
+ }
173
+
174
+ cert .Cert .DNSNames = []string {
175
+ "squid.proxy" ,
176
+ "squid.proxy.svc" ,
177
+ "squid.proxy.svc.cluster.local" ,
178
+ }
179
+ cert .Cert .KeyUsage = x509 .KeyUsageKeyEncipherment | x509 .KeyUsageDataEncipherment
180
+ cert .Cert .ExtKeyUsage = []x509.ExtKeyUsage {x509 .ExtKeyUsageServerAuth }
181
+ cert .Cert .Subject .CommonName = "squid.proxy"
182
+ cert .Cert .IsCA = true
183
+ cert .Cert .BasicConstraintsValid = true
184
+
185
+ err = cert .SelfSign ()
186
+ if err != nil {
187
+ return nil , nil , err
188
+ }
189
+
190
+ return cert .ToPEM ()
191
+ }
0 commit comments