10000 Support providing a fixed public host key for SFTP uploads by antoninbas · Pull Request #6848 · antrea-io/antrea · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Support providing a fixed public host key for SFTP uploads #6848

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

antoninbas
Copy link
Contributor

The SupportBundleCollection and PacketCapture CRDs can upload data to a user-provided SFTP server. Until now, there was no way for users to provide a verification mechanism for the host key from the server. Antrea would accept any host key when uploading the files, which is considered insecure. As a matter of fact, the usage of ssh.InsecureIgnoreHostKey as the verification callback was flagged in the code by security tools. And while there was a comment in the code explaining that "users can specify their own checks if needed", this is not accurate, as users have no way to provide a verification callback without changing the code manually.

We are therefore introducing a new field for both the SupportBundleCollection and PacketCapture CRDs, so that users can provide a fixed host public key (as a base64-encoded string), which will be the only key accepted by Antrea for SFTP upload. This seems like a good start, and in the future we may expand that support so that users can provide a "known_hosts" OpenSSH file, either as a ConfigMap or Secret.

@antoninbas antoninbas added action/release-note Indicates a PR that should be included in release notes. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API. labels Dec 6, 2024
@antoninbas antoninbas requested review from hangyan and tnqn December 6, 2024 22:32
@@ -401,6 +402,12 @@ func (c *Controller) createInternalSupportBundleCollection(bundle *v1alpha1.Supp
Password: authentication.BasicAuthentication.Password,
}
}
// Validate the format of the public key here, to catch invalid keys early.
if bundle.Spec.FileServer.HostPublicKey != nil {
Copy link
Member

Choose a reason for hiding this comment

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

this reminds me we do also have a validate function. maybe that part need updates too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, thanks for pointing this out

Copy link
Member
@hangyan hangyan Dec 10, 2024

Choose a reason for hiding this comment

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

well i was trying to say PacketCapture also have a validate function in the controller.. but glad this also applied to supportbundle

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For packetcapture, I don't think we need to add extra validation for now (I wouldn't add a validation webhook just for that, but maybe others will disagree?). If the provided key is invalid, the upload will fail, just like it would fail if authentication data was missing or incorrect.

Copy link
Member

Choose a reason for hiding this comment

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

i mean we already have a validatePacketCapture function to check protocol before, we can simply add this check here.

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.

It seems hostPublicKey doesn't take effect in SupportBundleCollection yet.

@@ -560,6 +560,9 @@ type BundleFileServer struct {
// The URL of the bundle file server. It is set with format: scheme://host[:port][/path],
// e.g, https://api.example.com:8443/v1/supportbundles/. If scheme is not set, https is used by default.
URL string
// HostPublicKey specifies the only host public key that will be accepted when connecting to
// the file server. If omitted, any host key will be accepted, which is not recommended.
HostPublicKey []byte
Copy link
Member

Choose a reason for hiding this comment

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

I don't find this field being set. The conversion function should also be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be set when we copy the FileServer struct (https://github.com/antoninbas/antrea/blob/2043606f83e65bed9d20e0075e50fa8fed436726/pkg/controller/supportbundlecollection/controller.go#L554), unless I am misunderstanding your question.
I forgot to run code generation, but it is done now and the conversion function should have been updated (I don't think we have a manual one?).

Copy link
Member

Choose a reason for hiding this comment

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

That code only sets the "internal" type, which will be converted into the "unversioned" API type in

out.FileServer = controlplane.BundleFileServer{
URL: in.FileServer.URL,
}

The missing part is in the conversion between the internal type and the unversioned API type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I added the missing code. I think I asked in the past, but I don't remember why we need 2 separate types here (unversioned API type and internal storage type)?

Copy link
Member

Choose a reason for hiding this comment

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

When we implemented NetworkPolicy, we introduced the internal storage type to address the performance issue that it can't efficiently figure out whether a resource should be sent to a Node, and the pod members that should be sent to a Node, see

type AppliedToGroup struct {

I guess SupportBundleCollection followed it for determining whether a resource should be sent to a Node. The unversioned type doesn't have a field to indicate that.

@antoninbas antoninbas force-pushed the support-providing-a-fixed-public-host-key-for-sftp-uploads branch 2 times, most recently from e182a5d to 2043606 Compare December 9, 2024 21:42
@antoninbas
Copy link
Contributor Author

I intend to have an e2e test for SupportBundleCollection, but I plan on doing it in a follow-up PR as this one is big enough already. There is some refactoring needed so we can share the SFTP server code between the SupportBundleCollection and PacketCapture e2e tests (not the case currently).

@antoninbas antoninbas force-pushed the support-providing-a-fixed-public-host-key-for-sftp-uploads branch from 2043606 to 0ca6053 Compare December 10, 2024 02:27
@antoninbas
Copy link
Contributor Author

/test-all

@antoninbas antoninbas force-pushed the support-providing-a-fixed-public-host-key-for-sftp-uploads branch from 0ca6053 to 85759a7 Compare December 10, 2024 02:49
@antoninbas antoninbas force-pushed the support-providing-a-fixed-public-host-key-for-sftp-uploads branch from 85759a7 to e4d97fd Compare December 10, 2024 05:43
The SupportBundleCollection and PacketCapture CRDs can upload data to a
user-provided SFTP server. Until now, there was no way for users to
provide a verification mechanism for the host key from the
server. Antrea would accept any host key when uploading the files, which
is considered insecure. As a matter of fact, the usage of
ssh.InsecureIgnoreHostKey as the verification callback was flagged in
the code by security tools. And while there was a comment in the code
explaining that "users can specify their own checks if needed", this is
not accurate, as users have no way to provide a verification callback
without changing the code manually.

We are therefore introducing a new field for both the
SupportBundleCollection and PacketCapture CRDs, so that users can
provide a fixed host public key (as a base64-encoded string), which will
be the only key accepted by Antrea for SFTP upload. This seems like a
good start, and in the future we may expand that support so that users
can provide a "known_hosts" OpenSSH file, either as a ConfigMap or
Secret.

Signed-off-by: Antonin Bas <antonin.bas@broadcom.com>
Signed-off-by: Antonin Bas <antonin.bas@broadcom.com>

Generate manifests

Signed-off-by: Antonin Bas <antonin.bas@broadcom.com>
Signed-off-by: Antonin Bas <antonin.bas@broadcom.com>
Signed-off-by: Antonin Bas <antonin.bas@broadcom.com>
@antoninbas antoninbas force-pushed the support-providing-a-fixed-public-host-key-for-sftp-uploads branch from e4d97fd to 6fcee11 Compare December 10, 2024 06:01
tnqn
tnqn previously approved these changes Dec 10, 2024
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

Signed-off-by: Antonin Bas <antonin.bas@broadcom.com>
@antoninbas antoninbas force-pushed the support-providing-a-fixed-public-host-key-for-sftp-uploads branch from 6fcee11 to 37b18af Compare December 10, 2024 06:19
@antoninbas
Copy link
Contributor Author

/test-all
/test-vm-e2e

@antoninbas
Copy link
Contributor Author

/test-vm-e2e

2 similar comments
@XinShuYang
Copy link
Contributor

/test-vm-e2e

@XinShuYang
Copy link
Contributor

/test-vm-e2e

@antoninbas antoninbas merged commit 521cd4b into antrea-io:main Dec 12, 2024
59 of 63 checks passed
@antoninbas antoninbas deleted the support-providing-a-fixed-public-host-key-for-sftp-uploads branch December 12, 2024 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/release-note Indicates a PR that should be included in release notes. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0