-
Notifications
You must be signed in to change notification settings - Fork 265
OCPBUGS-63443: Fix whereabouts-token-watcher DaemonSet improvements #2841
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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: | ||
|
|
@@ -954,6 +954,7 @@ spec: | |
| labels: | ||
| app: whereabouts-token-watcher | ||
| spec: | ||
| hostNetwork: true | ||
| nodeSelector: | ||
| kubernetes.io/os: linux | ||
| priorityClassName: "system-node-critical" | ||
|
|
@@ -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. | ||
|
|
@@ -1017,7 +1023,7 @@ spec: | |
| users: | ||
| - name: whereabouts | ||
| user: | ||
| token: "${SERVICE_ACCOUNT_TOKEN}" | ||
| token: "$(cat $SERVICE_ACCOUNT_TOKEN_PATH)" | ||
| contexts: | ||
| - name: whereabouts-context | ||
| context: | ||
|
|
@@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did the logic change here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so you changed it from:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right. I thought |
||
| 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: | ||
|
|
@@ -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}}" | ||
|
|
@@ -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}} | ||
| --- | ||
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.
What's the reason for this?
Uh oh!
There was an error while loading. Please reload this page.
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 pod writes the
/etc/kubernetes/cni/net.d/whereabouts.d/whereabouts.kubeconfigfile on the node. WithouthostNetwork: true, it fails with a permission error. Also, this pod should not rely on OVN-Kubernetes being ready.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.
How can the file access be dependent on this config?
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.
Pods with
hostNetwork: trueautomatically get the spc_t (super privileged container) SELinux type, which has broad access to host resources.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.
Setting
securityContext.seLinuxOptions:type: spc_tcan also resolve the permission issue. However, I don't think this pod should rely on OVN-Kubernetes.