Skip to content

Commit a5698e2

Browse files
committed
chore: check Requirements are sane before fetching extra resources
1 parent d647850 commit a5698e2

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ RUN --mount=target=. \
4343
FROM gcr.io/distroless/static-debian12:nonroot AS image
4444
WORKDIR /
4545
COPY --from=build /function /function
46+
47+
COPY package.yaml /package.yaml
4648
EXPOSE 9443
4749
USER nonroot:nonroot
4850
ENTRYPOINT ["/function"]

fn.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1.RunFunctionRequest)
7373
// function-extra-resources does not know if it has requested the resources already or not.
7474
//
7575
// If it has and these resources are now present, proceed with verification and conversion.
76-
if req.ExtraResources == nil {
76+
if len(rsp.GetRequirements().GetExtraResources()) > 0 && req.ExtraResources == nil {
7777
f.log.Debug("No extra resources present, exiting", "requirements", rsp.GetRequirements())
7878
return rsp, nil
7979
}
@@ -124,22 +124,25 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1.RunFunctionRequest)
124124
func buildRequirements(_ *v1alpha1.Input, xr *resource.Composite) *fnv1.Requirements {
125125
extraResources := make(map[string]*fnv1.ResourceSelector)
126126
spec := xr.Resource.Object["spec"].(map[string]any)
127-
for _, permission := range spec["permissions"].([]any) {
128-
for _, principal := range permission.(map[string]any)["principals"].([]any) {
129-
user, ok := principal.(map[string]any)["user"]
130-
if ok {
131-
extraResources[user.(string)] = &fnv1.ResourceSelector{
132-
ApiVersion: "iam.aws.upbound.io/v1beta1",
133-
Kind: "User",
134-
Match: &fnv1.ResourceSelector_MatchLabels{
135-
MatchLabels: &fnv1.MatchLabels{
136-
Labels: map[string]string{
137-
"crossplane.io/claim-name": user.(string),
138-
"crossplane.io/claim-namespace": xr.Resource.Unstructured.GetNamespace(),
139-
"s3.statnett.no/account-name": spec["accountRef"].(map[string]any)["name"].(string),
127+
permissions, ok := spec["permissions"].([]any)
128+
if ok {
129+
for _, permission := range permissions {
130+
for _, principal := range permission.(map[string]any)["principals"].([]any) {
131+
user, ok := principal.(map[string]any)["user"]
132+
if ok {
133+
extraResources[user.(string)] = &fnv1.ResourceSelector{
134+
ApiVersion: "iam.aws.upbound.io/v1beta1",
135+
Kind: "User",
136+
Match: &fnv1.ResourceSelector_MatchLabels{
137+
MatchLabels: &fnv1.MatchLabels{
138+
Labels: map[string]string{
139+
"crossplane.io/claim-name": user.(string),
140+
"crossplane.io/claim-namespace": xr.Resource.Unstructured.GetNamespace(),
141+
"s3.statnett.no/account-name": spec["accountRef"].(map[string]any)["name"].(string),
142+
},
140143
},
141144
},
142-
},
145+
}
143146
}
144147
}
145148
}

package.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
apiVersion: meta.pkg.crossplane.io/v1beta1
3+
kind: Function
4+
metadata:
5+
annotations:
6+
meta.crossplane.io/description: "a"
7+
meta.crossplane.io/license: "a"
8+
meta.crossplane.io/maintainer: "a"
9+
meta.crossplane.io/readme: "a"
10+
meta.crossplane.io/source: "a"
11+
creationTimestamp: null
12+
name: s3-user-arn
13+
spec: {}

0 commit comments

Comments
 (0)