UiPath Documentation
automation-suite
2.2510
true
Guia de instalação do Automation Suite no Linux
Importante :
A tradução automática foi aplicada parcialmente neste conteúdo. A localização de um conteúdo recém-publicado pode levar de 1 a 2 semanas para ficar disponível.

Migreção manual do ArgoCD NetworkPolicy (GHSA-47m3-95c7-g2g8)

Soluções para acesso de rede não autenticado ao repositório do ArgoCD e Redis no Automation Suite, com um procedimento de mitigação manual do NetworkPolicy.

Description

Uma vulnerabilidade que afeta o componente ArgoCD repo-server foi publicada recentemente e não está corrigida pelo ArgoCD neste momento.

O ArgoCD repo-server (porta 8081) e o ArgoCD Redis são acessíveis a partir de qualquer pod na rede do cluster, porque nenhuma NetworkPolicy restringe o ingresso a esses componentes por padrão. Como resultado, qualquer pod dentro da rede de clusters pode conectar-se a eles diretamente, pois o ArgoCD não requer autenticação para esses componentes internos. Para obter detalhes, consulte GHSA-47m3-95c7-g2g8.

Para mitigar o problema, você deve aplicar manualmente a PolíticaDeRede descrita na seção Solução desta página.

Pré-requisitos

  • Execute este procedimento a partir de um host kubectl acesso ao cluster.
  • O procedimento assume o namespace argocd do Automation Suite. Se o ArgoCD usar um namespace diferente, defina ARGOCD_NS antes de executar o script.
  • Essa mitigação depende da aplicação da PolíticaDeRede do Kubernetes. Os clusters compatíveis com o Automation Suite usam uma configuração CNI (Container Network Interface) compatível.

