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

Accept certificate authority optionally from a file #1

Merged
merged 1 commit into from
May 14, 2019
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ARG KUBERNETES_VERSION=

RUN set -x && \
apt-get update && \
apt-get install -y jq curl && \
apt-get install -y jq curl gettext-base && \
[ -z "$KUBERNETES_VERSION" ] && KUBERNETES_VERSION=$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt) ||: && \
curl -s -LO https://storage.googleapis.com/kubernetes-release/release/${KUBERNETES_VERSION}/bin/linux/amd64/kubectl && \
chmod +x ./kubectl && \
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ The version of this resource corresponds to the version of kubectl. We recommend
- `server`: *Optional.* The address and port of the API server.
- `token`: *Optional.* Bearer token for authentication to the API server.
- `namespace`: *Optional.* The namespace scope. Defaults to `default`. If set along with `kubeconfig`, `namespace` will override the namespace in the current-context
- `certificate_authority`: *Optional.* A certificate file for the certificate authority.
- `certificate_authority`: *Optional.* A certificate for the certificate authority.
```yaml
certificate_authority: |
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
```
- `certificate_authority_file`: *Optional.* A file to read the certificate from.
```yaml
certificate_authority_file: ca_certs.crt
```
- `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`.
- `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`.
- `aws_eks_cluster_name`: *Optional.* the AWS EKS cluster name, required when `use_aws_iam_authenticator` is true.
Expand Down
13 changes: 11 additions & 2 deletions assets/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,23 @@ setup_kubectl() {
# Optional. The address and port of the API server. Requires token.
local server
server="$(jq -r '.source.server // ""' < "$payload")"
# Optional. A certificate file for the certificate authority.
# Optional. A file to read the certificate from.
local certificate_authority_file
certificate_authority_file="$(jq -r '.source.certificate_authority_file // ""' < "$payload")"
# Optional. A certificate for the certificate authority.
local certificate_authority
certificate_authority="$(jq -r '.source.certificate_authority // ""' < "$payload")"
certificate_authority="$(jq -r '.source.certificate_authority // "${CERTIFICATE_AUTHORITY_FILE_CONTENTS}"' < "$payload")"
# Optional. If true, the API server's certificate will not be checked for
# validity. This will make your HTTPS connections insecure. Defaults to false.
local insecure_skip_tls_verify
insecure_skip_tls_verify="$(jq -r '.source.insecure_skip_tls_verify // ""' < "$payload")"

# When not set, try to get certificate_authority from a file, if provided
export CERTIFICATE_AUTHORITY_FILE_CONTENTS=""
[[ -n "${certificate_authority_file}" && ! -f "${certificate_authority_file}" ]] && certificate_authority_file=""
[[ -n "${certificate_authority_file}" && -f "${certificate_authority_file}" ]] && CERTIFICATE_AUTHORITY_FILE_CONTENTS="$(cat "${certificate_authority_file}")"
certificate_authority=$(echo "$certificate_authority" | envsubst)

# Build options for kubectl config set-cluster
local set_cluster_opts
set_cluster_opts=("--server=$server")
Expand Down