Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Commit e799eb0

Browse files
authored
Shorten the expiry window for the work queue SAS URLs assigned at node registration (#416)
The underlying impact is that nodes must re-register on a more frequent basis. Nodes find out they are out-of-date is during registration and immediately prior to starting a new set of work. Requiring nodes re-register on a shortened cycle provides more opportunities for nodes to get re-imaged. Additionally, this addresses an issue handling the SAS URL expiry in a more clean fashion in the supervisor.
1 parent 3b26ffe commit e799eb0

File tree

5 files changed

+26
-18
lines changed

5 files changed

+26
-18
lines changed

src/agent/onefuzz-supervisor/src/config.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
// Licensed under the MIT License.
33

44
use anyhow::Result;
5-
use onefuzz::{http::ResponseExt, jitter::delay_with_jitter};
6-
use reqwest::StatusCode;
5+
use onefuzz::{
6+
http::{is_auth_error_code, ResponseExt},
7+
jitter::delay_with_jitter,
8+
};
79
use reqwest_retry::SendRetry;
810
use std::{
911
path::{Path, PathBuf},
@@ -228,7 +230,7 @@ impl Registration {
228230
machine_id,
229231
});
230232
}
231-
Err(err) if status_code == StatusCode::UNAUTHORIZED => {
233+
Err(err) if is_auth_error_code(status_code) => {
232234
warn!(
233235
"Registration failed: {}\n retrying in {} seconds",
234236
err,
@@ -264,6 +266,7 @@ impl Registration {
264266
}
265267

266268
pub async fn renew(&mut self) -> Result<()> {
269+
info!("renewing registration");
267270
let token = self.config.credentials.access_token().await?;
268271

269272
let machine_id = self.machine_id.to_string();

src/agent/onefuzz-supervisor/src/work.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::path::PathBuf;
66

77
use anyhow::Result;
88
use downcast_rs::Downcast;
9-
use onefuzz::blob::BlobContainerUrl;
9+
use onefuzz::{blob::BlobContainerUrl, http::is_auth_error};
1010
use storage_queue::QueueClient;
1111
use tokio::fs;
1212
use uuid::Uuid;
@@ -189,17 +189,5 @@ impl WorkQueue {
189189
}
190190
}
191191

192-
fn is_auth_error(err: &anyhow::Error) -> bool {
193-
use reqwest::StatusCode;
194-
195-
if let Some(err) = err.downcast_ref::<reqwest::Error>() {
196-
if let Some(status) = err.status() {
197-
return status == StatusCode::UNAUTHORIZED;
198-
}
199-
}
200-
201-
false
202-
}
203-
204192
#[cfg(test)]
205193
pub mod double;

src/agent/onefuzz/src/http.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use anyhow::{bail, Result};
55
use async_trait::async_trait;
6-
use reqwest::Response;
6+
use reqwest::{Response, StatusCode};
77

88
#[async_trait]
99
pub trait ResponseExt: Sized {
@@ -31,3 +31,17 @@ impl ResponseExt for Response {
3131
Ok(self)
3232
}
3333
}
34+
35+
pub fn is_auth_error(err: &anyhow::Error) -> bool {
36+
if let Some(err) = err.downcast_ref::<reqwest::Error>() {
37+
if let Some(status) = err.status() {
38+
return is_auth_error_code(status);
39+
}
40+
}
41+
42+
false
43+
}
44+
45+
pub fn is_auth_error_code(status: StatusCode) -> bool {
46+
status == StatusCode::UNAUTHORIZED || status == StatusCode::FORBIDDEN
47+
}

src/api-service/__app__/agent_registration/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Copyright (c) Microsoft Corporation.
44
# Licensed under the MIT License.
55

6+
import datetime
67
import logging
78
from uuid import UUID
89

@@ -30,6 +31,7 @@ def create_registration_response(machine_id: UUID, pool: Pool) -> func.HttpRespo
3031
read=True,
3132
update=True,
3233
process=True,
34+
duration=datetime.timedelta(hours=24),
3335
)
3436
return ok(
3537
AgentRegistration(

src/api-service/__app__/onefuzzlib/azure/queue.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ def get_queue_sas(
4848
add: bool = False,
4949
update: bool = False,
5050
process: bool = False,
51+
duration: datetime.timedelta = datetime.timedelta(days=30),
5152
) -> str:
5253
account_id = get_primary_account(storage_type)
5354
logging.debug("getting queue sas %s (account_id: %s)", queue, account_id)
5455
name, key = get_storage_account_name_key(account_id)
55-
expiry = datetime.datetime.utcnow() + datetime.timedelta(days=30)
56+
expiry = datetime.datetime.utcnow() + duration
5657

5758
token = generate_queue_sas(
5859
name,

0 commit comments

Comments
 (0)