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

Authorization for trusted operations on production #62

Open
clangenb opened this issue Oct 27, 2023 · 0 comments
Open

Authorization for trusted operations on production #62

clangenb opened this issue Oct 27, 2023 · 0 comments

Comments

@clangenb
Copy link

clangenb commented Oct 27, 2023

Currently, anybody can submit a trusted operation and as long as it has a valid signature, it is accepted because we omit checking the signer field as can be seen here:

TrustedCall::pay_as_bid(_who, orders_string) => {

So for the trusted getters this is probably fine currently, as you need to know the actor ID to get your result (if this is an unacceptable privacy leak now, we have to derive a concept to map a trusted account to an actor ID and implement a lookup table in the trusted getter). But the pay-as-bid command needs to a privileged call, we don't want that anybody can execute this command. So this solve this, I suggest the following.

First you create your oli key with privileged rights. I suggest using https://crates.io/crates/subkey.

Then store the mnemonic somewhere safe, and hardcode the corresponding account id into the source code, analogous to what we have done for a demo here: https://github.com/integritee-network/worker/blob/46515c7dd1fb5875390f8c1a2c062120195e4dd3/core/parentchain/indirect-calls-executor/src/indirect_calls/transfer_to_alice_shields_funds.rs

Steps:

  1. With the mnemonic you get from subkey write some lines of rust code to print the corresponding byte array of the account id:
use sp_core::{sr25519, Pair};

// Don't ever commit the code containing the actual mnemonic. It would be safer to get this from some environment variable, but 
// as this is only a one time setup, I suggest that you are simply careful. :)
let oli_sudo_pair = sr25519::Pair::from_phrase("<mnemonic-from-subkey>", None).unwrap();
println!("{:?}", oli_sudo_pair.0.public().to_vec());
  1. Then hardcode the key into https://github.com/olisystems/BEST-Energy/blob/master/app-libs/stf/src/best_energy_helpers.rs and write some nice documentation ;).
/// Oli Sudo account id that has been obtained by
/// ```
/// use sp_core::{sr25519, Pair};
///
/// let oli_sudo = sr25519::Pair::from_phrase(<mnemonic-from-subkey>, None).unwrap();
/// println!("{:?}", oli_sudo.0.public().to_vec());
/// assert_eq!(OLI_SUDO, oli_sudo.0.public().into())
/// ```
pub const OLI_SUDO: AccountId = AccountId::new([<byte-array that has been printed above>]);

fn is_oli_sudo(account: &AccountId) -> bool {
     account_id == &OLI_SUDO
}
  1. Introduce an authentication check at
    TrustedCall::pay_as_bid(_who, orders_string) => {
TrustedCall::pay_as_bid(who, orders_string) => {
    ensure!(is_oli_sudo(&who), Self::Error::MissingPrivileges(who))
   //...
}

Then instead of executing the commands with ./integritee-cli pay-as-bid ... //Alice you have to use ./integritee-cli pay-as-bid ... <mnemonic>

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

No branches or pull requests

1 participant