Rbac resources per release for multiple installation on same cluster (#2302)
* Change RBAC resource names work for multiple Fission release * Fetch secret configmap and package cluster role based on the release name * Remove default namespace hardcoding from helm chart Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
@@ -46,6 +46,8 @@ spec:
|
|||||||
value: {{ .Values.debugEnv | quote }}
|
value: {{ .Values.debugEnv | quote }}
|
||||||
- name: PPROF_ENABLED
|
- name: PPROF_ENABLED
|
||||||
value: {{ .Values.pprof.enabled | quote }}
|
value: {{ .Values.pprof.enabled | quote }}
|
||||||
|
- name: HELM_RELEASE_NAME
|
||||||
|
value: {{ .Release.Name | quote }}
|
||||||
{{- include "opentracing.envs" . | indent 8 }}
|
{{- include "opentracing.envs" . | indent 8 }}
|
||||||
{{- include "opentelemtry.envs" . | indent 8 }}
|
{{- include "opentelemtry.envs" . | indent 8 }}
|
||||||
{{- if .Values.terminationMessagePath }}
|
{{- if .Values.terminationMessagePath }}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
apiVersion: rbac.authorization.k8s.io/v1
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
kind: ClusterRole
|
kind: ClusterRole
|
||||||
metadata:
|
metadata:
|
||||||
name: fission-cr-admin
|
name: {{ .Release.Name }}-fission-cr-admin
|
||||||
rules:
|
rules:
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- ""
|
- ""
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
kind: ClusterRoleBinding
|
kind: ClusterRoleBinding
|
||||||
apiVersion: rbac.authorization.k8s.io/v1
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
metadata:
|
metadata:
|
||||||
name: fission-cr-admin
|
name: {{ .Release.Name }}-fission-cr-admin
|
||||||
subjects:
|
subjects:
|
||||||
- kind: ServiceAccount
|
- kind: ServiceAccount
|
||||||
name: fission-svc
|
name: fission-svc
|
||||||
namespace: {{ .Release.Namespace }}
|
namespace: {{ .Release.Namespace }}
|
||||||
roleRef:
|
roleRef:
|
||||||
kind: ClusterRole
|
kind: ClusterRole
|
||||||
name: fission-cr-admin
|
name: {{ .Release.Name }}-fission-cr-admin
|
||||||
apiGroup: rbac.authorization.k8s.io
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ spec:
|
|||||||
value: {{ .Values.debugEnv | quote }}
|
value: {{ .Values.debugEnv | quote }}
|
||||||
- name: PPROF_ENABLED
|
- name: PPROF_ENABLED
|
||||||
value: {{ .Values.pprof.enabled | quote }}
|
value: {{ .Values.pprof.enabled | quote }}
|
||||||
|
- name: HELM_RELEASE_NAME
|
||||||
|
value: {{ .Release.Name | quote }}
|
||||||
{{- include "opentracing.envs" . | indent 8 }}
|
{{- include "opentracing.envs" . | indent 8 }}
|
||||||
{{- include "opentelemtry.envs" . | indent 8 }}
|
{{- include "opentelemtry.envs" . | indent 8 }}
|
||||||
readinessProbe:
|
readinessProbe:
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
apiVersion: rbac.authorization.k8s.io/v1
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
kind: ClusterRole
|
kind: ClusterRole
|
||||||
metadata:
|
metadata:
|
||||||
name: secret-configmap-getter
|
name: {{ .Release.Name }}-secret-configmap-getter
|
||||||
rules:
|
rules:
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- "*"
|
- "*"
|
||||||
@@ -17,7 +17,7 @@ rules:
|
|||||||
apiVersion: rbac.authorization.k8s.io/v1
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
kind: ClusterRole
|
kind: ClusterRole
|
||||||
metadata:
|
metadata:
|
||||||
name: package-getter
|
name: {{ .Release.Name }}-package-getter
|
||||||
rules:
|
rules:
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- "*"
|
- "*"
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
apiVersion: rbac.authorization.k8s.io/v1
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
kind: Role
|
kind: Role
|
||||||
metadata:
|
metadata:
|
||||||
name: fission-fetcher
|
name: {{ .Release.Name }}-fission-fetcher
|
||||||
namespace: default
|
namespace: {{ .Values.defaultNamespace }}
|
||||||
rules:
|
rules:
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- ""
|
- ""
|
||||||
@@ -38,8 +38,8 @@ rules:
|
|||||||
apiVersion: rbac.authorization.k8s.io/v1
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
kind: Role
|
kind: Role
|
||||||
metadata:
|
metadata:
|
||||||
name: fission-builder
|
name: {{ .Release.Name }}-fission-builder
|
||||||
namespace: default
|
namespace: {{ .Values.defaultNamespace }}
|
||||||
rules:
|
rules:
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- fission.io
|
- fission.io
|
||||||
@@ -60,7 +60,7 @@ apiVersion: rbac.authorization.k8s.io/v1
|
|||||||
kind: Role
|
kind: Role
|
||||||
metadata:
|
metadata:
|
||||||
namespace: {{ .Values.functionNamespace }}
|
namespace: {{ .Values.functionNamespace }}
|
||||||
name: event-fetcher
|
name: {{ .Release.Name }}-event-fetcher
|
||||||
rules:
|
rules:
|
||||||
- apiGroups: [""] # "" indicates the core API group
|
- apiGroups: [""] # "" indicates the core API group
|
||||||
resources: ["pods"]
|
resources: ["pods"]
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
apiVersion: rbac.authorization.k8s.io/v1
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
kind: RoleBinding
|
kind: RoleBinding
|
||||||
metadata:
|
metadata:
|
||||||
name: fission-fetcher
|
name: {{ .Release.Name }}-fission-fetcher
|
||||||
namespace: default
|
namespace: {{ .Values.defaultNamespace }}
|
||||||
roleRef:
|
roleRef:
|
||||||
apiGroup: rbac.authorization.k8s.io
|
apiGroup: rbac.authorization.k8s.io
|
||||||
kind: Role
|
kind: Role
|
||||||
name: fission-fetcher
|
name: {{ .Release.Name }}-fission-fetcher
|
||||||
subjects:
|
subjects:
|
||||||
- kind: ServiceAccount
|
- kind: ServiceAccount
|
||||||
name: fission-fetcher
|
name: fission-fetcher
|
||||||
@@ -16,12 +16,12 @@ subjects:
|
|||||||
apiVersion: rbac.authorization.k8s.io/v1
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
kind: RoleBinding
|
kind: RoleBinding
|
||||||
metadata:
|
metadata:
|
||||||
name: fission-builder
|
name: {{ .Release.Name }}-fission-builder
|
||||||
namespace: default
|
namespace: {{ .Values.defaultNamespace }}
|
||||||
roleRef:
|
roleRef:
|
||||||
apiGroup: rbac.authorization.k8s.io
|
apiGroup: rbac.authorization.k8s.io
|
||||||
kind: Role
|
kind: Role
|
||||||
name: fission-builder
|
name: {{ .Release.Name }}-fission-builder
|
||||||
subjects:
|
subjects:
|
||||||
- kind: ServiceAccount
|
- kind: ServiceAccount
|
||||||
name: fission-builder
|
name: fission-builder
|
||||||
@@ -31,12 +31,12 @@ subjects:
|
|||||||
apiVersion: rbac.authorization.k8s.io/v1
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
kind: RoleBinding
|
kind: RoleBinding
|
||||||
metadata:
|
metadata:
|
||||||
name: fission-fetcher-pod-reader
|
name: {{ .Release.Name }}-fission-fetcher-pod-reader
|
||||||
namespace: {{ .Values.functionNamespace }}
|
namespace: {{ .Values.functionNamespace }}
|
||||||
roleRef:
|
roleRef:
|
||||||
apiGroup: rbac.authorization.k8s.io
|
apiGroup: rbac.authorization.k8s.io
|
||||||
kind: Role
|
kind: Role
|
||||||
name: event-fetcher
|
name: {{ .Release.Name }}-event-fetcher
|
||||||
subjects:
|
subjects:
|
||||||
- kind: ServiceAccount
|
- kind: ServiceAccount
|
||||||
name: fission-fetcher
|
name: fission-fetcher
|
||||||
|
|||||||
@@ -68,6 +68,10 @@ functionNamespace: fission-function
|
|||||||
##
|
##
|
||||||
builderNamespace: fission-builder
|
builderNamespace: fission-builder
|
||||||
|
|
||||||
|
## defaultNamespace represents the default namespace in Kubernetes.
|
||||||
|
##
|
||||||
|
defaultNamespace: default
|
||||||
|
|
||||||
## createNamespace decides to create namespaces by the chart.
|
## createNamespace decides to create namespaces by the chart.
|
||||||
## If set to true, functionNamespace and builderNamespace namespaces mentioned above will be created by the chart.
|
## If set to true, functionNamespace and builderNamespace namespaces mentioned above will be created by the chart.
|
||||||
## Set to false if you want to create the namespaces manually.
|
## Set to false if you want to create the namespaces manually.
|
||||||
|
|||||||
@@ -140,10 +140,8 @@ const (
|
|||||||
FissionBuilderSA = "fission-builder"
|
FissionBuilderSA = "fission-builder"
|
||||||
FissionFetcherSA = "fission-fetcher"
|
FissionFetcherSA = "fission-fetcher"
|
||||||
|
|
||||||
SecretConfigMapGetterCR = "secret-configmap-getter"
|
|
||||||
SecretConfigMapGetterRB = "secret-configmap-getter-binding"
|
SecretConfigMapGetterRB = "secret-configmap-getter-binding"
|
||||||
|
|
||||||
PackageGetterCR = "package-getter"
|
|
||||||
PackageGetterRB = "package-getter-binding"
|
PackageGetterRB = "package-getter-binding"
|
||||||
|
|
||||||
ClusterRole = "ClusterRole"
|
ClusterRole = "ClusterRole"
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ func (pkgw *packageWatcher) build(ctx context.Context, srcpkg *fv1.Package) {
|
|||||||
// Add the package getter rolebinding to builder sa
|
// Add the package getter rolebinding to builder sa
|
||||||
// we continue here if role binding was not setup successfully. this is because without this, the fetcher won't be able to fetch the source pkg into the container and
|
// we continue here if role binding was not setup successfully. this is because without this, the fetcher won't be able to fetch the source pkg into the container and
|
||||||
// the build will fail eventually
|
// the build will fail eventually
|
||||||
err := utils.SetupRoleBinding(ctx, pkgw.logger, pkgw.k8sClient, fv1.PackageGetterRB, pkg.ObjectMeta.Namespace, fv1.PackageGetterCR, fv1.ClusterRole, fv1.FissionBuilderSA, builderNs)
|
err := utils.SetupRoleBinding(ctx, pkgw.logger, pkgw.k8sClient, fv1.PackageGetterRB, pkg.ObjectMeta.Namespace, utils.GetPackageGetterCR(), fv1.ClusterRole, fv1.FissionBuilderSA, builderNs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
pkgw.logger.Error("error setting up role binding for package",
|
pkgw.logger.Error("error setting up role binding for package",
|
||||||
zap.Error(err),
|
zap.Error(err),
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ func (deploy *NewDeploy) setupRBACObjs(ctx context.Context, deployNamespace stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create a cluster role binding for the fetcher SA, if not already created, granting access to do a get on packages in any ns
|
// create a cluster role binding for the fetcher SA, if not already created, granting access to do a get on packages in any ns
|
||||||
err = utils.SetupRoleBinding(ctx, deploy.logger, deploy.kubernetesClient, fv1.PackageGetterRB, fn.Spec.Package.PackageRef.Namespace, fv1.PackageGetterCR, fv1.ClusterRole, fv1.FissionFetcherSA, deployNamespace)
|
err = utils.SetupRoleBinding(ctx, deploy.logger, deploy.kubernetesClient, fv1.PackageGetterRB, fn.Spec.Package.PackageRef.Namespace, utils.GetPackageGetterCR(), fv1.ClusterRole, fv1.FissionFetcherSA, deployNamespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
deploy.logger.Error("error creating role binding for function",
|
deploy.logger.Error("error creating role binding for function",
|
||||||
zap.Error(err),
|
zap.Error(err),
|
||||||
@@ -151,7 +151,7 @@ func (deploy *NewDeploy) setupRBACObjs(ctx context.Context, deployNamespace stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create rolebinding in function namespace for fetcherSA.envNamespace to be able to get secrets and configmaps
|
// create rolebinding in function namespace for fetcherSA.envNamespace to be able to get secrets and configmaps
|
||||||
err = utils.SetupRoleBinding(ctx, deploy.logger, deploy.kubernetesClient, fv1.SecretConfigMapGetterRB, fn.ObjectMeta.Namespace, fv1.SecretConfigMapGetterCR, fv1.ClusterRole, fv1.FissionFetcherSA, deployNamespace)
|
err = utils.SetupRoleBinding(ctx, deploy.logger, deploy.kubernetesClient, fv1.SecretConfigMapGetterRB, fn.ObjectMeta.Namespace, utils.GetSecretConfigMapGetterCR(), fv1.ClusterRole, fv1.FissionFetcherSA, deployNamespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
deploy.logger.Error("error creating role binding for function",
|
deploy.logger.Error("error creating role binding for function",
|
||||||
zap.Error(err),
|
zap.Error(err),
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ func FunctionEventHandlers(logger *zap.Logger, kubernetesClient *kubernetes.Clie
|
|||||||
// setup rolebinding is tried, if it fails, we don't return. we just log an error and move on, because :
|
// setup rolebinding is tried, if it fails, we don't return. we just log an error and move on, because :
|
||||||
// 1. not all functions have secrets and/or configmaps, so things will work without this rolebinding in that case.
|
// 1. not all functions have secrets and/or configmaps, so things will work without this rolebinding in that case.
|
||||||
// 2. on the contrary, when the route is tried, the env fetcher logs will show a 403 forbidden message and same will be relayed to executor.
|
// 2. on the contrary, when the route is tried, the env fetcher logs will show a 403 forbidden message and same will be relayed to executor.
|
||||||
err := utils.SetupRoleBinding(ctx, logger, kubernetesClient, fv1.SecretConfigMapGetterRB, fn.ObjectMeta.Namespace, fv1.SecretConfigMapGetterCR, fv1.ClusterRole, fv1.FissionFetcherSA, envNs)
|
err := utils.SetupRoleBinding(ctx, logger, kubernetesClient, fv1.SecretConfigMapGetterRB, fn.ObjectMeta.Namespace, utils.GetSecretConfigMapGetterCR(), fv1.ClusterRole, fv1.FissionFetcherSA, envNs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("error creating rolebinding", zap.Error(err), zap.String("role_binding", fv1.SecretConfigMapGetterRB))
|
logger.Error("error creating rolebinding", zap.Error(err), zap.String("role_binding", fv1.SecretConfigMapGetterRB))
|
||||||
} else {
|
} else {
|
||||||
@@ -185,7 +185,7 @@ func FunctionEventHandlers(logger *zap.Logger, kubernetesClient *kubernetes.Clie
|
|||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
err := utils.SetupRoleBinding(ctx, logger, kubernetesClient, fv1.SecretConfigMapGetterRB,
|
err := utils.SetupRoleBinding(ctx, logger, kubernetesClient, fv1.SecretConfigMapGetterRB,
|
||||||
newFunc.ObjectMeta.Namespace, fv1.SecretConfigMapGetterCR, fv1.ClusterRole,
|
newFunc.ObjectMeta.Namespace, utils.GetSecretConfigMapGetterCR(), fv1.ClusterRole,
|
||||||
fv1.FissionFetcherSA, envNs)
|
fv1.FissionFetcherSA, envNs)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func PackageEventHandlers(logger *zap.Logger, kubernetesClient *kubernetes.Clien
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
// here, we return if we hit an error during rolebinding setup. this is because this rolebinding is mandatory for
|
// here, we return if we hit an error during rolebinding setup. this is because this rolebinding is mandatory for
|
||||||
// every function's package to be loaded into its env. without that, there's no point to move forward.
|
// every function's package to be loaded into its env. without that, there's no point to move forward.
|
||||||
err := utils.SetupRoleBinding(ctx, logger, kubernetesClient, fv1.PackageGetterRB, pkg.ObjectMeta.Namespace, fv1.PackageGetterCR, fv1.ClusterRole, fv1.FissionFetcherSA, envNs)
|
err := utils.SetupRoleBinding(ctx, logger, kubernetesClient, fv1.PackageGetterRB, pkg.ObjectMeta.Namespace, utils.GetPackageGetterCR(), fv1.ClusterRole, fv1.FissionFetcherSA, envNs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("error creating rolebinding for package",
|
logger.Error("error creating rolebinding for package",
|
||||||
zap.Error(err),
|
zap.Error(err),
|
||||||
@@ -83,7 +83,7 @@ func PackageEventHandlers(logger *zap.Logger, kubernetesClient *kubernetes.Clien
|
|||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
err := utils.SetupRoleBinding(ctx, logger, kubernetesClient, fv1.PackageGetterRB,
|
err := utils.SetupRoleBinding(ctx, logger, kubernetesClient, fv1.PackageGetterRB,
|
||||||
newPkg.ObjectMeta.Namespace, fv1.PackageGetterCR, fv1.ClusterRole,
|
newPkg.ObjectMeta.Namespace, utils.GetPackageGetterCR(), fv1.ClusterRole,
|
||||||
fv1.FissionFetcherSA, envNs)
|
fv1.FissionFetcherSA, envNs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("error updating rolebinding for package",
|
logger.Error("error updating rolebinding for package",
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package utils
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
|
||||||
@@ -295,3 +296,19 @@ func DeleteRoleBinding(ctx context.Context, k8sClient *kubernetes.Clientset, rol
|
|||||||
func MakeSAMapKey(saName, saNamespace string) string {
|
func MakeSAMapKey(saName, saNamespace string) string {
|
||||||
return fmt.Sprintf("%s-%s", saName, saNamespace)
|
return fmt.Sprintf("%s-%s", saName, saNamespace)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetSecretConfigMapGetterCR() string {
|
||||||
|
releaseName := os.Getenv("HELM_RELEASE_NAME")
|
||||||
|
if len(releaseName) > 0 {
|
||||||
|
return fmt.Sprintf("%s-secret-configmap-getter", releaseName)
|
||||||
|
}
|
||||||
|
return "secret-configmap-getter"
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetPackageGetterCR() string {
|
||||||
|
releaseName := os.Getenv("HELM_RELEASE_NAME")
|
||||||
|
if len(releaseName) > 0 {
|
||||||
|
return fmt.Sprintf("%s-package-getter", releaseName)
|
||||||
|
}
|
||||||
|
return "package-getter"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user