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

[ExternalNode]Implement SupportBundleCollection on Agent #4338

Merged
merged 1 commit into from
Dec 7, 2022

Conversation

mengdie-song
Copy link
Contributor

Implement SupportBundleCollection on Agent

  1. Watch internal SupportBundleCollection events.
  2. Refactor SupportBundle compression to util.
  3. Let agent to collect SupportBundle for Node/ExternalNode.
  4. Upload the collected SupportBundle to file server.
    Only SFTP and basic authentication are supported for now.

Signed-off-by: Mengdie Song songm@vmware.com

@codecov
Copy link

codecov bot commented Oct 26, 2022

Codecov Report

Merging #4338 (eedf1a2) into main (e94e4cf) will decrease coverage by 1.72%.
The diff coverage is 6.05%.

❗ Current head eedf1a2 differs from pull request most recent head 2f60340. Consider uploading reports for the commit 2f60340 to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4338      +/-   ##
==========================================
- Coverage   65.53%   63.80%   -1.73%     
==========================================
  Files         400      402       +2     
  Lines       56950    57195     +245     
==========================================
- Hits        37321    36494     -827     
- Misses      16948    18007    +1059     
- Partials     2681     2694      +13     
Flag Coverage Δ *Carryforward flag
e2e-tests 38.05% <6.29%> (?)
integration-tests 34.62% <ø> (-0.03%) ⬇️ Carriedforward from 19a7de0
kind-e2e-tests 40.18% <0.00%> (-7.32%) ⬇️ Carriedforward from 19a7de0
unit-tests 49.78% <7.69%> (-0.50%) ⬇️ Carriedforward from 19a7de0

*This pull request uses carry forward flags. Click here to find out more.

Impacted Files Coverage Δ
cmd/antrea-agent/agent.go 0.00% <0.00%> (ø)
...pportbundlecollection/support_bundle_controller.go 0.00% <0.00%> (ø)
pkg/util/compress/compress.go 54.54% <54.54%> (ø)
...kg/apiserver/registry/system/supportbundle/rest.go 79.63% <100.00%> (+0.50%) ⬆️
pkg/agent/proxy/endpointslicecache.go 0.00% <0.00%> (-83.60%) ⬇️
pkg/agent/flowexporter/exporter/certificate.go 0.00% <0.00%> (-50.00%) ⬇️
...g/agent/controller/serviceexternalip/controller.go 35.83% <0.00%> (-45.74%) ⬇️
pkg/agent/cniserver/ipam/antrea_ipam.go 51.08% <0.00%> (-22.95%) ⬇️
...nt/apiserver/handlers/serviceexternalip/handler.go 29.62% <0.00%> (-22.23%) ⬇️
pkg/agent/ipassigner/responder/arp_responder.go 55.29% <0.00%> (-17.65%) ⬇️
... and 64 more

@lgtm-com
Copy link

lgtm-com bot commented Oct 26, 2022

This pull request introduces 1 alert when merging 300dbab into 2971e09 - view on LGTM.com

new alerts:

  • 1 for Use of insecure HostKeyCallback implementation

@mengdie-song mengdie-song force-pushed the vmbm-supportbundle-agentimpl branch 2 times, most recently from 6ad148a to c34d1a3 Compare October 26, 2022 08:22
@lgtm-com
Copy link

lgtm-com bot commented Oct 26, 2022

This pull request introduces 1 alert when merging c34d1a3 into 2971e09 - view on LGTM.com

new alerts:

  • 1 for Use of insecure HostKeyCallback implementation

@lgtm-com
Copy link

lgtm-com bot commented Oct 31, 2022

This pull request introduces 1 alert when merging e426eff into e7aba77 - view on LGTM.com

new alerts:

  • 1 for Use of insecure HostKeyCallback implementation

@mengdie-song mengdie-song changed the title [WIP]Implement SupportBundleCollection on Agent Implement SupportBundleCollection on Agent Nov 1, 2022
@mengdie-song mengdie-song changed the title Implement SupportBundleCollection on Agent [ExternalNode]Implement SupportBundleCollection on Agent Nov 2, 2022
@lgtm-com
Copy link

