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

adds authentication helper for aws eks #404

Merged
merged 4 commits into from
Apr 2, 2019
Merged

Conversation

smcavallo
Copy link
Contributor

Adds a helper class which can retrieve a token which can be used to authenticate against aws eks

Signed-off-by: S.Cavallo smcavallo@hotmail.com

Signed-off-by: S.Cavallo <smcavallo@hotmail.com>
Signed-off-by: S.Cavallo <smcavallo@hotmail.com>
@cben
Copy link
Collaborator

cben commented Mar 28, 2019

Cool, reviewing...

Copy link
Collaborator

@cben cben left a comment

Choose a reason for hiding this comment

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

Nice! Some small questions.

'gems: [aws-sdk-core,aws-sigv4]. To support auth-provider eks, you must ' \
"include it in your calling application. Failed with: #{e.message}"
end
# https://github.com/aws/aws-sdk-ruby/pull/1848
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this mean one needs a sufficiently new aws-sdk-core? Is ainimal version worth documenting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now that you mention this, the only requirement is aws-sigv4. aws-sdk is not required. consumers can use any version of aws-sdk v2 or aws-sdk-core v3 as long as it contains a credentials object it can pass through to the aws-sig4 pre-signer class. i'll update the documentation

README.md Outdated
)
```

Note that this returns a token good for one hour. If your code requires authorization for longer than that, you should plan to
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it indeed 1 hour? (or just copy pasted)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

one minute - sorry - copy/paste

README.md Outdated
To obtain a token:

```ruby
require 'aws-sdk-core'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this be omitted? Its required in token().

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 removed it from token but will be required for anyone constructing the Aws::Credentials object

README.md Outdated
bearer_token: Kubeclient::AmazonEksCredentials.token(credentials, eks_cluster)
}
client = Kubeclient::Client.new(
'https://localhost:8443/api/', 'v1', auth_options: auth_options
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: is localhost realistic when running on EKS? What's a typical hostname (or use example.com) or port?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's the https endpoint for your eks cluster (same as you'd put in your kubeconfig. i've updated the docs.

README.md Outdated
@@ -287,6 +287,37 @@ Kubeclient::Client.new(
```


#### Amazon EKS Credentials

On Amazon EKS, when using aws-iam-authentication, with [credentials](https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Credentials.html),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you clarify whether it's for cluster running on EKS, or the code calling Kubeclient, or both?

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'll put a blurb in there. it's possible to use aws-iam-authentication with kubernetes clusters which are self-hosted on EC2. I've never tested these tokens in that configuration.

'X-K8s-Aws-Id' => eks_cluster
}
)
kube_token = 'k8s-aws-v1.' + Base64.urlsafe_encode64(presignedUrlString.to_s).chomp('==')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you have reference for removing the == padding? I think it's there in base64 because without it sometimes the decoding is ambiguous (?), so I worry if this works now but might break if length changes...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

when calling Base64.urlsafe_encode64 on the presignedurl, the result ends in ==
On the aws side, the request will not be authorized unless the == doesn't exist at the end. I don't know of a better solution - this is what we need to do when generating our tokens for them to work correctly.

Signed-off-by: S.Cavallo <smcavallo@hotmail.com>
Signed-off-by: S.Cavallo <smcavallo@hotmail.com>
@cben cben merged commit 9a3a941 into ManageIQ:master Apr 2, 2019
@cben
Copy link
Collaborator

cben commented Apr 2, 2019

Thanks again.

1 minute is really short, for the interested #393 is brainstorming on adding auto renewal to kubeclient.

cben added a commit to cben/kubeclient that referenced this pull request May 3, 2019
This was referenced May 3, 2019
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants