Skip to content
This repository was archived by the owner on Apr 27, 2020. It is now read-only.

Commit 6bea48f

Browse files
jens-solarisbanksuperbrothers
authored andcommitted
Allow EKS users to authenticate by assuming a role. (#64)
1 parent 65b8e9b commit 6bea48f

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ Anne Schuth
1010
Werner Buck
1111
Lucas de Haas
1212
Daniel Jensen
13+
Jens Herrmann

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ The version of this resource corresponds to the version of kubectl. We recommend
4949
- `insecure_skip_tls_verify`: *Optional.* If true, the API server's certificate will not be checked for validity. This will make your HTTPS connections insecure. Defaults to `false`.
5050
- `use_aws_iam_authenticator`: *Optional.* If true, the aws_iam_authenticator, required for connecting with EKS, is used. Requires `aws_eks_cluster_name`. Defaults to `false`.
5151
- `aws_eks_cluster_name`: *Optional.* the AWS EKS cluster name, required when `use_aws_iam_authenticator` is true.
52+
- `aws_eks_assume_role`: *Optional.* the AWS IAM role ARN to assume.
5253

5354
## Behavior
5455

assets/common.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ setup_kubectl() {
7272
use_aws_iam_authenticator="$(jq -r '.source.use_aws_iam_authenticator // ""' < "$payload")"
7373
local aws_eks_cluster_name
7474
aws_eks_cluster_name="$(jq -r '.source.aws_eks_cluster_name // ""' < "$payload")"
75+
local aws_eks_assume_role
76+
aws_eks_assume_role="$(jq -r '.source.aws_eks_assume_role // ""' < "$payload")"
77+
if [[ "$aws_eks_assume_role" ]]; then
78+
aws_eks_assume_role="- -r
79+
- ${aws_eks_assume_role}"
80+
fi
7581
if [[ "$use_aws_iam_authenticator" == "true" ]]; then
7682
if [ -z "$aws_eks_cluster_name" ]; then
7783
echoerr 'You must specify aws_eks_cluster_name when using aws_iam_authenticator.'
@@ -89,6 +95,7 @@ users:
8995
- token
9096
- -i
9197
- ${aws_eks_cluster_name}
98+
${aws_eks_assume_role}
9299
command: aws-iam-authenticator
93100
env: null
94101
EOF

test/suite.bats

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ teardown() {
4040
assert_not_match 'did not find expected key' "$output"
4141
}
4242

43+
@test "with outputs.aws_eks_assume_role" {
44+
run assets/out <<< "$(jq -n '{"source": {"use_aws_iam_authenticator": true, "aws_eks_cluster_name": "eks-cluster01", "aws_eks_assume_role": "arn:role", "server": $server, "token": $token}, "params": {"kubectl": "get po"}}' \
45+
--arg server "$server" \
46+
--arg token "$token" \
47+
--arg kubectl "get po nginx")"
48+
assert_not_match 'did not find expected key' "$output"
49+
}
50+
4351
@test "with source.kubeconfig" {
4452
run assets/out <<< "$(jq -n '{"source": {"kubeconfig": $kubeconfig}, "params": {"kubectl": $kubectl}}' \
4553
--arg kubeconfig "$(cat "$kubeconfig_file")" \

0 commit comments

Comments
 (0)