Skip to content

Commit f59a649

Browse files
authored
Merge pull request #31412 from marosset/gmsa-container-runtime
configure-gmsa.md updates
2 parents 02759c5 + 6ffd07c commit f59a649

File tree

1 file changed

+28
-60
lines changed

1 file changed

+28
-60
lines changed

content/en/docs/tasks/configure-pod-container/configure-gmsa.md

Lines changed: 28 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,19 @@ weight: 20
1010

1111
This page shows how to configure [Group Managed Service Accounts](https://docs.microsoft.com/en-us/windows-server/security/group-managed-service-accounts/group-managed-service-accounts-overview) (GMSA) for Pods and containers that will run on Windows nodes. Group Managed Service Accounts are a specific type of Active Directory account that provides automatic password management, simplified service principal name (SPN) management, and the ability to delegate the management to other administrators across multiple servers.
1212

13-
In Kubernetes, GMSA credential specs are configured at a Kubernetes cluster-wide scope as Custom Resources. Windows Pods, as well as individual containers within a Pod, can be configured to use a GMSA for domain based functions (e.g. Kerberos authentication) when interacting with other Windows services. As of v1.16, the Docker runtime supports GMSA for Windows workloads.
14-
15-
13+
In Kubernetes, GMSA credential specs are configured at a Kubernetes cluster-wide scope as Custom Resources. Windows Pods, as well as individual containers within a Pod, can be configured to use a GMSA for domain based functions (e.g. Kerberos authentication) when interacting with other Windows services.
1614

1715
## {{% heading "prerequisites" %}}
1816

19-
2017
You need to have a Kubernetes cluster and the `kubectl` command-line tool must be configured to communicate with your cluster. The cluster is expected to have Windows worker nodes. This section covers a set of initial steps required once for each cluster:
2118

2219
### Install the GMSACredentialSpec CRD
20+
2321
A [CustomResourceDefinition](/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/)(CRD) for GMSA credential spec resources needs to be configured on the cluster to define the custom resource type `GMSACredentialSpec`. Download the GMSA CRD [YAML](https://github.com/kubernetes-sigs/windows-gmsa/blob/master/admission-webhook/deploy/gmsa-crd.yml) and save it as gmsa-crd.yaml.
2422
Next, install the CRD with `kubectl apply -f gmsa-crd.yaml`
2523

2624
### Install webhooks to validate GMSA users
25+
2726
Two webhooks need to be configured on the Kubernetes cluster to populate and validate GMSA credential spec references at the Pod or container level:
2827

2928
1. A mutating webhook that expands references to GMSAs (by name from a Pod specification) into the full credential spec in JSON form within the Pod spec.
@@ -36,38 +35,38 @@ Installing the above webhooks and associated objects require the steps below:
3635

3736
1. Install a secret with the certificate from above.
3837

39-
1. Create a deployment for the core webhook logic.
38+
1. Create a deployment for the core webhook logic.
4039

41-
1. Create the validating and mutating webhook configurations referring to the deployment.
40+
1. Create the validating and mutating webhook configurations referring to the deployment.
4241

4342
A [script](https://github.com/kubernetes-sigs/windows-gmsa/blob/master/admission-webhook/deploy/deploy-gmsa-webhook.sh) can be used to deploy and configure the GMSA webhooks and associated objects mentioned above. The script can be run with a ```--dry-run=server``` option to allow you to review the changes that would be made to your cluster.
4443

4544
The [YAML template](https://github.com/kubernetes-sigs/windows-gmsa/blob/master/admission-webhook/deploy/gmsa-webhook.yml.tpl) used by the script may also be used to deploy the webhooks and associated objects manually (with appropriate substitutions for the parameters)
4645

47-
48-
4946
<!-- steps -->
5047

5148
## Configure GMSAs and Windows nodes in Active Directory
49+
5250
Before Pods in Kubernetes can be configured to use GMSAs, the desired GMSAs need to be provisioned in Active Directory as described in the [Windows GMSA documentation](https://docs.microsoft.com/en-us/windows-server/security/group-managed-service-accounts/getting-started-with-group-managed-service-accounts#BKMK_Step1). Windows worker nodes (that are part of the Kubernetes cluster) need to be configured in Active Directory to access the secret credentials associated with the desired GMSA as described in the [Windows GMSA documentation](https://docs.microsoft.com/en-us/windows-server/security/group-managed-service-accounts/getting-started-with-group-managed-service-accounts#to-add-member-hosts-using-the-set-adserviceaccount-cmdlet)
5351

5452
## Create GMSA credential spec resources
55-
With the GMSACredentialSpec CRD installed (as described earlier), custom resources containing GMSA credential specs can be configured. The GMSA credential spec does not contain secret or sensitive data. It is information that a container runtime can use to describe the desired GMSA of a container to Windows. GMSA credential specs can be generated in YAML format with a utility [PowerShell script](https://github.com/kubernetes-sigs/windows-gmsa/tree/master/scripts/GenerateCredentialSpecResource.ps1).
53+
54+
With the GMSACredentialSpec CRD installed (as described earlier), custom resources containing GMSA credential specs can be configured. The GMSA credential spec does not contain secret or sensitive data. It is information that a container runtime can use to describe the desired GMSA of a container to Windows. GMSA credential specs can be generated in YAML format with a utility [PowerShell script](https://github.com/kubernetes-sigs/windows-gmsa/tree/master/scripts/GenerateCredentialSpecResource.ps1).
5655

5756
Following are the steps for generating a GMSA credential spec YAML manually in JSON format and then converting it:
5857

5958
1. Import the CredentialSpec [module](https://github.com/MicrosoftDocs/Virtualization-Documentation/blob/live/windows-server-container-tools/ServiceAccounts/CredentialSpec.psm1): `ipmo CredentialSpec.psm1`
6059

6160
1. Create a credential spec in JSON format using `New-CredentialSpec`. To create a GMSA credential spec named WebApp1, invoke `New-CredentialSpec -Name WebApp1 -AccountName WebApp1 -Domain $(Get-ADDomain -Current LocalComputer)`
6261

63-
1. Use `Get-CredentialSpec` to show the path of the JSON file.
62+
1. Use `Get-CredentialSpec` to show the path of the JSON file.
6463

65-
1. Convert the credspec file from JSON to YAML format and apply the necessary header fields `apiVersion`, `kind`, `metadata` and `credspec` to make it a GMSACredentialSpec custom resource that can be configured in Kubernetes.
64+
1. Convert the credspec file from JSON to YAML format and apply the necessary header fields `apiVersion`, `kind`, `metadata` and `credspec` to make it a GMSACredentialSpec custom resource that can be configured in Kubernetes.
6665

6766
The following YAML configuration describes a GMSA credential spec named `gmsa-WebApp1`:
6867

6968
```yaml
70-
apiVersion: windows.k8s.io/v1alpha1
69+
apiVersion: windows.k8s.io/v1
7170
kind: GMSACredentialSpec
7271
metadata:
7372
name: gmsa-WebApp1 #This is an arbitrary name but it will be used as a reference
@@ -92,6 +91,7 @@ credspec:
9291
The above credential spec resource may be saved as `gmsa-Webapp1-credspec.yaml` and applied to the cluster using: `kubectl apply -f gmsa-Webapp1-credspec.yml`
9392

9493
## Configure cluster role to enable RBAC on specific GMSA credential specs
94+
9595
A cluster role needs to be defined for each GMSA credential spec resource. This authorizes the `use` verb on a specific GMSA resource by a subject which is typically a service account. The following example shows a cluster role that authorizes usage of the `gmsa-WebApp1` credential spec from above. Save the file as gmsa-webapp1-role.yaml and apply using `kubectl apply -f gmsa-webapp1-role.yaml`
9696

9797
```yaml
@@ -108,6 +108,7 @@ rules:
108108
```
109109

110110
## Assign role to service accounts to use specific GMSA credspecs
111+
111112
A service account (that Pods will be configured with) needs to be bound to the cluster role create above. This authorizes the service account to use the desired GMSA credential spec resource. The following shows the default service account being bound to a cluster role `webapp1-role` to use `gmsa-WebApp1` credential spec resource created above.
112113

113114
```yaml
@@ -127,6 +128,7 @@ roleRef:
127128
```
128129

129130
## Configure GMSA credential spec reference in Pod spec
131+
130132
The Pod spec field `securityContext.windowsOptions.gmsaCredentialSpecName` is used to specify references to desired GMSA credential spec custom resources in Pod specs. This configures all containers in the Pod spec to use the specified GMSA. A sample Pod spec with the annotation populated to refer to `gmsa-WebApp1`:
131133

132134
```yaml
@@ -197,55 +199,17 @@ As Pod specs with GMSA fields populated (as described above) are applied in a cl
197199

198200
1. The container runtime configures each Windows container with the specified GMSA credential spec so that the container can assume the identity of the GMSA in Active Directory and access services in the domain using that identity.
199201

200-
## Containerd
201-
202-
On Windows Server 2019, in order to use GMSA with containerd, you must be running OS Build 17763.1817 (or later) which can be installed using the patch [KB5000822](https://support.microsoft.com/en-us/topic/march-9-2021-kb5000822-os-build-17763-1817-2eb6197f-e3b1-4f42-ab51-84345e063564).
203-
204-
There is also a known issue with containerd that occurs when trying to connect to SMB shares from Pods. Once you have configured GMSA, the pod will be unable to connect to the share using the hostname or FQDN, but connecting to the share using an IP address works as expected.
202+
## Authenticating to network shares usinig hostname of FQDN
205203

206-
```PowerShell
207-
ping adserver.ad.local
208-
```
209-
and correctly resolves the hostname to an IPv4 address. The output is similar to:
204+
If you are experiencing issues connecting to SMB shares from Pods using hostname or FQDN, but are able to access the shares via their IPv4 address then make sure the following registry key is set on the Windows nodes.
210205

211-
```
212-
Pinging adserver.ad.local [192.168.111.18] with 32 bytes of data:
213-
Reply from 192.168.111.18: bytes=32 time=6ms TTL=124
214-
Reply from 192.168.111.18: bytes=32 time=5ms TTL=124
215-
Reply from 192.168.111.18: bytes=32 time=5ms TTL=124
216-
Reply from 192.168.111.18: bytes=32 time=5ms TTL=124
206+
```cmd
207+
reg add "HKLM\SYSTEM\CurrentControlSet\Services\hns\State" /v EnableCompartmentNamespace /t REG_DWORD /d 1
217208
```
218209

219-
However, when attempting to browse the directory using the hostname
220-
221-
```PowerShell
222-
cd \\adserver.ad.local\test
223-
```
224-
225-
you see an error that implies the target share doesn't exist:
226-
227-
```
228-
cd : Cannot find path '\\adserver.ad.local\test' because it does not exist.
229-
At line:1 char:1
230-
+ cd \\adserver.ad.local\test
231-
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
232-
+ CategoryInfo : ObjectNotFound: (\\adserver.ad.local\test:String) [Set-Location], ItemNotFoundException
233-
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
234-
```
235-
236-
but you notice that the error disappears if you browse to the share using its IPv4 address instead; for example:
237-
238-
```PowerShell
239-
cd \\192.168.111.18\test
240-
```
241-
242-
After you change into a directory within the share, you see a prompt similar to:
243-
244-
```
245-
Microsoft.PowerShell.Core\FileSystem::\\192.168.111.18\test>
246-
```
247-
248-
To correct the behaviour you must run the following on the node `reg add "HKLM\SYSTEM\CurrentControlSet\Services\hns\State" /v EnableCompartmentNamespace /t REG_DWORD /d 1` to add the required registry key. This node change will only take effect in newly created pods, meaning you must now recreate any running pods which require access to SMB shares.
210+
Running Pods will then need to be recreated to pick up the behavior changes.
211+
More information on how this registry key is used can be found [here](
212+
https://github.com/microsoft/hcsshim/blob/885f896c5a8548ca36c88c4b87fd2208c8d16543/internal/uvm/create.go#L74-L83)
249213

250214
## Troubleshooting
251215

@@ -258,8 +222,10 @@ In the example below the Pod did not get the credspec correctly:
258222
```PowerShell
259223
kubectl exec -it iis-auth-7776966999-n5nzr powershell.exe
260224
```
225+
261226
`nltest.exe /parentdomain` results in the following error:
262-
```
227+
228+
```PowerShell
263229
Getting parent domain failed: Status = 1722 0x6ba RPC_S_SERVER_UNAVAILABLE
264230
```
265231

@@ -278,7 +244,8 @@ nltest.exe /query
278244
```
279245

280246
Results in the following output:
281-
```
247+
248+
```PowerShell
282249
I_NetLogonControl failed: Status = 1722 0x6ba RPC_S_SERVER_UNAVAILABLE
283250
```
284251

@@ -289,7 +256,8 @@ nltest /sc_reset:domain.example
289256
```
290257

291258
If the command is successful you will see and output similar to this:
292-
```
259+
260+
```PowerShell
293261
Flags: 30 HAS_IP HAS_TIMESERV
294262
Trusted DC Name \\dc10.domain.example
295263
Trusted DC Connection Status Status = 0 0x0 NERR_Success

0 commit comments

Comments
 (0)