Skip to content
This repository was archived by the owner on Sep 30, 2020. It is now read-only.

Commit 3bac739

Browse files
authored
Merge pull request #1475 from mumoshu/cherry-pick-1474
0.12.x: Allow user control over controller.iam.role.name
2 parents aca24cf + e396b4e commit 3bac739

File tree

4 files changed

+50
-21
lines changed

4 files changed

+50
-21
lines changed

core/controlplane/config/templates/stack-template.json

+9-5
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
"IAMInstanceProfileController": {
214214
"Properties": {
215215
"Path": "/",
216-
{{ if and (.Controller.IAMConfig.Role.UseStrict) (.Controller.IAMConfig.Role.Name) }}
216+
{{ if and (.Controller.IAMConfig.Role.ManageExternally) (.Controller.IAMConfig.Role.Name) }}
217217
"Roles": [
218218
"{{.Controller.IAMConfig.Role.Name}}"
219219
]
@@ -232,7 +232,7 @@
232232
"Properties" : {
233233
"Description" : "Policy for managing kube-aws k8s controllers",
234234
"Path" : "/",
235-
{{ if and (.Controller.IAMConfig.Role.UseStrict) (.Controller.IAMConfig.Role.Name) }}
235+
{{ if and (.Controller.IAMConfig.Role.ManageExternally) (.Controller.IAMConfig.Role.Name) }}
236236
"Roles" : [
237237
"{{.Controller.IAMConfig.Role.Name}}"
238238
],
@@ -478,9 +478,13 @@
478478
"Version": "2012-10-17"
479479
},
480480
"Path": "/",
481-
{{if and (.Controller.IAMConfig.Role.Name) (not .Controller.IAMConfig.Role.UseStrict) }}
482-
"RoleName": {"Fn::Join": ["-", ["{{$.ClusterName}}", {"Ref": "AWS::Region"}, "{{.Controller.IAMConfig.Role.Name}}"]]},
483-
{{end}}
481+
{{ if and (.Controller.IAMConfig.Role.Name) (not .Controller.IAMConfig.Role.ManageExternally) -}}
482+
"RoleName": {{if .Controller.IAMConfig.Role.StrictName -}}
483+
"{{ .Controller.IAMConfig.Role.Name }}",
484+
{{ else -}}
485+
{"Fn::Join": ["-", ["{{ $.ClusterName }}", {"Ref": "AWS::Region"}, "{{ .Controller.IAMConfig.Role.Name }}"]]},
486+
{{ end -}}
487+
{{ end -}}
484488
"ManagedPolicyArns": [
485489
{{range $policyIndex, $policyArn := .Controller.IAMConfig.Role.ManagedPolicies }}
486490
"{{$policyArn.Arn}}",

core/root/config/templates/cluster.yaml

+9-4
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,15 @@ kmsKeyArn: "{{.KMSKeyARN}}"
218218
# # the Statements included in the ManagedPolicy are the minimun ones required for the Controllers to run.
219219
# name: "yourManagedRole"
220220
#
221-
# # If useStrict is enabled (i.e set to true), kube-aws will not create a new IAM role and will instead use an existing one.
222-
# # The existing role name must be set under iam.role.name and must exist on AWS before the cluster is rolled out.
223-
# # By default, useStrict is disabled (i.e set to false)
224-
# useStrict: true
221+
# # If strictName is enabled then the name specified above in "name" is not not altered by kube-aws.
222+
# # strictName is "false" by default which means that kube-aws will prepend the ian role name with the result of "ClusterName-AWSRegion-"
223+
# # strictName: true
224+
#
225+
# # If manageExternally is enabled (i.e set to true), kube-aws will not create a new IAM role and will instead use an existing one.
226+
# # The existing role name must be set under iam.role.name and must exist on AWS before the cluster is rolled out.
227+
# # When using manageExternally, strictName is also assumed by kube-aws
228+
# # By default, manageExternally is disabled (i.e set to false)
229+
# manageExternally: true
225230
#
226231
# # If you set managedPolicies here it will be attached in addition to the created managedPolicy in kube-aws for the cluster.
227232
# # CAUTION: if you attach a more restrictive policy in some resources (i.e ec2:* Deny) you can make kube-aws fail.

model/iamconfig.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ type IAMConfig struct {
1414
}
1515

1616
type IAMRole struct {
17-
ARN `yaml:",inline"`
18-
Name string `yaml:"name,omitempty"`
19-
UseStrict bool `yaml:"useStrict,omitempty"`
20-
ManagedPolicies []IAMManagedPolicy `yaml:"managedPolicies,omitempty"`
17+
ARN `yaml:",inline"`
18+
Name string `yaml:"name,omitempty"`
19+
StrictName bool `yaml:"strictName,omitempty"`
20+
ManageExternally bool `yaml:"manageExternally,omitempty"`
21+
ManagedPolicies []IAMManagedPolicy `yaml:"managedPolicies,omitempty"`
2122
}
2223

2324
type IAMManagedPolicy struct {

test/integration/maincluster_test.go

+27-8
Original file line numberDiff line numberDiff line change
@@ -1744,38 +1744,57 @@ worker:
17441744
},
17451745
},
17461746
{
1747-
context: "WithControllerIAMDefaultUseStrict",
1747+
context: "WithControllerIAMDefaultManageExternally",
17481748
configYaml: minimalValidConfigYaml,
17491749
assertConfig: []ConfigTester{
17501750
func(c *config.Config, t *testing.T) {
17511751
expectedValue := false
17521752

1753-
if c.Controller.IAMConfig.Role.UseStrict != expectedValue {
1754-
t.Errorf("controller's iam.role.useStrict didn't match : expected=%v actual=%v", expectedValue, c.Controller.IAMConfig.Role.UseStrict)
1753+
if c.Controller.IAMConfig.Role.ManageExternally != expectedValue {
1754+
t.Errorf("controller's iam.role.manageExternally didn't match : expected=%v actual=%v", expectedValue, c.Controller.IAMConfig.Role.ManageExternally)
17551755
}
17561756
},
17571757
},
17581758
},
17591759
{
1760-
context: "WithControllerIAMEnabledUseStrict",
1760+
context: "WithControllerIAMEnabledManageExternally",
17611761
configYaml: minimalValidConfigYaml + `
17621762
controller:
17631763
iam:
17641764
role:
17651765
name: myrole1
1766-
useStrict: true
1766+
manageExternally: true
17671767
`,
17681768
assertConfig: []ConfigTester{
17691769
func(c *config.Config, t *testing.T) {
1770-
expectedUseStrict := true
1770+
expectedManageExternally := true
17711771
expectedRoleName := "myrole1"
17721772

17731773
if expectedRoleName != c.Controller.IAMConfig.Role.Name {
17741774
t.Errorf("controller's iam.role.name didn't match : expected=%v actual=%v", expectedRoleName, c.Controller.IAMConfig.Role.Name)
17751775
}
17761776

1777-
if expectedUseStrict != c.Controller.IAMConfig.Role.UseStrict {
1778-
t.Errorf("controller's iam.role.useStrict didn't matchg : expected=%v actual=%v", expectedUseStrict, c.Controller.IAMConfig.Role.UseStrict)
1777+
if expectedManageExternally != c.Controller.IAMConfig.Role.ManageExternally {
1778+
t.Errorf("controller's iam.role.manageExternally didn't match : expected=%v actual=%v", expectedManageExternally, c.Controller.IAMConfig.Role.ManageExternally)
1779+
}
1780+
},
1781+
},
1782+
},
1783+
{
1784+
context: "WithControllerIAMEnabledStrictName",
1785+
configYaml: minimalValidConfigYaml + `
1786+
controller:
1787+
iam:
1788+
role:
1789+
name: myrole1
1790+
strictName: true
1791+
`,
1792+
assertConfig: []ConfigTester{
1793+
func(c *config.Config, t *testing.T) {
1794+
expectedRoleName := "myrole1"
1795+
1796+
if expectedRoleName != c.Controller.IAMConfig.Role.Name {
1797+
t.Errorf("controller's iam.role.name didn't match : expected=%v actual=%v", expectedRoleName, c.Controller.IAMConfig.Role.Name)
17791798
}
17801799
},
17811800
},

0 commit comments

Comments
 (0)