Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 63ba131

Browse files
authored
Merge pull request #133 from JoshVanL/dev-cluster-deploy-improvments
Dev cluster deploy improvments
2 parents ca45885 + dc0fbd6 commit 63ba131

File tree

22 files changed

+218
-108
lines changed

22 files changed

+218
-108
lines changed

.dockerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
*
2-
!/bin/kube-oidc-proxy
2+
!/bin/kube-oidc-proxy-linux

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ LABEL description="OIDC reverse proxy authenticator based on Kubernetes"
44

55
RUN apk --no-cache --update add ca-certificates
66

7-
COPY ./bin/kube-oidc-proxy /usr/bin/kube-oidc-proxy
7+
COPY ./bin/kube-oidc-proxy-linux /usr/bin/kube-oidc-proxy
88

99
CMD ["/usr/bin/kube-oidc-proxy"]

Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ BINDIR ?= $(CURDIR)/bin
33
HACK_DIR ?= hack
44
PATH := $(BINDIR):$(PATH)
55
ARTIFACTS ?= artifacts
6+
ARCH ?= amd64
67

78
SHELL = /bin/bash -o pipefail
89

@@ -91,25 +92,26 @@ test: generate verify ## run all go tests
9192
go test -v -bench $$(go list ./pkg/... ./cmd/... | grep -v pkg/e2e) | tee $(ARTIFACTS)/go-test.stdout
9293
cat $(ARTIFACTS)/go-test.stdout | go run github.com/jstemmer/go-junit-report > $(ARTIFACTS)/junit-go-test.xml
9394

94-
e2e: ## run end to end tests
95+
e2e: depend ## run end to end tests
9596
mkdir -p $(ARTIFACTS)
9697
KUBE_OIDC_PROXY_ROOT_PATH="$$(pwd)" go test -timeout 30m -v --count=1 ./test/e2e/suite/.
9798

9899
build: generate ## build kube-oidc-proxy
99100
CGO_ENABLED=0 go build -ldflags '-w $(shell hack/version-ldflags.sh)' -o ./bin/kube-oidc-proxy ./cmd/.
100101

101102
docker_build: generate test build ## build docker image
103+
GOARCH=$(ARCH) GOOS=linux CGO_ENABLED=0 go build -ldflags '-w $(shell hack/version-ldflags.sh)' -o ./bin/kube-oidc-proxy-linux ./cmd/.
102104
docker build -t kube-oidc-proxy .
103105

104106
all: test build ## runs tests, build
105107

106108
image: all docker_build ## runs tests, build and docker build
107109

108-
dev_cluster_create: ## create dev cluster for development testing
110+
dev_cluster_create: depend ## create dev cluster for development testing
109111
KUBE_OIDC_PROXY_ROOT_PATH="$$(pwd)" go run -v ./test/environment/dev create
110112

111-
dev_cluster_deploy: ## deploy into dev cluster
113+
dev_cluster_deploy: depend ## deploy into dev cluster
112114
KUBE_OIDC_PROXY_ROOT_PATH="$$(pwd)" go run -v ./test/environment/dev deploy
113115

114-
dev_cluster_destroy: ## destroy dev cluster
116+
dev_cluster_destroy: depend ## destroy dev cluster
115117
KUBE_OIDC_PROXY_ROOT_PATH="$$(pwd)" go run -v ./test/environment/dev destroy

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,7 @@ users:
132132

133133
## Development
134134
*NOTE*: building kube-oidc-proxy requires Go version 1.12 or higher.
135+
136+
To help with development, there is a suite of tools you can use to deploy a
137+
functioning proxy from source locally. You can read more
138+
[here](./docs/tasks/development-testing.md).

