-
Notifications
You must be signed in to change notification settings - Fork 605
Add support for service account auth for incluster deployments #4552
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -202,7 +202,7 @@ | |
| } | ||
| } | ||
|
|
||
| func TestParseFlags(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| args []string | ||
|
|
@@ -250,6 +250,14 @@ | |
| assert.Equal(t, "warn", conf.LogLevel) | ||
| }, | ||
| }, | ||
| { | ||
| name: "use_service_account_token_flag", | ||
| args: []string{"go run ./cmd", "--use-service-account-token", "--service-account-token-path=/custom/token/path"}, | ||
| verify: func(t *testing.T, conf *config.Config) { | ||
| assert.Equal(t, true, conf.UseServiceAccountToken) | ||
| assert.Equal(t, "/custom/token/path", conf.ServiceAccountTokenPath) | ||
| }, | ||
|
Comment on lines
+253
to
+259
|
||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1009,6 +1009,8 @@ | |||||||||||||
| oidcScopes string, | ||||||||||||||
| oidcSkipTLSVerify bool, | ||||||||||||||
| oidcCACert string, | ||||||||||||||
| useServiceAccountToken bool, | ||||||||||||||
| serviceAccountTokenPath string, | ||||||||||||||
| ) (*Context, error) { | ||||||||||||||
| clusterConfig, err := rest.InClusterConfig() | ||||||||||||||
| if err != nil { | ||||||||||||||
|
|
@@ -1032,6 +1034,12 @@ | |||||||||||||
| contextName = makeDNSFriendly(contextName) | ||||||||||||||
|
|
||||||||||||||
| inClusterAuthInfo := &api.AuthInfo{} | ||||||||||||||
| if useServiceAccountToken { | ||||||||||||||
| if serviceAccountTokenPath == "" { | ||||||||||||||
| serviceAccountTokenPath = "/var/run/secrets/kubernetes.io/serviceaccount/token" | ||||||||||||||
|
||||||||||||||
| serviceAccountTokenPath = "/var/run/secrets/kubernetes.io/serviceaccount/token" | |
| if clusterConfig.BearerTokenFile != "" { | |
| serviceAccountTokenPath = clusterConfig.BearerTokenFile | |
| } else { | |
| serviceAccountTokenPath = "/var/run/secrets/kubernetes.io/serviceaccount/token" | |
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -245,6 +245,12 @@ spec: | |||||||||||||||||
| {{- with .Values.config.pluginsDir}} | ||||||||||||||||||
| - "-plugins-dir={{ . }}" | ||||||||||||||||||
| {{- end }} | ||||||||||||||||||
| {{- if .Values.config.useServiceAccountToken }} | ||||||||||||||||||
| - "-use-service-account-token" | ||||||||||||||||||
| {{- end }} | ||||||||||||||||||
| {{- if and .Values.config.useServiceAccountToken .Values.config.serviceAccountTokenPath }} | ||||||||||||||||||
|
Comment on lines
+248
to
+251
|
||||||||||||||||||
| {{- if .Values.config.useServiceAccountToken }} | |
| - "-use-service-account-token" | |
| {{- end }} | |
| {{- if and .Values.config.useServiceAccountToken .Values.config.serviceAccountTokenPath }} | |
| {{- if and .Values.config.inCluster .Values.config.useServiceAccountToken }} | |
| - "-use-service-account-token" | |
| {{- end }} | |
| {{- if and .Values.config.inCluster .Values.config.useServiceAccountToken .Values.config.serviceAccountTokenPath }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| --- | ||
| # Source: headlamp/templates/serviceaccount.yaml | ||
| apiVersion: v1 | ||
| kind: ServiceAccount | ||
| metadata: | ||
| name: headlamp | ||
| labels: | ||
| helm.sh/chart: headlamp-0.39.0 | ||
| app.kubernetes.io/name: headlamp | ||
| app.kubernetes.io/instance: headlamp | ||
| app.kubernetes.io/version: "0.39.0" | ||
| app.kubernetes.io/managed-by: Helm | ||
| --- | ||
| # Source: headlamp/templates/secret.yaml | ||
| apiVersion: v1 | ||
| kind: Secret | ||
| metadata: | ||
| name: oidc | ||
| type: Opaque | ||
| data: | ||
| --- | ||
| # Source: headlamp/templates/clusterrolebinding.yaml | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRoleBinding | ||
| metadata: | ||
| name: headlamp-admin | ||
| labels: | ||
| helm.sh/chart: headlamp-0.39.0 | ||
| app.kubernetes.io/name: headlamp | ||
| app.kubernetes.io/instance: headlamp | ||
| app.kubernetes.io/version: "0.39.0" | ||
| app.kubernetes.io/managed-by: Helm | ||
| roleRef: | ||
| apiGroup: rbac.authorization.k8s.io | ||
| kind: ClusterRole | ||
| name: cluster-admin | ||
| subjects: | ||
| - kind: ServiceAccount | ||
| name: headlamp | ||
| namespace: default | ||
| --- | ||
| # Source: headlamp/templates/service.yaml | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: headlamp | ||
| labels: | ||
| helm.sh/chart: headlamp-0.39.0 | ||
| app.kubernetes.io/name: headlamp | ||
| app.kubernetes.io/instance: headlamp | ||
| app.kubernetes.io/version: "0.39.0" | ||
| app.kubernetes.io/managed-by: Helm | ||
| spec: | ||
| type: ClusterIP | ||
|
|
||
| ports: | ||
| - port: 80 | ||
| targetPort: http | ||
| protocol: TCP | ||
| name: http | ||
| selector: | ||
| app.kubernetes.io/name: headlamp | ||
| app.kubernetes.io/instance: headlamp | ||
| --- | ||
| # Source: headlamp/templates/deployment.yaml | ||
| # This block of code is used to extract the values from the env. | ||
| # This is done to check if the values are non-empty and if they are, they are used in the deployment.yaml. | ||
|
|
||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: headlamp | ||
| labels: | ||
| helm.sh/chart: headlamp-0.39.0 | ||
| app.kubernetes.io/name: headlamp | ||
| app.kubernetes.io/instance: headlamp | ||
| app.kubernetes.io/version: "0.39.0" | ||
| app.kubernetes.io/managed-by: Helm | ||
| spec: | ||
| replicas: 1 | ||
| selector: | ||
| matchLabels: | ||
| app.kubernetes.io/name: headlamp | ||
| app.kubernetes.io/instance: headlamp | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app.kubernetes.io/name: headlamp | ||
| app.kubernetes.io/instance: headlamp | ||
| spec: | ||
| serviceAccountName: headlamp | ||
| securityContext: | ||
| {} | ||
| containers: | ||
| - name: headlamp | ||
| securityContext: | ||
| privileged: false | ||
| runAsGroup: 101 | ||
| runAsNonRoot: true | ||
| runAsUser: 100 | ||
| image: "ghcr.io/headlamp-k8s/headlamp:v0.39.0" | ||
| imagePullPolicy: IfNotPresent | ||
|
|
||
| env: | ||
| args: | ||
| - "-in-cluster" | ||
| - "-plugins-dir=/headlamp/plugins" | ||
| - "-use-service-account-token" | ||
| - "-service-account-token-path=/custom/token" | ||
| # Check if externalSecret is disabled | ||
| ports: | ||
| - name: http | ||
| containerPort: 4466 | ||
| protocol: TCP | ||
| livenessProbe: | ||
| httpGet: | ||
| path: "/" | ||
| port: http | ||
| readinessProbe: | ||
| httpGet: | ||
| path: "/" | ||
| port: http | ||
| resources: | ||
| {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--service-account-token-pathis given a non-empty default value. This makes it hard to distinguish "flag not set" from "set", and it also prevents mode validation similar to the OIDC flags (because the value is always non-empty). Consider defaulting this flag to an empty string and applying the default path only when--use-service-account-tokenis true (the kubeconfig code already has this fallback).