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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic authentication #221

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ run: ## Run a controller from your host.
GRAFANA_TOKEN=$(DEV_GRAFANA_API_KEY) \
go run ./cmd/controller

.PHONY: run-with-password
run-with-password: ## Run a controller from your host.
GRAFANA_HOST=http://$(DEV_GRAFANA_HOST):$(DEV_CLUSTER_PORT) \
GRAFANA_USER=admin \
GRAFANA_PASSWORD=$(DEV_GRAFANA_PASSWORD) \
go run ./cmd/controller

##@ Build

.PHONY: build
Expand Down
25 changes: 20 additions & 5 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func main() {
var probeAddr string
var grafanaHost string
var grafanaToken string
var grafanaUser string
var grafanaPassword string
var insecureSkipVerify bool
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
Expand All @@ -54,6 +56,8 @@ func main() {
"Enabling this will ensure there is only one active controller operator.")
flag.StringVar(&grafanaHost, "grafana-host", "http://localhost:3000", "The host to use to reach Grafana.")
flag.StringVar(&grafanaToken, "grafana-api-key", "", "The API key to use to authenticate to Grafana.")
flag.StringVar(&grafanaUser, "grafana-user", "", "The user to use to authenticate to Grafana.")
flag.StringVar(&grafanaPassword, "grafana-password", "", "The password to use to authenticate to Grafana.")
flag.BoolVar(&insecureSkipVerify, "insecure-skip-verify", false, "Skips SSL certificates verification. Useful when self-signed certificates are used, but can be insecure. Enabled at your own risks.")
opts := zap.Options{
Development: true,
Expand All @@ -62,6 +66,8 @@ func main() {

must(viper.BindEnv("grafana-host", "GRAFANA_HOST"))
must(viper.BindEnv("grafana-token", "GRAFANA_TOKEN"))
must(viper.BindEnv("grafana-user", "GRAFANA_USER"))
must(viper.BindEnv("grafana-password", "GRAFANA_PASSWORD"))
must(viper.BindEnv("insecure-skip-verify", "INSECURE_SKIP_VERIFY"))

pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
Expand All @@ -75,11 +81,20 @@ func main() {
//nolint:gosec
InsecureSkipVerify: viper.GetBool("insecure-skip-verify"),
})
grabanaClient := grabana.NewClient(
httpClient,
viper.GetString("grafana-host"),
grabana.WithAPIToken(viper.GetString("grafana-token")),
)
var grabanaClient *grabana.Client
if viper.GetString("grafana-user") != "" {
grabanaClient = grabana.NewClient(
httpClient,
viper.GetString("grafana-host"),
grabana.WithBasicAuth(viper.GetString("grafana-user"), viper.GetString("grafana-password")),
)
} else {
grabanaClient = grabana.NewClient(
httpClient,
viper.GetString("grafana-host"),
grabana.WithAPIToken(viper.GetString("grafana-token")),
)
}

// controllers setup
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Expand Down