mirror of
https://github.com/int128/kubelogin.git
synced 2026-02-14 16:39:51 +00:00
Add acceptance test (#315)
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,6 +1,7 @@
|
|||||||
/.idea
|
/.idea
|
||||||
|
|
||||||
/system_test/output/
|
/system_test/output/
|
||||||
|
/acceptance_test/output/
|
||||||
|
|
||||||
/dist/output
|
/dist/output
|
||||||
/coverage.out
|
/coverage.out
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ users:
|
|||||||
- --oidc-client-secret=YOUR_CLIENT_SECRET
|
- --oidc-client-secret=YOUR_CLIENT_SECRET
|
||||||
```
|
```
|
||||||
|
|
||||||
See [the setup guide](docs/setup.md) for more.
|
See [setup guide](docs/setup.md) for more.
|
||||||
|
|
||||||
|
|
||||||
### Run
|
### Run
|
||||||
@@ -101,6 +101,8 @@ You got a token with the following claims:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can verify kubelogin works with your provider using [acceptance test](acceptance_test).
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
|||||||
42
acceptance_test/Makefile
Normal file
42
acceptance_test/Makefile
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
CLUSTER_NAME := kubelogin-acceptance-test
|
||||||
|
OUTPUT_DIR := $(CURDIR)/output
|
||||||
|
|
||||||
|
KUBECONFIG := $(OUTPUT_DIR)/kubeconfig.yaml
|
||||||
|
export KUBECONFIG
|
||||||
|
|
||||||
|
# create a Kubernetes cluster
|
||||||
|
.PHONY: cluster
|
||||||
|
cluster:
|
||||||
|
# create a cluster
|
||||||
|
mkdir -p $(OUTPUT_DIR)
|
||||||
|
sed -e "s|OIDC_ISSUER_URL|$(OIDC_ISSUER_URL)|" -e "s|OIDC_CLIENT_ID|$(OIDC_CLIENT_ID)|" cluster.yaml > $(OUTPUT_DIR)/cluster.yaml
|
||||||
|
kind create cluster --name $(CLUSTER_NAME) --config $(OUTPUT_DIR)/cluster.yaml
|
||||||
|
# set up access control
|
||||||
|
kubectl create clusterrole cluster-readonly --verb=get,watch,list --resource='*.*'
|
||||||
|
kubectl create clusterrolebinding cluster-readonly --clusterrole=cluster-readonly --user=$(YOUR_EMAIL)
|
||||||
|
# set up kubectl
|
||||||
|
kubectl config set-credentials oidc \
|
||||||
|
--exec-api-version=client.authentication.k8s.io/v1beta1 \
|
||||||
|
--exec-command=$(CURDIR)/../kubelogin \
|
||||||
|
--exec-arg=get-token \
|
||||||
|
--exec-arg=--token-cache-dir=$(OUTPUT_DIR)/token-cache \
|
||||||
|
--exec-arg=--oidc-issuer-url=$(OIDC_ISSUER_URL) \
|
||||||
|
--exec-arg=--oidc-client-id=$(OIDC_CLIENT_ID) \
|
||||||
|
--exec-arg=--oidc-client-secret=$(OIDC_CLIENT_SECRET) \
|
||||||
|
--exec-arg=--oidc-extra-scope=email
|
||||||
|
# switch the default user
|
||||||
|
kubectl config set-context --current --user=oidc
|
||||||
|
|
||||||
|
# clean up the resources
|
||||||
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
-rm -r $(OUTPUT_DIR)
|
||||||
|
.PHONY: delete-cluster
|
||||||
|
delete-cluster:
|
||||||
|
kind delete cluster --name $(CLUSTER_NAME)
|
||||||
|
|
||||||
|
.PHONY: check
|
||||||
|
check:
|
||||||
|
docker version
|
||||||
|
kind version
|
||||||
|
kubectl version --client
|
||||||
75
acceptance_test/README.md
Normal file
75
acceptance_test/README.md
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
# kubelogin/acceptance_test
|
||||||
|
|
||||||
|
This is a manual test for verifying Kubernetes OIDC authentication with your OIDC provider.
|
||||||
|
|
||||||
|
|
||||||
|
## Purpose
|
||||||
|
|
||||||
|
This test checks the following points:
|
||||||
|
|
||||||
|
1. You can set up your OIDC provider using [setup guide](../docs/setup.md).
|
||||||
|
1. The plugin works with your OIDC provider.
|
||||||
|
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
### Prerequisite
|
||||||
|
|
||||||
|
You need to build the plugin into the parent directory.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
make -C ..
|
||||||
|
```
|
||||||
|
|
||||||
|
You need to set up your provider.
|
||||||
|
See [setup guide](../docs/setup.md) for more.
|
||||||
|
|
||||||
|
You need to install the following tools:
|
||||||
|
|
||||||
|
- Docker
|
||||||
|
- Kind
|
||||||
|
- kubectl
|
||||||
|
|
||||||
|
You can check if the tools are available.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
make check
|
||||||
|
```
|
||||||
|
|
||||||
|
### 1. Create a cluster
|
||||||
|
|
||||||
|
Create a cluster.
|
||||||
|
For example, you can create a cluster with Google account authentication.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
make OIDC_ISSUER_URL=https://accounts.google.com \
|
||||||
|
OIDC_CLIENT_ID=REDACTED.apps.googleusercontent.com \
|
||||||
|
OIDC_CLIENT_SECRET=REDACTED \
|
||||||
|
YOUR_EMAIL=REDACTED@gmail.com
|
||||||
|
```
|
||||||
|
|
||||||
|
It will do the following steps:
|
||||||
|
|
||||||
|
1. Create a cluster.
|
||||||
|
1. Set up access control. It allows read-only access from your email address.
|
||||||
|
1. Set up kubectl to enable the plugin.
|
||||||
|
|
||||||
|
You can change kubectl configuration in generated `output/kubeconfig.yaml`.
|
||||||
|
|
||||||
|
### 2. Run kubectl
|
||||||
|
|
||||||
|
Make sure you can log in to the provider and access the cluster.
|
||||||
|
|
||||||
|
```console
|
||||||
|
% export KUBECONFIG=$PWD/output/kubeconfig.yaml
|
||||||
|
% kubectl get pods -A
|
||||||
|
```
|
||||||
|
|
||||||
|
### Clean up
|
||||||
|
|
||||||
|
To delete the cluster and generated files:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
make delete-cluster
|
||||||
|
make clean
|
||||||
|
```
|
||||||
13
acceptance_test/cluster.yaml
Normal file
13
acceptance_test/cluster.yaml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
kind: Cluster
|
||||||
|
apiVersion: kind.x-k8s.io/v1alpha4
|
||||||
|
kubeadmConfigPatches:
|
||||||
|
- |
|
||||||
|
apiVersion: kubeadm.k8s.io/v1beta2
|
||||||
|
kind: ClusterConfiguration
|
||||||
|
metadata:
|
||||||
|
name: config
|
||||||
|
apiServer:
|
||||||
|
extraArgs:
|
||||||
|
oidc-issuer-url: OIDC_ISSUER_URL
|
||||||
|
oidc-client-id: OIDC_CLIENT_ID
|
||||||
|
oidc-username-claim: email
|
||||||
@@ -1,13 +1,17 @@
|
|||||||
# kubelogin/system_test
|
# kubelogin/system_test
|
||||||
|
|
||||||
This is a system test for verifying the OIDC initial setup and plugin behavior using a real Kubernetes cluster and OIDC provider.
|
This is an automated test for verifying behavior of the plugin with a real Kubernetes cluster and OIDC provider.
|
||||||
|
|
||||||
It is intended to verify the following points:
|
|
||||||
|
|
||||||
- User can set up Kubernetes OIDC authentication and this plugin.
|
## Purpose
|
||||||
- User can access a cluster after login.
|
|
||||||
|
|
||||||
It performs the test using the following components:
|
This test checks the following points:
|
||||||
|
|
||||||
|
1. User can set up Kubernetes OIDC authentication using [setup guide](../docs/setup.md).
|
||||||
|
1. User can log in to an OIDC provider on a browser.
|
||||||
|
1. User can access the cluster using a token returned from the plugin.
|
||||||
|
|
||||||
|
It depends on the following components:
|
||||||
|
|
||||||
- Kubernetes cluster (Kind)
|
- Kubernetes cluster (Kind)
|
||||||
- OIDC provider (Dex)
|
- OIDC provider (Dex)
|
||||||
|
|||||||
Reference in New Issue
Block a user