Skip to content

Commit

Permalink
Merge pull request #33 from gianlucam76/remove-rbac-proxy
Browse files Browse the repository at this point in the history
Remove RBAC proxy sidecar
  • Loading branch information
gianlucam76 authored Feb 28, 2024
2 parents c0f8f1d + 2ffa1aa commit f904b40
Show file tree
Hide file tree
Showing 22 changed files with 358 additions and 473 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ARCH ?= amd64
OS ?= $(shell uname -s | tr A-Z a-z)
K8S_LATEST_VER ?= $(shell curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)
export CONTROLLER_IMG ?= $(REGISTRY)/$(IMAGE_NAME)
TAG ?= v0.24.0
TAG ?= dev

## Tool Binaries
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/controller-gen
Expand All @@ -51,7 +51,7 @@ KUBECTL := $(TOOLS_BIN_DIR)/kubectl
CLUSTERCTL := $(TOOLS_BIN_DIR)/clusterctl

GOLANGCI_LINT_VERSION := "v1.55.2"
CLUSTERCTL_VERSION := "v1.6.1"
CLUSTERCTL_VERSION := "v1.6.2"

$(CONTROLLER_GEN): $(TOOLS_DIR)/go.mod # Build controller-gen from tools folder.
cd $(TOOLS_DIR); $(GOBUILD) -tags=tools -o $(subst $(TOOLS_DIR)/hack/tools/,,$@) sigs.k8s.io/controller-tools/cmd/controller-gen
Expand Down
66 changes: 48 additions & 18 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"

Expand All @@ -51,22 +52,27 @@ import (
)

var (
setupLog = ctrl.Log.WithName("setup")
metricsAddr string
probeAddr string
agentInMgmtCluster bool
reportMode controller.ReportMode
tmpReportMode int
restConfigQPS float32
restConfigBurst int
webhookPort int
syncPeriod time.Duration
setupLog = ctrl.Log.WithName("setup")
diagnosticsAddress string
insecureDiagnostics bool
agentInMgmtCluster bool
reportMode controller.ReportMode
tmpReportMode int
restConfigQPS float32
restConfigBurst int
webhookPort int
syncPeriod time.Duration
healthAddr string
)

const (
defaulReportMode = int(controller.CollectFromManagementCluster)
)

// Add RBAC for the authorized diagnostics endpoint.
//+kubebuilder:rbac:groups=authentication.k8s.io,resources=tokenreviews,verbs=create
//+kubebuilder:rbac:groups=authorization.k8s.io,resources=subjectaccessreviews,verbs=create

