Skip to content

Commit 35cd334

Browse files
authored
Add resource-based permissions support for Lambda aliases (#161)
this commit adds support for managing Lambda resource based permissions directly on aliases. Now users can declaratively define, update, and remove permissions for Lambda functions accessed through aliases. The implementation leverages the AWS::Lambda `AddPermission` and `RemovePermission` APIs to synchronize the desired permissions state defined in the CRD with the actual alias permisions in AWS. Example alias: ```yaml apiVersion: lambda.services.k8s.aws/v1alpha1 kind: Alias metadata: name: alias1 spec: name: alias1 functionName: test-function-w-ack functionVersion: $LATEST description: some alias permissions: - statementID: "1" action: lambda:InvokeFunction principal: s3.amazonaws.com sourceARN: arn:aws:s3:::mybucket - statementID: "2" action: lambda:InvokeFunction principal: s3.amazonaws.com sourceARN: arn:aws:s3:::mybucket2 - statementID: "3" action: lambda:InvokeFunction principal: s3.amazonaws.com sourceARN: arn:aws:s3:::mybucket3 - statementID: "4" action: lambda:InvokeFunction principal: s3.amazonaws.com sourceARN: arn:aws:s3:::mybucket4 ``` By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 731aff1 commit 35cd334

18 files changed

+684
-32
lines changed
+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
ack_generate_info:
2-
build_date: "2025-02-20T18:13:42Z"
3-
build_hash: a326346bd3a6973254d247c9ab2dc76790c36241
2+
build_date: "2025-03-25T01:59:31Z"
3+
build_hash: 3722729cebe6d3c03c7e442655ef0846f91566a2
44
go_version: go1.24.0
5-
version: v0.43.2
6-
api_directory_checksum: 086df7708184fcedddb2910d4980cdff3bf9de8f
5+
version: v0.43.2-7-g3722729
6+
api_directory_checksum: b37edb8bba9d3847d4bdf1e842b7a597821c8c37
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.32.6
99
generator_config_info:
10-
file_checksum: 7e92f95044b114e8b39e4b28ea82afbdc992a3cb
10+
file_checksum: 3dbfbaabdb68f05226834184bacb6be1028ba38d
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

apis/v1alpha1/alias.go

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha1/generator.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ ignore:
2727
- PublishVersionOutput.LoggingConfig
2828
- PublishVersionOutput.RuntimeVersionConfig
2929
- VpcConfig.Ipv6AllowedForDualStack
30+
- AddPermissionInput.FunctionName # We grab this from the Alias resource
31+
- AddPermissionInput.Qualifier # We grab this from the Alias resource
3032
operations:
3133
GetFunction:
3234
output_wrapper_field_path: Configuration
@@ -161,7 +163,14 @@ resources:
161163
from:
162164
operation: PutProvisionedConcurrencyConfig
163165
path: .
166+
Permissions:
167+
custom_field:
168+
list_of: AddPermissionInput
169+
compare:
170+
is_ignored: true
164171
hooks:
172+
delta_pre_compare:
173+
code: customPreCompare(delta, a, b)
165174
sdk_update_pre_build_request:
166175
template_path: hooks/alias/sdk_update_pre_build_request.go.tpl
167176
sdk_read_one_post_set_output:

apis/v1alpha1/types.go

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha1/zz_generated.deepcopy.go

+71
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/lambda.services.k8s.aws_aliases.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,31 @@ spec:
132132
name:
133133
description: The name of the alias.
134134
type: string
135+
permissions:
136+
description: Permissions configures a set of Lambda permissions to
137+
grant to an alias.
138+
items:
139+
properties:
140+
action:
141+
type: string
142+
eventSourceToken:
143+
type: string
144+
functionURLAuthType:
145+
type: string
146+
principal:
147+
type: string
148+
principalOrgID:
149+
type: string
150+
revisionID:
151+
type: string
152+
sourceARN:
153+
type: string
154+
sourceAccount:
155+
type: string
156+
statementID:
157+
type: string
158+
type: object
159+
type: array
135160
provisionedConcurrencyConfig:
136161
description: |-
137162
Configures provisioned concurrency to a function's alias

documentation.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ resources:
2121
The maximum number of times to retry when the function returns an error.
2222
Alias:
2323
fields:
24+
Permissions:
25+
prepend: Permissions configures a set of Lambda permissions to grant to an alias.
2426
FunctionEventInvokeConfig:
2527
prepend: |
2628
Configures options for asynchronous invocation on an alias.

generator.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ ignore:
2727
- PublishVersionOutput.LoggingConfig
2828
- PublishVersionOutput.RuntimeVersionConfig
2929
- VpcConfig.Ipv6AllowedForDualStack
30+
- AddPermissionInput.FunctionName # We grab this from the Alias resource
31+
- AddPermissionInput.Qualifier # We grab this from the Alias resource
3032
operations:
3133
GetFunction:
3234
output_wrapper_field_path: Configuration
@@ -161,7 +163,14 @@ resources:
161163
from:
162164
operation: PutProvisionedConcurrencyConfig
163165
path: .
166+
Permissions:
167+
custom_field:
168+
list_of: AddPermissionInput
169+
compare:
170+
is_ignored: true
164171
hooks:
172+
delta_pre_compare:
173+
code: customPreCompare(delta, a, b)
165174
sdk_update_pre_build_request:
166175
template_path: hooks/alias/sdk_update_pre_build_request.go.tpl
167176
sdk_read_one_post_set_output:

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ require (
1717
github.com/aws/aws-sdk-go-v2/service/lambda v1.69.8
1818
github.com/aws/smithy-go v1.22.2
1919
github.com/go-logr/logr v1.4.2
20+
github.com/micahhausler/aws-iam-policy v0.4.2
2021
github.com/spf13/pflag v1.0.5
2122
k8s.io/api v0.31.0
2223
k8s.io/apimachinery v0.31.0

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
126126
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
127127
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
128128
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
129+
github.com/micahhausler/aws-iam-policy v0.4.2 h1:HF7bERLnpqEmffV9/wTT4jZ7TbSNVk0JbpXo1Cj3up0=
130+
github.com/micahhausler/aws-iam-policy v0.4.2/go.mod h1:Ojgst9ZFn+VEEJpqtuw/LxVGqEf2+hwWBlkYWvF/XWM=
129131
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
130132
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
131133
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=

helm/crds/lambda.services.k8s.aws_aliases.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,31 @@ spec:
132132
name:
133133
description: The name of the alias.
134134
type: string
135+
permissions:
136+
description: Permissions configures a set of Lambda permissions to
137+
grant to an alias.
138+
items:
139+
properties:
140+
action:
141+
type: string
142+
eventSourceToken:
143+
type: string
144+
functionURLAuthType:
145+
type: string
146+
principal:
147+
type: string
148+
principalOrgID:
149+
type: string
150+
revisionID:
151+
type: string
152+
sourceARN:
153+
type: string
154+
sourceAccount:
155+
type: string
156+
statementID:
157+
type: string
158+
type: object
159+
type: array
135160
provisionedConcurrencyConfig:
136161
description: |-
137162
Configures provisioned concurrency to a function's alias

pkg/resource/alias/delta.go

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)