Solução

  1. Execute o script a seguir. Ele detecta sua versão do ArgoCD e o modo do Redis (independente ou de alta disponibilidade, HA) e aplica a PolíticaDeRede correspondente automaticamente:

    export ARGOCD_NS="${ARGOCD_NS:-argocd}"
    export ARGOCD_RELEASE="$(kubectl -n "$ARGOCD_NS" get pod -l app.kubernetes.io/name=argocd-server -o jsonpath='{.items[0].metadata.labels.app\.kubernetes\.io/instance}')"
    
    test -n "$ARGOCD_RELEASE" || { echo "Cannot detect Argo CD Helm release"; exit 1; }
    
    if kubectl -n "$ARGOCD_NS" get pod -l "release=${ARGOCD_RELEASE},app=redis-ha-haproxy,component=haproxy" --no-headers 2>/dev/null | grep -q .; then
      REDIS_MODE=ha
    else
      REDIS_MODE=standalone
    fi
    
    echo "Argo CD namespace: $ARGOCD_NS"
    echo "Argo CD release: $ARGOCD_RELEASE"
    echo "Redis mode: $REDIS_MODE"
    
    cat <<EOF | kubectl apply -f -
    apiVersion: networking.k8s.io/v1
    kind: NetworkPolicy
    metadata:
      name: argocd-repo-server-manual-mitigation
      namespace: ${ARGOCD_NS}
    spec:
      podSelector:
        matchLabels:
          app.kubernetes.io/name: argocd-repo-server
          app.kubernetes.io/instance: ${ARGOCD_RELEASE}
      policyTypes:
        - Ingress
      ingress:
        - from:
            - podSelector:
                matchLabels:
                  app.kubernetes.io/name: argocd-server
                  app.kubernetes.io/instance: ${ARGOCD_RELEASE}
            - podSelector:
                matchLabels:
                  app.kubernetes.io/name: argocd-application-controller
                  app.kubernetes.io/instance: ${ARGOCD_RELEASE}
            - podSelector:
                matchLabels:
                  app.kubernetes.io/name: argocd-applicationset-controller
                  app.kubernetes.io/instance: ${ARGOCD_RELEASE}
            - podSelector:
                matchLabels:
                  app.kubernetes.io/name: argocd-notifications-controller
                  app.kubernetes.io/instance: ${ARGOCD_RELEASE}
          ports:
            - protocol: TCP
              port: 8081
        - from:
            - namespaceSelector: {}
          ports:
            - protocol: TCP
              port: 8084
    EOF
    
    if [ "$REDIS_MODE" = "ha" ]; then
      cat <<EOF | kubectl apply -f -
    apiVersion: networking.k8s.io/v1
    kind: NetworkPolicy
    metadata:
      name: argocd-redis-ha-server-manual-mitigation
      namespace: ${ARGOCD_NS}
    spec:
      podSelector:
        matchLabels:
          release: ${ARGOCD_RELEASE}
          app: redis-ha
      policyTypes:
        - Ingress
      ingress:
        - from:
            - podSelector:
                matchLabels:
                  release: ${ARGOCD_RELEASE}
                  app: redis-ha
            - podSelector:
                matchLabels:
                  release: ${ARGOCD_RELEASE}
                  app: redis-ha-haproxy
                  component: haproxy
          ports:
            - protocol: TCP
              port: 6379
            - protocol: TCP
              port: 26379
    ---
    apiVersion: networking.k8s.io/v1
    kind: NetworkPolicy
    metadata:
      name: argocd-redis-ha-haproxy-manual-mitigation
      namespace: ${ARGOCD_NS}
    spec:
      podSelector:
        matchLabels:
          release: ${ARGOCD_RELEASE}
          app: redis-ha-haproxy
          component: haproxy
          app.kubernetes.io/name: argocd-redis-ha-haproxy
      policyTypes:
        - Ingress
      ingress:
        - from:
            - podSelector:
                matchLabels:
                  app.kubernetes.io/name: argocd-server
                  app.kubernetes.io/instance: ${ARGOCD_RELEASE}
            - podSelector:
                matchLabels:
                  app.kubernetes.io/name: argocd-repo-server
                  app.kubernetes.io/instance: ${ARGOCD_RELEASE}
            - podSelector:
                matchLabels:
                  app.kubernetes.io/name: argocd-application-controller
                  app.kubernetes.io/instance: ${ARGOCD_RELEASE}
          ports:
            - protocol: TCP
              port: 6379
    EOF
    else
      cat <<EOF | kubectl apply -f -
    apiVersion: networking.k8s.io/v1
    kind: NetworkPolicy
    metadata:
      name: argocd-redis-manual-mitigation
      namespace: ${ARGOCD_NS}
    spec:
      podSelector:
        matchLabels:
          app.kubernetes.io/name: argocd-redis
          app.kubernetes.io/instance: ${ARGOCD_RELEASE}
      policyTypes:
        - Ingress
      ingress:
        - from:
            - podSelector:
                matchLabels:
                  app.kubernetes.io/name: argocd-server
                  app.kubernetes.io/instance: ${ARGOCD_RELEASE}
            - podSelector:
                matchLabels:
                  app.kubernetes.io/name: argocd-repo-server
                  app.kubernetes.io/instance: ${ARGOCD_RELEASE}
            - podSelector:
                matchLabels:
                  app.kubernetes.io/name: argocd-application-controller
                  app.kubernetes.io/instance: ${ARGOCD_RELEASE}
          ports:
            - protocol: TCP
              port: 6379
        - from:
            - namespaceSelector: {}
          ports:
            - protocol: TCP
              port: 9121
    EOF
    fi
    export ARGOCD_NS="${ARGOCD_NS:-argocd}"
    export ARGOCD_RELEASE="$(kubectl -n "$ARGOCD_NS" get pod -l app.kubernetes.io/name=argocd-server -o jsonpath='{.items[0].metadata.labels.app\.kubernetes\.io/instance}')"
    
    test -n "$ARGOCD_RELEASE" || { echo "Cannot detect Argo CD Helm release"; exit 1; }
    
    if kubectl -n "$ARGOCD_NS" get pod -l "release=${ARGOCD_RELEASE},app=redis-ha-haproxy,component=haproxy" --no-headers 2>/dev/null | grep -q .; then
      REDIS_MODE=ha
    else
      REDIS_MODE=standalone
    fi
    
    echo "Argo CD namespace: $ARGOCD_NS"
    echo "Argo CD release: $ARGOCD_RELEASE"
    echo "Redis mode: $REDIS_MODE"
    
    cat <<EOF | kubectl apply -f -
    apiVersion: networking.k8s.io/v1
    kind: NetworkPolicy
    metadata:
      name: argocd-repo-server-manual-mitigation
      namespace: ${ARGOCD_NS}
    spec:
      podSelector:
        matchLabels:
          app.kubernetes.io/name: argocd-repo-server
          app.kubernetes.io/instance: ${ARGOCD_RELEASE}
      policyTypes:
        - Ingress
      ingress:
        - from:
            - podSelector:
                matchLabels:
                  app.kubernetes.io/name: argocd-server
                  app.kubernetes.io/instance: ${ARGOCD_RELEASE}
            - podSelector:
                matchLabels:
                  app.kubernetes.io/name: argocd-application-controller
                  app.kubernetes.io/instance: ${ARGOCD_RELEASE}
            - podSelector:
                matchLabels:
                  app.kubernetes.io/name: argocd-applicationset-controller
                  app.kubernetes.io/instance: ${ARGOCD_RELEASE}
            - podSelector:
                matchLabels:
                  app.kubernetes.io/name: argocd-notifications-controller
                  app.kubernetes.io/instance: ${ARGOCD_RELEASE}
          ports:
            - protocol: TCP
              port: 8081
        - from:
            - namespaceSelector: {}
          ports:
            - protocol: TCP
              port: 8084
    EOF
    
    if [ "$REDIS_MODE" = "ha" ]; then
      cat <<EOF | kubectl apply -f -
    apiVersion: networking.k8s.io/v1
    kind: NetworkPolicy
    metadata:
      name: argocd-redis-ha-server-manual-mitigation
      namespace: ${ARGOCD_NS}
    spec:
      podSelector:
        matchLabels:
          release: ${ARGOCD_RELEASE}
          app: redis-ha
      policyTypes:
        - Ingress
      ingress:
        - from:
            - podSelector:
                matchLabels:
                  release: ${ARGOCD_RELEASE}
                  app: redis-ha
            - podSelector:
                matchLabels:
                  release: ${ARGOCD_RELEASE}
                  app: redis-ha-haproxy
                  component: haproxy
          ports:
            - protocol: TCP
              port: 6379
            - protocol: TCP
              port: 26379
    ---
    apiVersion: networking.k8s.io/v1
    kind: NetworkPolicy
    metadata:
      name: argocd-redis-ha-haproxy-manual-mitigation
      namespace: ${ARGOCD_NS}
    spec:
      podSelector:
        matchLabels:
          release: ${ARGOCD_RELEASE}
          app: redis-ha-haproxy
          component: haproxy
          app.kubernetes.io/name: argocd-redis-ha-haproxy
      policyTypes:
        - Ingress
      ingress:
        - from:
            - podSelector:
                matchLabels:
                  app.kubernetes.io/name: argocd-server
                  app.kubernetes.io/instance: ${ARGOCD_RELEASE}
            - podSelector:
                matchLabels:
                  app.kubernetes.io/name: argocd-repo-server
                  app.kubernetes.io/instance: ${ARGOCD_RELEASE}
            - podSelector:
                matchLabels:
                  app.kubernetes.io/name: argocd-application-controller
                  app.kubernetes.io/instance: ${ARGOCD_RELEASE}
          ports:
            - protocol: TCP
              port: 6379
    EOF
    else
      cat <<EOF | kubectl apply -f -
    apiVersion: networking.k8s.io/v1
    kind: NetworkPolicy
    metadata:
      name: argocd-redis-manual-mitigation
      namespace: ${ARGOCD_NS}
    spec:
      podSelector:
        matchLabels:
          app.kubernetes.io/name: argocd-redis
          app.kubernetes.io/instance: ${ARGOCD_RELEASE}
      policyTypes:
        - Ingress
      ingress:
        - from:
            - podSelector:
                matchLabels:
                  app.kubernetes.io/name: argocd-server
                  app.kubernetes.io/instance: ${ARGOCD_RELEASE}
            - podSelector:
                matchLabels:
                  app.kubernetes.io/name: argocd-repo-server
                  app.kubernetes.io/instance: ${ARGOCD_RELEASE}
            - podSelector:
                matchLabels:
                  app.kubernetes.io/name: argocd-application-controller
                  app.kubernetes.io/instance: ${ARGOCD_RELEASE}
          ports:
            - protocol: TCP
              port: 6379
        - from:
            - namespaceSelector: {}
          ports:
            - protocol: TCP
              port: 9121
    EOF
    fi
    

