Skip to content
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

Allow configurable backend modes for aws-iam-authenticator #9500

Merged
merged 1 commit into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion docs/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ spec:
rbac: {}
```

The creation of a AWS IAM authenticator config as a ConfigMap is also required.
By default the creation of an AWS IAM authenticator config as a ConfigMap is also required.
For more details on AWS IAM authenticator please visit [kubernetes-sigs/aws-iam-authenticator](https://github.com/kubernetes-sigs/aws-iam-authenticator)

Example config:
Expand Down Expand Up @@ -113,6 +113,17 @@ data:
- system:masters
```

It is also possible to configure alternative backend modes for aws-iam-authenticator. The `backendMode` configuration option allows defining multiple backends in a comma separated string. The mappings in these backends will be merged. When the same mapping is found in multiple backends, the first backend in the list will take precedence. If MountedFile is not included in the list of backends, no configmap is required and the [cluster-id](https://github.com/kubernetes-sigs/aws-iam-authenticator#what-is-a-cluster-id) will default to the cluster's master API DNS name. The cluster-id can be overridden by setting the `clusterID` API field. If you wish to continue using a configmap for authenticator settings other than mappings, MountedFile must be included in the backendMode list.

This requires an aws-iam-authenticator image >= 0.5.0 For more information see [usergroup-mappings](https://github.com/kubernetes-sigs/aws-iam-authenticator#4-create-iam-roleuser-to-kubernetes-usergroup-mappings)

```yaml
authentication:
aws:
backendMode: CRD,MountedFile
clusterID: demo.cluster.us-west-2
```

### Creating a new cluster with IAM Authenticator on.

* Create a cluster following the [AWS getting started guide](getting_started/aws.md)
Expand Down
9 changes: 9 additions & 0 deletions k8s/crds/kops.k8s.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ spec:
properties:
aws:
properties:
backendMode:
description: BackendMode is the AWS IAM Authenticator backend
to use. Default MountedFile
type: string
clusterID:
description: ClusterID identifies the cluster performing authentication
to prevent certain replay attacks. Default master public
DNS name
type: string
cpuLimit:
anyOf:
- type: integer
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/kops/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ type KopeioAuthenticationSpec struct {
type AwsAuthenticationSpec struct {
// Image is the AWS IAM Authenticator docker image to use
Image string `json:"image,omitempty"`
// BackendMode is the AWS IAM Authenticator backend to use. Default MountedFile
BackendMode string `json:"backendMode,omitempty"`
// ClusterID identifies the cluster performing authentication to prevent certain replay attacks. Default master public DNS name
ClusterID string `json:"clusterID,omitempty"`
// MemoryRequest memory request of AWS IAM Authenticator container. Default 20Mi
MemoryRequest *resource.Quantity `json:"memoryRequest,omitempty"`
// CPURequest CPU request of AWS IAM Authenticator container. Default 10m
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/kops/v1alpha2/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ type KopeioAuthenticationSpec struct {
type AwsAuthenticationSpec struct {
// Image is the AWS IAM Authenticator docker image to uses
Image string `json:"image,omitempty"`
// BackendMode is the AWS IAM Authenticator backend to use. Default MountedFile
BackendMode string `json:"backendMode,omitempty"`
// ClusterID identifies the cluster performing authentication to prevent certain replay attacks. Default master public DNS name
ClusterID string `json:"clusterID,omitempty"`
// MemoryRequest memory request of AWS IAM Authenticator container. Default 20Mi
MemoryRequest *resource.Quantity `json:"memoryRequest,omitempty"`
// CPURequest CPU request of AWS IAM Authenticator container. Default 10m
Expand Down
4 changes: 4 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.

13 changes: 13 additions & 0 deletions upup/models/bindata.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,18 @@ spec:
image: {{ or .Authentication.Aws.Image "602401143452.dkr.ecr.us-west-2.amazonaws.com/amazon/aws-iam-authenticator:v0.5.1-debian-stretch" }}
args:
- server
{{- if or (not .Authentication.Aws.BackendMode) (contains "MountedFile" .Authentication.Aws.BackendMode) }}
- --config=/etc/aws-iam-authenticator/config.yaml
{{- end }}
{{- if or .Authentication.Aws.ClusterID (not (contains "MountedFile" .Authentication.Aws.BackendMode))}}
- --cluster-id={{ or .Authentication.Aws.ClusterID .MasterPublicName }}
{{- end }}
- --state-dir=/var/aws-iam-authenticator
- --kubeconfig-pregenerated=true
{{- if .Authentication.Aws.BackendMode }}
- --backend-mode={{ .Authentication.Aws.BackendMode }}
{{- end }}

resources:
requests:
memory: {{ or .Authentication.Aws.MemoryRequest "20Mi" }}
Expand All @@ -145,16 +154,20 @@ spec:
port: 21362
scheme: HTTPS
volumeMounts:
{{- if or (not .Authentication.Aws.BackendMode) (contains "MountedFile" .Authentication.Aws.BackendMode) }}
- name: config
mountPath: /etc/aws-iam-authenticator/
{{- end }}
- name: state
mountPath: /var/aws-iam-authenticator/
- name: output
mountPath: /etc/kubernetes/aws-iam-authenticator/
volumes:
{{- if or (not .Authentication.Aws.BackendMode) (contains "MountedFile" .Authentication.Aws.BackendMode) }}
- name: config
configMap:
name: aws-iam-authenticator
{{- end }}
- name: output
hostPath:
path: /srv/kubernetes/aws-iam-authenticator/
Expand Down
1 change: 1 addition & 0 deletions upup/pkg/fi/cloudup/bootstrapchannelbuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func TestBootstrapChannelBuilder_BuildTasks(t *testing.T) {
runChannelBuilderTest(t, "cilium", []string{"dns-controller.addons.k8s.io-k8s-1.12", "kops-controller.addons.k8s.io-k8s-1.16"})
runChannelBuilderTest(t, "weave", []string{})
runChannelBuilderTest(t, "amazonvpc", []string{"networking.amazon-vpc-routed-eni-k8s-1.12", "networking.amazon-vpc-routed-eni-k8s-1.16"})
runChannelBuilderTest(t, "awsiamauthenticator", []string{"authentication.aws-k8s-1.12"})
}

func runChannelBuilderTest(t *testing.T, key string, addonManifests []string) {
Expand Down
1 change: 1 addition & 0 deletions upup/pkg/fi/cloudup/template_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func (tf *TemplateFunctions) AddTo(dest template.FuncMap, secretStore fi.SecretS

sprigTxtFuncMap := sprig.TxtFuncMap()
dest["indent"] = sprigTxtFuncMap["indent"]
dest["contains"] = sprigTxtFuncMap["contains"]

dest["ClusterName"] = tf.ClusterName
dest["HasTag"] = tf.HasTag
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: iamidentitymappings.iamauthenticator.k8s.aws
spec:
group: iamauthenticator.k8s.aws
names:
categories:
- all
kind: IAMIdentityMapping
plural: iamidentitymappings
singular: iamidentitymapping
scope: Cluster
subresources:
status: {}
validation:
openAPIV3Schema:
properties:
spec:
properties:
arn:
type: string
groups:
items:
type: string
type: array
username:
type: string
required:
- arn
- username
version: v1alpha1

---

apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: aws-iam-authenticator
rules:
- apiGroups:
- iamauthenticator.k8s.aws
resources:
- iamidentitymappings
verbs:
- get
- list
- watch
- apiGroups:
- iamauthenticator.k8s.aws
resources:
- iamidentitymappings/status
verbs:
- patch
- update
- apiGroups:
- ""
resources:
- events
verbs:
- create
- update
- patch

---

apiVersion: v1
kind: ServiceAccount
metadata:
name: aws-iam-authenticator
namespace: kube-system

---

apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: aws-iam-authenticator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: aws-iam-authenticator
subjects:
- kind: ServiceAccount
name: aws-iam-authenticator
namespace: kube-system

---

apiVersion: apps/v1
kind: DaemonSet
metadata:
labels:
k8s-app: aws-iam-authenticator
name: aws-iam-authenticator
namespace: kube-system
spec:
selector:
matchLabels:
k8s-app: aws-iam-authenticator
template:
metadata:
annotations:
scheduler.alpha.kubernetes.io/critical-pod: ""
labels:
k8s-app: aws-iam-authenticator
spec:
containers:
- args:
- server
- --cluster-id=api.minimal.example.com
- --state-dir=/var/aws-iam-authenticator
- --kubeconfig-pregenerated=true
- --backend-mode=CRD
image: 602401143452.dkr.ecr.us-west-2.amazonaws.com/amazon/aws-iam-authenticator:v0.5.1-debian-stretch
livenessProbe:
httpGet:
host: 127.0.0.1
path: /healthz
port: 21362
scheme: HTTPS
name: aws-iam-authenticator
resources:
limits:
cpu: 100m
memory: 20Mi
requests:
cpu: 10m
memory: 20Mi
volumeMounts:
- mountPath: /var/aws-iam-authenticator/
name: state
- mountPath: /etc/kubernetes/aws-iam-authenticator/
name: output
hostNetwork: true
nodeSelector:
node-role.kubernetes.io/master: ""
priorityClassName: system-node-critical
serviceAccountName: aws-iam-authenticator
tolerations:
- effect: NoSchedule
key: node-role.kubernetes.io/master
- key: CriticalAddonsOnly
operator: Exists
volumes:
- hostPath:
path: /srv/kubernetes/aws-iam-authenticator/
name: output
- hostPath:
path: /srv/kubernetes/aws-iam-authenticator/
name: state
updateStrategy:
type: RollingUpdate
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apiVersion: kops.k8s.io/v1alpha2
kind: Cluster
metadata:
creationTimestamp: "2016-12-10T22:42:27Z"
name: minimal.example.com
spec:
addons:
- manifest: s3://somebucket/example.yaml
authentication:
aws:
backendMode: CRD
kubernetesApiAccess:
- 0.0.0.0/0
channel: stable
cloudProvider: aws
configBase: memfs://clusters.example.com/minimal.example.com
etcdClusters:
- etcdMembers:
- instanceGroup: master-us-test-1a
name: master-us-test-1a
name: main
- etcdMembers:
- instanceGroup: master-us-test-1a
name: master-us-test-1a
name: events
iam: {}
kubernetesVersion: v1.14.6
masterInternalName: api.internal.minimal.example.com
masterPublicName: api.minimal.example.com
additionalSans:
- proxy.api.minimal.example.com
networkCIDR: 172.20.0.0/16
networking:
kubenet: {}
nonMasqueradeCIDR: 100.64.0.0/10
sshAccess:
- 0.0.0.0/0
topology:
masters: public
nodes: public
subnets:
- cidr: 172.20.32.0/19
name: us-test-1a
type: Public
zone: us-test-1a
Loading