Starting with VKS 3.5.0, you can customize 'requirePasswordOnSudo' in cluster configurations.
If you enable this feature, it prevents direct log collection via the 'vks-support-bundler' tool.
VMware vSphere Kubernetes Service >= 3.5.0
The 'vks-support-bundler' requires elevated privileges without a password prompt to execute log collection scripts on cluster nodes. When 'requirePasswordOnSudo' is active, the tool cannot complete these tasks.
You can use the following workaround to gather logs by temporarily enabling `NOPASSWD` sudo.
You must create a DaemonSet to modify the sudoers files on cluster nodes.
**Note:** This DaemonSet changes the configuration on all nodes in the workload cluster. If you only enabled `requirePasswordOnSudo` on specific nodes, identify them in advance before applying the DaemonSet.
If your current image is not pullable, update it with a customer-pullable 'photon:5.0' image.
enable-nopasswd-sudo.yaml -
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: modify-sudoers
namespace: kube-system
spec:
selector:
matchLabels:
app: modify-sudoers
template:
metadata:
labels:
app: modify-sudoers
spec:
restartPolicy: Always
volumes:
- name: hostfs
hostPath:
path: /
initContainers:
- name: modify-sudoers
image: photon:5.0
command:
- /bin/sh
- -xc
- |
echo "Checking current sudoers configuration..."
chroot /host cat /etc/sudoers.d/90-cloud-init-users 2>/dev/null
echo "Modifying sudoers file to allow NOPASSWD..."
chroot /host sed -i 's/^\([^ ]*\) ALL=(ALL) ALL/\1 ALL=(ALL) NOPASSWD:ALL/' /etc/sudoers.d/90-cloud-init-users
echo "Verifying changes..."
chroot /host cat /etc/sudoers.d/90-cloud-init-users 2>/dev/null
echo "Done"
securityContext:
privileged: true
runAsGroup: 0
allowPrivilegeEscalation: true
capabilities:
add: ["ALL"]
volumeMounts:
- name: hostfs
mountPath: /host
containers:
- name: sleep
image: photon:5.0
command: ["/bin/sh", "-c", "while true; do sleep 3600; done"]
securityContext:
runAsUser: 0
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
seccompProfile:
type: RuntimeDefault
tolerations:
- key: node-role.kubernetes.io/master
operator: Exists
effect: NoSchedule
- key: node-role.kubernetes.io/control-plane
operator: Exists
effect: NoSchedule
- key: CriticalAddonsOnly
operator: Exists
- key: node.alpha.kubernetes.io/notReady
operator: Exists
effect: NoExecute
- key: node.alpha.kubernetes.io/unreachable
operator: Exists
effect: NoExecute
Please refer to https://knowledge.broadcom.com/external/article/345464/gathering-logs-for-vsphere-with-tanzu.html for more info.
3.1 If You Enabled requirePasswordOnSudo on All Nodes
Apply the following DaemonSet to revert the configuration:
revert-nopasswd-sudo.yaml -
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: revert-sudoers
namespace: kube-system
spec:
selector:
matchLabels:
app: revert-sudoers
template:
metadata:
labels:
app: revert-sudoers
spec:
restartPolicy: Always
volumes:
- name: hostfs
hostPath: /
initContainers:
- name: revert-sudoers
image: photon:5.0
command:
- /bin/sh
- -xc
- |
echo "Checking current sudoers configuration..."
chroot /host cat /etc/sudoers.d/90-cloud-init-users 2>/dev/null
echo "Reverting sudoers file to require password..."
chroot /host sed -i 's/^\([^ ]*\) ALL=(ALL) NOPASSWD:ALL/\1 ALL=(ALL) ALL/' /etc/sudoers.d/90-cloud-init-users
echo "Verifying changes..."
chroot /host cat /etc/sudoers.d/90-cloud-init-users 2>/dev/null
echo "Done"
securityContext:
privileged: true
runAsGroup: 0
allowPrivilegeEscalation: true
capabilities:
add: ["ALL"]
volumeMounts:
- name: hostfs
mountPath: /host
containers:
- name: sleep
image: photon:5.0
command: ["/bin/sh", "-c", "while true; do sleep 3600; done"]
securityContext:
runAsUser: 0
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
seccompProfile:
type: RuntimeDefault
tolerations:
- key: node-role.kubernetes.io/master
operator: Exists
effect: NoSchedule
- key: node-role.kubernetes.io/control-plane
operator: Exists
effect: NoSchedule
- key: CriticalAddonsOnly
operator: Exists
- key: node.alpha.kubernetes.io/notReady
operator: Exists
effect: NoExecute
- key: node.alpha.kubernetes.io/unreachable
operator: Exists
effect: NoExecute
3.2 If NOT all nodes are enabled with requirePasswordOnSudo
Please edit nodeAffinity to select nodes who need applying daemonSet. The example below shows the daemonSet will work on node with label 'vks.vmware.com/nodepool=worker' which will be reverted back to require password on sudo.
revert-nopasswd-sudo.yaml -
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: revert-sudoers
namespace: kube-system
spec:
selector:
matchLabels:
app: revert-sudoers
template:
metadata:
labels:
app: revert-sudoers
spec:
restartPolicy: Always
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: vks.vmware.com/nodepool
operator: In
values:
- worker
volumes:
- name: hostfs
hostPath:
path: /
initContainers:
- name: revert-sudoers
image: photon:5.0
command:
- /bin/sh
- -xc
- |
echo "Checking current sudoers configuration..."
chroot /host cat /etc/sudoers.d/90-cloud-init-users 2>/dev/null
echo "Reverting sudoers file to require password..."
chroot /host sed -i 's/^\([^ ]*\) ALL=(ALL) NOPASSWD:ALL/\1 ALL=(ALL) ALL/' /etc/sudoers.d/90-cloud-init-users
echo "Verifying changes..."
chroot /host cat /etc/sudoers.d/90-cloud-init-users 2>/dev/null
echo "Done"
securityContext:
privileged: true
runAsGroup: 0
allowPrivilegeEscalation: true
capabilities:
add: ["ALL"]
volumeMounts:
- name: hostfs
mountPath: /host
containers:
- name: sleep
image: photon:5.0
command: ["/bin/sh", "-c", "while true; do sleep 3600; done"]
securityContext:
runAsUser: 0
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
seccompProfile:
type: RuntimeDefault
tolerations:
- key: node-role.kubernetes.io/master
operator: Exists
effect: NoSchedule
- key: node-role.kubernetes.io/control-plane
operator: Exists
effect: NoSchedule
- key: CriticalAddonsOnly
operator: Exists
- key: node.alpha.kubernetes.io/notReady
operator: Exists
effect: NoExecute
- key: node.alpha.kubernetes.io/unreachable
operator: Exists
effect: NoExecute
kubectl apply -f revert-nopasswd-sudo.yaml'.You can now delete the temporary DaemonSets once the process is complete:
kubectl delete daemonset -n kube-system modify-sudoers
kubectl delete daemonset -n kube-system revert-sudoers