func main() {
scheme, err := controller.InitScheme()
if err != nil {
Expand All @@ -88,10 +94,8 @@ func main() {

ctrlOptions := ctrl.Options{
Scheme: scheme,
HealthProbeBindAddress: probeAddr,
Metrics: metricsserver.Options{
BindAddress: metricsAddr,
},
Metrics: getDiagnosticsOptions(),
HealthProbeBindAddress: healthAddr,
WebhookServer: webhook.NewServer(
webhook.Options{
Port: webhookPort,
Expand Down Expand Up @@ -143,11 +147,13 @@ func main() {
}

func initFlags(fs *pflag.FlagSet) {
fs.StringVar(&metricsAddr, "metrics-bind-address", ":8080",
"The address the metric endpoint binds to.")
fs.StringVar(&diagnosticsAddress, "diagnostics-address", ":8443",
"The address the diagnostics endpoint binds to. Per default metrics are served via https and with"+
"authentication/authorization. To serve via http and without authentication/authorization set --insecure-diagnostics."+
"If --insecure-diagnostics is not set the diagnostics endpoint also serves pprof endpoints and an endpoint to change the log level.")

fs.StringVar(&probeAddr, "health-probe-bind-address", ":8081",
"The address the probe endpoint binds to.")
fs.BoolVar(&insecureDiagnostics, "insecure-diagnostics", false,
"Enable insecure diagnostics serving. For more details see the description of --diagnostics-address.")

fs.BoolVar(&agentInMgmtCluster,
"agent-in-mgmt-cluster",
Expand All @@ -159,6 +165,9 @@ func initFlags(fs *pflag.FlagSet) {
defaulReportMode,
"flag which is passed to sveltos deployments created for a cluster shard")

fs.StringVar(&healthAddr, "health-addr", ":9440",
"The address the health endpoint binds to.")

const defautlRestConfigQPS = 20
fs.Float32Var(&restConfigQPS, "kube-api-qps", defautlRestConfigQPS,
fmt.Sprintf("Maximum queries per second from the controller client to the Kubernetes API server. Defaults to %d",
Expand Down Expand Up @@ -246,3 +255,24 @@ func capiCRDHandler(gvk *schema.GroupVersionKind) {
}
}
}

// getDiagnosticsOptions returns metrics options which can be used to configure a Manager.
func getDiagnosticsOptions() metricsserver.Options {
// If "--insecure-diagnostics" is set, serve metrics via http
// and without authentication/authorization.
if insecureDiagnostics {
return metricsserver.Options{
BindAddress: diagnosticsAddress,
SecureServing: false,
}
}

// If "--insecure-diagnostics" is not set, serve metrics via https
// and with authentication/authorization. As the endpoint is protected,
// we also serve pprof endpoints and an endpoint to change the log level.
return metricsserver.Options{
BindAddress: diagnosticsAddress,
SecureServing: true,
FilterProvider: filters.WithAuthenticationAndAuthorization,
}
}
26 changes: 1 addition & 25 deletions config/default/manager_auth_proxy_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,8 @@ spec:
template:
spec:
containers:
- name: kube-rbac-proxy
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- "ALL"
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.14.1
args:
- "--secure-listen-address=0.0.0.0:8443"
- "--upstream=http://127.0.0.1:8080/"
- "--logtostderr=true"
- "--v=0"
ports:
- containerPort: 8443
protocol: TCP
name: https
resources:
limits:
cpu: 500m
memory: 128Mi
requests:
cpu: 5m
memory: 64Mi
- name: manager
args:
- "--health-probe-bind-address=:8081"
- "--metrics-bind-address=127.0.0.1:8080"
- "--diagnostics-address=:8443"
- "--v=5"
- "--report-mode=0"
2 changes: 1 addition & 1 deletion config/default/manager_image_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ spec:
spec:
containers:
# Change the value of image field below to your controller image URL
- image: projectsveltos/shard-controller-amd64:v0.24.0
- image: projectsveltos/shard-controller-amd64:dev
name: manager
15 changes: 13 additions & 2 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,32 @@ spec:
args:
image: controller:latest
name: manager
ports:
- containerPort: 8443
name: metrics
protocol: TCP
- containerPort: 9440
name: healthz
protocol: TCP
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- "ALL"
livenessProbe:
failureThreshold: 3
httpGet:
path: /healthz
port: 8081
port: healthz
scheme: HTTP
initialDelaySeconds: 15
periodSeconds: 20
readinessProbe:
failureThreshold: 3
httpGet:
path: /readyz
port: 8081
port: healthz
scheme: HTTP
initialDelaySeconds: 5
periodSeconds: 10
# TODO(user): Configure the resources accordingly based on the project requirements.
Expand Down
8 changes: 4 additions & 4 deletions config/rbac/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ resources:
# Comment the following 4 lines if you want to disable
# the auth proxy (https://github.com/brancz/kube-rbac-proxy)
# which protects your /metrics endpoint.
- auth_proxy_service.yaml
- auth_proxy_role.yaml
- auth_proxy_role_binding.yaml
- auth_proxy_client_clusterrole.yaml
# - auth_proxy_service.yaml
# - auth_proxy_role.yaml
# - auth_proxy_role_binding.yaml
# - auth_proxy_client_clusterrole.yaml
12 changes: 12 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ rules:
- get
- list
- watch
- apiGroups:
- authentication.k8s.io
resources:
- tokenreviews
verbs:
- create
- apiGroups:
- authorization.k8s.io
resources:
- subjectaccessreviews
verbs:
- create
- apiGroups:
- cluster.x-k8s.io
resources:
Expand Down
27 changes: 24 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/onsi/ginkgo/v2 v2.15.0
github.com/onsi/gomega v1.31.1
github.com/pkg/errors v0.9.1
github.com/projectsveltos/libsveltos v0.24.0
github.com/projectsveltos/libsveltos v0.24.1-0.20240221165142-94ea5e6f7fa7
github.com/spf13/pflag v1.0.5
golang.org/x/text v0.14.0
k8s.io/api v0.29.1
Expand All @@ -19,20 +19,24 @@ require (
k8s.io/component-base v0.29.1
k8s.io/klog/v2 v2.120.1
k8s.io/utils v0.0.0-20240102154912-e7106e64919e
sigs.k8s.io/cluster-api v1.6.1
sigs.k8s.io/controller-runtime v0.17.0
sigs.k8s.io/cluster-api v1.6.2
sigs.k8s.io/controller-runtime v0.17.2
)

require (
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fluxcd/pkg/apis/meta v1.3.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
Expand All @@ -41,11 +45,13 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/cel-go v0.17.7 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand All @@ -60,21 +66,36 @@ require (
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/stoewer/go-strcase v1.2.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.0 // indirect
go.opentelemetry.io/otel v1.20.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.20.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.20.0 // indirect
go.opentelemetry.io/otel/metric v1.20.0 // indirect
go.opentelemetry.io/otel/sdk v1.20.0 // indirect
go.opentelemetry.io/otel/trace v1.20.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/oauth2 v0.14.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.16.1 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiserver v0.29.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/kubectl v0.29.1 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.28.0 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
Expand Down
Loading

0 comments on commit f904b40

Please sign in to comment.