argoproj / argo-cd

Declarative Continuous Deployment for Kubernetes
https://argo-cd.readthedocs.io
Apache License 2.0
16.75k stars 5.08k forks source link

tree output with app selector permission denied #18714

Open Slevy35 opened 3 weeks ago

Slevy35 commented 3 weeks ago

Checklist:

Describe the bug

when specifying the output flag with the value tree i get permission denied error

To Reproduce

# works 
argocd app sync my-app --output tree

# not working 
argocd app sync -l app=my-app --output tree

Expected behavior

Screenshots

Version

argocd: v2.11.2+25f7504
  BuildDate: 2024-05-23T15:31:09Z
  GitCommit: 25f7504ecc198e7d7fdc055fdb83ae50eee5edd0
  GitTreeState: clean
  GoVersion: go1.22.3
  Compiler: gc
  Platform: darwin/arm64
argocd-server: v2.10.9+c071af8
  BuildDate: 2024-04-30T15:53:28Z
  GitCommit: c071af808170bfc39cbdf6b9be4d0212dd66db0c
  GitTreeState: clean
  GoVersion: go1.21.3
  Compiler: gc
  Platform: linux/amd64
  Kustomize Version: v5.2.1 2023-10-19T20:13:51Z
  Helm Version: v3.14.3+gf03cc04
  Kubectl Version: v0.26.11
  Jsonnet Version: v0.20.0

Logs

argocd-server-857d9cb6b7-cd8hl time="2024-06-18T11:40:43Z" level=warning msg="finished unary call with code PermissionDenied" error="rpc error: code = PermissionDenied desc = permission denied" grpc.code=PermissionDenied grpc.method=ResourceTree grpc.service=application.ApplicationService grpc.start_time="2024-06-18T11:40:43Z" grpc.time_ms=0.583 span.kind=server system=grpc
agaudreault commented 2 weeks ago

@Slevy35 Just to clarify, does argocd app sync -l app=my-app --output json works?

thecooldrop commented 2 weeks ago

In order to be able to reproduce this, could you provide the permissions which are assigned to the user with which you are trying to perform the action?

Edit: I would like to work on this issue.

thecooldrop commented 2 weeks ago

Issue can be reproduced on master. Following script can be used to reproduce the state:

kind create cluster && \
kubectl create namespace argocd && \
kubectl apply -f manifests/install.yaml -n argocd && \
kubectl config set-context --current --namespace=argocd;
sleep 60;

kubectl port-forward svc/argocd-server -n argocd 8080:80 > /dev/null 2>&1 &
pid=$!
trap '{
    # echo killing $pid
    kill $pid
}' EXIT

sleep 10;
ADMIN_PASSWORD=$(kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d; echo)
argocd login localhost:8080 --username admin --password $ADMIN_PASSWORD --insecure

argocd app create --app-namespace argocd \
--dest-namespace argocd \
--dest-server https://kubernetes.default.svc \
--label app=my-app \
--name exampleapp \
--repo https://github.com/argoproj/argocd-example-apps \
--path apps \
--insecure

argocd app sync -l app=my-app --output tree

The last command in script seems to execute the sync, and the created root application ends up being synced, but permission denied still gets displayed. Given that command is executed as admin, and admin should have all permissions (I assume), then this is definitely a bug.

Following output gets generated during execution of the script:

Deleting cluster "kind" ...
Deleted nodes: ["kind-control-plane"]
Creating cluster "kind" ...
 ✓ Ensuring node image (kindest/node:v1.29.2) đŸ–ŧ
 ✓ Preparing nodes đŸ“Ļ  
 ✓ Writing configuration 📜 
 ✓ Starting control-plane 🕹ī¸ 
 ✓ Installing CNI 🔌 
 ✓ Installing StorageClass 💾 
Set kubectl context to "kind-kind"
You can now use your cluster with:

kubectl cluster-info --context kind-kind