lgtm-com bot commented Nov 2, 2022

This pull request introduces 1 alert when merging 00f2e0f into e7aba77 - view on LGTM.com

new alerts:

  • 1 for Use of insecure HostKeyCallback implementation

if strings.ToLower(arr[0]) != "sftp" {
return fmt.Errorf("only sftp is supported for now, protocol %s is not supported", strings.ToLower(arr[0]))
}
url = fileServer.URL[7:]
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to calculate the index for url instead of hard-coded with 7 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about it. But the prefix length is fixed which is seven. If we use index, it would be like strings.Index(fileServer.URL, "://") + 3, which is not necessary in my mind.

@lgtm-com
Copy link

lgtm-com bot commented Nov 2, 2022

This pull request introduces 1 alert when merging 39f2c7c into e7aba77 - view on LGTM.com

new alerts:

  • 1 for Use of insecure HostKeyCallback implementation

@lgtm-com
Copy link

lgtm-com bot commented Nov 4, 2022

This pull request introduces 1 alert when merging 7ca6995 into 85e144c - view on LGTM.com

new alerts:

  • 1 for Use of insecure HostKeyCallback implementation

@lgtm-com
Copy link

lgtm-com bot commented Nov 8, 2022

This pull request introduces 1 alert when merging 5094000 into 339ed6f - view on LGTM.com

new alerts:

  • 1 for Use of insecure HostKeyCallback implementation

@lgtm-com
Copy link

lgtm-com bot commented Nov 8, 2022

This pull request introduces 1 alert when merging 345a488 into 339ed6f - view on LGTM.com

new alerts:

  • 1 for Use of insecure HostKeyCallback implementation

@mengdie-song
Copy link
Contributor Author

/test-all

@lgtm-com
Copy link

lgtm-com bot commented Nov 9, 2022

This pull request introduces 1 alert when merging c72beea into e516aca - view on LGTM.com

new alerts:

  • 1 for Use of insecure HostKeyCallback implementation

@lgtm-com
Copy link

lgtm-com bot commented Nov 10, 2022

This pull request introduces 1 alert when merging 9471a3c into e516aca - view on LGTM.com

new alerts:

  • 1 for Use of insecure HostKeyCallback implementation

@lgtm-com
Copy link

lgtm-com bot commented Nov 11, 2022

This pull request introduces 1 alert when merging 5803c73 into 5051f54 - view on LGTM.com

new alerts:

  • 1 for Use of insecure HostKeyCallback implementation

@mengdie-song
Copy link
Contributor Author

/test-all

@vicky-liu vicky-liu added this to the Antrea v1.10 release milestone Dec 2, 2022
@lgtm-com
Copy link

lgtm-com bot commented Dec 2, 2022

This pull request introduces 1 alert when merging ba22c7f into 19a7de0 - view on LGTM.com

new alerts:

  • 1 for Use of insecure HostKeyCallback implementation

Heads-up: LGTM.com's PR analysis will be disabled on the 5th of December, and LGTM.com will be shut down ⏻ completely on the 16th of December 2022. Please enable GitHub code scanning, which uses the same CodeQL engine ⚙️ that powers LGTM.com. For more information, please check out our post on the GitHub blog.

@lgtm-com
Copy link

lgtm-com bot commented Dec 2, 2022

This pull request introduces 1 alert when merging 0b07cfe into 19a7de0 - view on LGTM.com

new alerts:

  • 1 for Use of insecure HostKeyCallback implementation

Heads-up: LGTM.com's PR analysis will be disabled on the 5th of December, and LGTM.com will be shut down ⏻ completely on the 16th of December 2022. Please enable GitHub code scanning, which uses the same CodeQL engine ⚙️ that powers LGTM.com. For more information, please check out our post on the GitHub blog.


