Systems Integration
KubeVela application natively supports impersonation even without the Authentication flag enabled. That means when the Authentication flag is disabled, you can manually set the identity to impersonate in the application’s annotation fields. For example, the following guide will give an example on how to manually set the application to impersonate as a ServiceAccount.
Example
Let’s assume that we have two namespaces:
demo-service: for managing applicationdemo-service-prod: to deploy components for the production environment
In this example, we will make the Application use a specific ServiceAccount instead of the controller ServiceAccount.
Creating ServiceAccount
Create deployer ServiceAccount in demo-service namespace.
apiVersion: v1kind: ServiceAccountmetadata:name: deployernamespace: demo-service
Creating Role/RoleBinding
Allow deployer ServiceAccount in demo-service to manage Deployments in demo-service-prod by creating Role/RoleBinding.
Notice that KubeVela application requires the identity to impersonate to have the privileges for writing ControllerRevision. If you use
--optimize-disable-component-revisionin the KubeVela controller, you can ignore this requirement.
apiVersion: rbac.authorization.k8s.io/v1kind: Rolemetadata:name: deployments:adminnamespace: demo-service-prodrules:- apiGroups: ["apps"]resources: ["deployments"]verbs: ["*"]---apiVersion: rbac.authorization.k8s.io/v1kind: RoleBindingmetadata:name: deployments:adminnamespace: demo-service-prodroleRef:apiGroup: rbac.authorization.k8s.iokind: Rolename: deployments:adminsubjects:- kind: ServiceAccountname: deployernamespace: demo-service
Deploying an Application with ServiceAccount
apiVersion: core.oam.dev/v1beta1kind: Applicationmetadata:name: multi-env-demo-with-service-accountnamespace: demo-serviceannotations:app.oam.dev/service-account-name: deployer # the name of the ServiceAccount we createdspec:components:- name: nginx-servertype: webserviceproperties:image: nginx:1.21port: 80policies:- name: envtype: env-bindingproperties:created: falseenvs:- name: prodpatch:components:- name: nginx-servertype: webserviceproperties:image: nginx:1.20port: 80placement:namespaceSelector:name: demo-service-prodworkflow:steps:- name: deploy-prod-servertype: deploy2envproperties:policy: envenv: prod
After deploying the Application, you can check the Application is deployed successfully.
$ vela status multi-env-demo-with-service-account -n demo-serviceAbout:Name: multi-env-demo-with-service-accountNamespace: demo-serviceCreated at: 2022-05-31 17:58:14 +0800 CSTStatus: runningWorkflow:mode: StepByStepfinished: trueSuspend: falseTerminated: falseSteps- id:ut3bxuisoyname:deploy-prod-servertype:deploy2envphase:succeededmessage:Services:- Name: nginx-serverCluster: local Namespace: demo-service-prodType: webserviceHealthy Ready:1/1No trait applied
If you set non-authorized ServiceAccount to the annotation, you can find an error message like below in the Application status.
Dispatch: Found 1 errors. [(cannot get object: deployments.apps "nginx-server" is forbidden: User "system:serviceaccount:demo-service:non-authorized-account" cannot get resource "deployments" in API group "apps" in the namespace "demo-service-prod")]
Impersonate as User/Groups
If you would like to let the application to impersonate as specific user and group, you can set the annotation app.oam.dev/username and app.oam.dev/group in the application respectively.