Creating Kubernetes Service Accounts and Kubeconfigs for Anonymization Cluster
A service account in the anonymization cluster namespace has access to the anonymization namespace. It might also have access to the whole cluster. These permissions for the service account allow the user to create, read, update, and delete objects in the anonymization Kubernetes cluster or the namespace. Additionally, the kubeconfig is required to access the service account using a token.
In this section, you create a Kubernetes service account and the role-based access control (RBAC) configuration manually using kubectl.
Ensure that the user has access to permissions for creating and updating the following resources in the Kubernetes cluster:
Kubernetes Service Accounts
Kubernetes Roles and Rolebindings
Optional: Kubernetes ClusterRoles and Rolebindings
Use the steps provided in the followng link to create the namespace and assign the required permissions to the cluster.
Creating the Service AccountComplete the steps provided in the following link to retrieve the tokens for the Protegrity Anonymization API service account and to create a kubeconfig with access to the service account.
Obtaining the Tokens for the Service Account
Obtaining the Tokens for the Service Account
Complete the steps provided int his section to retrieve the tokens for the Protegrity Anonymization API service account and to create a kubeconfig with access to the service account.
Open a command line interface on the base machine for running the configuration commands.
Note: A copy of the commands is available in the
kubconfigcmd.txtfile in therbacdirectory of the Protegrity Anonymization API package. Use the code form the file to run the commands.Set the environment variables for running the configuration commands using the following command.
SERVICE_ACCOUNT_NAME=anon-service-account CONTEXT=$(kubectl config current-context) NAMESPACE=anon-namespace NEW_CONTEXT=anon-context SECRET_NAME=$(kubectl get serviceaccount ${SERVICE_ACCOUNT_NAME} -n ${NAMESPACE} --context ${CONTEXT} --namespace ${NAMESPACE} -o jsonpath='{.secrets[0].name}') TOKEN_DATA=$(kubectl get secret ${SECRET_NAME} -n ${NAMESPACE} --context ${CONTEXT} --namespace ${NAMESPACE} -o jsonpath='{.data.token}') TOKEN=$(echo ${TOKEN_DATA} | base64 -d)Note: Ensure that you use the appropriate values as per your configuration in the above command.
Set the token in the config credentials using the following command.
kubectl config set-credentials <username> --token=$TOKENFor example,
kubectl config set-credentials test-user --token=$TOKENRetrieve the cluster name using the following command.
kubectl config get-clustersSet the context in kubeconfig using the following command.
kubectl config set-context ${NEW_CONTEXT} --cluster=<name of your cluster> --user=test-userSet the current context to to use the new anonymization config using the following command.
kubectl config use-context ${NEW_CONTEXT}Verify the new context using the following command.
kubectl config current-contextVerify the status of the pods using the following command.
kubectl get pods -n <name space>
Creating the Service Account
Use the steps provided in this section to create the namespace and assign the required permissions to the cluster.
Create the Kubernetes Service Account using the following steps.
Navigate to the
rbacdirectory of the extracted Protegrity Anonymization API package.Open the
anon-service-account.yamlfile using a text editor.Update the namespace as per your configuration in the
anon-service-account.yamlfile.Save and close the file.
From a command prompt, navigate to the
rbacdirectory and run the following command to create the service account.kubectl apply -f anon-service-account.yaml
Grant the appropriate permission to the service account using any one of the following two steps.
Grant cluster-admin permissions for the service account to all the namespaces using the following steps.
Note: You need to run this step only if you want to grant the service account access to all namespaces in your cluster.
A Kubernetes ClusterRoleBinding is available at the cluster level, but the subject of the ClusterRoleBinding exists in a single namespace. Hence, you must specify the namespace for the service account.
Navigate to the
rbacdirectory of the extracted Protegrity Anonymization API package.Open the
anon-clusterrolebinding.yamlfile using a text editor.Update the namespace as per your configuration in the
anon-clusterrolebinding.yamlfile.Save and close the file.
From a command prompt, navigate to the
rbacdirectory and run the following command to assign the appropriate permissions.kubectl apply -f anon-clusterrolebinding.yaml
Grant namespace-specific permissions to the service account using the following steps.
Note: You need to run this step only if you want to grant the service account access to just the Protegrity Anonymization API namespace.
Ensure that you create a role with a set of permissions and rolebinding for attaching the role to the service account.
Navigate to the
rbacdirectory of the extracted Protegrity Anonymization API package.Open the
anon-role-and-rolebinding.yamlfile using a text editor.Update the namespace, role, and service account name as per your configuration in the
anon-role-and-rolebinding.yamlfile.Save and close the file.
From a command prompt, navigate to the
rbacdirectory and run the following command to assign the appropriate permissions.kubectl apply -f anon-role-and-rolebinding.yaml
Feedback
Was this page helpful?