Skip to content
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

Add missing permission for impersonation #1651

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/ci-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
go mod download
- name: Run the operator locally
env:
ARGOCD_CLUSTER_CONFIG_NAMESPACES: argocd-e2e-cluster-config
ARGOCD_CLUSTER_CONFIG_NAMESPACES: argocd-e2e-cluster-config, argocd-test-impersonation
run: |
set -o pipefail
make install generate fmt vet
Expand Down
11 changes: 11 additions & 0 deletions controllers/argocd/policyrule.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ func policyRuleForApplicationController() []v1.PolicyRule {
"*",
},
},
{
APIGroups: []string{
"",
},
Resources: []string{
"serviceaccounts",
},
Verbs: []string{
"impersonate",
},
},
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: v1
kind: Namespace
metadata:
name: argocd-test-impersonation
---
apiVersion: argoproj.io/v1beta1
kind: ArgoCD
metadata:
name: argocd-test
namespace: argocd-test-impersonation
spec:
extraConfig:
application.sync.impersonation.enabled: "true"
server:
route:
enabled: true
status:
phase: Available
---
kind: ConfigMap
apiVersion: v1
metadata:
name: argocd-cm
namespace: argocd-test-impersonation
data:
application.sync.impersonation.enabled: 'true'
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Namespace
metadata:
name: argocd-test-impersonation
---
apiVersion: argoproj.io/v1beta1
kind: ArgoCD
metadata:
name: argocd-test
namespace: argocd-test-impersonation
spec:
extraConfig:
application.sync.impersonation.enabled: "true"
server:
route:
enabled: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
name: guestbook-proj
namespace: argocd-test-impersonation
spec:
clusterResourceWhitelist:
- group: '*'
kind: '*'
destinationServiceAccounts:
- defaultServiceAccount: guestbook-deployer
namespace: guestbook
server: 'https://kubernetes.default.svc'
destinations:
- namespace: guestbook
server: 'https://kubernetes.default.svc'
sourceRepos:
- 'https://github.com/argoproj/argocd-example-apps.git'
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
name: guestbook-proj
namespace: argocd-test-impersonation
spec:
clusterResourceWhitelist:
- group: '*'
kind: '*'
destinationServiceAccounts:
- defaultServiceAccount: guestbook-deployer
namespace: guestbook
server: 'https://kubernetes.default.svc'
destinations:
- namespace: guestbook
server: 'https://kubernetes.default.svc'
sourceRepos:
- 'https://github.com/argoproj/argocd-example-apps.git'
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v1
kind: Namespace
metadata:
name: guestbook
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: guestbook-deployer
namespace: guestbook
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: guestbook-deployer-rb
namespace: guestbook
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: guestbook-deployer
namespace: guestbook
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v1
kind: Namespace
metadata:
name: guestbook
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: guestbook-deployer
namespace: guestbook
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: guestbook-deployer-rb
namespace: guestbook
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: guestbook-deployer
namespace: guestbook
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: guestbook
namespace: argocd-test-impersonation
spec:
destination:
namespace: guestbook
server: 'https://kubernetes.default.svc'
project: guestbook-proj
source:
directory:
jsonnet: {}
recurse: true
path: guestbook
repoURL: 'https://github.com/argoproj/argocd-example-apps'
syncPolicy:
automated: {}
syncOptions:
- ServerSideApply=true
- CreateNamespace=true
status:
sync:
status: Synced
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: guestbook
namespace: argocd-test-impersonation
spec:
destination:
namespace: guestbook
server: 'https://kubernetes.default.svc'
project: guestbook-proj
source:
directory:
jsonnet: {}
recurse: true
path: guestbook
repoURL: 'https://github.com/argoproj/argocd-example-apps'
syncPolicy:
automated: {}
syncOptions:
- ServerSideApply=true
- CreateNamespace=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
name: guestbook-proj
namespace: argocd-test-impersonation
spec:
clusterResourceWhitelist:
- group: '*'
kind: '*'
destinationServiceAccounts:
- defaultServiceAccount: guestbook-deployer
namespace: guestbook
server: 'https://kubernetes.default.svc'
destinations:
- namespace: guestbook
server: 'https://kubernetes.default.svc'
- namespace: guestbook-dev
server: 'https://kubernetes.default.svc'
sourceRepos:
- 'https://github.com/argoproj/argocd-example-apps.git'
---
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: guestbook-dev
namespace: argocd-test-impersonation
spec:
destination:
namespace: guestbook-dev
server: 'https://kubernetes.default.svc'
project: guestbook-proj
source:
directory:
jsonnet: {}
recurse: true
path: guestbook
repoURL: 'https://github.com/argoproj/argocd-example-apps'
syncPolicy:
automated: {}
syncOptions:
- ServerSideApply=true
status:
health:
status: Missing
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
name: guestbook-proj
namespace: argocd-test-impersonation
spec:
clusterResourceWhitelist:
- group: '*'
kind: '*'
destinationServiceAccounts:
- defaultServiceAccount: guestbook-deployer
namespace: guestbook
server: 'https://kubernetes.default.svc'
destinations:
- namespace: guestbook
server: 'https://kubernetes.default.svc'
- namespace: guestbook-dev
server: 'https://kubernetes.default.svc'
sourceRepos:
- 'https://github.com/argoproj/argocd-example-apps.git'
---
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: guestbook-dev
namespace: argocd-test-impersonation
spec:
destination:
namespace: guestbook-dev
server: 'https://kubernetes.default.svc'
project: guestbook-proj
source:
directory:
jsonnet: {}
recurse: true
path: guestbook
repoURL: 'https://github.com/argoproj/argocd-example-apps'
syncPolicy:
automated: {}
syncOptions:
- ServerSideApply=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: guestbook-deployer
namespace: guestbook-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |
error_message=$(kubectl get app guestbook-dev -n argocd-test-impersonation -o jsonpath='{.status.operationState.message}')
expected_error="failed to find a matching service account to impersonate\: no matching service account found for destination server"

if echo "$error_message" | grep -q "$expected_error"; then
exit 0
else
exit 1
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
apiVersion: kuttl.dev/v1beta1
kind: TestStep
delete:
- apiVersion: argoproj.io/v1beta1
kind: ArgoCD
name: argocd-test
- apiVersion: v1
kind: Namespace
name: argocd-test-impersonation
- apiVersion: v1
kind: Namespace
name: guestbook
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @anandf, the current steps mentioned here do not work for a ns scoped instance. Could you please suggest the required modifications?

Even after adding the managed-by label, I see this error:

message: 'ComparisonError: Failed to load live state: Namespace "guestbook" for Deployment "guestbook-ui" is not managed'

Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of guestbook namespace, can you try using argocd-test-impersonation as the destination ns ? For a namespace scoped ArgoCD instance, you can deploy manifests only in the same ns as the RBAC permits only that by default. Otherwise, you have to create a ns guestbook and apply the managed-by label. You cannot test the CreateNamespace=true sync policy in that case.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: v1
kind: Namespace
metadata:
name: argocd-test-ns-scoped
---
apiVersion: argoproj.io/v1beta1
kind: ArgoCD
metadata:
name: argocd-test
namespace: argocd-test-ns-scoped
spec:
extraConfig:
application.sync.impersonation.enabled: "true"
server:
route:
enabled: true
status:
phase: Available
---
kind: ConfigMap
apiVersion: v1
metadata:
name: argocd-cm
namespace: argocd-test-ns-scoped
data:
application.sync.impersonation.enabled: 'true'
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Namespace
metadata:
name: argocd-test-ns-scoped
---
apiVersion: argoproj.io/v1beta1
kind: ArgoCD
metadata:
name: argocd-test
namespace: argocd-test-ns-scoped
spec:
extraConfig:
application.sync.impersonation.enabled: "true"
server:
route:
enabled: true
Loading