@@ -20,32 +20,35 @@ import (
20
20
"encoding/json"
21
21
"fmt"
22
22
"io/ioutil"
23
+ "log"
24
+ "net/http"
25
+ "os"
26
+ "strconv"
27
+ "strings"
28
+
23
29
"k8s.io/api/admission/v1beta1"
24
30
corev1 "k8s.io/api/core/v1"
25
31
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26
32
"k8s.io/apimachinery/pkg/labels"
27
33
"k8s.io/client-go/kubernetes"
28
34
corev1Types "k8s.io/client-go/kubernetes/typed/core/v1"
29
- "log"
30
- "net/http"
31
- "os"
32
- "strings"
33
- "strconv"
34
35
)
35
36
36
37
const (
37
- signingProxyWebhookAnnotationHostKey = "sidecar.aws.signing-proxy/host"
38
- signingProxyWebhookAnnotationInjectKey = "sidecar.aws.signing-proxy/inject"
39
- signingProxyWebhookAnnotationNameKey = "sidecar.aws.signing-proxy/name"
40
- signingProxyWebhookAnnotationRegionKey = "sidecar.aws.signing-proxy/region"
41
- signingProxyWebhookAnnotationRoleArnKey = "sidecar.aws.signing-proxy/role-arn"
42
- signingProxyWebhookAnnotationStatusKey = "sidecar.aws.signing-proxy/status"
38
+ signingProxyWebhookAnnotationSchemeKey = "sidecar.aws.signing-proxy/upstream-url-scheme"
39
+ signingProxyWebhookAnnotationHostKey = "sidecar.aws.signing-proxy/host"
40
+ signingProxyWebhookAnnotationInjectKey = "sidecar.aws.signing-proxy/inject"
41
+ signingProxyWebhookAnnotationNameKey = "sidecar.aws.signing-proxy/name"
42
+ signingProxyWebhookAnnotationRegionKey = "sidecar.aws.signing-proxy/region"
43
+ signingProxyWebhookAnnotationRoleArnKey = "sidecar.aws.signing-proxy/role-arn"
44
+ signingProxyWebhookAnnotationStatusKey = "sidecar.aws.signing-proxy/status"
43
45
signingProxyWebhookAnnotationUnsignedPayloadKey = "sidecar.aws.signing-proxy/unsigned-payload"
44
- signingProxyWebhookLabelHostKey = "sidecar-host"
45
- signingProxyWebhookLabelNameKey = "sidecar-name"
46
- signingProxyWebhookLabelRegionKey = "sidecar-region"
47
- signingProxyWebhookLabelRoleArnKey = "sidecar-role-arn"
48
- signingProxyWebhookLabelUnsignedPayloadKey = "sidecar-unsigned-payload"
46
+ signingProxyWebhookLabelSchemeKey = "sidecar-upstream-url-scheme"
47
+ signingProxyWebhookLabelHostKey = "sidecar-host"
48
+ signingProxyWebhookLabelNameKey = "sidecar-name"
49
+ signingProxyWebhookLabelRegionKey = "sidecar-region"
50
+ signingProxyWebhookLabelRoleArnKey = "sidecar-role-arn"
51
+ signingProxyWebhookLabelUnsignedPayloadKey = "sidecar-unsigned-payload"
49
52
)
50
53
51
54
var (
@@ -157,13 +160,13 @@ func (whsvr *WebhookServer) mutate(ctx context.Context, admissionReview *v1beta1
157
160
158
161
var patchOperations []PatchOperation
159
162
160
- host , name , region , unsignedPayload := whsvr .getUpstreamEndpointParameters (nsLabels , & pod .ObjectMeta )
163
+ host , name , region , unsignedPayload , scheme := whsvr .getUpstreamEndpointParameters (nsLabels , & pod .ObjectMeta )
161
164
162
- sidecarArgs := []string {"--name" , name , "--region" , region , "--host" , host , "--port" , ":8005" }
165
+ sidecarArgs := []string {"--name" , name , "--region" , region , "--host" , host , "--port" , ":8005" , "--upstream-url-scheme" , scheme }
163
166
s , _ := strconv .ParseBool (unsignedPayload )
164
-
165
- if ( s ) {
166
- sidecarArgs = []string {"--name" , name , "--region" , region , "--host" , host , "--port" , ":8005" , "--unsigned-payload" }
167
+
168
+ if s {
169
+ sidecarArgs = []string {"--name" , name , "--region" , region , "--host" , host , "--port" , ":8005" , "--unsigned-payload" , "--upstream-url-scheme" , scheme }
167
170
}
168
171
169
172
roleArn := whsvr .getRoleArn (nsLabels , & pod .ObjectMeta )
@@ -268,7 +271,7 @@ func (whsvr *WebhookServer) shouldMutate(nsLabels map[string]string, podMetadata
268
271
return annotationInject
269
272
}
270
273
271
- func (whsvr * WebhookServer ) getUpstreamEndpointParameters (nsLabels map [string ]string , podMetadata * metav1.ObjectMeta ) (string , string , string , string ) {
274
+ func (whsvr * WebhookServer ) getUpstreamEndpointParameters (nsLabels map [string ]string , podMetadata * metav1.ObjectMeta ) (string , string , string , string , string ) {
272
275
annotations := podMetadata .GetAnnotations ()
273
276
274
277
if annotations == nil {
@@ -285,13 +288,14 @@ func (whsvr *WebhookServer) getUpstreamEndpointParameters(nsLabels map[string]st
285
288
}
286
289
287
290
if labelInject {
288
- return extractParameters (host , nsLabels [signingProxyWebhookLabelNameKey ], nsLabels [signingProxyWebhookLabelRegionKey ], nsLabels [signingProxyWebhookLabelUnsignedPayloadKey ])
291
+ return extractParameters (host , nsLabels [signingProxyWebhookLabelNameKey ], nsLabels [signingProxyWebhookLabelRegionKey ], nsLabels [signingProxyWebhookLabelUnsignedPayloadKey ], nsLabels [ signingProxyWebhookLabelSchemeKey ] )
289
292
}
290
293
291
- return extractParameters (host , annotations [signingProxyWebhookAnnotationNameKey ], annotations [signingProxyWebhookAnnotationRegionKey ], annotations [signingProxyWebhookAnnotationUnsignedPayloadKey ])
294
+ return extractParameters (host , annotations [signingProxyWebhookAnnotationNameKey ], annotations [signingProxyWebhookAnnotationRegionKey ], annotations [signingProxyWebhookAnnotationUnsignedPayloadKey ], annotations [ signingProxyWebhookAnnotationSchemeKey ] )
292
295
}
293
296
294
- func extractParameters (host string , name string , region string , unsignedPayload string ) (string , string , string , string ) {
297
+ func extractParameters (host string , name string , region string , unsignedPayload string , upstreamUrlScheme string ) (string , string , string , string , string ) {
298
+
295
299
if strings .TrimSpace (name ) == "" {
296
300
name = host [:strings .IndexByte (host , '.' )]
297
301
}
@@ -302,7 +306,13 @@ func extractParameters(host string, name string, region string, unsignedPayload
302
306
region = hostModified [:strings .IndexByte (hostModified , '.' )]
303
307
}
304
308
305
- return host , name , region , unsignedPayload
309
+ upstreamUrlScheme = strings .ToLower (upstreamUrlScheme )
310
+
311
+ if upstreamUrlScheme == "" || (upstreamUrlScheme != "http" && upstreamUrlScheme != "https" ) {
312
+ upstreamUrlScheme = "https"
313
+ }
314
+
315
+ return host , name , region , unsignedPayload , upstreamUrlScheme
306
316
}
307
317
308
318
func (whsvr * WebhookServer ) getRoleArn (nsLabels map [string ]string , podMetadata * metav1.ObjectMeta ) string {
0 commit comments