Skip to content

Commit 9435389

Browse files
committed
Prevent the controller from calling GetFunctionCodeSigningConfig when a functions packageType is Image
Functions code signing config should only be called when a function is created using an s3bucket and a key. Functions created using a container image cannot get a code signing configuration.
1 parent 597e948 commit 9435389

File tree

3 files changed

+72
-11
lines changed

3 files changed

+72
-11
lines changed

pkg/resource/function/hooks.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -500,17 +500,19 @@ func (rm *resourceManager) setResourceAdditionalFields(
500500
}
501501
ko.Spec.ReservedConcurrentExecutions = getFunctionConcurrencyOutput.ReservedConcurrentExecutions
502502

503-
var getFunctionCodeSigningConfigOutput *svcsdk.GetFunctionCodeSigningConfigOutput
504-
getFunctionCodeSigningConfigOutput, err = rm.sdkapi.GetFunctionCodeSigningConfigWithContext(
505-
ctx,
506-
&svcsdk.GetFunctionCodeSigningConfigInput{
507-
FunctionName: ko.Spec.Name,
508-
},
509-
)
510-
rm.metrics.RecordAPICall("GET", "GetFunctionCodeSigningConfig", err)
511-
if err != nil {
512-
return err
503+
if ko.Spec.PackageType != nil && *ko.Spec.PackageType == "Zip" {
504+
var getFunctionCodeSigningConfigOutput *svcsdk.GetFunctionCodeSigningConfigOutput
505+
getFunctionCodeSigningConfigOutput, err = rm.sdkapi.GetFunctionCodeSigningConfigWithContext(
506+
ctx,
507+
&svcsdk.GetFunctionCodeSigningConfigInput{
508+
FunctionName: ko.Spec.Name,
509+
},
510+
)
511+
rm.metrics.RecordAPICall("GET", "GetFunctionCodeSigningConfig", err)
512+
if err != nil {
513+
return err
514+
}
515+
ko.Spec.CodeSigningConfigARN = getFunctionCodeSigningConfigOutput.CodeSigningConfigArn
513516
}
514-
ko.Spec.CodeSigningConfigARN = getFunctionCodeSigningConfigOutput.CodeSigningConfigArn
515517
return nil
516518
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: lambda.services.k8s.aws/v1alpha1
2+
kind: Function
3+
metadata:
4+
name: $FUNCTION_NAME
5+
annotations:
6+
services.k8s.aws/region: $AWS_REGION
7+
spec:
8+
name: $FUNCTION_NAME
9+
code:
10+
imageURI: busybox
11+
role: $LAMBDA_ROLE
12+
description: function created by ACK lambda-controller e2e tests
13+
packageType: image

test/e2e/tests/test_function.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,49 @@ def test_function_code_signing_config(self, lambda_client, code_signing_config):
313313
# Check Lambda function doesn't exist
314314
exists = self.function_exists(lambda_client, resource_name)
315315
assert not exists
316+
317+
def test_function_package_type_image(self, lambda_client, code_signing_config):
318+
resource_name = random_suffix_name("lambda-function", 24)
319+
320+
resources = get_bootstrap_resources()
321+
322+
replacements = REPLACEMENT_VALUES.copy()
323+
replacements["FUNCTION_NAME"] = resource_name
324+
replacements["LAMBDA_ROLE"] = resources.LambdaBasicRoleARN
325+
replacements["AWS_REGION"] = get_region()
326+
327+
# Load Lambda CR
328+
resource_data = load_lambda_resource(
329+
"function_package_type_image",
330+
additional_replacements=replacements,
331+
)
332+
logging.debug(resource_data)
333+
334+
# Create k8s resource
335+
ref = k8s.CustomResourceReference(
336+
CRD_GROUP, CRD_VERSION, RESOURCE_PLURAL,
337+
resource_name, namespace="default",
338+
)
339+
k8s.create_custom_resource(ref, resource_data)
340+
cr = k8s.wait_resource_consumed_by_controller(ref)
341+
342+
assert cr is not None
343+
assert k8s.get_resource_exists(ref)
344+
345+
time.sleep(CREATE_WAIT_AFTER_SECONDS)
346+
347+
cr = k8s.wait_resource_consumed_by_controller(ref)
348+
349+
# Check Lambda function exists
350+
exists = self.function_exists(lambda_client, resource_name)
351+
assert exists
352+
353+
# Delete k8s resource
354+
_, deleted = k8s.delete_custom_resource(ref)
355+
assert deleted is True
356+
357+
time.sleep(DELETE_WAIT_AFTER_SECONDS)
358+
359+
# Check Lambda function doesn't exist
360+
exists = self.function_exists(lambda_client, resource_name)
361+
assert not exists

0 commit comments

Comments
 (0)