Skip to content

Commit acd995e

Browse files
URL decode Role AssumeRolePolicyDocument (#28)
Description of changes: The response from creating or reading a `Role` encodes the `AssumeRolePolicyDocument` with URL encoding (any non-alphanumeric character is converted to hex). When attempting to update the role with the encoded string, the API returns an error. This pull request adds hook code to convert it back into a multiline string so that it matches the original spec. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent e280311 commit acd995e

File tree

8 files changed

+1090
-7
lines changed

8 files changed

+1090
-7
lines changed

apis/v1alpha1/ack-generate-metadata.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
ack_generate_info:
2-
build_date: "2022-04-15T17:26:33Z"
3-
build_hash: 50c64871bcaf88b9ee200eb8d6b8245fa8f675eb
4-
go_version: go1.17.5
5-
version: v0.18.4
2+
build_date: "2022-05-12T22:56:43Z"
3+
build_hash: c651d2bb60694df1f7a5dad823258472a1a6fc8a
4+
go_version: go1.18.1
5+
version: v0.18.4-12-gc651d2b
66
api_directory_checksum: 7d8d584cdaec82ab61d867fc030cb9bb45ac706f
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.42.0

go.local.mod

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
module github.com/aws-controllers-k8s/iam-controller
2+
3+
go 1.17
4+
5+
replace github.com/aws-controllers-k8s/runtime => ../runtime
6+
7+
require (
8+
github.com/aws-controllers-k8s/runtime v0.0.0
9+
github.com/aws/aws-sdk-go v1.42.0
10+
github.com/go-logr/logr v1.2.0
11+
github.com/spf13/pflag v1.0.5
12+
k8s.io/api v0.23.0
13+
k8s.io/apimachinery v0.23.0
14+
k8s.io/client-go v0.23.0
15+
sigs.k8s.io/controller-runtime v0.11.0
16+
)
17+
18+
require (
19+
github.com/beorn7/perks v1.0.1 // indirect
20+
github.com/cenkalti/backoff/v4 v4.1.2 // indirect
21+
github.com/cespare/xxhash/v2 v2.1.1 // indirect
22+
github.com/davecgh/go-spew v1.1.1 // indirect
23+
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
24+
github.com/fsnotify/fsnotify v1.5.1 // indirect
25+
github.com/go-logr/zapr v1.2.0 // indirect
26+
github.com/gogo/protobuf v1.3.2 // indirect
27+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
28+
github.com/golang/protobuf v1.5.2 // indirect
29+
github.com/google/go-cmp v0.5.5 // indirect
30+
github.com/google/gofuzz v1.1.0 // indirect
31+
github.com/google/uuid v1.1.2 // indirect
32+
github.com/googleapis/gnostic v0.5.5 // indirect
33+
github.com/imdario/mergo v0.3.12 // indirect
34+
github.com/itchyny/gojq v0.12.6 // indirect
35+
github.com/itchyny/timefmt-go v0.1.3 // indirect
36+
github.com/jaypipes/envutil v1.0.0 // indirect
37+
github.com/jmespath/go-jmespath v0.4.0 // indirect
38+
github.com/json-iterator/go v1.1.12 // indirect
39+
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
40+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
41+
github.com/modern-go/reflect2 v1.0.2 // indirect
42+
github.com/pkg/errors v0.9.1 // indirect
43+
github.com/prometheus/client_golang v1.11.0 // indirect
44+
github.com/prometheus/client_model v0.2.0 // indirect
45+
github.com/prometheus/common v0.28.0 // indirect
46+
github.com/prometheus/procfs v0.6.0 // indirect
47+
go.uber.org/atomic v1.7.0 // indirect
48+
go.uber.org/multierr v1.6.0 // indirect
49+
go.uber.org/zap v1.19.1 // indirect
50+
golang.org/x/net v0.0.0-20210825183410-e898025ed96a // indirect
51+
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
52+
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881 // indirect
53+
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
54+
golang.org/x/text v0.3.7 // indirect
55+
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
56+
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
57+
google.golang.org/appengine v1.6.7 // indirect
58+
google.golang.org/protobuf v1.27.1 // indirect
59+
gopkg.in/inf.v0 v0.9.1 // indirect
60+
gopkg.in/yaml.v2 v2.4.0 // indirect
61+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
62+
k8s.io/apiextensions-apiserver v0.23.0 // indirect
63+
k8s.io/component-base v0.23.0 // indirect
64+
k8s.io/klog/v2 v2.30.0 // indirect
65+
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
66+
k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b // indirect
67+
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
68+
sigs.k8s.io/structured-merge-diff/v4 v4.2.0 // indirect
69+
sigs.k8s.io/yaml v1.3.0 // indirect
70+
)

go.local.sum

Lines changed: 969 additions & 0 deletions
Large diffs are not rendered by default.

pkg/resource/role/hooks.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package role
1515

1616
import (
1717
"context"
18+
"net/url"
1819

1920
ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log"
2021
ackutil "github.com/aws-controllers-k8s/runtime/pkg/util"
@@ -275,3 +276,7 @@ func (rm *resourceManager) removeTags(
275276
rm.metrics.RecordAPICall("DELETE", "UntagRole", err)
276277
return err
277278
}
279+
280+
func decodeAssumeDocument(encoded string) (string, error) {
281+
return url.QueryUnescape(encoded)
282+
}

pkg/resource/role/sdk.go

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/hooks/role/sdk_create_post_set_output.go.tpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
if ko.Spec.AssumeRolePolicyDocument != nil {
2+
if doc, err := decodeAssumeDocument(*ko.Spec.AssumeRolePolicyDocument); err != nil {
3+
return nil, err
4+
} else {
5+
ko.Spec.AssumeRolePolicyDocument = &doc
6+
}
7+
}
18
if err := rm.syncPolicies(ctx, &resource{ko}); err != nil {
29
return nil, err
310
}

templates/hooks/role/sdk_read_one_post_set_output.go.tpl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
if ko.Spec.AssumeRolePolicyDocument != nil {
2+
if doc, err := decodeAssumeDocument(*ko.Spec.AssumeRolePolicyDocument); err != nil {
3+
return nil, err
4+
} else {
5+
ko.Spec.AssumeRolePolicyDocument = &doc
6+
}
7+
}
18
if policies, err := rm.getPolicies(ctx, &resource{ko}); err != nil {
29
return nil, err
310
} else {
@@ -7,4 +14,4 @@
714
return nil, err
815
} else {
916
ko.Spec.Tags = tags
10-
}
17+
}

test/e2e/resources/role_simple.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,19 @@ spec:
66
name: $ROLE_NAME
77
description: $ROLE_DESCRIPTION
88
maxSessionDuration: $MAX_SESSION_DURATION
9-
assumeRolePolicyDocument: '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":["ec2.amazonaws.com"]},"Action":["sts:AssumeRole"]}]}'
9+
assumeRolePolicyDocument: >
10+
{
11+
"Version":"2012-10-17",
12+
"Statement": [{
13+
"Effect":"Allow",
14+
"Principal": {
15+
"Service": [
16+
"ec2.amazonaws.com"
17+
]
18+
},
19+
"Action": ["sts:AssumeRole"]
20+
}]
21+
}
1022
tags:
1123
- key: tag1
1224
value: val1

0 commit comments

Comments
 (0)