c2f079b4e3
* feat(helm): add helm chart backport to ce EE-1409 (#5425) * EE-1311 Helm Chart Backport from EE * backport to ce Co-authored-by: Matt Hook <hookenz@gmail.com> * feat(helm) helm chart backport from ee EE-1311 (#5436) * Add missing defaultHelmRepoUrl and mock testing * Backport EE-1477 * Backport updates to helm tests from EE * add https by default changes and ssl to tls renaming from EE * Port install integration test. Disabled by default to pass CI checks * merged changes from EE for the integration test * kube proxy whitelist updated to support internal helm install command Co-authored-by: zees-dev <dev.786zshan@gmail.com> * Pull in all changes from tech review in EE-943 * feat(helm): add helm chart backport to ce EE-1409 (#5425) * EE-1311 Helm Chart Backport from EE * backport to ce Co-authored-by: Matt Hook <hookenz@gmail.com> * Pull in all changes from tech review in EE-943 * added helm to sidebar after rebase, sync CE with EE * backport EE-1278, squashed, diffed, updated * helm install openapi spec update * resolved conflicts, updated code * - matching ee codebase at 0afe57034449ee0e9f333d92c252a13995a93019 - helm install using endpoint middleware - remove trailing slash from added/persisted helm repo urls * feat(helm) use libhelm url validator and improved path assembly EE-1554 (#5561) * feat(helm/userrepos) fix getting global repo for ordinary users EE-1562 (#5567) * feat(helm/userrepos) fix getting global repo for ordinary users EE-1562 * post review changes and further backported changes from EE * resolved conflicts, updated code * fixed helm_install handler unit test * user cannot add existing repo if suffix is '/' (#5571) * feat(helm/docs) fix broken swagger docs EE-1278 (#5572) * Fix swagger docs * minor correction * fix(helm): migrating code from user handler to helm handler (#5573) * - migrated user_helm_repos to helm endpoint handler - migrated api operations from user factory/service to helm factory/service - passing endpointId into helm service/factory as endpoint provider is deprecated * upgrade libhelm to hide secrets Co-authored-by: Matt Hook <hookenz@gmail.com> * removed duplicate file - due to merge conflict * dependency injection in helm factory Co-authored-by: Richard Wei <54336863+WaysonWei@users.noreply.github.com> Co-authored-by: Matt Hook <hookenz@gmail.com>
104 lines
3.8 KiB
Go
104 lines
3.8 KiB
Go
package helm
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
"github.com/portainer/libhelm"
|
|
"github.com/portainer/libhelm/options"
|
|
httperror "github.com/portainer/libhttp/error"
|
|
portainer "github.com/portainer/portainer/api"
|
|
"github.com/portainer/portainer/api/http/middlewares"
|
|
"github.com/portainer/portainer/api/http/security"
|
|
"github.com/portainer/portainer/api/kubernetes"
|
|
)
|
|
|
|
const (
|
|
handlerActivityContext = "Kubernetes"
|
|
)
|
|
|
|
type requestBouncer interface {
|
|
AuthenticatedAccess(h http.Handler) http.Handler
|
|
}
|
|
|
|
// Handler is the HTTP handler used to handle endpoint group operations.
|
|
type Handler struct {
|
|
*mux.Router
|
|
requestBouncer requestBouncer
|
|
dataStore portainer.DataStore
|
|
kubeConfigService kubernetes.KubeConfigService
|
|
helmPackageManager libhelm.HelmPackageManager
|
|
}
|
|
|
|
// NewHandler creates a handler to manage endpoint group operations.
|
|
func NewHandler(bouncer requestBouncer, dataStore portainer.DataStore, helmPackageManager libhelm.HelmPackageManager, kubeConfigService kubernetes.KubeConfigService) *Handler {
|
|
h := &Handler{
|
|
Router: mux.NewRouter(),
|
|
requestBouncer: bouncer,
|
|
dataStore: dataStore,
|
|
helmPackageManager: helmPackageManager,
|
|
kubeConfigService: kubeConfigService,
|
|
}
|
|
|
|
h.Use(middlewares.WithEndpoint(dataStore.Endpoint(), "id"))
|
|
|
|
// `helm list -o json`
|
|
h.Handle("/{id}/kubernetes/helm",
|
|
bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.helmList))).Methods(http.MethodGet)
|
|
|
|
// `helm delete RELEASE_NAME`
|
|
h.Handle("/{id}/kubernetes/helm/{release}",
|
|
bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.helmDelete))).Methods(http.MethodDelete)
|
|
|
|
// `helm install [NAME] [CHART] flags`
|
|
h.Handle("/{id}/kubernetes/helm",
|
|
bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.helmInstall))).Methods(http.MethodPost)
|
|
|
|
h.Handle("/{id}/kubernetes/helm/repositories",
|
|
bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.userGetHelmRepos))).Methods(http.MethodGet)
|
|
h.Handle("/{id}/kubernetes/helm/repositories",
|
|
bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.userCreateHelmRepo))).Methods(http.MethodPost)
|
|
|
|
return h
|
|
}
|
|
|
|
// NewTemplateHandler creates a template handler to manage endpoint group operations.
|
|
func NewTemplateHandler(bouncer requestBouncer, helmPackageManager libhelm.HelmPackageManager) *Handler {
|
|
h := &Handler{
|
|
Router: mux.NewRouter(),
|
|
helmPackageManager: helmPackageManager,
|
|
requestBouncer: bouncer,
|
|
}
|
|
|
|
h.Handle("/templates/helm",
|
|
bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.helmRepoSearch))).Methods(http.MethodGet)
|
|
|
|
// helm show [COMMAND] [CHART] [REPO] flags
|
|
h.Handle("/templates/helm/{command:chart|values|readme}",
|
|
bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.helmShow))).Methods(http.MethodGet)
|
|
|
|
return h
|
|
}
|
|
|
|
// getHelmClusterAccess obtains the core k8s cluster access details from request.
|
|
// The cluster access includes the cluster server url, the user's bearer token and the tls certificate.
|
|
// The cluster access is passed in as kube config CLI params to helm binary.
|
|
func (handler *Handler) getHelmClusterAccess(r *http.Request) (*options.KubernetesClusterAccess, *httperror.HandlerError) {
|
|
endpoint, err := middlewares.FetchEndpoint(r)
|
|
if err != nil {
|
|
return nil, &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint on request context", err}
|
|
}
|
|
|
|
bearerToken, err := security.ExtractBearerToken(r)
|
|
if err != nil {
|
|
return nil, &httperror.HandlerError{http.StatusUnauthorized, "Unauthorized", err}
|
|
}
|
|
|
|
kubeConfigInternal := handler.kubeConfigService.GetKubeConfigInternal(endpoint.ID, bearerToken)
|
|
return &options.KubernetesClusterAccess{
|
|
ClusterServerURL: kubeConfigInternal.ClusterServerURL,
|
|
CertificateAuthorityFile: kubeConfigInternal.CertificateAuthorityFile,
|
|
AuthToken: kubeConfigInternal.AuthToken,
|
|
}, nil
|
|
}
|