mirror of https://github.com/kubernetes/kops.git
Add version logic to UseServiceAccountIAM
Co-authored-by: John Gardiner Myers <jgmyers@proofpoint.com>
This commit is contained in:
parent
a61ecf4c58
commit
d8895c57ec
|
@ -411,5 +411,5 @@ func (m *KopsModelContext) NodePortRange() (utilnet.PortRange, error) {
|
|||
|
||||
// UseServiceAccountIAM returns true if we are using service-account bound IAM roles.
|
||||
func (m *KopsModelContext) UseServiceAccountIAM() bool {
|
||||
return featureflag.UseServiceAccountIAM.Enabled()
|
||||
return featureflag.UseServiceAccountIAM.Enabled() && m.IsKubernetesGTE("1.12")
|
||||
}
|
||||
|
|
|
@ -157,9 +157,10 @@ func (b *IAMModelBuilder) buildIAMRole(role iam.Subject, iamName string, c *fi.M
|
|||
func (b *IAMModelBuilder) buildIAMRolePolicy(role iam.Subject, iamName string, iamRole *awstasks.IAMRole, c *fi.ModelBuilderContext) error {
|
||||
iamPolicy := &iam.PolicyResource{
|
||||
Builder: &iam.PolicyBuilder{
|
||||
Cluster: b.Cluster,
|
||||
Role: role,
|
||||
Region: b.Region,
|
||||
Cluster: b.Cluster,
|
||||
Role: role,
|
||||
Region: b.Region,
|
||||
UseServiceAccountIAM: b.UseServiceAccountIAM(),
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,6 @@ import (
|
|||
"k8s.io/klog/v2"
|
||||
"k8s.io/kops/pkg/apis/kops"
|
||||
"k8s.io/kops/pkg/apis/kops/model"
|
||||
"k8s.io/kops/pkg/featureflag"
|
||||
"k8s.io/kops/pkg/util/stringorslice"
|
||||
"k8s.io/kops/upup/pkg/fi"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/awstasks"
|
||||
|
@ -107,12 +106,13 @@ func (l *Statement) Equal(r *Statement) bool {
|
|||
// PolicyBuilder struct defines all valid fields to be used when building the
|
||||
// AWS IAM policy document for a given instance group role.
|
||||
type PolicyBuilder struct {
|
||||
Cluster *kops.Cluster
|
||||
HostedZoneID string
|
||||
KMSKeys []string
|
||||
Region string
|
||||
ResourceARN *string
|
||||
Role Subject
|
||||
Cluster *kops.Cluster
|
||||
HostedZoneID string
|
||||
KMSKeys []string
|
||||
Region string
|
||||
ResourceARN *string
|
||||
Role Subject
|
||||
UseServiceAccountIAM bool
|
||||
}
|
||||
|
||||
// BuildAWSPolicy builds a set of IAM policy statements based on the
|
||||
|
@ -157,7 +157,7 @@ func (r *NodeRoleMaster) BuildAWSPolicy(b *PolicyBuilder) (*Policy, error) {
|
|||
addKMSIAMPolicies(p, stringorslice.Slice(b.KMSKeys), b.Cluster.Spec.IAM.Legacy)
|
||||
}
|
||||
|
||||
if !b.UseServiceAccountIAM() {
|
||||
if !b.UseServiceAccountIAM {
|
||||
if b.Cluster.Spec.IAM.Legacy {
|
||||
addLegacyDNSControllerPermissions(b, p)
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ func (r *NodeRoleNode) BuildAWSPolicy(b *PolicyBuilder) (*Policy, error) {
|
|||
return nil, fmt.Errorf("failed to generate AWS IAM S3 access statements: %v", err)
|
||||
}
|
||||
|
||||
if !b.UseServiceAccountIAM() && b.Cluster.Spec.IAM.Legacy {
|
||||
if !b.UseServiceAccountIAM && b.Cluster.Spec.IAM.Legacy {
|
||||
addLegacyDNSControllerPermissions(b, p)
|
||||
AddDNSControllerPermissions(b, p)
|
||||
}
|
||||
|
@ -572,11 +572,6 @@ func addECRPermissions(p *Policy) {
|
|||
})
|
||||
}
|
||||
|
||||
// UseServiceAccountIAM returns true if we are using service-account bound IAM roles.
|
||||
func (b *PolicyBuilder) UseServiceAccountIAM() bool {
|
||||
return featureflag.UseServiceAccountIAM.Enabled()
|
||||
}
|
||||
|
||||
// addLegacyDNSControllerPermissions adds legacy IAM permissions used by the node roles.
|
||||
func addLegacyDNSControllerPermissions(b *PolicyBuilder, p *Policy) {
|
||||
// Legacy IAM permissions for node roles
|
||||
|
|
Loading…
Reference in New Issue