-
Notifications
You must be signed in to change notification settings - Fork 478
storage: Deny localhost/private-ips in storage connections #26186
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
87073a4
storage: Deny localhost/private-ips in source/sink connections
rjobanp 07049d6
Fix other error checks to use dns error response; properly report err…
rjobanp 108e666
Provide all resolved IPs to mysql, postgres, and ssh clients
rjobanp 789c8d1
Cargo vet certifications
rjobanp a6e4449
Revert kafka client changes until rdkafka can be updated
rjobanp 0bc46ea
Use a BtreeSet to ensure consistent matching for ssh tunnel connections
rjobanp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,6 +187,26 @@ who = "Gus Wynn <[email protected]>" | |
criteria = "maintained-and-necessary" | ||
version = "4.2.0" | ||
|
||
[[audits.postgres]] | ||
who = "Roshan Jobanputra <[email protected]>" | ||
criteria = "safe-to-deploy" | ||
version = "0.19.5@git:91522e47643ebb6d6a5e392957b2319e5bb522ad" | ||
|
||
[[audits.postgres-openssl]] | ||
who = "Roshan Jobanputra <[email protected]>" | ||
criteria = "safe-to-deploy" | ||
version = "0.5.0@git:91522e47643ebb6d6a5e392957b2319e5bb522ad" | ||
|
||
[[audits.postgres-protocol]] | ||
who = "Roshan Jobanputra <[email protected]>" | ||
criteria = "safe-to-deploy" | ||
version = "0.6.5@git:91522e47643ebb6d6a5e392957b2319e5bb522ad" | ||
|
||
[[audits.postgres-types]] | ||
who = "Roshan Jobanputra <[email protected]>" | ||
criteria = "safe-to-deploy" | ||
version = "0.2.5@git:91522e47643ebb6d6a5e392957b2319e5bb522ad" | ||
|
||
[[audits.quanta]] | ||
who = "Roshan Jobanputra <[email protected]>" | ||
criteria = "safe-to-deploy" | ||
|
@@ -292,6 +312,11 @@ who = "Moritz Hoffmann <[email protected]>" | |
criteria = "safe-to-deploy" | ||
version = "0.12.0@git:46b28dc48bf5ed26dc0a0d5dbbd53c7964526f27" | ||
|
||
[[audits.tokio-postgres]] | ||
who = "Roshan Jobanputra <[email protected]>" | ||
criteria = "safe-to-deploy" | ||
version = "0.7.8@git:91522e47643ebb6d6a5e392957b2319e5bb522ad" | ||
|
||
[[audits.tracing-capture]] | ||
who = "Matt Jibson <[email protected]>" | ||
criteria = "safe-to-deploy" | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright Materialize, Inc. and contributors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License in the LICENSE file at the | ||
// root of this repository, or online at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::collections::BTreeSet; | ||
use std::io; | ||
use std::net::IpAddr; | ||
|
||
use tokio::net::lookup_host; | ||
|
||
const DUMMY_PORT: u16 = 11111; | ||
|
||
/// Resolves a host address and ensures it is a global address when `enforce_global` is set. | ||
/// This parameter is useful when connecting to user-defined unverified addresses. | ||
pub async fn resolve_address( | ||
mut host: &str, | ||
enforce_global: bool, | ||
) -> Result<BTreeSet<IpAddr>, io::Error> { | ||
// `net::lookup_host` requires a port to be specified, but we don't care about the port. | ||
let mut port = DUMMY_PORT; | ||
// If a port is already specified, use it and remove it from the host. | ||
if let Some(idx) = host.find(':') { | ||
if let Ok(p) = host[idx + 1..].parse() { | ||
port = p; | ||
host = &host[..idx]; | ||
} | ||
} | ||
|
||
let mut addrs = lookup_host((host, port)).await?; | ||
let mut ips = BTreeSet::new(); | ||
while let Some(addr) = addrs.next() { | ||
let ip = addr.ip(); | ||
if enforce_global && !is_global(ip) { | ||
Err(io::Error::new( | ||
io::ErrorKind::AddrNotAvailable, | ||
"address is not global", | ||
))? | ||
} else { | ||
ips.insert(ip); | ||
} | ||
} | ||
|
||
if ips.len() == 0 { | ||
Err(io::Error::new( | ||
io::ErrorKind::AddrNotAvailable, | ||
"no addresses found", | ||
))? | ||
} | ||
Ok(ips) | ||
} | ||
|
||
fn is_global(addr: IpAddr) -> bool { | ||
// TODO: Switch to `addr.is_global()` once stable: https://github.com/rust-lang/rust/issues/27709 | ||
match addr { | ||
IpAddr::V4(ip) => { | ||
!(ip.is_unspecified() || ip.is_private() || ip.is_loopback() || ip.is_link_local()) | ||
} | ||
IpAddr::V6(ip) => !(ip.is_loopback() || ip.is_unspecified()), | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
These ones seem to cover more cases, so probably worth making a tracking issue in our repo for this! (actually let me know if you want help on the process of trying to push these through stabilization!)
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.
good call - made a tracking issue https://github.com/MaterializeInc/materialize/issues/26649