-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rbac aad practice #16
base: master
Are you sure you want to change the base?
Conversation
* Create Azure Key Vault to hold secrets Enable K8S cluster managed identity to fetch them * Deploy Azure Key Vault Provider for Secrets Store CSI Driver to K8S cluster, in order to enable fetching of Azure Key Vault stored secrets to Pods. Signed-off-by: Harri Hirvonsalo <[email protected]>
…ory and Kubernetes RBAC
Moved TODOs in the beginning Added note about destroying and applying the cluster Added link
role_based_access_control { | ||
enabled = true | ||
azure_active_directory { | ||
managed = true | ||
admin_group_object_ids = [ | ||
"93b4062c-6cf4-4ed3-af28-9633d2785bda" | ||
] | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is one essential part of enabling AAD integration for K8S cluster.
kind: Role | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
metadata: | ||
name: dev-user-full-access | ||
namespace: dev | ||
rules: | ||
- apiGroups: ["", "extensions", "apps"] | ||
resources: ["*"] | ||
verbs: ["*"] | ||
- apiGroups: ["batch"] | ||
resources: | ||
- jobs | ||
- cronjobs | ||
verbs: ["*"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These create the roles that can be used to limit access via RBAC.
kind: Role | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
metadata: | ||
name: sre-user-full-access | ||
namespace: sre | ||
rules: | ||
- apiGroups: ["", "extensions", "apps"] | ||
resources: ["*"] | ||
verbs: ["*"] | ||
- apiGroups: ["batch"] | ||
resources: | ||
- jobs | ||
- cronjobs | ||
verbs: ["*"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These create the roles that can be used to limit access via RBAC.
kind: RoleBinding | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
metadata: | ||
name: dev-user-access | ||
namespace: dev | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: Role | ||
name: dev-user-full-access | ||
subjects: | ||
- kind: Group | ||
namespace: dev | ||
name: 6301165d-4aac-45d5-a8b5-373bc6520e2f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These create the rolebindings that can be used to limit access via RBAC. Groups must be created with azure cli or some other way.
kind: RoleBinding | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
metadata: | ||
name: sre-user-access | ||
namespace: sre | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: Role | ||
name: sre-user-full-access | ||
subjects: | ||
- kind: Group | ||
namespace: sre | ||
name: 785e6c8f-6e5f-4543-a88d-fa391591ea61 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These create the rolebindings that can be used to limit access via RBAC. Groups must be created with azure cli or some other way.
#### 5. Role-based access control (RBAC), Azure Active Directory (AAD) and namespaces | ||
|
||
To enable RBAC through AAD via this Terraform plan the following steps were done: | ||
|
||
1. Added a role_based_access_control-block to resource "azurerm_kubernetes_cluster" found in modules/k8s/main.tf. | ||
- that block contains an array named admin_group_object_ids, which contains the id of an AD group. That AD group contains admins of the cluster. Currently, creating the group and adding admins is a manual process. The group id can be queried via Azure CLI or Azure Portal. | ||
2. After enabling AAD/RBAC, K8S csi driver installation needs sufficient K8S cluster credentials. One easy way of providing them is to use kubeconfig with --admin flag: | ||
- `az aks get-credentials -g <RESOURCE_GROUP_NAME> -n <CLUSTER_NAME> --admin`. This creates an entry in the kubeconfig (default path is ~/.kube/config). | ||
3. Added following lines to provider "helm" in modules/k8s_csi_driver_azure/main.tf: | ||
- `config_path = "~/.kube/config"` | ||
- `config_context = "<ADMIN_CONTEXT_NAME_HERE>"` | ||
- Note: do not specify username and password if using kubeconfig to authenticate. | ||
4. Then, this guide was followed: https://docs.microsoft.com/en-us/azure/aks/azure-ad-rbac with following exceptions: | ||
- In step `Create demo users in Azure AD`, new users weren't created. Instead, | ||
$AKSDEV_ID and $AKSSRE_ID were replaced by existing users' ids. | ||
- Note: if you are in the cluster admin AD group, you will see all cluster resources regardless of whether you use cluster admin or cluster user context (acquired via the az aks get-credentials command). | ||
- Note: if you destroy the resources and then apply them again, you may need to acquire new credentials to kubeconfig to be able to install the K8S CSI driver. | ||
|
||
After doing those steps, with your cluster user credentials, you should only be able to see and modify resources in specific namespaces. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These steps document how to enable AAD-assisted RBAC in K8S cluster
Request for comments