Skip to content

kubectl debug: add netadmin profile #115712

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

Merged

Conversation

wedaly
Copy link
Member

@wedaly wedaly commented Feb 12, 2023

What type of PR is this?

/kind feature

What this PR does / why we need it:

Add the netadmin profile from KEP 1441
https://github.com/kubernetes/enhancements/tree/master/keps/sig-cli/1441-kubectl-debug#debugging-profiles

Which issue(s) this PR fixes:

xref kubernetes/kubectl#1108

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Added "netadmin" debugging profiles for kubectl debug.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

KEP 1441

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 12, 2023
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot
Copy link
Contributor

Hi @wedaly. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Feb 12, 2023
@k8s-ci-robot k8s-ci-robot added area/kubectl sig/cli Categorizes an issue or PR as relevant to SIG CLI. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Feb 12, 2023
@wedaly
Copy link
Member Author

wedaly commented Feb 12, 2023

/cc @verb @sding3

@k8s-ci-robot k8s-ci-robot requested a review from verb February 12, 2023 17:22
@k8s-ci-robot
Copy link
Contributor

@wedaly: GitHub didn't allow me to request PR reviews from the following users: sding3.

Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/cc @verb @sding3

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link
Contributor

@sding3 sding3 left a comment

Choose a reason for hiding this comment

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

Cross referencing the KEP, the profiles LGTM.

image

Left one nit on the placement of the allowNetadminCapability call.

return false
})
}

func addCapability(c *corev1.Container, capability corev1.Capability) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for factoring this out into its own function. 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

I'm wondering if we even need allowNetadminCapability() and allowProcessTracing(), or if we should just be using allowCapability(pod, containerName, capability) for both, but then I decided it's probably easier to make these decisions after all of the profiles have been added.

Comment on lines 199 to 208
switch style {
case node:
allowNetadminCapability(pod, containerName)
useHostNamespaces(pod)
setPrivileged(pod, containerName)

case podCopy:
allowNetadminCapability(pod, containerName)

case ephemeral:
allowNetadminCapability(pod, containerName)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like allowNetadminCapability is used in all three debugging styles, so we could shift it up to before the switch:

Suggested change
switch style {
case node:
allowNetadminCapability(pod, containerName)
useHostNamespaces(pod)
setPrivileged(pod, containerName)
case podCopy:
allowNetadminCapability(pod, containerName)
case ephemeral:
allowNetadminCapability(pod, containerName)
}
allowNetadminCapability(pod, containerName)
switch style {
case node:
useHostNamespaces(pod)
setPrivileged(pod, containerName)
case podCopy, ephemeral:
// no additional modifications needed
}

Copy link
Contributor

@verb verb left a comment

Choose a reason for hiding this comment

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

/lgtm
/ok-to-test

return false
})
}

func addCapability(c *corev1.Container, capability corev1.Capability) {
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

I'm wondering if we even need allowNetadminCapability() and allowProcessTracing(), or if we should just be using allowCapability(pod, containerName, capability) for both, but then I decided it's probably easier to make these decisions after all of the profiles have been added.

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 13, 2023
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 13, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 937ab9e471f94e9d7a93e463069952069146b6d3

@wedaly
Copy link
Member Author

wedaly commented Feb 13, 2023

/assign @soltysh

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 13, 2023
@k8s-ci-robot k8s-ci-robot requested a review from verb February 13, 2023 22:34
@k8s-ci-robot k8s-ci-robot added the do-not-merge/contains-merge-commits Indicates a PR which contains merge commits. label Feb 13, 2023
@wedaly wedaly force-pushed the kubectl-netadmin-debug-profile branch from 454c846 to f5095bf Compare February 13, 2023 22:40
@wedaly
Copy link
Member Author

wedaly commented Feb 13, 2023

Rebased to address merge conflict.

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/contains-merge-commits Indicates a PR which contains merge commits. label Feb 13, 2023
@verb
Copy link
Contributor

verb commented Feb 14, 2023

@ardaguclu Do you have time to review this for approval?

Copy link
Member

@ardaguclu ardaguclu left a comment

Choose a reason for hiding this comment

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

Thanks for the new profile. I left a few comments but they are not blocker for this PR and can be done in followup.

/approve

if c.SecurityContext == nil {
c.SecurityContext = &corev1.SecurityContext{}
}
c.SecurityContext.Privileged = pointer.BoolPtr(true)
Copy link
Member

Choose a reason for hiding this comment

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

nit: BoolPtr is deprecated, pointer.Bool is recommended.

Copy link
Member Author

Choose a reason for hiding this comment

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

followup PR: #115837

SecurityContext: &corev1.SecurityContext{
Privileged: pointer.BoolPtr(true),
Capabilities: &corev1.Capabilities{
Add: []corev1.Capability{"NET_ADMIN"},
Copy link
Member

Choose a reason for hiding this comment

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

nit: Could you please add a test case to cover that already existed capability in the container is also shown.

Copy link
Member Author

Choose a reason for hiding this comment

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

added in followup PR: #115839

@@ -294,6 +294,27 @@ func TestGenerateDebugContainer(t *testing.T) {
},
},
},
{
name: "netadmin profile",
Copy link
Member

Choose a reason for hiding this comment

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

nit: I think we need to add unit tests also in TestGenerateNodeDebugPod and TestGeneratePodCopyWithDebugContainer.

Copy link
Member Author

Choose a reason for hiding this comment

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

added in followup PR: #115839

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ardaguclu, sding3, verb, wedaly

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 16, 2023
@ardaguclu
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 16, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 300b30552472fc3748ffd52a2057f853d238a90e

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. area/kubectl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. 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.

6 participants