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

Fix CRD mapper blocking all others because caches never sync and revamp backend-mode flag #303

Merged
merged 6 commits into from
Apr 7, 2020

Conversation

wongma7
Copy link
Contributor

@wongma7 wongma7 commented Mar 14, 2020

Fixes #297 and #288

Discovered in #297 and #288 that there is a bug where if you place backend-mode CRD before the other backends/mappers...the others never start. And we have CRD as default the first...(which seems in hindsight like quite an oversight since it never left "alpha" :]). So I consider this a critical bugfix. The fix is small and in the first commit.

Now this bug wouldn't exist in the first place if I explicitly maintained behavior from pre-0.5.0 by keeping backend-mode equal to File instead of implicitly trusting that the fallback logic for backend-mode was sound when it is not. This is the second commit.

Moreover, it seems there's consensus that the backend-mode flag is confusing and the README in*sufficient. File and ConfigMap are super confusing because both are files...and both are configmaps... So to remove ambiguity I've deprecated them and renamed backend ConfigMap to EKSConfigMap and File to MountedConfigMap. Open to other suggestions. These are the last 2 commits.

I've stopped short of refactoring the code (package file and package configmap) to match the new names because I don't want to risk more instability. But that can be done in the future if we get more sophisticated integration/e2e tests which are at the moment hard to write without infrastructure for deploying a kops cluster, etc.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 14, 2020
@wongma7 wongma7 requested a review from nckturner March 14, 2020 01:30
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 14, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wongma7

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 14, 2020
Copy link
Contributor

@bhks bhks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall Looks good to me !!!!!

*Nit comments

