Skip to content

Commit

Permalink
Use kubeops serviceaccount to retrieve charts (#1449)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres Martinez Gotor authored Jan 15, 2020
1 parent 1bb93b2 commit 1ad2e03
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
44 changes: 44 additions & 0 deletions chart/kubeapps/templates/kubeops-rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{{- if .Values.useHelm3 -}}
{{- if .Values.rbac.create -}}
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: Role
metadata:
name: {{ template "kubeapps.kubeops.fullname" . }}
labels:
app: {{ template "kubeapps.kubeops.fullname" . }}
chart: {{ template "kubeapps.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
rules:
- apiGroups:
- ""
resources:
- secrets
verbs:
- get
- apiGroups:
- "kubeapps.com"
resources:
- apprepositories
verbs:
- get
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
name: {{ template "kubeapps.kubeops.fullname" . }}
labels:
app: {{ template "kubeapps.kubeops.fullname" . }}
chart: {{ template "kubeapps.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ template "kubeapps.kubeops.fullname" . }}
subjects:
- kind: ServiceAccount
name: {{ template "kubeapps.kubeops.fullname" . }}
namespace: {{ .Release.Namespace }}
{{- end -}}
{{- end }}{{/* matches useHelm3 */}}
27 changes: 23 additions & 4 deletions cmd/kubeops/internal/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,34 +66,53 @@ func WithHandlerConfig(storageForDriver agent.StorageForDriver, options Options)
return func(w http.ResponseWriter, req *http.Request, params handlerutil.Params) {
namespace := params[namespaceParam]
token := auth.ExtractToken(req.Header.Get(authHeader))

// User configuration and clients, using user token
// Used to perform Helm operations
restConfig, err := NewInClusterConfig(token)
if err != nil {
// TODO log details rather than return potentially sensitive details in error.
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
kubeClient, err := kubernetes.NewForConfig(restConfig)
userKubeClient, err := kubernetes.NewForConfig(restConfig)
if err != nil {
// TODO log details rather than return potentially sensitive details in error.
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
appRepoClient, err := appRepo.NewForConfig(restConfig)
actionConfig, err := agent.NewActionConfig(storageForDriver, restConfig, userKubeClient, namespace)
if err != nil {
// TODO log details rather than return potentially sensitive details in error.
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

// System configuration and clients, using the service serviceaccount
// Used to retrieve apprepositories and secrets related to them
svcRestConfig, err := rest.InClusterConfig()
if err != nil {
// TODO log details rather than return potentially sensitive details in error.
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
actionConfig, err := agent.NewActionConfig(storageForDriver, restConfig, kubeClient, namespace)
svcKubeClient, err := kubernetes.NewForConfig(svcRestConfig)
if err != nil {
// TODO log details rather than return potentially sensitive details in error.
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
appRepoClient, err := appRepo.NewForConfig(svcRestConfig)
if err != nil {
// TODO log details rather than return potentially sensitive details in error.
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

cfg := Config{
Options: options,
ActionConfig: actionConfig,
ChartClient: chartUtils.NewChartClient(kubeClient, appRepoClient, options.UserAgent),
ChartClient: chartUtils.NewChartClient(svcKubeClient, appRepoClient, options.UserAgent),
}
f(cfg, w, req, params)
}
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ k8s.io/cli-runtime v0.0.0-20191016114015-74ad18325ed5 h1:8ZfMjkMBzcXEawLsYHg9lDM
k8s.io/cli-runtime v0.0.0-20191016114015-74ad18325ed5/go.mod h1:sDl6WKSQkDM6zS1u9F49a0VooQ3ycYFBFLqd2jf2Xfo=
k8s.io/client-go v0.0.0-20191016111102-bec269661e48 h1:C2XVy2z0dV94q9hSSoCuTPp1KOG7IegvbdXuz9VGxoU=
k8s.io/client-go v0.0.0-20191016111102-bec269661e48/go.mod h1:hrwktSwYGI4JK+TJA3dMaFyyvHVi/aLarVHpbs8bgCU=
k8s.io/client-go v11.0.0+incompatible h1:LBbX2+lOwY9flffWlJM7f1Ct8V2SRNiMRDFeiwnJo9o=
k8s.io/code-generator v0.0.0-20191004115455-8e001e5d1894/go.mod h1:mJUgkl06XV4kstAnLHAIzJPVCOzVR+ZcfPIv4fUsFCY=
k8s.io/component-base v0.0.0-20191016111319-039242c015a9/go.mod h1:SuWowIgd/dtU/m/iv8OD9eOxp3QZBBhTIiWMsBQvKjI=
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
Expand Down

0 comments on commit 1ad2e03

Please sign in to comment.