Skip to content

Commit

Permalink
Add support for IRSA in he api
Browse files Browse the repository at this point in the history
Apply suggestions from code review

Co-authored-by: John Gardiner Myers <[email protected]>
  • Loading branch information
Ole Markus With and johngmyers committed Apr 30, 2021
1 parent 7a63ed8 commit 3df5506
Show file tree
Hide file tree
Showing 33 changed files with 2,306 additions and 18 deletions.
14 changes: 13 additions & 1 deletion cmd/kops/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,19 @@ func TestNTHQueueProcessor(t *testing.T) {
newIntegrationTest("nthsqsresources.example.com", "nth_sqs_resources").runTestCloudformation(t)
}

// TestCustomIRSA runs a simple configuration, but with some additional IAM roles for ServiceAccounts
func TestCustomIRSA(t *testing.T) {
featureflag.ParseFlags("+PublicJWKS")
unsetFeatureFlags := func() {
featureflag.ParseFlags("-PublicJWKS")
}
defer unsetFeatureFlags()
newIntegrationTest("minimal.example.com", "irsa").
withServiceAccountRole("myserviceaccount.default", false).
withServiceAccountRole("myotherserviceaccount.myapp", true).
runTestTerraformAWS(t)
}

func (i *integrationTest) runTest(t *testing.T, h *testutils.IntegrationTestHarness, expectedDataFilenames []string, tfFileName string, expectedTfFileName string, phase *cloudup.Phase) {
ctx := context.Background()

Expand Down Expand Up @@ -606,7 +619,6 @@ func (i *integrationTest) runTestTerraformAWS(t *testing.T) {
}...)
}
}

expectedFilenames = append(expectedFilenames, i.expectServiceAccountRolePolicies...)

i.runTest(t, h, expectedFilenames, tfFileName, tfFileName, nil)
Expand Down
46 changes: 46 additions & 0 deletions k8s/crds/kops.k8s.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1158,9 +1158,55 @@ spec:
type: boolean
permissionsBoundary:
type: string
serviceAccountMappings:
description: ServiceAccountMappings defines the relatinship between
Kubernetes ServiceAccounts and IAM roles.
items:
description: ServiceAccountMapping defines the relationship
between a Kubernetes ServiceAccount and an IAM Role.
properties:
iamPolicyARNs:
items:
type: string
type: array
inlinePolicy:
type: string
name:
type: string
namespace:
type: string
required:
- name
- namespace
type: object
type: array
required:
- legacy
type: object
iamRolesForServiceAccounts:
description: IAMRolesForServiceAccount defines the IRSA configuration.
properties:
serviceAccounts:
items:
description: ServiceAccountMapping defines the relationship
between a Kubernetes ServiceAccount and an IAM Role.
properties:
iamPolicyARNs:
items:
type: string
type: array
inlinePolicy:
type: string
name:
type: string
namespace:
type: string
required:
- name
- namespace
type: object
type: array
type: object
isolateMasters:
description: 'IsolateMasters determines whether we should lock down
masters so that they are not on the pod network. true is the kube-up
Expand Down
18 changes: 18 additions & 0 deletions pkg/apis/kops/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,22 @@ type ClusterSpec struct {
ClusterAutoscaler *ClusterAutoscalerConfig `json:"clusterAutoscaler,omitempty"`
// WarmPool defines the default warm pool settings for instance groups (AWS only).
WarmPool *WarmPoolSpec `json:"warmPool,omitempty"`

// IAMRolesForServiceAccount defines the IRSA configuration.
IAMRolesForServiceAccounts *IAMRolesForServiceAccountsConfig `json:"iamRolesForServiceAccounts,omitempty"`
}

// InstanceRoleForServiceAccountConfig defines the IRSA configuration.
type IAMRolesForServiceAccountsConfig struct {
ServiceAccounts []ServiceAccountMapping `json:"serviceAccounts,omitempty"`
}

// ServiceAccountMapping defines the relationship between a Kubernetes ServiceAccount and an IAM Role.
type ServiceAccountMapping struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
IAMPolicyARNs []string `json:"iamPolicyARNs,omitempty"`
InlinePolicy string `json:"inlinePolicy,omitempty"`
}

// NodeAuthorizationSpec is used to node authorization
Expand Down Expand Up @@ -271,6 +287,8 @@ type IAMSpec struct {
Legacy bool `json:"legacy"`
AllowContainerRegistry bool `json:"allowContainerRegistry,omitempty"`
PermissionsBoundary *string `json:"permissionsBoundary,omitempty"`
// ServiceAccountMappings defines the relatinship between Kubernetes ServiceAccounts and IAM roles.
ServiceAccountMappings []ServiceAccountMapping `json:"serviceAccountMappings,omitempty"`
}

// HookSpec is a definition hook
Expand Down
18 changes: 18 additions & 0 deletions pkg/apis/kops/v1alpha2/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,22 @@ type ClusterSpec struct {
ClusterAutoscaler *ClusterAutoscalerConfig `json:"clusterAutoscaler,omitempty"`
// WarmPool defines the default warm pool settings for instance groups (AWS only).
WarmPool *WarmPoolSpec `json:"warmPool,omitempty"`

// IAMRolesForServiceAccount defines the IRSA configuration.
IAMRolesForServiceAccounts *IAMRolesForServiceAccountsConfig `json:"iamRolesForServiceAccounts,omitempty"`
}

// IAMRoleForServiceAccountConfig defines the IRSA configuration.
type IAMRolesForServiceAccountsConfig struct {
ServiceAccounts []ServiceAccountMapping `json:"serviceAccounts,omitempty"`
}

// ServiceAccountMapping defines the relationship between a Kubernetes ServiceAccount and an IAM Role.
type ServiceAccountMapping struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
IAMPolicyARNs []string `json:"iamPolicyARNs,omitempty"`
InlinePolicy string `json:"inlinePolicy,omitempty"`
}

// NodeAuthorizationSpec is used to node authorization
Expand Down Expand Up @@ -269,6 +285,8 @@ type IAMSpec struct {
Legacy bool `json:"legacy"`
AllowContainerRegistry bool `json:"allowContainerRegistry,omitempty"`
PermissionsBoundary *string `json:"permissionsBoundary,omitempty"`
// ServiceAccountMappings defines the relatinship between Kubernetes ServiceAccounts and IAM roles.
ServiceAccountMappings []ServiceAccountMapping `json:"serviceAccountMappings,omitempty"`
}

// HookSpec is a definition hook
Expand Down
126 changes: 126 additions & 0 deletions pkg/apis/kops/v1alpha2/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3df5506

Please sign in to comment.