`mapUsers` and `mapRoles` fields of its configuration. See [Full Configuration
Format](#full-configuration-format) below for details.

Using the `--backend-mode` flag, you can configure the server to source
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice Job on Improving the documentation and clarification 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, this explanation is helpful.

@@ -97,7 +100,7 @@ func init() {
viper.BindPFlag("server.address", serverCmd.Flags().Lookup("address"))

serverCmd.Flags().StringSlice("backend-mode",
[]string{mapper.ModeCRD, mapper.ModeConfigMap, mapper.ModeFile},
[]string{mapper.ModeMountedConfigMap},
Copy link
Contributor

@bhks bhks Mar 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should mention in the document that if you don't define the MountedConfigMap along with others in the flags it will not be part of chain and whatever user provides will be the only mode available.

Its kind of now the default behavior and will gets overridden.

I was thinking if we would like to have this mode always available in the server and if customer provides other chain that would come first in chain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a call-out for this.

Note that when setting a single backend, the server will *only* source from
that one and ignore the others even if they exist. For example, with
`--backend-mode=CRD`, the server will *only* source from `IAMIdentityMappings`
and ignore the mounted file and EKS ConfigMap.

I was thinking if we would like to have this mode always available in the server and if customer provides other chain that would come first in chain.

IMO we should see if these changes are sufficient, and if not we should add this as a final fallback.

pkg/server/server.go Show resolved Hide resolved
@rifelpet
Copy link
Contributor

This fixes my issue of the authenticator failing to initialize as reported in #288. With aws-iam-authenticator server --config /path/to/config.yaml and no --backend-mode specified, it successfully parses my config file's identity mappings.

I then removed --config, added an IAMIdentityMapping resource to my cluster, and didnt add any --backend-mode and it seems that authenticator started up with MountedConfigMap (even though there was no config map mounted) and didnt detect my IAMIdentityMapping. These are the logs from that:

time="2020-03-16T16:24:15Z" level=info msg="starting mapper \"MountedConfigMap\""
time="2020-03-16T16:24:15Z" level=info msg="loaded existing keypair" certPath=/var/aws-iam-authenticator/cert.pem keyPath=/var/aws-iam-authenticator/key.pem
time="2020-03-16T16:24:15Z" level=info msg="listening on https://127.0.0.1:21362/authenticate"
time="2020-03-16T16:24:15Z" level=info msg="reconfigure your apiserver with `--authentication-token-webhook-config-file=/etc/kubernetes/aws-iam-authenticator/kubeconfig.yaml` to enable (assuming default hostPath mounts)"
time="2020-03-16T16:24:15Z" level=info msg="Starting the h.ec2Provider.startEc2DescribeBatchProcessing "

Adding --backend-mode=CRD starts the authenticator as expected:

time="2020-03-16T16:31:36Z" level=info msg="creating event broadcaster"
time="2020-03-16T16:31:36Z" level=info msg="setting up event handlers"
time="2020-03-16T16:31:36Z" level=info msg="starting mapper \"CRD\""
time="2020-03-16T16:31:36Z" level=info msg="loaded existing keypair" certPath=/var/aws-iam-authenticator/cert.pem keyPath=/var/aws-iam-authenticator/key.pem
time="2020-03-16T16:31:36Z" level=info msg="listening on https://127.0.0.1:21362/authenticate"
time="2020-03-16T16:31:36Z" level=info msg="reconfigure your apiserver with `--authentication-token-webhook-config-file=/etc/kubernetes/aws-iam-authenticator/kubeconfig.yaml` to enable (assuming default hostPath mounts)"
time="2020-03-16T16:31:36Z" level=info msg="starting aws iam authenticator controller"
time="2020-03-16T16:31:36Z" level=info msg="waiting for informer caches to sync"
time="2020-03-16T16:31:36Z" level=info msg="Starting the h.ec2Provider.startEc2DescribeBatchProcessing "

Since the CRD mapper is a new feature, should we expect that users will need to set --backend-mode=CRD in order to use it? It'd be great if the order of backend modes would correctly "skip" any modes that arent setup (no file set, no IAMIdentityMappings present, etc) or if all 3 modes could work concurrently with some strategy for dealing with mapping conflicts. That would probably fall outside the scope of this PR though.

@jeffhubLR
Copy link

Validated that this PR returns to previous behavior. ConfigMap (aka MountedConfigMap) works as-is with no additional changes to a previously working configuration. Documentation updates are much appreciated.

Testing steps:
Built cluster with kops 1.17.0-Beta.1, which pulled in the 0.5.0 release that exhibited the broken behavior.
Updated aws-iam-authenticator daemonset to use image built from this PR.
Terminated aws-iam-authenticator pods.
Pod startup output:

time="2020-03-16T17:07:57Z" level=info msg="starting mapper \"MountedConfigMap\""
time="2020-03-16T17:07:57Z" level=info msg="mapping IAM role" groups="[system:masters]" role="arn:aws:iam::xxxxxxxxxxxx:role/xxxxx" username="aws:accountid:{{AccountID}}:session:{{SessionName}}"
time="2020-03-16T17:07:57Z" level=info msg="loaded existing keypair" certPath=/var/aws-iam-authenticator/cert.pem keyPath=/var/aws-iam-authenticator/key.pem
time="2020-03-16T17:07:57Z" level=info msg="listening on https://127.0.0.1:21362/authenticate"
time="2020-03-16T17:07:57Z" level=info msg="reconfigure your apiserver with `--authentication-token-webhook-config-file=/etc/kubernetes/aws-iam-authenticator/kubeconfig.yaml` to enable (assuming default hostPath mounts)"
time="2020-03-16T17:07:57Z" level=info msg="Starting the h.ec2Provider.startEc2DescribeBatchProcessing "

And validated it is functioning:

time="2020-03-16T17:20:59Z" level=info msg="access granted" arn="arn:aws:iam::xxxxxxxxxxxx:role/xxxxx" client="127.0.0.1:48922" groups="[system:masters]" method=POST path=/authenticate uid="aws-iam-authenticator:xxxxxxxxxxxx:xxxxxxxxxxxxxxx" username="aws:accountid:xxxxxxxxxxxx:session:xxxxxxxxxxxxx"

Thanks, Matthew!

README.md Outdated Show resolved Hide resolved
@wongma7
Copy link
Contributor Author

wongma7 commented Mar 16, 2020

Since the CRD mapper is a new feature, should we expect that users will need to set --backend-mode=CRD in order to use it?

Yes, originally there was a feature gate flag, but I felt it was redundant and didn't want users to deal with 2 flags that would do roughly the same thing. i.e.: having CRD in your --backend-mode is equivalent to feature-gate on and omitting it from your --backend-mode is equivalent to feature-gate off.

It'd be great if the order of backend modes would correctly "skip" any modes that arent setup (no file set, no IAMIdentityMappings present, etc) or if all 3 modes could work concurrently with some strategy for dealing with mapping conflicts. That would probably fall outside the scope of this PR though.

Yes, the goal is for all 3 modes to work concurrently and the server to use the first mapping it finds (according to the order of the backends in --backend-mode). So if there's a conflict, the order of the backends resolves it. Any situation that violates this behavior is a bug!

Copy link
Contributor

@bhks bhks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!!!!!

@rifelpet
Copy link
Contributor

In that case I do seem to be experiencing a bug. Its possible that its related to the CRD and me being on k8s 1.16.

With no --config nor --backend-mode specified and an IAMIdentityMapping resource present on the cluster:

time="2020-03-16T21:59:54Z" level=info msg="starting mapper \"MountedConfigMap\""
time="2020-03-16T21:59:54Z" level=info msg="loaded existing keypair" certPath=/var/aws-iam-authenticator/cert.pem keyPath=/var/aws-iam-authenticator/key.pem
time="2020-03-16T21:59:54Z" level=info msg="listening on https://127.0.0.1:21362/authenticate"
time="2020-03-16T21:59:54Z" level=info msg="reconfigure your apiserver with `--authentication-token-webhook-config-file=/etc/kubernetes/aws-iam-authenticator/kubeconfig.yaml` to enable (assuming default hostPath mounts)"
time="2020-03-16T21:59:54Z" level=info msg="Starting the h.ec2Provider.startEc2DescribeBatchProcessing "
time="2020-03-16T22:00:08Z" level=info msg="STS response" accesskeyid=ASIA4XXXXXXXXXXXX accountid=XXXXXXXXXXXX arn="arn:aws:sts::XXXXXXXXXXXX:assumed-role/foo/foo" client="127.0.0.1:64070" method=POST path=/authenticate session=foo userid=AROA4XTGQXXXXXXXXXXXX
time="2020-03-16T22:00:08Z" level=warning msg="access denied" arn="arn:aws:iam::XXXXXXXXXXXX:role/foo" client="127.0.0.1:64070" error="ARN is not mapped" method=POST path=/authenticate

with --backend-mode=CRD:

time="2020-03-16T22:07:34Z" level=info msg="creating event broadcaster"
time="2020-03-16T22:07:34Z" level=info msg="setting up event handlers"
time="2020-03-16T22:07:34Z" level=info msg="starting mapper \"CRD\""
time="2020-03-16T22:07:34Z" level=info msg="loaded existing keypair" certPath=/var/aws-iam-authenticator/cert.pem keyPath=/var/aws-iam-authenticator/key.pem
time="2020-03-16T22:07:34Z" level=info msg="listening on https://127.0.0.1:21362/authenticate"
time="2020-03-16T22:07:34Z" level=info msg="reconfigure your apiserver with `--authentication-token-webhook-config-file=/etc/kubernetes/aws-iam-authenticator/kubeconfig.yaml` to enable (assuming default hostPath mounts)"
time="2020-03-16T22:07:34Z" level=info msg="starting aws iam authenticator controller"
time="2020-03-16T22:07:34Z" level=info msg="waiting for informer caches to sync"
time="2020-03-16T22:07:34Z" level=info msg="Starting the h.ec2Provider.startEc2DescribeBatchProcessing "
time="2020-03-16T22:09:08Z" level=info msg="STS response" accesskeyid=ASIA4XXXXXXXXXXXX accountid=XXXXXXXXXXXX arn="arn:aws:sts::XXXXXXXXXXXX:assumed-role/foo/foo" client="127.0.0.1:64070" method=POST path=/authenticate session=foo userid=AROA4XTGQXXXXXXXXXXXX
time="2020-03-16T22:09:08Z" level=warning msg="access denied" arn="arn:aws:iam::XXXXXXXXXXXX:role/foo" client="127.0.0.1:64070" error="ARN is not mapped" method=POST path=/authenticate

What leads me to believe its a k8s 1.16 problem is the CRD's status field:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  annotations:
  name: iamidentitymappings.iamauthenticator.k8s.aws
spec:
  conversion:
    strategy: None
  group: iamauthenticator.k8s.aws
  names:
    categories:
    - all
    kind: IAMIdentityMapping
    listKind: IAMIdentityMappingList
    plural: iamidentitymappings
    singular: iamidentitymapping
  preserveUnknownFields: true
  scope: Cluster
  versions:
  - name: v1alpha1
    schema:
      openAPIV3Schema:
        properties:
          spec:
            properties:
              arn:
                type: string
              groups:
                items:
                  type: string
                type: array
              username:
                type: string
            required:
            - arn
            - username
    served: true
    storage: true
    subresources:
      status: {}
status:
  acceptedNames:
    categories:
    - all
    kind: IAMIdentityMapping
    listKind: IAMIdentityMappingList
    plural: iamidentitymappings
    singular: iamidentitymapping
  conditions:
  - lastTransitionTime: "2020-02-14T01:59:29Z"
    message: no conflicts found
    reason: NoConflicts
    status: "True"
    type: NamesAccepted
  - lastTransitionTime: null
    message: the initial names have been accepted
    reason: InitialNamesAccepted
    status: "True"
    type: Established
  - lastTransitionTime: "2020-03-05T17:04:08Z"
    message: '[spec.validation.openAPIV3Schema.properties[spec].type: Required value:
      must not be empty for specified object fields, spec.validation.openAPIV3Schema.type:
      Required value: must not be empty at the root]'
    reason: Violations
    status: "True"
    type: NonStructuralSchema
  storedVersions:
  - v1alpha1

So this bug may not be a blocker for this PR. Given that this PR fixed my initial issue of the "MountedFile" not working I think it is good to merge, but we should look at migrating the CRD to apiextensions.k8s.io/v1 in order for the custom resources to work on k8s 1.16+.

@wongma7
Copy link
Contributor Author

wongma7 commented Mar 17, 2020

@rifelpet thanks for testing, it was a basic coding error (I confused informerFactory.Start with informer.Run ...). I've tested myself that CRD works now.

I created a CRD that maps my role to system:masters and added an entry in mapRoles to the file that maps my role to system:asdf.

    2 apiVersion: iamauthenticator.k8s.aws/v1alpha1                                             
    3 kind: IAMIdentityMapping                                                                  
    4 metadata:                                                                                 
    5   name: kubernetes-admin                                                                  
    6 spec:                                                                                     
    7   arn: arn:aws:iam::xxxxxxxxxxxx:role/ec2-admin                                           
    8   username: kubernetes-admin                                                              
    9   groups:                                                                                 
   10   - system:masters    
   90       mapRoles:                                                                           
   91       # statically map arn:aws:iam::000000000000:role/KubernetesAdmin to a cluster admin  
   92       - roleARN: arn:aws:iam::xxxxxxxxxxxx:role/ec2-admin                                 
   93         username: kubernetes-admin                                                        
   94         groups:                                                                           
   95         - system:asdf 

With --backend-mode=CRD,File, logs look like this, I get mapped to system:masters (notice the lines about syncing like successfully synced kubernetes-admin that indicate the CRD mode is actually working):

$ k logs --context local -f -n kube-system aws-iam-authenticator-bxlb9
time="2020-03-17T01:15:24Z" level=warning msg="warning: backend-mode \"File\" is deprecated, use
 \"MountedFile\" instead"
time="2020-03-17T01:15:24Z" level=info msg="creating event broadcaster"
time="2020-03-17T01:15:24Z" level=info msg="setting up event handlers"
time="2020-03-17T01:15:24Z" level=info msg="starting mapper \"CRD\""
time="2020-03-17T01:15:24Z" level=info msg="starting mapper \"MountedFile\""
time="2020-03-17T01:15:24Z" level=info msg="mapping IAM role" groups="[system:asdf]" role="arn:a
ws:iam::xxxxxxxxxxxx:role/ec2-admin" username=kubernetes-admin
time="2020-03-17T01:15:24Z" level=info msg="mapping IAM role" groups="[system:bootstrappers aws:
instances]" role="arn:aws:iam::000000000000:role/KubernetesNode" username="aws:{{AccountID}}:ins
tance:{{SessionName}}"
time="2020-03-17T01:15:24Z" level=info msg="mapping IAM role" groups="[system:masters]" role="arn:aws:iam::000000000000:role/KubernetesAdmin" username="admin:{{SessionName}}"
time="2020-03-17T01:15:24Z" level=info msg="mapping IAM role" groups="[developers]" role="arn:aw
s:iam::000000000000:role/KubernetesUsers" username="{{SessionNameRaw}}"
time="2020-03-17T01:15:24Z" level=info msg="mapping IAM user" groups="[system:masters]" user="ar
n:aws:iam::000000000000:user/Alice" username=alice
time="2020-03-17T01:15:24Z" level=info msg="starting aws iam authenticator controller"
time="2020-03-17T01:15:24Z" level=info msg="waiting for informer caches to sync"
time="2020-03-17T01:15:24Z" level=info msg="loaded existing keypair" certPath=/var/aws-iam-authe
nticator/cert.pem keyPath=/var/aws-iam-authenticator/key.pem
time="2020-03-17T01:15:24Z" level=info msg="loaded existing keypair" certPath=/var/aws-iam-authe
nticator/cert.pem keyPath=/var/aws-iam-authenticator/key.pem
time="2020-03-17T01:15:24Z" level=info msg="writing webhook kubeconfig file" kubeconfigPath=/etc
/kubernetes/aws-iam-authenticator/kubeconfig.yaml
time="2020-03-17T01:15:24Z" level=info msg="listening on https://127.0.0.1:21362/authenticate"
time="2020-03-17T01:15:24Z" level=info msg="reconfigure your apiserver with `--authentication-to
ken-webhook-config-file=/etc/kubernetes/aws-iam-authenticator/kubeconfig.yaml` to enable (assumi
ng default hostPath mounts)"
time="2020-03-17T01:15:24Z" level=info msg="Starting the h.ec2Provider.startEc2DescribeBatchProc
essing "
time="2020-03-17T01:15:24Z" level=info msg="starting workers"
time="2020-03-17T01:15:24Z" level=info msg="started workers"
time="2020-03-17T01:15:24Z" level=info msg="successfully synced kubernetes-admin"
time="2020-03-17T01:15:24Z" level=info msg="Event(v1.ObjectReference{Kind:\"IAMIdentityMapping\"
, Namespace:\"\", Name:\"kubernetes-admin\", UID:\"e2913dcf-12be-4226-a176-6e58b5c53be8\", APIVe
rsion:\"iamauthenticator.k8s.aws/v1alpha1\", ResourceVersion:\"1846\", FieldPath:\"\"}): type: '
Normal' reason: 'Synced' Identity synced successfully"
time="2020-03-17T01:15:24Z" level=info msg="successfully synced kubernetes-admin"
time="2020-03-17T01:15:24Z" level=info msg="Event(v1.ObjectReference{Kind:\"IAMIdentityMapping\"
, Namespace:\"\", Name:\"kubernetes-admin\", UID:\"e2913dcf-12be-4226-a176-6e58b5c53be8\", APIVe
rsion:\"iamauthenticator.k8s.aws/v1alpha1\", ResourceVersion:\"1850\", FieldPath:\"\"}): type: '
Normal' reason: 'Synced' Identity synced successfully"
time="2020-03-17T01:15:40Z" level=info msg="STS response" accesskeyid=ASDF accou
ntid=xxxxxxxxxxxx arn="arn:aws:sts::xxxxxxxxxxxx:assumed-role/ec2-admin/i-asdf" cli
ent="127.0.0.1:49834" method=POST path=/authenticate session=i-asdf userid=USERID
time="2020-03-17T01:15:40Z" level=info msg="access granted" arn="arn:aws:iam::xxxxxxxxxxxx:role/
ec2-admin" client="127.0.0.1:49834" groups="[system:masters]" method=POST path=/authenticate uid
="aws-iam-authenticator:xxxxxxxxxxxx:USERID" username=kubernetes-admin

With --backend-mode=File,CRD, logs should look like this, I get mapped to system:asdf:

time="2020-03-17T01:17:12Z" level=info msg="creating event broadcaster"
time="2020-03-17T01:17:12Z" level=info msg="setting up event handlers"
time="2020-03-17T01:17:12Z" level=info msg="starting mapper \"MountedFile\""
time="2020-03-17T01:17:12Z" level=info msg="starting mapper \"CRD\""
time="2020-03-17T01:17:12Z" level=info msg="mapping IAM role" groups="[system:asdf]" role="arn:a
ws:iam::xxxxxxxxxxxx:role/ec2-admin" username=kubernetes-admin
time="2020-03-17T01:17:12Z" level=info msg="mapping IAM role" groups="[system:bootstrappers aws:
instances]" role="arn:aws:iam::000000000000:role/KubernetesNode" username="aws:{{AccountID}}:ins
tance:{{SessionName}}"
time="2020-03-17T01:17:12Z" level=info msg="mapping IAM role" groups="[system:masters]" role="ar
n:aws:iam::000000000000:role/KubernetesAdmin" username="admin:{{SessionName}}"
time="2020-03-17T01:17:12Z" level=info msg="mapping IAM role" groups="[developers]" role="arn:aw
s:iam::000000000000:role/KubernetesUsers" username="{{SessionNameRaw}}"
time="2020-03-17T01:17:12Z" level=info msg="mapping IAM user" groups="[system:masters]" user="ar
n:aws:iam::000000000000:user/Alice" username=alice
time="2020-03-17T01:17:12Z" level=info msg="starting aws iam authenticator controller"
time="2020-03-17T01:17:12Z" level=info msg="waiting for informer caches to sync"
time="2020-03-17T01:17:12Z" level=info msg="loaded existing keypair" certPath=/var/aws-iam-authe
nticator/cert.pem keyPath=/var/aws-iam-authenticator/key.pem
time="2020-03-17T01:17:12Z" level=info msg="loaded existing keypair" certPath=/var/aws-iam-authe
nticator/cert.pem keyPath=/var/aws-iam-authenticator/key.pem
time="2020-03-17T01:17:12Z" level=info msg="writing webhook kubeconfig file" kubeconfigPath=/etc
/kubernetes/aws-iam-authenticator/kubeconfig.yaml
time="2020-03-17T01:17:12Z" level=info msg="listening on https://127.0.0.1:21362/authenticate"
time="2020-03-17T01:17:12Z" level=info msg="reconfigure your apiserver with `--authentication-to
ken-webhook-config-file=/etc/kubernetes/aws-iam-authenticator/kubeconfig.yaml` to enable (assumi
ng default hostPath mounts)"
time="2020-03-17T01:17:12Z" level=info msg="Starting the h.ec2Provider.startEc2DescribeBatchProc
essing "
time="2020-03-17T01:17:12Z" level=info msg="starting workers"
time="2020-03-17T01:17:12Z" level=info msg="started workers"
time="2020-03-17T01:17:12Z" level=info msg="successfully synced kubernetes-admin"
time="2020-03-17T01:17:12Z" level=info msg="Event(v1.ObjectReference{Kind:\"IAMIdentityMapping\"
, Namespace:\"\", Name:\"kubernetes-admin\", UID:\"e0c56bef-b1fd-45b5-8880-cdd88ae95f31\", APIVe
rsion:\"iamauthenticator.k8s.aws/v1alpha1\", ResourceVersion:\"1944\", FieldPath:\"\"}): type: '
Normal' reason: 'Synced' Identity synced successfully"
time="2020-03-17T01:17:12Z" level=info msg="successfully synced kubernetes-admin"
time="2020-03-17T01:17:12Z" level=info msg="Event(v1.ObjectReference{Kind:\"IAMIdentityMapping\"
, Namespace:\"\", Name:\"kubernetes-admin\", UID:\"e0c56bef-b1fd-45b5-8880-cdd88ae95f31\", APIVe
rsion:\"iamauthenticator.k8s.aws/v1alpha1\", ResourceVersion:\"1948\", FieldPath:\"\"}): type: '
Normal' reason: 'Synced' Identity synced successfully"
time="2020-03-17T01:17:25Z" level=info msg="STS response" accesskeyid=ASDF accou
ntid=xxxxxxxxxxxx arn="arn:aws:sts::xxxxxxxxxxxx:assumed-role/ec2-admin/i-asdf" cli
ent="127.0.0.1:50122" method=POST path=/authenticate session=i-asdf userid=USERID
time="2020-03-17T01:17:25Z" level=info msg="access granted" arn="arn:aws:iam::xxxxxxxxxxxx:role/
ec2-admin" client="127.0.0.1:50122" groups="[system:asdf]" method=POST path=/authenticate uid="aws-iam-authenticator:xxxxxxxxxxxx:USERID" username=kubernetes-admin

Finally, with --backend-mode=File or backend-mode not set at all, there's no mention of CRDs in the log even though I have an IAMIdentityMapping present...this is expected.

$ k logs --context local -f -n kube-system aws-iam-authenticator-nj2qj
time="2020-03-17T01:25:30Z" level=info msg="starting mapper \"MountedFile\""
time="2020-03-17T01:25:30Z" level=info msg="mapping IAM role" groups="[system:asdf]" role="arn:a
ws:iam::x:role/ec2-admin" username=kubernetes-admin
time="2020-03-17T01:25:30Z" level=info msg="mapping IAM role" groups="[system:bootstrappers aws:
instances]" role="arn:aws:iam::000000000000:role/KubernetesNode" username="aws:{{AccountID}}:ins
tance:{{SessionName}}"
time="2020-03-17T01:25:30Z" level=info msg="mapping IAM role" groups="[system:masters]" role="ar
n:aws:iam::000000000000:role/KubernetesAdmin" username="admin:{{SessionName}}"
time="2020-03-17T01:25:30Z" level=info msg="mapping IAM role" groups="[developers]" role="arn:aw
s:iam::000000000000:role/KubernetesUsers" username="{{SessionNameRaw}}"
time="2020-03-17T01:25:30Z" level=info msg="mapping IAM user" groups="[system:masters]" user="ar
n:aws:iam::000000000000:user/Alice" username=alice
time="2020-03-17T01:25:30Z" level=info msg="loaded existing keypair" certPath=/var/aws-iam-authe
nticator/cert.pem keyPath=/var/aws-iam-authenticator/key.pem
time="2020-03-17T01:25:30Z" level=info msg="loaded existing keypair" certPath=/var/aws-iam-authe
nticator/cert.pem keyPath=/var/aws-iam-authenticator/key.pem
time="2020-03-17T01:25:30Z" level=info msg="writing webhook kubeconfig file" kubeconfigPath=/etc
/kubernetes/aws-iam-authenticator/kubeconfig.yaml
time="2020-03-17T01:25:30Z" level=info msg="listening on https://127.0.0.1:21362/authenticate"
time="2020-03-17T01:25:30Z" level=info msg="reconfigure your apiserver with `--authentication-to
ken-webhook-config-file=/etc/kubernetes/aws-iam-authenticator/kubeconfig.yaml` to enable (assumi
ng default hostPath mounts)"
time="2020-03-17T01:25:30Z" level=info msg="Starting the h.ec2Provider.startEc2DescribeBatchProc
essing "
time="2020-03-17T01:25:35Z" level=info msg="STS response" accesskeyid=x accou
ntid=x arn="arn:aws:sts::x:assumed-role/ec2-admin/i-x" cli
ent="127.0.0.1:50544" method=POST path=/authenticate session=i-x userid=x
time="2020-03-17T01:25:35Z" level=info msg="access granted" arn="arn:aws:iam::x:role/
ec2-admin" client="127.0.0.1:50544" groups="[system:asdf]" method=POST path=/authenticate uid="a
ws-iam-authenticator:x" username=kubernetes-admin

@rifelpet
Copy link
Contributor

rifelpet commented Mar 17, 2020

I can confirm the behavior with everything you outlined above. I see you updated the default value for --backend-mode to be MountedFile rather than all 3 modes in a list. Is there a reason for that? I think with the current fixes in this PR that it should be safe to preserve the original default of all 3 modes enabled.

For Kops' built-in support I'll probably have it default to having all 3 modes enabled.

Thanks for your work on this! I'm looking forward to this getting merged and a new release cut.

@wongma7
Copy link
Contributor Author

wongma7 commented Mar 17, 2020

I can confirm the behavior with everything you outlined above. I see you updated the default value for --backend-mode to be MountedFile rather than all 3 modes in a list. Is there a reason for that? I think with the current fixes in this PR that it should be safe to preserve the original default of all 3 modes enabled.

Yes, it should be safe…I just wanted to revert to pre-0.5.0 in an (over)abundance of caution. One other thing is that I’ve found the logging from the EKS mode can be annoying when the aws-auth configmap doesn’t exist, so I’d rather wait to turn it on by default.

README.md Outdated Show resolved Hide resolved
`mapUsers` and `mapRoles` fields of its configuration. See [Full Configuration
Format](#full-configuration-format) below for details.

Using the `--backend-mode` flag, you can configure the server to source
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, this explanation is helpful.

README.md Show resolved Hide resolved
cmd/aws-iam-authenticator/server.go Show resolved Hide resolved
pkg/mapper/configmap/mapper.go Outdated Show resolved Hide resolved
pkg/mapper/crd/mapper.go Show resolved Hide resolved
pkg/mapper/file/mapper.go Outdated Show resolved Hide resolved
ModeConfigMap string = "ConfigMap"
ModeCRD string = "CRD"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: just File might be more techincally correct since it doesn't have to run in a container, but I understand that it probably makes more sense in most cases, so MountedFile might be the better option.

pkg/mapper/mapper.go Outdated Show resolved Hide resolved
@nckturner
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 7, 2020
@k8s-ci-robot k8s-ci-robot merged commit 50ad704 into kubernetes-sigs:master Apr 7, 2020
@rifelpet
Copy link
Contributor

@nckturner any chance we could get a new aws-iam-authenticator release that includes this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

--backend-mode behavior unclear
7 participants