Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions bindata/network/multus/multus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ metadata:
namespace: openshift-multus
annotations:
kubernetes.io/description: |
This deamon watches over the whereabouts service account token and CA
This daemon watches over the whereabouts service account token and CA
file for changes and will regenerate a kubeconfig if changes are seen
release.openshift.io/version: "{{.ReleaseVersion}}"
spec:
Expand All @@ -954,6 +954,7 @@ spec:
labels:
app: whereabouts-token-watcher
spec:
hostNetwork: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for this?

Copy link
Contributor Author

@pliurh pliurh Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pod writes the/etc/kubernetes/cni/net.d/whereabouts.d/whereabouts.kubeconfig file on the node. Without hostNetwork: true, it fails with a permission error. Also, this pod should not rely on OVN-Kubernetes being ready.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can the file access be dependent on this config?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pods with hostNetwork: true automatically get the spc_t (super privileged container) SELinux type, which has broad access to host resources.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting securityContext.seLinuxOptions:type: spc_t can also resolve the permission issue. However, I don't think this pod should rely on OVN-Kubernetes.

nodeSelector:
kubernetes.io/os: linux
priorityClassName: "system-node-critical"
Expand All @@ -971,11 +972,16 @@ spec:

set -u -e

# Helper functions for logging
function log { echo "$(date -Iseconds) $@"; }
function warn { echo "$(date -Iseconds) WARNING: $@" >&2; }
function error { echo "$(date -Iseconds) ERROR: $@" >&2; }

SERVICE_ACCOUNT_PATH=/var/run/secrets/kubernetes.io/serviceaccount
KUBE_CA_FILE=${KUBE_CA_FILE:-$SERVICE_ACCOUNT_PATH/ca.crt}
SERVICE_ACCOUNT_TOKEN=$(cat $SERVICE_ACCOUNT_PATH/token)
SERVICE_ACCOUNT_TOKEN_PATH=$SERVICE_ACCOUNT_PATH/token
SKIP_TLS_VERIFY=${SKIP_TLS_VERIFY:-false}
WHEREABOUTS_KUBECONFIG=${CNI_CONF_DIR:-/host/etc/cni/net.d}/whereabouts.d/whereabouts.kubeconfig

function generateKubeConfig {
# Check if we're running as a k8s pod.
Expand Down Expand Up @@ -1017,7 +1023,7 @@ spec:
users:
- name: whereabouts
user:
token: "${SERVICE_ACCOUNT_TOKEN}"
token: "$(cat $SERVICE_ACCOUNT_TOKEN_PATH)"
contexts:
- name: whereabouts-context
context:
Expand Down Expand Up @@ -1048,20 +1054,20 @@ spec:
export LAST_SERVICEACCOUNT_MD5SUM="$(get_token_md5sum)"
export LAST_KUBE_CA_FILE_MD5SUM="$(get_ca_file_md5sum)"

echo "Sleep and Watching for service account token and CA file changes..."
log "Sleep and Watching for service account token and CA file changes..."
# enter sleep/watch loop
while true; do
# Check the md5sum of the service account token and ca.
svcaccountsum="$(get_token_md5sum)"
casum="$(get_ca_file_md5sum)"
if [ "$svcaccountsum" != "$LAST_SERVICEACCOUNT_MD5SUM" ] || ! [ "$SKIP_TLS_VERIFY" == "true" ] && [ "$casum" != "$LAST_KUBE_CA_FILE_MD5SUM" ]; then
if [ "$svcaccountsum" != "$LAST_SERVICEACCOUNT_MD5SUM" ] || ( [ "$SKIP_TLS_VERIFY" != "true" ] && [ "$casum" != "$LAST_KUBE_CA_FILE_MD5SUM" ] ); then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did the logic change here?

Copy link
Contributor Author

@pliurh pliurh Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The original logic is wrong. We shall regenerate the kubeconfig when either the token or the CA of the SA is updated. SKIP_TLS_VERIFY is always false.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so you changed it from: ! (a == true) && (b != c) to (a != true) && (b != c), isn't this the same? Although I find your version better I think they should be logically equivalent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I thought && has the same precedence as || in bash. But using parentheses makes is more clear.

log "Detected service account or CA file change, regenerating kubeconfig..."
generateKubeConfig
LAST_SERVICEACCOUNT_MD5SUM="$svcaccountsum"
LAST_KUBE_CA_FILE_MD5SUM="$casum"
fi

sleep 1s
sleep 60s
done

resources:
Expand All @@ -1072,6 +1078,8 @@ spec:
volumeMounts:
- name: whereabouts-flatfile-configmap
mountPath: /etc/whereabouts/config
- mountPath: /host/etc/cni/net.d
name: cni-net-dir
env:
- name: KUBERNETES_SERVICE_PORT
value: "{{.KUBERNETES_SERVICE_PORT}}"
Expand All @@ -1081,13 +1089,15 @@ spec:
value: "/host/opt/cni/bin/"
- name: CNI_CONF_DIR
value: "/host/etc/cni/net.d"
- name: SLEEP
value: "false"
- name: WHEREABOUTS_NAMESPACE
value: "openshift-multus"
volumes:
- name: whereabouts-flatfile-configmap
configMap:
name: whereabouts-flatfile-config
- name: cni-net-dir
hostPath:
path: {{ .SystemCNIConfDir }}
type: Directory
{{- end}}
---