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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make MinTokenExpiration configurable by cli flag #156

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
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func main() {
region := flag.String("aws-default-region", "", "If set, AWS_DEFAULT_REGION and AWS_REGION will be set to this value in mutated containers")
regionalSTS := flag.Bool("sts-regional-endpoint", false, "Whether to inject the AWS_STS_REGIONAL_ENDPOINTS=regional env var in mutated pods. Defaults to `false`.")
watchConfigMap := flag.Bool("watch-config-map", false, "Enables watching serviceaccounts that are configured through the pod-identity-webhook configmap instead of using annotations")
flag.Int64Var(&pkg.MinTokenExpiration, "min-token-expiration", pkg.MinTokenExpiration, "Minimum token expiration in seconds. The value is used if user configured the shorter duration than this value")

version := flag.Bool("version", false, "Display the version and exit")

Expand All @@ -90,6 +91,10 @@ func main() {
os.Exit(0)
}

if pkg.MinTokenExpiration < 600 {
klog.Fatal("min-token-expiration must be at least 600 (10 min)")
}

config, err := clientcmd.BuildConfigFromFlags(*apiURL, *kubeconfig)
if err != nil {
klog.Fatalf("Error creating config: %v", err.Error())
Expand Down
8 changes: 7 additions & 1 deletion pkg/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ const (
// Default token expiration in seconds if none is defined,
// which is 24hrs as that is max for EKS
DefaultTokenExpiration = int64(86400)
// 1hr is min for kube-apiserver
)

var (
// Minimum token expiration in seconds.
// The value is used if user configured the shorter duration than this value
// This value must be at least 600(=10min) due to kubernetes spec (ref ServiceAccountTokenProjection.ExpirationSeconds).
// Note: this can be configured by cli flags
MinTokenExpiration = int64(3600)
)