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

add HTTPS support to owner onboarding server #578

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

rdotjain
Copy link
Contributor

@rdotjain rdotjain commented Nov 21, 2023

  • made upload/delete endpoints for ov management api function
  • added tests for ov management api
  • added HTTPS support to owner server

To-Do:

  • add CI Tests

This commit adds TLS support to owner-onboarding-server. It also adds
a new module ov_management that handles enpoints for ov management api.

Signed-off-by: Rupanshi Jain <rupanshijain45678@gmail.com>
Signed-off-by: Rupanshi Jain <rupanshijain45678@gmail.com>
let ov_list: [&str; 1] = ["89cb17fd-95e7-4de8-a36a-686926a7f88f"];
let delete_ov = client
.post(format!(
"http://localhost:{}/management/v1/ownership_voucher/delete",

Check notice

Code scanning / devskim

Accessing localhost could indicate debug code, or could hinder scaling. Note test

Do not leave debug code in production

let add_ov = client
.post(format!(
"https://localhost:{}/management/v1/ownership_voucher", //DevSkim: ignore DS137138

Check notice

Code scanning / devskim

Accessing localhost could indicate debug code, or could hinder scaling. Note test

Do not leave debug code in production
user_data: Arc<OwnerServiceUD>,
) -> core::result::Result<Box<dyn warp::reply::Reply>, warp::Rejection> {
// check for ov type
let content_type = content_type.to_str().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally, we cannot bail on a server, we should return an error and continue listening to requests

let mut reader = body.reader();
//max limit of ov size is 1024 * 32 bytes
let mut dst = [0; 32768];
let _ = reader.read(&mut dst).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with how warp handles possible DoS attacks, what happens when they send us 2GB, 20GB, 200GB of data? do we read all of it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a content length limit filter, so any request exceeding 1024*16 bytes should be should be a no-go and get rejected by the server

.and(warp::body::content_length_limit(1024 * 16))


let ovs = match content_type {
"application/x-pem-file" => OwnershipVoucher::many_from_pem(&dst[..]),
"application/cbor" => OwnershipVoucher::deserialize_many_from_reader(&dst[..]),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this add_ovfunction only adds a single OV, so you should use from_pem and deserialize_from_reader instead

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, reading things again, we do want to add multiple vouchers at the same time, so the lines that say:

//max limit of ov size is 1024 * 32 bytes
 let mut dst = [0; 32768];

are misleading.

Do you mean to say that the max body size is 1024 * 32 bytes instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes my bad, this is the max body size. Also, it seems like we are capping all requests at 1024*16 bytes for body size, will make this change.

.and(warp::body::content_length_limit(1024 * 16))

}

// check-empty
let ovs = ovs.unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cannot bail again

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can do a match over here to handle err or the result

) -> core::result::Result<Box<dyn warp::reply::Reply>, warp::Rejection> {
let mut unknown_device = Vec::new();
for uuid in &uuids {
if Guid::from_str(uuid).is_err() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you'll be needing the unwrapped uuid also below, you can let uuid = match [...] and do the error handling of the uuid first.

Ok(None) => {
unknown_device.push(uuid.to_string());
}
Err(_) => {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't we do anything when there is an error trying to find an OV?

NoOwnershipVoucherFound,
#[error("Unable to parse UUID")]
UuidParseError,
#[error("Pem format error")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pem -> PEM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we always know that it is a PEM format error when we are parsing stuff?

}
bail!("Some tests failed");
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you also need to test when a proper OV is sent in PEM format, when a proper OV is sent in cbor format, when multiple OVs are sent in both formats, when the formats are mixed up and when the actual OV count does not match the sent OV count.

other changes include:
- read cert and key from config
- grammar fixes

Signed-off-by: Rupanshi Jain <rupanshijain45678@gmail.com>
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

Successfully merging this pull request may close these issues.

2 participants