Verificar

Execute os seguintes comandos para confirmar que a mitigação foi aplicada com sucesso:

kubectl -n "$ARGOCD_NS" get networkpolicy
kubectl -n "$ARGOCD_NS" get pods
kubectl get applications.argoproj.io -A
kubectl -n "$ARGOCD_NS" get networkpolicy
kubectl -n "$ARGOCD_NS" get pods
kubectl get applications.argoproj.io -A

Confirme o seguinte:

  • argocd-repo-server-manual-mitigation existe.
  • Para o Redis HA, argocd-redis-ha-server-manual-mitigation e argocd-redis-ha-haproxy-manual-mitigation existem.
  • Para o Redis independente, argocd-redis-manual-mitigation existe.
  • Os pods do ArgoCD são Running ou Completed.
  • Os aplicativos ArgoCD permanecem Synced e Healthy.

Confirmar mitigação

Execute essas verificações após aplicar as políticas. Eles verificam se o tráfego do ArgoCD necessário ainda funciona e o tráfego não permitido está bloqueado.

  1. Execute o seguinte script:

    export ARGOCD_NS="${ARGOCD_NS:-argocd}"
    export ARGOCD_RELEASE="${ARGOCD_RELEASE:-$(kubectl -n "$ARGOCD_NS" get pod -l app.kubernetes.io/name=argocd-server -o jsonpath='{.items[0].metadata.labels.app\.kubernetes\.io/instance}')}"
    
    if kubectl -n "$ARGOCD_NS" get pod -l "release=${ARGOCD_RELEASE},app=redis-ha-haproxy,component=haproxy" --no-headers 2>/dev/null | grep -q .; then
      REDIS_MODE=ha
    else
      REDIS_MODE=standalone
    fi
    
    SERVER_POD="$(kubectl -n "$ARGOCD_NS" get pod -l app.kubernetes.io/name=argocd-server -o jsonpath='{.items[0].metadata.name}')"
    APPSET_POD="$(kubectl -n "$ARGOCD_NS" get pod -l app.kubernetes.io/name=argocd-applicationset-controller -o jsonpath='{.items[0].metadata.name}' 2>/dev/null || true)"
    FAILED_CHECKS=""
    
    tcp_check() {
      pod="$1"
      host="$2"
      port="$3"
      expected="$4"
      name="$5"
    
      code="$(kubectl -n "$ARGOCD_NS" exec "$pod" -- sh -c '
        host="$1"
        port="$2"
        if command -v nc >/dev/null 2>&1; then
          timeout 5 nc -z -w 3 "$host" "$port" >/dev/null 2>&1
          printf "%s\n" "$?"
        elif command -v bash >/dev/null 2>&1; then
          timeout 5 bash -c "</dev/tcp/${host}/${port}" >/dev/null 2>&1
          printf "%s\n" "$?"
        else
          printf "%s\n" "NO_TCP_TOOL"
        fi
      ' sh "$host" "$port" 2>/dev/null | tail -n 1)"
    
      if [ "$expected" = "allow" ] && [ "$code" = "0" ]; then
        return
      elif [ "$expected" = "deny" ] && [ "$code" != "0" ] && [ "$code" != "NO_TCP_TOOL" ] && [ -n "$code" ]; then
        return
      else
        FAILED_CHECKS="${FAILED_CHECKS}
    - ${name}: expected ${expected}, got exit code ${code}"
      fi
    }
    
    tcp_check "$SERVER_POD" argocd-repo-server 8081 allow "argocd-server to repo-server:8081"
    
    if [ "$REDIS_MODE" = "ha" ]; then
      HAPROXY_POD="$(kubectl -n "$ARGOCD_NS" get pod -l app=redis-ha-haproxy,component=haproxy -o jsonpath='{.items[0].metadata.name}')"
    
      tcp_check "$SERVER_POD" argocd-redis-ha-haproxy 6379 allow "argocd-server to redis-ha-haproxy:6379"
      tcp_check "$HAPROXY_POD" argocd-redis-ha 6379 allow "redis-ha-haproxy to redis-ha:6379"
      tcp_check "$HAPROXY_POD" argocd-repo-server 8081 deny "redis-ha-haproxy to repo-server:8081"
    
      if [ -n "$APPSET_POD" ]; then
        tcp_check "$APPSET_POD" argocd-redis-ha-haproxy 6379 deny "applicationset-controller to redis-ha-haproxy:6379"
      fi
    else
      REDIS_POD="$(kubectl -n "$ARGOCD_NS" get pod -l app.kubernetes.io/name=argocd-redis -o jsonpath='{.items[0].metadata.name}')"
    
      tcp_check "$SERVER_POD" argocd-redis 6379 allow "argocd-server to redis:6379"
      tcp_check "$REDIS_POD" argocd-repo-server 8081 deny "redis to repo-server:8081"
    
      if [ -n "$APPSET_POD" ]; then
        tcp_check "$APPSET_POD" argocd-redis 6379 deny "applicationset-controller to redis:6379"
      fi
    fi
    
    if [ -z "$FAILED_CHECKS" ]; then
      echo "MITIGATION CHECK: PASS"
    else
      echo "MITIGATION CHECK: FAIL"
      echo "$FAILED_CHECKS"
      exit 1
    fi
    export ARGOCD_NS="${ARGOCD_NS:-argocd}"
    export ARGOCD_RELEASE="${ARGOCD_RELEASE:-$(kubectl -n "$ARGOCD_NS" get pod -l app.kubernetes.io/name=argocd-server -o jsonpath='{.items[0].metadata.labels.app\.kubernetes\.io/instance}')}"
    
    if kubectl -n "$ARGOCD_NS" get pod -l "release=${ARGOCD_RELEASE},app=redis-ha-haproxy,component=haproxy" --no-headers 2>/dev/null | grep -q .; then
      REDIS_MODE=ha
    else
      REDIS_MODE=standalone
    fi
    
    SERVER_POD="$(kubectl -n "$ARGOCD_NS" get pod -l app.kubernetes.io/name=argocd-server -o jsonpath='{.items[0].metadata.name}')"
    APPSET_POD="$(kubectl -n "$ARGOCD_NS" get pod -l app.kubernetes.io/name=argocd-applicationset-controller -o jsonpath='{.items[0].metadata.name}' 2>/dev/null || true)"
    FAILED_CHECKS=""
    
    tcp_check() {
      pod="$1"
      host="$2"
      port="$3"
      expected="$4"
      name="$5"
    
      code="$(kubectl -n "$ARGOCD_NS" exec "$pod" -- sh -c '
        host="$1"
        port="$2"
        if command -v nc >/dev/null 2>&1; then
          timeout 5 nc -z -w 3 "$host" "$port" >/dev/null 2>&1
          printf "%s\n" "$?"
        elif command -v bash >/dev/null 2>&1; then
          timeout 5 bash -c "</dev/tcp/${host}/${port}" >/dev/null 2>&1
          printf "%s\n" "$?"
        else
          printf "%s\n" "NO_TCP_TOOL"
        fi
      ' sh "$host" "$port" 2>/dev/null | tail -n 1)"
    
      if [ "$expected" = "allow" ] && [ "$code" = "0" ]; then
        return
      elif [ "$expected" = "deny" ] && [ "$code" != "0" ] && [ "$code" != "NO_TCP_TOOL" ] && [ -n "$code" ]; then
        return
      else
        FAILED_CHECKS="${FAILED_CHECKS}
    - ${name}: expected ${expected}, got exit code ${code}"
      fi
    }
    
    tcp_check "$SERVER_POD" argocd-repo-server 8081 allow "argocd-server to repo-server:8081"
    
    if [ "$REDIS_MODE" = "ha" ]; then
      HAPROXY_POD="$(kubectl -n "$ARGOCD_NS" get pod -l app=redis-ha-haproxy,component=haproxy -o jsonpath='{.items[0].metadata.name}')"
    
      tcp_check "$SERVER_POD" argocd-redis-ha-haproxy 6379 allow "argocd-server to redis-ha-haproxy:6379"
      tcp_check "$HAPROXY_POD" argocd-redis-ha 6379 allow "redis-ha-haproxy to redis-ha:6379"
      tcp_check "$HAPROXY_POD" argocd-repo-server 8081 deny "redis-ha-haproxy to repo-server:8081"
    
      if [ -n "$APPSET_POD" ]; then
        tcp_check "$APPSET_POD" argocd-redis-ha-haproxy 6379 deny "applicationset-controller to redis-ha-haproxy:6379"
      fi
    else
      REDIS_POD="$(kubectl -n "$ARGOCD_NS" get pod -l app.kubernetes.io/name=argocd-redis -o jsonpath='{.items[0].metadata.name}')"
    
      tcp_check "$SERVER_POD" argocd-redis 6379 allow "argocd-server to redis:6379"
      tcp_check "$REDIS_POD" argocd-repo-server 8081 deny "redis to repo-server:8081"
    
      if [ -n "$APPSET_POD" ]; then
        tcp_check "$APPSET_POD" argocd-redis 6379 deny "applicationset-controller to redis:6379"
      fi
    fi
    
    if [ -z "$FAILED_CHECKS" ]; then
      echo "MITIGATION CHECK: PASS"
    else
      echo "MITIGATION CHECK: FAIL"
      echo "$FAILED_CHECKS"
      exit 1
    fi
    

    Resultado esperado: MITIGATION CHECK: PASS

Reverter

Se necessário, siga as seguintes etapas para remover a mitigação:

  1. Exclua as políticas de mitigação manuais:

    kubectl -n "$ARGOCD_NS" delete networkpolicy \
      argocd-repo-server-manual-mitigation \
      argocd-redis-manual-mitigation \
      argocd-redis-ha-server-manual-mitigation \
      argocd-redis-ha-haproxy-manual-mitigation \
      --ignore-not-found
    kubectl -n "$ARGOCD_NS" delete networkpolicy \
      argocd-repo-server-manual-mitigation \
      argocd-redis-manual-mitigation \
      argocd-redis-ha-server-manual-mitigation \
      argocd-redis-ha-haproxy-manual-mitigation \
      --ignore-not-found
    
  2. Confirme que a reversão foi concluída com sucesso:

    kubectl -n "$ARGOCD_NS" get networkpolicy
    kubectl -n "$ARGOCD_NS" get pods
    kubectl get applications.argoproj.io -A
    kubectl -n "$ARGOCD_NS" get networkpolicy
    kubectl -n "$ARGOCD_NS" get pods
    kubectl get applications.argoproj.io -A
    

    Confirme o seguinte:

    • As políticas de mitigação manual serão removidas.
    • Os pods ArgoCD permanecem Running ou Completed.
    • Os aplicativos ArgoCD permanecem Synced e Healthy.

Esta página foi útil?

Conectar

Precisa de ajuda? Suporte

Quer aprender? Academia UiPath

Tem perguntas? Fórum do UiPath

Fique por dentro das novidades