Have a nice day! 👋
namespace/argocd created
customresourcedefinition.apiextensions.k8s.io/applications.argoproj.io created
customresourcedefinition.apiextensions.k8s.io/applicationsets.argoproj.io created
customresourcedefinition.apiextensions.k8s.io/appprojects.argoproj.io created
serviceaccount/argocd-application-controller created
serviceaccount/argocd-applicationset-controller created
serviceaccount/argocd-dex-server created
serviceaccount/argocd-notifications-controller created
serviceaccount/argocd-redis created
serviceaccount/argocd-repo-server created
serviceaccount/argocd-server created
role.rbac.authorization.k8s.io/argocd-application-controller created
role.rbac.authorization.k8s.io/argocd-applicationset-controller created
role.rbac.authorization.k8s.io/argocd-dex-server created
role.rbac.authorization.k8s.io/argocd-notifications-controller created
role.rbac.authorization.k8s.io/argocd-redis created
role.rbac.authorization.k8s.io/argocd-server created
clusterrole.rbac.authorization.k8s.io/argocd-application-controller created
clusterrole.rbac.authorization.k8s.io/argocd-applicationset-controller created
clusterrole.rbac.authorization.k8s.io/argocd-server created
rolebinding.rbac.authorization.k8s.io/argocd-application-controller created
rolebinding.rbac.authorization.k8s.io/argocd-applicationset-controller created
rolebinding.rbac.authorization.k8s.io/argocd-dex-server created
rolebinding.rbac.authorization.k8s.io/argocd-notifications-controller created
rolebinding.rbac.authorization.k8s.io/argocd-redis created
rolebinding.rbac.authorization.k8s.io/argocd-server created
clusterrolebinding.rbac.authorization.k8s.io/argocd-application-controller created
clusterrolebinding.rbac.authorization.k8s.io/argocd-applicationset-controller created
clusterrolebinding.rbac.authorization.k8s.io/argocd-server created
configmap/argocd-cm created
configmap/argocd-cmd-params-cm created
configmap/argocd-gpg-keys-cm created
configmap/argocd-notifications-cm created
configmap/argocd-rbac-cm created
configmap/argocd-ssh-known-hosts-cm created
configmap/argocd-tls-certs-cm created
secret/argocd-notifications-secret created
secret/argocd-secret created
service/argocd-applicationset-controller created
service/argocd-dex-server created
service/argocd-metrics created
service/argocd-notifications-controller-metrics created
service/argocd-redis created
service/argocd-repo-server created
service/argocd-server created
service/argocd-server-metrics created
deployment.apps/argocd-applicationset-controller created
deployment.apps/argocd-dex-server created
deployment.apps/argocd-notifications-controller created
deployment.apps/argocd-redis created
deployment.apps/argocd-repo-server created
deployment.apps/argocd-server created
statefulset.apps/argocd-application-controller created
networkpolicy.networking.k8s.io/argocd-application-controller-network-policy created
networkpolicy.networking.k8s.io/argocd-applicationset-controller-network-policy created
networkpolicy.networking.k8s.io/argocd-dex-server-network-policy created
networkpolicy.networking.k8s.io/argocd-notifications-controller-network-policy created
networkpolicy.networking.k8s.io/argocd-redis-network-policy created
networkpolicy.networking.k8s.io/argocd-repo-server-network-policy created
networkpolicy.networking.k8s.io/argocd-server-network-policy created
Context "kind-kind" modified.
'admin:login' logged in successfully
Context 'localhost:8080' updated
application 'exampleapp' created
TIMESTAMP  GROUP        KIND   NAMESPACE                  NAME    STATUS   HEALTH        HOOK  MESSAGE
2024-06-24T21:14:04+02:00  argoproj.io  Application      argocd        helm-guestbook  OutOfSync  Missing              
2024-06-24T21:14:04+02:00  argoproj.io  Application      argocd            helm-hooks  OutOfSync  Missing              
2024-06-24T21:14:04+02:00  argoproj.io  Application      argocd   kustomize-guestbook  OutOfSync  Missing              
2024-06-24T21:14:04+02:00  argoproj.io  Application      argocd            sync-waves  OutOfSync  Missing              
2024-06-24T21:14:04+02:00                Namespace                     helm-guestbook  OutOfSync  Missing              
2024-06-24T21:14:04+02:00                Namespace                         helm-hooks  OutOfSync  Missing              
2024-06-24T21:14:04+02:00                Namespace                kustomize-guestbook  OutOfSync  Missing              
2024-06-24T21:14:04+02:00                Namespace                         sync-waves  OutOfSync  Missing              
2024-06-24T21:14:04+02:00          Namespace                    helm-guestbook    Synced  Missing              
2024-06-24T21:14:04+02:00          Namespace                        helm-hooks    Synced  Missing              
2024-06-24T21:14:04+02:00          Namespace               kustomize-guestbook    Synced  Missing              
2024-06-24T21:14:04+02:00          Namespace                        sync-waves    Synced  Missing              
2024-06-24T21:14:06+02:00          Namespace      argocd        helm-guestbook   Running   Synced              namespace/helm-guestbook created
2024-06-24T21:14:06+02:00          Namespace      argocd            sync-waves   Running   Synced              namespace/sync-waves created
2024-06-24T21:14:06+02:00          Namespace      argocd   kustomize-guestbook   Running   Synced              namespace/kustomize-guestbook created
2024-06-24T21:14:06+02:00          Namespace      argocd            helm-hooks   Running   Synced              namespace/helm-hooks created
2024-06-24T21:14:06+02:00                Namespace       argocd            sync-waves  Succeeded   Synced              namespace/sync-waves created
2024-06-24T21:14:06+02:00                Namespace       argocd   kustomize-guestbook  Succeeded   Synced              namespace/kustomize-guestbook created
2024-06-24T21:14:06+02:00                Namespace       argocd            helm-hooks  Succeeded   Synced              namespace/helm-hooks created
2024-06-24T21:14:06+02:00  argoproj.io  Application      argocd            helm-hooks  OutOfSync  Missing              application.argoproj.io/helm-hooks created
2024-06-24T21:14:06+02:00  argoproj.io  Application      argocd        helm-guestbook  OutOfSync  Missing              application.argoproj.io/helm-guestbook created
2024-06-24T21:14:06+02:00                Namespace       argocd        helm-guestbook  Succeeded   Synced              namespace/helm-guestbook created
2024-06-24T21:14:06+02:00  argoproj.io  Application      argocd            sync-waves  OutOfSync  Missing              application.argoproj.io/sync-waves created
2024-06-24T21:14:06+02:00  argoproj.io  Application      argocd   kustomize-guestbook  OutOfSync  Missing              application.argoproj.io/kustomize-guestbook created
2024-06-24T21:14:06+02:00  argoproj.io  Application      argocd            helm-hooks    Synced  Missing              application.argoproj.io/helm-hooks created
2024-06-24T21:14:06+02:00  argoproj.io  Application      argocd            sync-waves    Synced  Missing              application.argoproj.io/sync-waves created
2024-06-24T21:14:06+02:00  argoproj.io  Application      argocd        helm-guestbook    Synced  Missing              application.argoproj.io/helm-guestbook created
2024-06-24T21:14:06+02:00  argoproj.io  Application      argocd   kustomize-guestbook    Synced  Missing              application.argoproj.io/kustomize-guestbook created

Name:               argocd/exampleapp
Project:            default
Server:             https://kubernetes.default.svc
Namespace:          argocd
URL:                https://localhost:8080/applications/argocd/exampleapp
Repo:               https://github.com/argoproj/argocd-example-apps
Target:             
Path:               apps
SyncWindow:         Sync Allowed
Sync Policy:        <none>
Sync Status:        Synced to  (d7927a2)
Health Status:      Healthy

Operation:          Sync
Sync Revision:      d7927a27b4533926b7d86b5f249cd9ebe7625e90
Phase:              Succeeded
Start:              2024-06-24 21:14:04 +0200 CEST
Finished:           2024-06-24 21:14:06 +0200 CEST
Duration:           2s
Message:            successfully synced (all tasks run)
FATA[0003] rpc error: code = PermissionDenied desc = permission denied 

In UI the end state is:

image

Running argocd app sync exampleapp --output tree works without issue.

Further running argocd app sync -l app=my-app --output json (and any other non-tree output format) runs without issue, so this seems to be specific to handling of tree output format

thecooldrop commented 4 days ago

I am still on this, but work and lack of knowledge are getting in the way. I am chipping away at it though 😄

thecooldrop commented 2 days ago

Bug location found and fixed, I just need to implement the tests now.