docs/tasks/development-testing.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Development Testing
2+
3+
In order to help development for the proxy, there are a few tools in place for
4+
quick testing.
5+
6+
# Creating a Cluster
7+
8+
Use `make dev_cluster_create` to spin up a kind cluster locally. This will also
9+
build the proxy and other tooling from source, build their images, and load them
10+
onto each node.
11+
12+
# Deploying the Proxy
13+
14+
This will build the proxy and other tooling from source,build the images, and
15+
load them onto each node. This will then deploy the proxy alongside a fake OIDC
16+
issuer so that the proxy is fully functional. The proxy will then be reachable
17+
from a node port service in the cluster.
18+
19+
20+
```bash
21+
make dev_cluster_deploy
22+
```
23+
24+
This command will output a signed OIDC token that is valid for the proxy. You
25+
can then make calls to the proxy, like the following:
26+
27+
```bash
28+
curl -k https://172.17.0.2:30226 -H 'Authorization: bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.ewoJImlzcyI6Imh0dHBzOi8vb2lkYy1pc3N1ZXItZTJlLmt1YmUtb2lkYy1wcm94eS1lMmUtNmhiNGcuc3ZjLmNsdXN0ZXIubG9jYWw6NjQ0MyIsCgkiYXVkIjpbImt1YmUtb2lkYy1wcm94eS1lMmUtY2xpZW50LWlkIiwiYXVkLTIiXSwKCSJlbWFpbCI6InVzZXJAZXhhbXBsZS5jb20iLAoJImdyb3VwcyI6WyJncm91cC0xIiwiZ3JvdXAtMiJdLAoJImV4cCI6MTU4MjU1NTYzMQoJfQ.qWCM5zUHGslmwbgyZnMjhVeCLJd3R3c7xjtatjT_pv1VY-PpJ8IGBsbcCpur1fAm2CAbr0juM3yzwV1S3TUjhNhE8Wo6rxjA2Flnmwj7Nn2Got6T_cMFHQ_3A6YC72qkMwH-7SvXFB-C5Bk96vi9-clrxJ_b1XjfMPViZEVCJphh9HVzrZ5DPOAR0PDl-qnVys_CRkF0NEwEvAZL5SFumBqjtLBI9XUlWbB6VTljPOExL1zkv8NevZF8DxVsYFaW9HOYH8vNgC07kj_oUVkmAjP-2tVngcBKka0IBmuz2r-RfWNy9VJ-yb19AbtJNw6fjASy7O6VifuH4ZpjP5JSIg'
29+
```
30+
31+
You are also able to deploy a server that the proxy connects to. This is useful
32+
for checking the headers and request body sent to the target server by the
33+
proxy which are present in the server logs. To enable this, set the following
34+
environment variable:
35+
36+
```bash
37+
KUBE_OIDC_PROXY_FAKE_APISERVER=true make dev_cluster_deploy
38+
```
39+
40+
# Delete the cluster
41+
42+
To delete the test kind cluster, use `make dev_cluster_destroy`.

test/e2e/framework/helper/deploy.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func (h *Helper) DeployIssuer(ns string) (*util.KeyBundle, *url.URL, error) {
209209
return bundle, appURL, nil
210210
}
211211

