-
Notifications
You must be signed in to change notification settings - Fork 136
support xdp auth in tailcall #985
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
Conversation
8a61e3f to
bc1cc07
Compare
Codecov ReportAttention: Patch coverage is
... and 2 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
|
/retest |
| uint32(constants.TailCallPolicyCheck), | ||
| uint32(xa.PolicyCheck.FD()), | ||
| ebpf.UpdateAny); err != nil { | ||
| return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case where only error is returned, is it possible to know if it is a policyCheck error or a ruleCheck error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add some more error info
|
/retest |
bpf/kmesh/workload/include/authz.h
Outdated
| __uint(key_size, sizeof(struct bpf_sock_tuple)); | ||
| __uint(value_size, sizeof(struct match_ctx)); | ||
| __uint(max_entries, 256); | ||
| } tailcall_info_map SEC(".maps"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest add kmesh prefix
Add __uint(map_flags, BPF_F_NO_PREALLOC);
Is 256 enough? I think we should greatly increase to support higher throughput if BPF_F_NO_PREALLOC set
bpf/kmesh/workload/include/authz.h
Outdated
|
|
||
| // Safely access policyId and check if the policy exists | ||
| if (bpf_probe_read_kernel(&policyId, sizeof(policyId), (void *)(policies->policyIds + res->policy_index)) != 0) { | ||
| BPF_LOG(ERR, AUTH, "Failed to read policyId, thrown it to user auth"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| BPF_LOG(ERR, AUTH, "Failed to read policyId, thrown it to user auth"); | |
| BPF_LOG(ERR, AUTH, "Failed to read policyId, throw it to user auth"); |
bpf/kmesh/workload/include/authz.h
Outdated
| if (bpf_probe_read_kernel(&policyId, sizeof(policyId), (void *)(policies->policyIds + res->policy_index)) != 0) { | ||
| BPF_LOG(ERR, AUTH, "Failed to read policyId, thrown it to user auth"); | ||
| if (bpf_map_delete_elem(&tailcall_info_map, &tuple_key) != 0) { | ||
| BPF_LOG(DEBUG, AUTH, "Failed to delete context from map"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| BPF_LOG(DEBUG, AUTH, "Failed to delete context from map"); | |
| BPF_LOG(DEBUG, AUTH, "Failed to delete tailcall context from map"); |
bpf/kmesh/workload/include/authz.h
Outdated
| return AUTH_DENY; | ||
| res = bpf_map_lookup_elem(&tailcall_info_map, &tuple_key); | ||
| if (!res) { | ||
| BPF_LOG(ERR, AUTH, "Failed to retrieve res from map"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please be more clear
| BPF_LOG(ERR, AUTH, "Failed to retrieve match_ctx from map"); | ||
| return XDP_PASS; | ||
| } | ||
| for (i = 0; i < MAX_MEMBER_NUM_PER_POLICY; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MAX_MEMBER_NUM_PER_POLICY does not only limit the policy numbers but also the rules number per policy, right?
bpf/kmesh/workload/xdp.c
Outdated
| int xdp_shutdown(struct xdp_md *ctx) | ||
| { | ||
| int ret = 0; | ||
| struct match_ctx res; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please rename
bpf/kmesh/workload/include/authz.h
Outdated
| return AUTH_ALLOW; | ||
| } else { | ||
| return AUTH_DENY; | ||
| res->policy_index++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we move the policy index check here?
if (res->policy_index < 0 || res->policy_index >= MAX_MEMBER_NUM_PER_POLICY) {
BPF_LOG(ERR, AUTH, "Policy index out of bounds");
return XDP_PASS;
}
bpf/kmesh/workload/include/authz.h
Outdated
| break; | ||
| } | ||
| rule = (Istio__Security__Rule *)kmesh_get_ptr_val((void *)*((__u64 *)rulesPtr + i)); | ||
| if (!res) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant check with line 342?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant check with line 342?
In xdp type eBPF program, the null pointer check may fail. An additional check is needed here, otherwise the verifier will report an error.
| static int construct_tuple_key(struct xdp_md *ctx, struct bpf_sock_tuple *tuple_info, struct xdp_info *info) | ||
| { | ||
| int ret = parser_xdp_info(ctx, info); | ||
| if (ret != PARSER_SUCC) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant check
f4e6c66 to
16dca7c
Compare
8e71cd8 to
2ff203f
Compare
|
/retest |
2ff203f to
637d38e
Compare
bpf/kmesh/workload/include/authz.h
Outdated
| if (bpf_map_delete_elem(&kmesh_tc_info_map, &tuple_key) != 0) { | ||
| BPF_LOG(DEBUG, AUTH, "Failed to delete tailcall context from map"); | ||
| } | ||
| bpf_tail_call(ctx, &xdp_tailcall_map, TAIL_CALL_AUTH_IN_USER_SPACE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code has multiple calls in the function, can it converge to one place?:
bpf_map_delete_elem(&kmesh_tc_info_map, &tuple_key)
bpf_tail_call(ctx, &xdp_tailcall_map, TAIL_CALL_AUTH_IN_USER_SPACE);
| } | ||
|
|
||
| static inline int match_check(Istio__Security__Match *match, struct xdp_info *info, struct bpf_sock_tuple *tuple_info) | ||
| static int match_check(Istio__Security__Match *match, struct xdp_info *info, struct bpf_sock_tuple *tuple_info) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove the inline here?
bpf/kmesh/workload/include/authz.h
Outdated
| __uint(value_size, sizeof(struct match_context)); | ||
| __uint(map_flags, BPF_F_NO_PREALLOC); | ||
| __uint(max_entries, MAP_SIZE_OF_AUTH_TAILCALL); | ||
| } kmesh_tc_info_map SEC(".maps"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| } kmesh_tc_info_map SEC(".maps"); | |
| } kmesh_tc_args SEC(".maps"); |
| uint32(constants.TailCallPolicyCheck), | ||
| uint32(xa.PolicyCheck.FD()), | ||
| ebpf.UpdateAny); err != nil { | ||
| return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add some more error info
bpf/kmesh/workload/xdp.c
Outdated
|
|
||
| static inline int match_workload_policy(struct xdp_info *info, struct bpf_sock_tuple *tuple_info) | ||
| SEC("xdp_auth") | ||
| int xdp_shutdown(struct xdp_md *ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| int xdp_shutdown(struct xdp_md *ctx) | |
| int xdp_authz(struct xdp_md *ctx) |
| } | ||
|
|
||
| static inline int match_workload_policy(struct xdp_info *info, struct bpf_sock_tuple *tuple_info) | ||
| SEC("xdp_auth") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| SEC("xdp_auth") | |
| SEC("xdp_authz") |
bpf/kmesh/workload/xdp.c
Outdated
| } | ||
| match_ctx.policies = policies; | ||
| match_ctx.policy_index = 0; | ||
| ret = bpf_map_update_elem(&kmesh_tc_info_map, &tuple_key, &match_ctx, BPF_ANY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we write a ctx to this map, and in the another place this ctx could be read , is it safe to access policies concurrently?
|
|
||
| static inline int | ||
| do_auth(Istio__Security__Authorization *policy, struct xdp_info *info, struct bpf_sock_tuple *tuple_info) | ||
| SEC("xdp_auth") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| SEC("xdp_auth") | |
| SEC("xdp_authz") |
|
A switch needs to be added to determine whether to enable link-level authentication or packet-based authentication. |
2acab18 to
68a44df
Compare
2d5c667 to
9380fa6
Compare
9380fa6 to
f558a42
Compare
669dd29 to
949a4af
Compare
|
It is painful for me to review such a big pr with round and round update/review. We should incrementallly update. Never force push |
bpf/include/common.h
Outdated
| struct { | ||
| __uint(type, BPF_MAP_TYPE_ARRAY); | ||
| __uint(max_entries, 1); | ||
| __uint(max_entries, 4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit https://github.com/kmesh-net/kmesh/pull/1015/files#diff-e531188f2d6f84d9df52b52c90eb506619ef6d6d6ec4169dd093fcc33531a3fbR66 we are changing to a config map
bpf/kmesh/workload/include/authz.h
Outdated
| return PARSER_SUCC; | ||
| } | ||
|
|
||
| static int matchDstPorts(Istio__Security__Match *match, struct xdp_info *info, struct bpf_sock_tuple *tuple_info) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be called match_dst_port
bpf/kmesh/workload/include/authz.h
Outdated
| __u32 i; | ||
|
|
||
| if (match->n_destination_ports == 0 && match->n_not_destination_ports == 0) { | ||
| BPF_LOG(DEBUG, AUTH, "No ports configured, matching by default"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log should be started with small cased word
bpf/kmesh/workload/include/authz.h
Outdated
| __u32 i; | ||
|
|
||
| if (rule->n_clauses == 0) { | ||
| BPF_LOG(ERR, AUTH, "rule has no clauses\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not an error, it is a valid case to have {}
| struct xdp_info info = {0}; | ||
| int ret; | ||
|
|
||
| if (construct_tuple_key(ctx, &tuple_key, &info) != PARSER_SUCC) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of parsing this everywhere, can we move the parsed res into kmesh_tc_args
| int ret; | ||
| int i; | ||
|
|
||
| if (construct_tuple_key(ctx, &tuple_key, &info) != PARSER_SUCC) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto if we add to the kmesh_tc_args, we will not need to parse again
bpf/kmesh/workload/xdp.c
Outdated
| return XDP_DROP; | ||
| } | ||
|
|
||
| static bool is_authz_enabled() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| static bool is_authz_enabled() | |
| static bool is_authz_offload_enabled() |
| if (bpf_map_update_elem(&map_of_auth, &tuple_key, &auth_result, BPF_ANY) != 0) { | ||
| BPF_LOG(ERR, AUTH, "Failed to update auth result in map_of_auth"); | ||
| } | ||
| return match_ctx->action == ISTIO__SECURITY__ACTION__DENY ? XDP_DROP : XDP_PASS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this logic is not correct. Say we have two authorizationPolicy set, wih the returned result, i think we may miss the second policy check
Signed-off-by: weli-l <1289113577@qq.com>
Signed-off-by: weli-l <1289113577@qq.com>
Signed-off-by: weli-l <1289113577@qq.com>
Signed-off-by: weli-l <1289113577@qq.com>
Signed-off-by: weli-l <1289113577@qq.com>
949a4af to
cc2168d
Compare
Signed-off-by: weli-l <1289113577@qq.com>
7851592 to
88af784
Compare
Signed-off-by: weli-l <1289113577@qq.com>
88af784 to
7161af5
Compare
Signed-off-by: weli-l <1289113577@qq.com>
hzxuzhonghu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hzxuzhonghu 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 |
What type of PR is this?
What this PR does / why we need it:
support xdp auth in tail call
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: