-
Notifications
You must be signed in to change notification settings - Fork 5
Add S3 blob storage with cashier billing to ic-gateway #193
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
Open
shilingwang
wants to merge
25
commits into
main
Choose a base branch
from
shiling/blob-storage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
608d9a6
add s3 connection with billing to ic-gateway
shilingwang f134ffe
remove the whoami part
shilingwang 9130d35
use cors middleware
shilingwang 0073d2c
move header constant to router
shilingwang 7e4873c
refactor storage/handlers.rs
shilingwang bb89666
refactor storage to be similar like ic
shilingwang 589733e
refactor to put all storage related code under routing/storage
shilingwang 049e553
address comments
shilingwang 0dfc412
change the new endpoint name with prefix of storage/v1
shilingwang 47ddf5d
remove the fake ingress to prevent production leak
shilingwang a0a65d3
remove unreachable second BUDGET_REFRESH_DELAY
shilingwang 0206638
use existing dns resolver
shilingwang eef096c
merge buckt config into bucket
shilingwang 24bc0ab
rename type into wire
shilingwang 31d5f30
use axum for typed header
shilingwang da44896
use ic-certificate instead of agent
shilingwang e500812
remove unnecessary enum
shilingwang ae53726
addressing comments
shilingwang a9b0a7d
add comments for IngressAuthImpl
shilingwang 47011eb
remove intelligent_teering probe but just use CLI
shilingwang 163ce6a
remove &self
shilingwang c538716
addressing comments
shilingwang 96acd36
make price_component safe
shilingwang 32a87ab
make download in parallel
shilingwang 77d80ea
let the certificate last only 30 minutes
shilingwang 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
Large diffs are not rendered by default.
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
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,113 @@ | ||
| use std::sync::Arc; | ||
|
|
||
| use candid::Principal; | ||
| use ic_bn_lib::ic_agent::{Agent, AgentError, Certificate, hash_tree::LookupResult}; | ||
| use tracing::warn; | ||
|
|
||
| use super::types::{OwnerEgressSignature, PutBlobTreeRequest, StorageGatewayAuthorization}; | ||
|
|
||
| #[derive(Debug)] | ||
| pub enum AuthError { | ||
| MissingAuth(String), | ||
| Forbidden(String), | ||
| } | ||
|
|
||
| impl std::fmt::Display for AuthError { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| match self { | ||
| Self::MissingAuth(m) => write!(f, "authentication required: {m}"), | ||
| Self::Forbidden(m) => write!(f, "forbidden: {m}"), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub trait IngressAuth: Send + Sync { | ||
|
shilingwang marked this conversation as resolved.
|
||
| fn check_put_blob(&self, request: &PutBlobTreeRequest) -> Result<(), AuthError>; | ||
| } | ||
|
|
||
| /// Stub that accepts everything. Used with `--fake-ingress-auth`. | ||
| #[derive(Default)] | ||
| pub struct IngressAuthStub; | ||
|
|
||
| impl IngressAuth for IngressAuthStub { | ||
| fn check_put_blob(&self, _request: &PutBlobTreeRequest) -> Result<(), AuthError> { Ok(()) } | ||
| } | ||
|
|
||
| /// Production implementation: verify IC egress certificate. | ||
| pub struct IngressAuthImpl { | ||
| agent: Arc<Agent>, | ||
|
shilingwang marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| impl IngressAuthImpl { | ||
| pub fn new(agent: Arc<Agent>) -> Self { Self { agent } } | ||
|
|
||
| fn parse_certificate(bytes: &[u8]) -> Result<Certificate, AuthError> { | ||
| serde_cbor::from_slice::<Certificate>(bytes).map_err(|e| { | ||
| AuthError::Forbidden(format!("failed to parse certificate: {e}")) | ||
| }) | ||
| } | ||
|
|
||
| fn verify_certificate( | ||
| &self, | ||
| cert: &Certificate, | ||
| canister: Principal, | ||
| ) -> Result<(), AuthError> { | ||
| match self.agent.verify(cert, canister) { | ||
| Ok(()) => Ok(()), | ||
| Err(AgentError::CertificateOutdated(_)) => { | ||
| warn!("Egress certificate is outdated (stale but valid signature)"); | ||
| Err(AuthError::Forbidden("certificate outdated".into())) | ||
| } | ||
| Err(e) => Err(AuthError::Forbidden(format!("certificate verification failed: {e}"))), | ||
| } | ||
| } | ||
|
|
||
| fn extract_payload(cert: &Certificate) -> Result<OwnerEgressSignature, AuthError> { | ||
| cert.tree | ||
| .list_paths() | ||
| .iter() | ||
| .find_map(|path| { | ||
| if let LookupResult::Found(value) = cert.tree.lookup_path(path) { | ||
| candid::decode_one::<OwnerEgressSignature>(value).ok() | ||
| } else { | ||
| None | ||
| } | ||
| }) | ||
| .ok_or_else(|| AuthError::Forbidden("no valid OwnerEgressSignature in certificate tree".into())) | ||
| } | ||
|
|
||
| fn check_payload(payload: &OwnerEgressSignature, root_hash: &str) -> Result<(), AuthError> { | ||
| if payload.method != "upload" { | ||
| Err(AuthError::Forbidden(format!("invalid method: {}", payload.method))) | ||
| } else if payload.blob_hash != root_hash { | ||
| Err(AuthError::Forbidden(format!( | ||
| "blob hash mismatch: expected {root_hash}, got {}", | ||
| payload.blob_hash | ||
| ))) | ||
| } else { | ||
| Ok(()) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl IngressAuth for IngressAuthImpl { | ||
| fn check_put_blob(&self, request: &PutBlobTreeRequest) -> Result<(), AuthError> { | ||
| let root_hash = request | ||
| .blob_tree | ||
| .root_hash() | ||
| .ok_or_else(|| AuthError::Forbidden("blob tree has no root hash".into()))? | ||
| .to_string(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need to stringify it here? Can't we check it directly? I guess because |
||
|
|
||
| match &request.auth { | ||
| StorageGatewayAuthorization::None => { | ||
| Err(AuthError::MissingAuth("no authorization provided".into())) | ||
| } | ||
| StorageGatewayAuthorization::OwnerEgressSignature(cert_bytes) => { | ||
| let cert = Self::parse_certificate(cert_bytes)?; | ||
| self.verify_certificate(&cert, request.owner)?; | ||
| let payload = Self::extract_payload(&cert)?; | ||
| Self::check_payload(&payload, &root_hash) | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.