212-
func (h *Helper) DeployFakeAPIServer(ns string) (*util.KeyBundle, *url.URL, error) {
212+
func (h *Helper) DeployFakeAPIServer(ns string) ([]corev1.Volume, *url.URL, error) {
213213
cnt := corev1.Container{
214214
Name: FakeAPIServerName,
215215
Image: FakeAPIServerName,
@@ -239,7 +239,31 @@ func (h *Helper) DeployFakeAPIServer(ns string) (*util.KeyBundle, *url.URL, erro
239239
return nil, nil, err
240240
}
241241

242-
return bundle, appURL, nil
242+
sec, err := h.KubeClient.CoreV1().Secrets(ns).Create(&corev1.Secret{
243+
ObjectMeta: metav1.ObjectMeta{
244+
GenerateName: "fake-apiserver-ca-",
245+
Namespace: ns,
246+
},
247+
Data: map[string][]byte{
248+
"ca.pem": bundle.CertBytes,
249+
},
250+
})
251+
if err != nil {
252+
return nil, nil, err
253+
}
254+
255+
extraVolumes := []corev1.Volume{
256+
{
257+
Name: "fake-apiserver",
258+
VolumeSource: corev1.VolumeSource{
259+
Secret: &corev1.SecretVolumeSource{
260+
SecretName: sec.Name,
261+
},
262+
},
263+
},
264+
}
265+
266+
return extraVolumes, appURL, nil
243267
}
244268

245269
func (h *Helper) deployApp(ns, name string, serviceType corev1.ServiceType, container corev1.Container, volumes ...corev1.Volume) (*util.KeyBundle, *url.URL, error) {

test/e2e/suite/cases/headers/headers.go

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@ package headers
44
import (
55
"fmt"
66
"net/http"
7-
"net/url"
87
"strings"
98
"time"
109

1110
. "github.com/onsi/ginkgo"
1211
. "github.com/onsi/gomega"
1312

14-
corev1 "k8s.io/api/core/v1"
15-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16-
1713
"github.com/jetstack/kube-oidc-proxy/test/e2e/framework"
1814
testutil "github.com/jetstack/kube-oidc-proxy/test/util"
1915
)
@@ -28,10 +24,11 @@ var _ = framework.CasesDescribe("Headers", func() {
2824
})
2925

3026
It("should not respond with any extra headers if none are set on the proxy", func() {
31-
fakeAPIServerURL, extraVolumes := deployFakeAPIServer(f)
27+
extraOIDCVolumes, fakeAPIServerURL, err := f.Helper().DeployFakeAPIServer(f.Namespace.Name)
28+
Expect(err).NotTo(HaveOccurred())
3229

3330
By("Redeploying proxy to send traffic to fake API server")
34-
f.DeployProxyWith(extraVolumes, fmt.Sprintf("--server=%s", fakeAPIServerURL), "--certificate-authority=/fake-apiserver/ca.pem")
31+
f.DeployProxyWith(extraOIDCVolumes, fmt.Sprintf("--server=%s", fakeAPIServerURL), "--certificate-authority=/fake-apiserver/ca.pem")
3532

3633
resp := sendRequestToProxy(f)
3734

@@ -44,10 +41,12 @@ var _ = framework.CasesDescribe("Headers", func() {
4441
})
4542

4643
It("should respond with remote address and custom extra headers when they are set", func() {
47-
fakeAPIServerURL, extraVolumes := deployFakeAPIServer(f)
44+
By("Deploying fake API Server")
45+
extraOIDCVolumes, fakeAPIServerURL, err := f.Helper().DeployFakeAPIServer(f.Namespace.Name)
46+
Expect(err).NotTo(HaveOccurred())
4847

4948
By("Redeploying proxy to send traffic to fake API server with extra headers set")
50-
f.DeployProxyWith(extraVolumes, fmt.Sprintf("--server=%s", fakeAPIServerURL), "--certificate-authority=/fake-apiserver/ca.pem",
49+
f.DeployProxyWith(extraOIDCVolumes, fmt.Sprintf("--server=%s", fakeAPIServerURL), "--certificate-authority=/fake-apiserver/ca.pem",
5150
"--extra-user-header-client-ip", "--extra-user-headers=key1=foo,key2=foo,key1=bar")
5251

5352
resp := sendRequestToProxy(f)
@@ -86,36 +85,6 @@ var _ = framework.CasesDescribe("Headers", func() {
8685
})
8786
})
8887

89-
func deployFakeAPIServer(f *framework.Framework) (*url.URL, []corev1.Volume) {
90-
By("Deploying fake API Server")
91-
fAPIServerBundle, fakeAPIServerURL, err := f.Helper().DeployFakeAPIServer(f.Namespace.Name)
92-
Expect(err).NotTo(HaveOccurred())
93-
94-
sec, err := f.KubeClientSet.CoreV1().Secrets(f.Namespace.Name).Create(&corev1.Secret{
95-
ObjectMeta: metav1.ObjectMeta{
96-
GenerateName: "fake-apiserver-ca-",
97-
Namespace: f.Namespace.Name,
98-
},
99-
Data: map[string][]byte{
100-
"ca.pem": fAPIServerBundle.CertBytes,
101-
},
102-
})
103-
Expect(err).NotTo(HaveOccurred())
104-
105-
extraVolumes := []corev1.Volume{
106-
{
107-
Name: "fake-apiserver",
108-
VolumeSource: corev1.VolumeSource{
109-
Secret: &corev1.SecretVolumeSource{
110-
SecretName: sec.Name,
111-
},
112-
},
113-
},
114-
}
115-
116-
return fakeAPIServerURL, extraVolumes
117-
}
118-
11988
func sendRequestToProxy(f *framework.Framework) *http.Response {
12089
By("Building request to proxy")
12190
tokenPayload := f.Helper().NewTokenPayload(

test/e2e/suite/suite.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ var (
1818

1919
var _ = SynchronizedBeforeSuite(func() []byte {
2020
var err error
21-
env, err = environment.Create(1, 0)
21+
env, err = environment.New(1, 0)
2222
if err != nil {
23-
log.Fatalf("Error provisioning environment: %v", err)
23+
log.Fatalf("Error provisioning environment: %s", err)
24+
}
25+
26+
if err := env.Create(); err != nil {
27+
log.Fatalf("Error creating environment: %s", err)
2428
}
2529

2630
cfg.KubeConfigPath = env.KubeConfigPath()
@@ -29,7 +33,7 @@ var _ = SynchronizedBeforeSuite(func() []byte {
2933
cfg.Environment = env
3034

3135
if err := framework.DefaultConfig.Validate(); err != nil {
32-
log.Fatalf("Invalid test config: %v", err)
36+
log.Fatalf("Invalid test config: %s", err)
3337
}
3438

3539
return nil

test/environment/dev/dev.go

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package main
33

44
import (
55
"fmt"
6+
"net/url"
67
"os"
78
"path/filepath"
9+
"strings"
810
"time"
911

1012
corev1 "k8s.io/api/core/v1"
@@ -20,6 +22,8 @@ import (
2022

2123
const (
2224
clientID = "kube-oidc-proxy-e2e-client-id"
25+
26+
EnvFakeAPIServer = "KUBE_OIDC_PROXY_FAKE_APISERVER"
2327
)
2428

2529
func main() {
@@ -44,23 +48,28 @@ func main() {
4448
}
4549

4650
func create() {
47-
env, err := environment.Create(1, 1)
51+
env, err := environment.New(1, 1)
4852
errExit(err)
4953

54+
errExit(env.Create())
55+
5056
fmt.Printf("> dev environment created.\n")
5157
fmt.Printf("export KUBECONFIG=%s\n", env.KubeConfigPath())
5258
}
5359

5460
func deploy() {
55-
k := new(kind.Kind)
56-
kubeconfig := k.KubeConfigPath()
57-
rootPath, err := environment.RootPath()
61+
env, err := environment.New(1, 1)
5862
errExit(err)
5963

64+
fmt.Printf("> reloading all images\n")
65+
errExit(env.Kind().LoadAllImages())
66+
67+
kubeconfig := env.KubeConfigPath()
68+
6069
cfg := &config.Config{
6170
KubeConfigPath: kubeconfig,
62-
RepoRoot: rootPath,
63-
Kubectl: filepath.Join(rootPath, "bin", "kubectl"),
71+
RepoRoot: env.RootPath(),
72+
Kubectl: filepath.Join(env.RootPath(), "bin", "kubectl"),
6473
}
6574

6675
err = cfg.Validate()
@@ -93,9 +102,24 @@ func deploy() {
93102

94103
fmt.Printf("> deployed issuer at url %s\n", issuerURL)
95104

96-
_, proxyURL, err := helper.DeployProxy(ns, issuerURL,
97-
"kube-oidc-proxy-e2e-client-id", issuerKeyBundle, nil)
98-
errExit(err)
105+
var proxyURL *url.URL
106+
if e := os.Getenv(EnvFakeAPIServer); strings.ToLower(e) == "true" {
107+
extraOIDCVolume, fURL, err := helper.DeployFakeAPIServer(ns.Name)
108+
errExit(err)
109+
110+
fmt.Printf("> deployed fake API server at url %s\n", fURL)
111+
112+
_, proxyURL, err = helper.DeployProxy(ns, issuerURL,
113+
"kube-oidc-proxy-e2e-client-id", issuerKeyBundle, extraOIDCVolume,
114+
fmt.Sprintf("--server=%s", fURL), "--certificate-authority=/fake-apiserver/ca.pem")
115+
errExit(err)
116+
117+
} else {
118+
_, proxyURL, err = helper.DeployProxy(ns, issuerURL,
119+
"kube-oidc-proxy-e2e-client-id", issuerKeyBundle, nil)
120+
errExit(err)
121+
}
122+
99123
fmt.Printf("> deployed proxy at url %s\n", proxyURL)
100124

101125
tokenPayload := helper.NewTokenPayload(issuerURL, clientID, time.Now().Add(time.Hour*48))

0 commit comments

Comments
 (0)