-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add feature: Custom IAM Roles #2139
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,6 +132,9 @@ type ClusterSpec struct { | |
// missing: default policy (currently OS security upgrades that do not require a reboot) | ||
UpdatePolicy *string `json:"updatePolicy,omitempty"` | ||
|
||
// Use custom IAM roles for cluster roles | ||
RoleCustomIamRoles map[string]string `json:"roleCustomIamRoles,omitempty"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IamRoles? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean to change the variable name? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yah ... sorry was not clear. How about the name |
||
|
||
// Additional policies to add for roles | ||
AdditionalPolicies *map[string]string `json:"additionalPolicies,omitempty"` | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -19,13 +19,14 @@ package model | |||||
import ( | ||||||
"encoding/json" | ||||||
"fmt" | ||||||
"reflect" | ||||||
"strings" | ||||||
"text/template" | ||||||
|
||||||
"k8s.io/kops/pkg/apis/kops" | ||||||
"k8s.io/kops/pkg/model/iam" | ||||||
"k8s.io/kops/upup/pkg/fi" | ||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awstasks" | ||||||
"reflect" | ||||||
"strings" | ||||||
"text/template" | ||||||
) | ||||||
|
||||||
// IAMModelBuilder configures IAM objects | ||||||
|
@@ -64,33 +65,52 @@ func (b *IAMModelBuilder) Build(c *fi.ModelBuilderContext) error { | |||||
// Generate IAM objects etc for each role | ||||||
for _, role := range roles { | ||||||
name := b.IAMName(role) | ||||||
roleAsString := reflect.ValueOf(role).String() | ||||||
|
||||||
var iamRole *awstasks.IAMRole | ||||||
{ | ||||||
rolePolicy, err := b.buildAWSIAMRolePolicy() | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
customIamRoles := b.Cluster.Spec.RoleCustomIamRoles | ||||||
|
||||||
// If we've specified an IAMRoleArn for this cluster role, | ||||||
// do not create a new one | ||||||
if customIamRoles[roleAsString] != "" { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review Notes I do need to have you put this functionality behind a feature flag.
|
||||||
arn := customIamRoles[roleAsString] | ||||||
rs := strings.Split(arn, "/") | ||||||
roleName := rs[len(rs)-1] | ||||||
iamRole = &awstasks.IAMRole{ | ||||||
Name: s(name), | ||||||
RolePolicyDocument: fi.WrapResource(rolePolicy), | ||||||
Name: &roleName, | ||||||
ID: &arn, | ||||||
|
||||||
// We set Policy Document to nil as this role will be managed externaly | ||||||
RolePolicyDocument: nil, | ||||||
} | ||||||
c.AddTask(iamRole) | ||||||
} else { | ||||||
{ | ||||||
rolePolicy, err := b.buildAWSIAMRolePolicy() | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
} | ||||||
iamRole = &awstasks.IAMRole{ | ||||||
Name: s(name), | ||||||
RolePolicyDocument: fi.WrapResource(rolePolicy), | ||||||
} | ||||||
c.AddTask(iamRole) | ||||||
} | ||||||
|
||||||
policy, err := b.buildAWSIAMPolicy(role) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
{ | ||||||
t := &awstasks.IAMRolePolicy{ | ||||||
Name: s(name), | ||||||
Role: iamRole, | ||||||
PolicyDocument: fi.WrapResource(fi.NewStringResource(policy)), | ||||||
policy, err := b.buildAWSIAMPolicy(role) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
{ | ||||||
t := &awstasks.IAMRolePolicy{ | ||||||
Name: s(name), | ||||||
Role: iamRole, | ||||||
PolicyDocument: fi.WrapResource(fi.NewStringResource(policy)), | ||||||
} | ||||||
c.AddTask(t) | ||||||
} | ||||||
c.AddTask(t) | ||||||
} | ||||||
|
||||||
var iamInstanceProfile *awstasks.IAMInstanceProfile | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
apiVersion: kops/v1alpha1 | ||
kind: Cluster | ||
metadata: | ||
creationTimestamp: 2017-01-01T00:00:00Z | ||
name: custom-iam-role.example.com | ||
spec: | ||
adminAccess: | ||
- 0.0.0.0/0 | ||
api: | ||
dns: {} | ||
channel: stable | ||
cloudProvider: aws | ||
configBase: memfs://tests/custom-iam-role.example.com | ||
etcdClusters: | ||
- etcdMembers: | ||
- name: a | ||
zone: us-test-1a | ||
name: main | ||
- etcdMembers: | ||
- name: a | ||
zone: us-test-1a | ||
name: events | ||
kubernetesVersion: v1.4.8 | ||
masterPublicName: api.custom-iam-role.example.com | ||
networkCIDR: 172.20.0.0/16 | ||
networking: | ||
kubenet: {} | ||
nonMasqueradeCIDR: 100.64.0.0/10 | ||
roleCustomIamRoles: | ||
Master: foo | ||
Node: bar | ||
topology: | ||
dns: | ||
type: Public | ||
masters: public | ||
nodes: public | ||
zones: | ||
- cidr: 172.20.32.0/19 | ||
name: us-test-1a | ||
|
||
--- | ||
|
||
apiVersion: kops/v1alpha1 | ||
kind: InstanceGroup | ||
metadata: | ||
creationTimestamp: 2017-01-01T00:00:00Z | ||
labels: | ||
kops.k8s.io/cluster: custom-iam-role.example.com | ||
name: master-us-test-1a | ||
spec: | ||
image: kope.io/k8s-1.4-debian-jessie-amd64-hvm-ebs-2016-10-21 | ||
machineType: m3.medium | ||
maxSize: 1 | ||
minSize: 1 | ||
role: Master | ||
zones: | ||
- us-test-1a | ||
|
||
--- | ||
|
||
apiVersion: kops/v1alpha1 | ||
kind: InstanceGroup | ||
metadata: | ||
creationTimestamp: 2017-01-01T00:00:00Z | ||
labels: | ||
kops.k8s.io/cluster: custom-iam-role.example.com | ||
name: nodes | ||
spec: | ||
image: kope.io/k8s-1.4-debian-jessie-amd64-hvm-ebs-2016-10-21 | ||
machineType: t2.medium | ||
maxSize: 2 | ||
minSize: 2 | ||
role: Node | ||
zones: | ||
- us-test-1a |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
apiVersion: kops/v1alpha2 | ||
kind: Cluster | ||
metadata: | ||
creationTimestamp: 2017-01-01T00:00:00Z | ||
name: custom-iam-role.example.com | ||
spec: | ||
api: | ||
dns: {} | ||
channel: stable | ||
cloudProvider: aws | ||
configBase: memfs://tests/custom-iam-role.example.com | ||
etcdClusters: | ||
- etcdMembers: | ||
- instanceGroup: master-us-test-1a | ||
name: a | ||
name: main | ||
- etcdMembers: | ||
- instanceGroup: master-us-test-1a | ||
name: a | ||
name: events | ||
kubernetesApiAccess: | ||
- 0.0.0.0/0 | ||
kubernetesVersion: v1.4.8 | ||
masterPublicName: api.custom-iam-role.example.com | ||
networkCIDR: 172.20.0.0/16 | ||
networking: | ||
kubenet: {} | ||
nonMasqueradeCIDR: 100.64.0.0/10 | ||
roleCustomIamRoles: | ||
Master: foo | ||
Node: bar | ||
sshAccess: | ||
- 0.0.0.0/0 | ||
subnets: | ||
- cidr: 172.20.32.0/19 | ||
name: us-test-1a | ||
type: Public | ||
zone: us-test-1a | ||
topology: | ||
dns: | ||
type: Public | ||
masters: public | ||
nodes: public | ||
|
||
--- | ||
|
||
apiVersion: kops/v1alpha2 | ||
kind: InstanceGroup | ||
metadata: | ||
creationTimestamp: 2017-01-01T00:00:00Z | ||
labels: | ||
kops.k8s.io/cluster: custom-iam-role.example.com | ||
name: master-us-test-1a | ||
spec: | ||
image: kope.io/k8s-1.4-debian-jessie-amd64-hvm-ebs-2016-10-21 | ||
machineType: m3.medium | ||
maxSize: 1 | ||
minSize: 1 | ||
role: Master | ||
subnets: | ||
- us-test-1a | ||
|
||
--- | ||
|
||
apiVersion: kops/v1alpha2 | ||
kind: InstanceGroup | ||
metadata: | ||
creationTimestamp: 2017-01-01T00:00:00Z | ||
labels: | ||
kops.k8s.io/cluster: custom-iam-role.example.com | ||
name: nodes | ||
spec: | ||
image: kope.io/k8s-1.4-debian-jessie-amd64-hvm-ebs-2016-10-21 | ||
machineType: t2.medium | ||
maxSize: 2 | ||
minSize: 2 | ||
role: Node | ||
subnets: | ||
- us-test-1a |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
ClusterName: custom-iam-role.example.com | ||
Zones: | ||
- us-test-1a | ||
Cloud: aws | ||
KubernetesVersion: v1.4.8 | ||
MasterIAMRole: foo | ||
NodeIAMRole: bar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say that we leave this at a yaml / API / clusterspec level. Not sure if we want more cli flags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested it myself with the cli flags, but fine if it ends up in the yaml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @sp-borja-juncosa is on vacations, but I guess that it could be easy to remove the cli flags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sp-andres-diaz that would be awesome ... please and thank-you