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

Use Cluster secret ref namespace in unified-auth-controller when generate ClusterRoleBinding #2516

Merged
merged 2 commits into from
Sep 17, 2022

Conversation

XiShanYongYe-Chang
Copy link
Member

Signed-off-by: changzhen changzhen5@huawei.com

What type of PR is this?

/kind bug

What this PR does / why we need it:

As talked in #2480 (comment) and #2495, we need to use cluster impersonate secret ref in unified-auth-controller when generating ClusterRoleBinding. As a result, we can access subCluster resources through the aggregate-apiserver when the cluster uses different namespaces to store secrets.

Which issue(s) this PR fixes:
Fixes #2495

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

karmada-controller-manager: use cluster secret ref namespace in unified-auth-controller when generate ClusterRoleBinding

@karmada-bot karmada-bot added the kind/bug Categorizes issue or PR as related to a bug. label Sep 15, 2022
@karmada-bot karmada-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 15, 2022
@XiShanYongYe-Chang
Copy link
Member Author

How to verify it?

  • Create a kind cluster and join it to the karmada:
# create a kind cluster named cz01
kind create cluster --name cz01 --kubeconfig /root/.kube/cz01.config --image kindest/node:v1.23.4
# rename kind context
kubectl config rename-context "kind-cz01" "cz01" --kubeconfig /root/.kube/cz01.config
# Kind cluster uses `127.0.0.1` as kube-apiserver endpoint by default, thus kind clusters can't reach each other.
# So we need to update endpoint with container IP.
container_ip=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' cz01-control-plane)
kubectl config set-cluster "kind-cz01" --server="https://${container_ip}:6443" --kubeconfig /root/.kube/cz01.config
# join cluster
karmadactl join cz01 --cluster-kubeconfig='/root/.kube/cz01.config' --cluster-namespace='cz01'
  • Create serviceaccount zhangsan and grant permission to it:
kubectl create sa zhangsan
kubectl apply -f - <<EOF
apiVersion: v1
kind: Secret
metadata:
  name: zhangsan
  annotations:
    kubernetes.io/service-account.name: zhangsan
type: kubernetes.io/service-account-token
EOF
kubectl apply -f zhangsan-rbac.yaml
unfold me to see the yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: cluster-proxy-clusterrole
rules:
- apiGroups:
  - 'cluster.karmada.io'
  resources:
  - clusters/proxy
  resourceNames:
  - member1
  - member2
  - cz01
  verbs:
  - '*'
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: cluster-proxy-clusterrolebinding
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-proxy-clusterrole
subjects:
- kind: ServiceAccount
  name: zhangsan
  namespace: default
- kind: Group
  name: "system:serviceaccounts"
- kind: Group
  name: "system:serviceaccounts:default"
  • execute the request, we can refer to here

@RainbowMango
Copy link
Member

Do we have an E2E test to cover this feature?

@XiShanYongYe-Chang
Copy link
Member Author

Do we have an E2E test to cover this feature?

Yes, but E2E didn't test this point.

…rate ClusterRoleBinding

Signed-off-by: changzhen <changzhen5@huawei.com>
@karmada-bot karmada-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 16, 2022
@XiShanYongYe-Chang
Copy link
Member Author

Add the related e2e test case.

Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@karmada-bot karmada-bot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Sep 16, 2022
@XiShanYongYe-Chang
Copy link
Member Author

/hold

@karmada-bot karmada-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 16, 2022
Signed-off-by: changzhen <changzhen5@huawei.com>
@karmada-bot karmada-bot removed the lgtm Indicates that a PR is ready to be merged. label Sep 16, 2022
@XiShanYongYe-Chang
Copy link
Member Author

/hold cancel

I update the e2e test to fix the occasional errors: namespace not found in member cluster.

@karmada-bot karmada-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 16, 2022
Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

/lgtm

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Sep 17, 2022
@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: RainbowMango

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

karmada-bot added a commit that referenced this pull request Sep 19, 2022
…k-of-#2516-upstream-release-1.3

Automated cherry pick of #2516: Use Cluster secret ref namespace in
karmada-bot added a commit that referenced this pull request Sep 19, 2022
…k-of-#2516-upstream-release-1.2

Automated cherry pick of #2516: Use Cluster secret ref namespace in
@RainbowMango
Copy link
Member

Do we need to pick this patch for release-1.1?

@XiShanYongYe-Chang
Copy link
Member Author

Do we need to pick this patch for release-1.1?

I have cherry-picked to release-1.1, need to wait for the ci pass.

@XiShanYongYe-Chang XiShanYongYe-Chang deleted the fix-2495 branch September 19, 2022 08:56
karmada-bot added a commit that referenced this pull request Sep 20, 2022
…k-of-#2516-upstream-release-1.1

Automated cherry pick of #2516: Use Cluster secret ref namespace in
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use Cluster secret ref namespace in unified-auth-controller when generate ClusterRoleBinding
3 participants