Allow CORS requests in Secret Store API (#10584)
* allow CORS requests for Secret Store API (#10582) * secretstore CORS: fix error with unit tests * secretstore CORS: removed debug log * secretstore CORS: add missing response's header * secretstore CORS: switched to jsonrpc-server-utils for CORS validation
This commit is contained in:
committed by
Wei Tang
parent
c5fa7aab43
commit
4cc274e75f
@@ -623,6 +623,10 @@ usage! {
|
||||
"--no-secretstore-auto-migrate",
|
||||
"Do not run servers set change session automatically when servers set changes. This option has no effect when servers set is read from configuration file.",
|
||||
|
||||
ARG arg_secretstore_http_cors: (String) = "none", or |c: &Config| c.secretstore.as_ref()?.cors.as_ref().map(|vec| vec.join(",")),
|
||||
"--secretstore-http-cors=[URL]",
|
||||
"Specify CORS header for Secret Store HTTP API responses. Special options: \"all\", \"none\".",
|
||||
|
||||
ARG arg_secretstore_acl_contract: (Option<String>) = Some("registry".into()), or |c: &Config| c.secretstore.as_ref()?.acl_contract.clone(),
|
||||
"--secretstore-acl-contract=[SOURCE]",
|
||||
"Secret Store permissioning contract address source: none, registry (contract address is read from 'secretstore_acl_checker' entry in registry) or address.",
|
||||
@@ -1328,6 +1332,7 @@ struct SecretStore {
|
||||
http_interface: Option<String>,
|
||||
http_port: Option<u16>,
|
||||
path: Option<String>,
|
||||
cors: Option<Vec<String>>
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, Deserialize)]
|
||||
@@ -1854,6 +1859,7 @@ mod tests {
|
||||
arg_secretstore_http_interface: "local".into(),
|
||||
arg_secretstore_http_port: 8082u16,
|
||||
arg_secretstore_path: "$HOME/.parity/secretstore".into(),
|
||||
arg_secretstore_http_cors: "null".into(),
|
||||
|
||||
// IPFS
|
||||
flag_ipfs_api: false,
|
||||
@@ -2132,6 +2138,7 @@ mod tests {
|
||||
http_interface: None,
|
||||
http_port: Some(8082),
|
||||
path: None,
|
||||
cors: None,
|
||||
}),
|
||||
private_tx: None,
|
||||
ipfs: Some(Ipfs {
|
||||
|
||||
@@ -105,6 +105,7 @@ http_port = 8082
|
||||
interface = "local"
|
||||
port = 8083
|
||||
path = "$HOME/.parity/secretstore"
|
||||
cors = ["null"]
|
||||
|
||||
[ipfs]
|
||||
enable = false
|
||||
|
||||
@@ -638,6 +638,7 @@ impl Configuration {
|
||||
http_port: self.args.arg_ports_shift + self.args.arg_secretstore_http_port,
|
||||
data_path: self.directories().secretstore,
|
||||
admin_public: self.secretstore_admin_public()?,
|
||||
cors: self.secretstore_cors()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1058,6 +1059,10 @@ impl Configuration {
|
||||
self.interface(&self.args.arg_secretstore_http_interface)
|
||||
}
|
||||
|
||||
fn secretstore_cors(&self) -> Option<Vec<String>> {
|
||||
Self::cors(self.args.arg_secretstore_http_cors.as_ref())
|
||||
}
|
||||
|
||||
fn secretstore_self_secret(&self) -> Result<Option<NodeSecretKey>, String> {
|
||||
match self.args.arg_secretstore_secret {
|
||||
Some(ref s) if s.len() == 64 => Ok(Some(NodeSecretKey::Plain(s.parse()
|
||||
@@ -1969,4 +1974,19 @@ mod tests {
|
||||
_ => panic!("Should be Cmd::Run"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_parse_secretstore_cors() {
|
||||
// given
|
||||
|
||||
// when
|
||||
let conf0 = parse(&["parity"]);
|
||||
let conf1 = parse(&["parity", "--secretstore-http-cors", "*"]);
|
||||
let conf2 = parse(&["parity", "--secretstore-http-cors", "http://parity.io,http://something.io"]);
|
||||
|
||||
// then
|
||||
assert_eq!(conf0.secretstore_cors(), Some(vec![]));
|
||||
assert_eq!(conf1.secretstore_cors(), None);
|
||||
assert_eq!(conf2.secretstore_cors(), Some(vec!["http://parity.io".into(),"http://something.io".into()]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +84,8 @@ pub struct Configuration {
|
||||
pub data_path: String,
|
||||
/// Administrator public key.
|
||||
pub admin_public: Option<Public>,
|
||||
// Allowed CORS domains
|
||||
pub cors: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
/// Secret store dependencies
|
||||
@@ -195,6 +197,7 @@ mod server {
|
||||
admin_public: conf.admin_public,
|
||||
auto_migrate_enabled: conf.auto_migrate_enabled,
|
||||
},
|
||||
cors: conf.cors
|
||||
};
|
||||
|
||||
cconf.cluster_config.nodes.insert(self_secret.public().clone(), cconf.cluster_config.listener_address.clone());
|
||||
@@ -234,6 +237,7 @@ impl Default for Configuration {
|
||||
http_interface: "127.0.0.1".to_owned(),
|
||||
http_port: 8082,
|
||||
data_path: replace_home(&data_dir, "$BASE/secretstore"),
|
||||
cors: Some(vec![]),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user