func (c *SupportBundleController) addSupportBundleCollection(supportBundle *cpv1b2.SupportBundleCollection) {
c.supportBundleCollectionsMutex.Lock()
defer c.supportBundleCollectionsMutex.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

Unlock the mutex after cosuming resource, no need to wait until it is added into queue?

c.supportBundleCollectionsMutex.Lock()
c.supportBundleCollection = supportBundle
c.supportBundleCollectionsMutex.Unlock()
c.queue.Add(supportBundle.Name)

Copy link
Contributor

Choose a reason for hiding this comment

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

updated

}

func (c *SupportBundleController) deleteSupportBundleCollection(supportBundle *cpv1b2.SupportBundleCollection) {
c.supportBundleCollectionsMutex.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor

Choose a reason for hiding this comment

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

updated

antreaClientGetter agent.AntreaClientProvider
queue workqueue.Interface
supportBundleCollection *cpv1b2.SupportBundleCollection
supportBundleCollectionsMutex sync.RWMutex
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
supportBundleCollectionsMutex sync.RWMutex
supportBundleCollectionMutex sync.RWMutex

Copy link
Contributor

Choose a reason for hiding this comment

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

updated

@luolanzone
Copy link
Contributor

@ceclinux Could you address the latest comments of this PR and move forward? thanks.

@lgtm-com
Copy link

lgtm-com bot commented Dec 6, 2022

This pull request introduces 1 alert when merging 1f5f0e4 into b0e9636 - view on LGTM.com

new alerts:

  • 1 for Use of insecure HostKeyCallback implementation

Heads-up: LGTM.com's PR analysis will be disabled on the 5th of December, and LGTM.com will be shut down ⏻ completely on the 16th of December 2022. Please enable GitHub code scanning, which uses the same CodeQL engine ⚙️ that powers LGTM.com. For more information, please check out our post on the GitHub blog.

@luolanzone luolanzone added this to the Antrea v1.10 release milestone Dec 6, 2022
Copy link
Member

@tnqn tnqn left a comment

Choose a reason for hiding this comment

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

LGTM, two minor comments

klog.Info("Started watch for SupportBundleCollections")
eventCount := 0
defer func() {
klog.InfoS("Stopped watch for SupportBundleCollections", "total items received", eventCount)
Copy link
Member

Choose a reason for hiding this comment

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

sturctured logging's keys shouldn't be space connected words, see https://github.com/tnqn/code-review-comments#use-structure-logging.
"totalItemsReceived"

Copy link
Contributor

Choose a reason for hiding this comment

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

updated

Comment on lines 26 to 28
obj, err := c.Fake.
Invokes(testing.NewUpdateSubresourceAction(supportbundlecollectionsResource, "status", "", status), &v1beta2.SupportBundleCollectionStatus{})

if obj == nil {
return nil
}
return err
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
obj, err := c.Fake.
Invokes(testing.NewUpdateSubresourceAction(supportbundlecollectionsResource, "status", "", status), &v1beta2.SupportBundleCollectionStatus{})
if obj == nil {
return nil
}
return err
_, err := c.Fake.
Invokes(testing.NewUpdateSubresourceAction(supportbundlecollectionsResource, "status", "", status), &v1beta2.SupportBundleCollectionStatus{})
return err

Copy link
Contributor

Choose a reason for hiding this comment

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

updated

return
}
options := metav1.ListOptions{
FieldSelector: fields.OneTermEqualSelector("nodeName", c.nodeName).String(),
Copy link
Contributor

@wenyingd wenyingd Dec 6, 2022

Choose a reason for hiding this comment

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

Use k8s.NamespacedName(c.namespace, c.nodeName) as the ListOption with the "ExternalNode" case, which is expected after this PR #4401 is merged. Otherwise, ExternalNode would use an incorrect value when controller calculates the span.

Copy link
Contributor

Choose a reason for hiding this comment

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

updated

@lgtm-com
Copy link

lgtm-com bot commented Dec 7, 2022

This pull request introduces 1 alert when merging 424a31b into e94e4cf - view on LGTM.com

new alerts:

  • 1 for Use of insecure HostKeyCallback implementation

Heads-up: LGTM.com's PR analysis will be disabled on the 5th of December, and LGTM.com will be shut down ⏻ completely on the 16th of December 2022. Please enable GitHub code scanning, which uses the same CodeQL engine ⚙️ that powers LGTM.com. For more information, please check out our post on the GitHub blog.

klog.ErrorS(err, "Failed to get antrea client")
return
}
options := metav1.ListOptions{
Copy link
Contributor

Choose a reason for hiding this comment

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

You check use namespace/name as filter key only with ExternalNode case by checking c.supportBundleNodeType == controlplane.SupportBundleCollectionNodeTypeExternalNode. But for K8s worker Node, c.nodeName is expected.

Copy link
Contributor

Choose a reason for hiding this comment

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

updated

1. Watch internal SupportBundleCollection events.
2. Refactor SupportBundle compression to util.
3. Let agent to collect SupportBundle for Node/ExternalNode.
4. Upload the collected SupportBundle to file server.
   Only SFTP and basic authentication are supported for now.

Signed-off-by: Mengdie Song <songm@vmware.com>
Co-authored-by: Ruochen Shen <src655@gmail.com>
Copy link
Contributor

@wenyingd wenyingd left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@tnqn tnqn left a comment

Choose a reason for hiding this comment

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

LGTM

@tnqn
Copy link
Member

tnqn commented Dec 7, 2022

/test-all

@lgtm-com
Copy link

lgtm-com bot commented Dec 7, 2022

This pull request introduces 1 alert when merging 2f60340 into e94e4cf - view on LGTM.com

new alerts:

  • 1 for Use of insecure HostKeyCallback implementation

Heads-up: LGTM.com's PR analysis will be disabled on the 5th of December, and LGTM.com will be shut down ⏻ completely on the 16th of December 2022. Please enable GitHub code scanning, which uses the same CodeQL engine ⚙️ that powers LGTM.com. For more information, please check out our post on the GitHub blog.

@tnqn tnqn merged commit 1c73bd1 into antrea-io:main Dec 7, 2022
cfg := &ssh.ClientConfig{
User: serverAuth.BasicAuthentication.Username,
Auth: []ssh.AuthMethod{ssh.Password(serverAuth.BasicAuthentication.Password)},
// #nosec G106: skip host key check here and users can specify their own checks if needed
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there might be some potential issues with the ssh ClientConfig

  1. The comment is not working to pass the security checker [ExternalNode]Implement SupportBundleCollection on Agent #4338 (comment).
  2. I am confused about the phrase "users specify their own checks if needed."
  3. Also, is the security vulnerability critical in this case? Is it possible that the supportbunble tarball can be captured by the attackers through this security vulnerability?

I might have missed some context. Appreciate it if you provide some comments. @tnqn @wenyingd @mengdie-song @jianjuns

Copy link
Contributor

@wenyingd wenyingd Dec 21, 2022

Choose a reason for hiding this comment

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

I think your question is about the ssh configuration option “HostKeyCallback: ssh.InsecureIgnoreHostKey()“. Our choice is to ignore the public key returned by the server because we do not perform check on the key in our implementation. A candidate security risk for a general SSH connection is the target SFTP server connected with the IP address is not the one who has a different public key from the one client used to connect to. But in support bundle collection scenario, the user should ensure the sftp server is valid and accessible from Node/ExternalNode when creating the CR, and Agent is not supposed to connect to an incorrect server using the url provided by user. So I don't think it may introduce security risk to Agent. In another word, even Agent perform actions to cache and validate the public key, nothing could perform in the next step when we found they are dismatched.

GraysonWu pushed a commit to GraysonWu/antrea that referenced this pull request Jan 27, 2023
)

1. Watch internal SupportBundleCollection events.
2. Refactor SupportBundle compression to util.
3. Let agent to collect SupportBundle for Node/ExternalNode.
4. Upload the collected SupportBundle to file server.
   Only SFTP and basic authentication are supported for now.

Signed-off-by: Mengdie Song <songm@vmware.com>
Co-authored-by: Ruochen Shen <src655@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants