Skip to content

feat: dump authorizationPolicy#1222

Merged
kmesh-bot merged 3 commits intokmesh-net:mainfrom
yp969803:issue#214
Feb 27, 2025
Merged

feat: dump authorizationPolicy#1222
kmesh-bot merged 3 commits intokmesh-net:mainfrom
yp969803:issue#214

Conversation

@yp969803
Copy link
Copy Markdown
Contributor

@yp969803 yp969803 commented Feb 5, 2025

What type of PR is this?
/kind enhancement

What this PR does / why we need it:
support authorizationPolicy dump

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

Special notes for your reviewer:

Does this PR introduce a user-facing change?:
No


@kmesh-bot kmesh-bot added the kind/enhancement New feature or request label Feb 5, 2025
@kmesh-bot
Copy link
Copy Markdown
Collaborator

Welcome @yp969803! It looks like this is your first PR to kmesh-net/kmesh 🎉

@yp969803
Copy link
Copy Markdown
Contributor Author

yp969803 commented Feb 5, 2025

@hzxuzhonghu @LiZhenCheng9527 can you review the PR

Namespace string `json:"namespace"`
Scope string `json:"scope"`
Action string `json:"action"`
Rules []string `json:"rules"`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

rules are complex structure, we can use the original definition

@@ -460,7 +459,7 @@ type WorkloadDump struct {
Workloads []*Workload
Services []*Service
// TODO: add authorization
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

remove the todo now

"kmesh.net/kmesh/api/v2/workloadapi/security"
)

type PolicyCache interface {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we do have a policyStore in pkg/auth/policy_store.go, can we share with it

@yp969803
Copy link
Copy Markdown
Contributor Author

yp969803 commented Feb 6, 2025

@hzxuzhonghu can you review i have done the changes !

Copy link
Copy Markdown
Member

@hzxuzhonghu hzxuzhonghu left a comment

Choose a reason for hiding this comment

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

Generally LG

Can you add ut tests for it

@yp969803
Copy link
Copy Markdown
Contributor Author

yp969803 commented Feb 7, 2025

@hzxuzhonghu added unit test

fakeWorkloadCache.AddOrUpdateWorkload(w1)
fakeServiceCache.AddOrUpdateService(svc)
fakeAuth := auth.NewRbac(fakeWorkloadCache)
fakeAuth.UpdatePolicy(policy)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

YOu still need to update the GoldenFile

@yp969803
Copy link
Copy Markdown
Contributor Author

@hzxuzhonghu updated the golden file, can u review !

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 21, 2025

Codecov Report

Attention: Patch coverage is 60.00000% with 10 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@114428f). Learn more about missing BASE report.
Report is 56 commits behind head on main.

Files with missing lines Patch % Lines
pkg/auth/policy_store.go 0.00% 8 Missing ⚠️
pkg/auth/rbac.go 0.00% 2 Missing ⚠️
Files with missing lines Coverage Δ
pkg/controller/workload/workload_processor.go 62.07% <ø> (ø)
pkg/nets/nets.go 23.93% <ø> (ø)
pkg/status/api.go 73.75% <100.00%> (ø)
pkg/status/status_server.go 28.35% <100.00%> (ø)
pkg/auth/rbac.go 79.51% <0.00%> (ø)
pkg/auth/policy_store.go 59.49% <0.00%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 114428f...726da17. Read the comment docs.

@hzxuzhonghu
Copy link
Copy Markdown
Member

/retest

@yp969803
Copy link
Copy Markdown
Contributor Author

yp969803 commented Feb 26, 2025

@hzxuzhonghu all tests have passed, it can be merged now !

@LiZhenCheng9527
Copy link
Copy Markdown
Contributor

You still have some commits are unsign-off. https://github.com/kmesh-net/kmesh/runs/37606226574
Please check it.

@hzxuzhonghu hzxuzhonghu requested review from Copilot and removed request for Copilot February 27, 2025 06:49
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR adds support for dumping authorization policies along with workloads and services in the status dump endpoint. Key changes include:

  • Introducing a new AuthorizationPolicy type and its conversion function in pkg/status/api.go.
  • Adding list functions in pkg/auth/policy_store.go and pkg/auth/rbac.go to retrieve the policies.
  • Updating tests and the status server to include the authorization policies in the workload dump.

Reviewed Changes

File Description
pkg/status/api.go Adds the AuthorizationPolicy struct and a corresponding conversion function.
pkg/auth/policy_store.go Adds a list() function for returning a copied list of all policies.
pkg/status/status_server_test.go Updates tests to validate dumping of authorization policies.
pkg/auth/rbac.go Adds PoliciesList to expose the policies from the policy store.
pkg/status/status_server.go Modifies the workload dump to include converted authorization policies.
pkg/controller/workload/workload_processor.go Minor change ensuring policy updates are properly propagated.

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

yp969803 and others added 2 commits February 27, 2025 13:20
Signed-off-by: Yash Patel <yp969803@gmail.com>
Signed-off-by: Zhonghu Xu <xuzhonghu@huawei.com>
Copy link
Copy Markdown
Member

@hzxuzhonghu hzxuzhonghu left a comment

Choose a reason for hiding this comment

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

/lgtm

Signed-off-by: Yash Patel <yp969803@gmail.com>
@yp969803
Copy link
Copy Markdown
Contributor Author

@LiZhenCheng9527 added signoff message

@hzxuzhonghu
Copy link
Copy Markdown
Member

/retest

@LiZhenCheng9527
Copy link
Copy Markdown
Contributor

/lgtm
/approve

@kmesh-bot
Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hzxuzhonghu, LiZhenCheng9527

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

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [LiZhenCheng9527,hzxuzhonghu]

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

@kmesh-bot kmesh-bot merged commit a97167d into kmesh-net:main Feb 27, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support dump workload and authorizationPolicy

5 participants