-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding metrics-require-rbac flag, metrics-secure validation logic and…
… corresponding scaffolding logic (#116) Signed-off-by: Adam D. Cornett <[email protected]>
- Loading branch information
1 parent
3aaf111
commit 3ad1b57
Showing
11 changed files
with
144 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ import ( | |
"github.com/spf13/pflag" | ||
"k8s.io/client-go/tools/leaderelection/resourcelock" | ||
"sigs.k8s.io/controller-runtime/pkg/manager" | ||
"sigs.k8s.io/controller-runtime/pkg/metrics/filters" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook" | ||
) | ||
|
||
|
@@ -48,6 +49,7 @@ type Flags struct { | |
ProxyPort int | ||
EnableHTTP2 bool | ||
SecureMetrics bool | ||
MetricsRequireRBAC bool | ||
|
||
// If not nil, used to deduce which flags were set in the CLI. | ||
flagSet *pflag.FlagSet | ||
|
@@ -194,12 +196,16 @@ func (f *Flags) AddTo(flagSet *pflag.FlagSet) { | |
false, | ||
"enables HTTP/2 on the webhook and metrics servers", | ||
) | ||
|
||
flagSet.BoolVar(&f.SecureMetrics, | ||
"metrics-secure", | ||
false, | ||
"enables secure serving of the metrics endpoint", | ||
) | ||
flagSet.BoolVar(&f.MetricsRequireRBAC, | ||
"metrics-require-rbac", | ||
false, | ||
"enables protection of the metrics endpoint with RBAC-based authn/authz."+ | ||
"see https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/metrics/filters#WithAuthenticationAndAuthorization for more info") | ||
} | ||
|
||
// ToManagerOptions uses the flag set in f to configure options. | ||
|
@@ -254,5 +260,14 @@ func (f *Flags) ToManagerOptions(options manager.Options) manager.Options { | |
options.Metrics.TLSOpts = append(options.Metrics.TLSOpts, disableHTTP2) | ||
} | ||
options.Metrics.SecureServing = f.SecureMetrics | ||
|
||
if f.MetricsRequireRBAC { | ||
// FilterProvider is used to protect the metrics endpoint with authn/authz. | ||
// These configurations ensure that only authorized users and service accounts | ||
// can access the metrics endpoint. The RBAC are configured in 'config/rbac/kustomization.yaml'. More info: | ||
// https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/metrics/filters#WithAuthenticationAndAuthorization | ||
options.Metrics.FilterProvider = filters.WithAuthenticationAndAuthorization | ||
} | ||
|
||
return options | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters