mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-18 00:34:11 +00:00
fix: redact credential table options in user-visible output (#10346)
information_schema.tables.create_options (and SHOW TABLE STATUS) printed object store credentials of external tables verbatim, and SHOW CREATE TABLE masked only access_key_id and secret_access_key. Mask all four credential keys in both paths, and sort extra options in create_options by key. Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
This commit is contained in:
@@ -19,11 +19,10 @@ use common_base::secrets::{ExposeSecret, ExposeSecretMut, SecretString};
|
||||
use either::Either;
|
||||
use serde::Serialize;
|
||||
use sqlparser::ast::{Visit, VisitMut, Visitor, VisitorMut};
|
||||
use table::requests::{REDACTED_OPTION_VALUE, is_credential_option};
|
||||
|
||||
use crate::util::OptionValue;
|
||||
|
||||
const REDACTED_OPTIONS: [&str; 2] = ["access_key_id", "secret_access_key"];
|
||||
|
||||
/// Options hashmap.
|
||||
#[derive(Clone, Debug, Default, Serialize)]
|
||||
pub struct OptionMap {
|
||||
@@ -36,7 +35,7 @@ impl OptionMap {
|
||||
pub fn new<I: IntoIterator<Item = (String, OptionValue)>>(options: I) -> Self {
|
||||
let (secrets, options): (Vec<_>, Vec<_>) = options
|
||||
.into_iter()
|
||||
.partition(|(k, _)| REDACTED_OPTIONS.contains(&k.as_str()));
|
||||
.partition(|(k, _)| is_credential_option(k));
|
||||
Self {
|
||||
options: options.into_iter().collect(),
|
||||
secrets: secrets
|
||||
@@ -62,7 +61,7 @@ impl OptionMap {
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, k: String, v: String) {
|
||||
if REDACTED_OPTIONS.contains(&k.as_str()) {
|
||||
if is_credential_option(&k) {
|
||||
self.secrets.insert(k, SecretString::new(Box::new(v)));
|
||||
} else {
|
||||
self.options.insert(k, v.into());
|
||||
@@ -70,7 +69,7 @@ impl OptionMap {
|
||||
}
|
||||
|
||||
pub fn insert_options(&mut self, key: &str, value: OptionValue) {
|
||||
if REDACTED_OPTIONS.contains(&key) {
|
||||
if is_credential_option(key) {
|
||||
self.secrets.insert(
|
||||
key.to_string(),
|
||||
SecretString::new(Box::new(value.to_string())),
|
||||
@@ -173,7 +172,7 @@ impl OptionMap {
|
||||
value: Either::Right(if complete {
|
||||
value.expose_secret()
|
||||
} else {
|
||||
"******"
|
||||
REDACTED_OPTION_VALUE
|
||||
}),
|
||||
});
|
||||
options.chain(secrets)
|
||||
@@ -187,7 +186,7 @@ impl OptionMap {
|
||||
let secrets = self
|
||||
.secrets
|
||||
.keys()
|
||||
.map(|k| (k.as_str(), Either::Right("******")));
|
||||
.map(|k| (k.as_str(), Either::Right(REDACTED_OPTION_VALUE)));
|
||||
std::iter::chain(options, secrets)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user