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

Panic when using an azure object store with an invalid access key #4972

Closed
scsmithr opened this issue Oct 22, 2023 · 2 comments · Fixed by #4974
Closed

Panic when using an azure object store with an invalid access key #4972

scsmithr opened this issue Oct 22, 2023 · 2 comments · Fixed by #4974
Labels
bug object-store Object Store Interface

Comments

@scsmithr
Copy link
Contributor

Describe the bug

When using an azure object store configured with an invalid access key, attempting to use the store will result in a panic.

To Reproduce

Example:

use object_store::azure::MicrosoftAzureBuilder;
use object_store::{path::Path, ObjectStore};

#[tokio::main]
async fn main() {
    let store = MicrosoftAzureBuilder::new()
        .with_account("my_account")
        .with_container_name("my_container")
        .with_access_key("invalid")
        .build()
        .unwrap();

    let path = &Path::parse("/my_path").unwrap();
    let _res = store.get(&path).await;
}

Results in a panic during the get:

thread 'main' panicked at /Users/sean/.cargo/registry/src/index.crates.io-6f17d22bba15001f/object_store-0.7.1/src/azure/credential.rs:189:56:
called `Result::unwrap()` on an `Err` value: InvalidPadding

Expected behavior

No panic and instead an error gets returned.

The easy fix is to just propagate the error up from here:

/// Generate signed key for authorization via access keys
/// <https://docs.microsoft.com/en-us/rest/api/storageservices/authorize-with-shared-key>
fn generate_authorization(
h: &HeaderMap,
u: &Url,
method: &Method,
account: &str,
key: &str,
) -> String {
let str_to_sign = string_to_sign(h, u, method, account);
let auth = hmac_sha256(BASE64_STANDARD.decode(key).unwrap(), str_to_sign);
format!("SharedKey {}:{}", account, BASE64_STANDARD.encode(auth))
}

Additional context

Our use case is we configure object stores based on user provided values, and so a panic when provided with an invalid value is undesirable.

@scsmithr scsmithr added the bug label Oct 22, 2023
@tustvold
Copy link
Contributor

Agreed, we should probably check this on construction within the builder

@tustvold
Copy link
Contributor

tustvold commented Nov 2, 2023

label_issue.py automatically added labels {'object-store'} from #4974

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug object-store Object Store Interface
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants