Skip to content
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
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ on:
- main
paths:
- "**/*.go"
- "helm-charts/**"
- "go.mod"
- "go.sum"
- ".github/workflows/test.yml"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ test:
go mod tidy
git diff --exit-code go.mod go.sum
go mod verify
go test -v ${TEST_GCFLAGS} ${MKFILE_DIR}pkg/... ${MKFILE_DIR}cmd/... ${TEST_FLAGS}
go test -v ${TEST_GCFLAGS} ${MKFILE_DIR}pkg/... ${MKFILE_DIR}cmd/... ${MKFILE_DIR}helm-charts/easegress ${TEST_FLAGS}

integration_test: build
{ \
Expand Down
33 changes: 30 additions & 3 deletions helm-charts/easegress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,31 @@ helm install easegress -n easegress ./helm-charts/easegress \
--set 'cluster.nodeHostnames={hostname-xyz}'
```

The Admin API listens on `127.0.0.1:2381` inside the pod and is not exposed by a service by default.
Use `kubectl port-forward` for local administration:

```shell
kubectl port-forward -n easegress pod/easegress-0 2381:2381
```

Add filters and objects to Easegress:

```shell
egctl --server {NODE_IP}:31255 create object -f pipeline.yaml
egctl --server 127.0.0.1:2381 create object -f pipeline.yaml
```
where `pipeline.yaml` is an Easegress object definition.

To expose the Admin API through a NodePort, enable the admin service explicitly and configure authentication:

```shell
helm install easegress -n easegress ./helm-charts/easegress \
--set admin.apiAddr=0.0.0.0:2381 \
--set service.admin.enabled=true \
--set service.admin.type=NodePort \
--set admin.basicAuth.admin=change-me
```
where NODE_IP is the IP address a node running Easegress pod and `pipeline.yaml` Easegress object definition.

Set `admin.allowUnsafeNoAuth=true` only when an external control already protects the Admin API.

## Uninstall

Expand All @@ -63,7 +82,15 @@ The following table lists the configurable parameters of the Easegress Helm inst
| Key | Type | Default | Description |
|-----|------|---------|-------------|
| service.nodePort | int | `30780` | nodePort for easegress service. |
| service.adminPort | int | `31255` | nodePort for egctl access. |
| service.adminPort | int | `31255` | Deprecated fallback for `service.admin.nodePort`. |
| service.admin.enabled | bool | `false` | create a service for the Admin API. |
| service.admin.type | string | `ClusterIP` | service type for the Admin API. |
| service.admin.nodePort | int | `31255` | nodePort for egctl access when `service.admin.type` is `NodePort`. |
| admin.apiAddr | string | `127.0.0.1:2381` | address the Admin API listens on. |
| admin.basicAuth | map | `{}` | username to password map for Admin API basic authentication. |
| admin.allowUnsafeNoAuth | bool | `false` | allow external Admin API services without chart-configured authentication. |
| serviceAccount.automountServiceAccountToken | bool | `false` | mount the Kubernetes service account token into Easegress pods. |
| rbac.readSecrets | bool | `false` | grant read/list/watch permissions on Kubernetes Secrets. |
| cluster.primaryReplicas | int | `1` | number of easegress service that persists cluster data to disk |
| cluster.volumeType | string | `emptyDir` | `emptyDir`: use pods internal filesystem that is not persisted when pod crashes. Use `emptyDir` only when primaryReplicas is 1. | `persistentVolume`, create as many persistenVolumes and persistentVolumeClaims as there are nodeHostnames.
| cluster.volumeLocalPath | string | `/opt/easegress` | local path of persistenVolume on nodes |
Expand Down
149 changes: 149 additions & 0 deletions helm-charts/easegress/chart_security_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
* Copyright (c) 2017, The Easegress Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package easegress

import (
"os"
"strings"
"testing"

"gopkg.in/yaml.v3"
)

func readChartValues(t *testing.T) map[string]interface{} {
t.Helper()

data, err := os.ReadFile("values.yaml")
if err != nil {
t.Fatalf("read values.yaml: %v", err)
}

values := map[string]interface{}{}
if err := yaml.Unmarshal(data, &values); err != nil {
t.Fatalf("parse values.yaml: %v", err)
}
return values
}

func chartString(t *testing.T, values map[string]interface{}, keys ...string) string {
t.Helper()

value := chartValue(t, values, keys...)
got, ok := value.(string)
if !ok {
t.Fatalf("%s must be a string, got %T", strings.Join(keys, "."), value)
}
return got
}

func chartBool(t *testing.T, values map[string]interface{}, keys ...string) bool {
t.Helper()

value := chartValue(t, values, keys...)
got, ok := value.(bool)
if !ok {
t.Fatalf("%s must be a bool, got %T", strings.Join(keys, "."), value)
}
return got
}

func chartValue(t *testing.T, values map[string]interface{}, keys ...string) interface{} {
t.Helper()

var value interface{} = values
for _, key := range keys {
current, ok := value.(map[string]interface{})
if !ok {
t.Fatalf("%s parent must be a map, got %T", strings.Join(keys, "."), value)
}
value, ok = current[key]
if !ok {
t.Fatalf("missing chart value %s", strings.Join(keys, "."))
}
}
return value
}

func readChartFile(t *testing.T, path string) string {
t.Helper()

data, err := os.ReadFile(path)
if err != nil {
t.Fatalf("read %s: %v", path, err)
}
return string(data)
}

func TestDefaultChartDoesNotExposeAdminNodePort(t *testing.T) {
values := readChartValues(t)

if got := chartString(t, values, "admin", "apiAddr"); got != "127.0.0.1:2381" {
t.Fatalf("default admin.apiAddr = %q, want local-only 127.0.0.1:2381", got)
}
if chartBool(t, values, "service", "admin", "enabled") {
t.Fatal("default service.admin.enabled must be false")
}
if got := chartString(t, values, "service", "admin", "type"); got == "NodePort" || got == "LoadBalancer" {
t.Fatalf("default service.admin.type = %q, want non-external service type", got)
}

serviceTemplate := readChartFile(t, "templates/Service.yaml")
for _, required := range []string{
"{{- if .Values.service.admin.enabled }}",
"{{- if and .Values.service.admin.enabled $adminAPILoopback -}}",
"admin service requires admin.apiAddr to listen on a non-loopback address",
"admin service type NodePort/LoadBalancer requires admin.basicAuth or admin.allowUnsafeNoAuth=true",
"nodePort: {{ default .Values.service.adminPort .Values.service.admin.nodePort }}",
} {
if !strings.Contains(serviceTemplate, required) {
t.Fatalf("templates/Service.yaml missing admin-service guard %q", required)
}
}
if strings.Contains(serviceTemplate, "nodePort: {{ .Values.service.adminPort }}") {
t.Fatal("templates/Service.yaml must not unconditionally render the admin NodePort")
}
}

func TestDefaultChartDoesNotExposeKubernetesSecrets(t *testing.T) {
values := readChartValues(t)

if chartBool(t, values, "rbac", "readSecrets") {
t.Fatal("default rbac.readSecrets must be false")
}
if chartBool(t, values, "serviceAccount", "automountServiceAccountToken") {
t.Fatal("default serviceAccount.automountServiceAccountToken must be false")
}

clusterRole := readChartFile(t, "templates/ClusterRole.yaml")
if strings.Contains(clusterRole, `resources: ["services", "endpoints", "secrets"]`) {
t.Fatal("ClusterRole must not always grant secrets access")
}
if !strings.Contains(clusterRole, "{{- if .Values.rbac.readSecrets }}") {
t.Fatal("ClusterRole must gate secrets access on rbac.readSecrets")
}

for _, path := range []string{
"templates/StatefulSet.yaml",
"templates/Deployment.yaml",
} {
workload := readChartFile(t, path)
if !strings.Contains(workload, "automountServiceAccountToken: {{ .Values.serviceAccount.automountServiceAccountToken }}") {
t.Fatalf("%s must render serviceAccount.automountServiceAccountToken", path)
}
}
}
7 changes: 6 additions & 1 deletion helm-charts/easegress/templates/ClusterRole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ metadata:
name: {{ .Release.Name }}
rules:
- apiGroups: [""] # "" indicates the core API group
resources: ["services", "endpoints", "secrets"]
resources: ["services", "endpoints"]
verbs: ["get", "watch", "list"]
{{- if .Values.rbac.readSecrets }}
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "watch", "list"]
{{- end }}
- apiGroups: ["networking.k8s.io"]
resources: ["ingresses"]
verbs: ["get", "watch", "list"]
16 changes: 14 additions & 2 deletions helm-charts/easegress/templates/ConfigMap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ data:
{{- range $i, $e := until (.Values.cluster.primaryReplicas | int) }}
- {{ $releasename }}-{{$i}}: http://{{ $releasename }}-{{$i}}.easegress-hs.{{ $releasenamespace }}:2380
{{- end }}
api-addr: 0.0.0.0:2381
api-addr: {{ .Values.admin.apiAddr }}
data-dir: /opt/easegress/data
wal-dir: ""
cpu-profile-file: ""
memory-profile-file: ""
log-dir: {{ .Values.log.path }}
debug: false
{{- with .Values.admin.basicAuth }}
basic-auth:
{{- range $username, $password := . }}
{{ $username | quote }}: {{ $password | quote }}
{{- end }}
{{- end }}
eg-secondary.yaml: |
cluster-name: easegress
cluster-role: secondary
Expand All @@ -34,13 +40,19 @@ data:
{{ else }}
- http://{{ .Release.Name }}-0.easegress-hs.{{ .Release.Namespace }}:2380
{{ end }}
api-addr: 0.0.0.0:2381
api-addr: {{ .Values.admin.apiAddr }}
data-dir: /opt/easegress/data
wal-dir: ""
cpu-profile-file: ""
memory-profile-file: ""
log-dir: {{ .Values.log.path }}
debug: false
{{- with .Values.admin.basicAuth }}
basic-auth:
{{- range $username, $password := . }}
{{ $username | quote }}: {{ $password | quote }}
{{- end }}
{{- end }}
kind: ConfigMap
metadata:
name: {{ .Release.Name }}
Expand Down
1 change: 1 addition & 0 deletions helm-charts/easegress/templates/Deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ spec:
app: {{ .Release.Name }}
spec:
serviceAccountName: {{ .Release.Name }}
automountServiceAccountToken: {{ .Values.serviceAccount.automountServiceAccountToken }}
containers:
- args:
- -c
Expand Down
20 changes: 18 additions & 2 deletions helm-charts/easegress/templates/Service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ spec:

{{- end }}

{{- $adminType := default "ClusterIP" .Values.service.admin.type -}}
{{- $adminExternallyExposed := or (eq $adminType "NodePort") (eq $adminType "LoadBalancer") -}}
{{- $adminAPIAddr := .Values.admin.apiAddr | toString -}}
{{- $adminAPILoopback := or (regexMatch "^(localhost|127(\\.[0-9]{1,3}){3}):[0-9]+$" $adminAPIAddr) (regexMatch "^(\\[::1\\]|::1):[0-9]+$" $adminAPIAddr) -}}
{{- if and .Values.service.admin.enabled $adminAPILoopback -}}
{{- fail "admin service requires admin.apiAddr to listen on a non-loopback address" -}}
{{- end }}
{{- if and .Values.service.admin.enabled $adminExternallyExposed (empty .Values.admin.basicAuth) (not .Values.admin.allowUnsafeNoAuth) -}}
{{- fail "admin service type NodePort/LoadBalancer requires admin.basicAuth or admin.allowUnsafeNoAuth=true" -}}
{{- end }}

{{- if .Values.service.admin.enabled }}
apiVersion: v1
kind: Service
metadata:
Expand All @@ -38,12 +50,16 @@ spec:
port: 2381
protocol: TCP
targetPort: 2381
nodePort: {{ .Values.service.adminPort }}
{{- if $adminExternallyExposed }}
nodePort: {{ default .Values.service.adminPort .Values.service.admin.nodePort }}
{{- end }}
selector:
app: {{ .Release.Name }}
type: NodePort
type: {{ $adminType }}

---
{{- end }}

kind: Service
apiVersion: v1
metadata:
Expand Down
3 changes: 2 additions & 1 deletion helm-charts/easegress/templates/StatefulSet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ spec:
app: {{ .Release.Name }}
spec:
serviceAccountName: {{ .Release.Name }}
automountServiceAccountToken: {{ .Values.serviceAccount.automountServiceAccountToken }}
containers:
- args:
- -c
Expand Down Expand Up @@ -98,4 +99,4 @@ spec:
volumeMode: Filesystem
{{- end }}

{{- end }}
{{- end }}
23 changes: 22 additions & 1 deletion helm-charts/easegress/values.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
service:
# nodePort for easegress service
nodePort: 30780
# nodeport for egctl access
# Deprecated. Use service.admin.nodePort.
adminPort: 31255
admin:
# disabled by default because the admin API controls the Easegress instance
enabled: false
type: ClusterIP
# nodePort for egctl access when service.admin.type is NodePort
nodePort: 31255

admin:
# listen on localhost by default; set to 0.0.0.0:2381 only when exposing the admin API intentionally
apiAddr: 127.0.0.1:2381
# map of username to password for admin API basic authentication
basicAuth: {}
# set true only if an external admin service is protected outside this chart
allowUnsafeNoAuth: false

serviceAccount:
automountServiceAccountToken: false

rbac:
# enable only for features that must read Kubernetes TLS secrets, such as IngressController
readSecrets: false

# image for easegress deployment
image:
Expand Down
Loading
Loading