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

Commit 2a796a2

Browse files
authored
Merge branch 'main' into user/noharper/remove-debug-repro-cli
2 parents 4a78482 + 7efea43 commit 2a796a2

File tree

39 files changed

+2113
-246
lines changed

39 files changed

+2113
-246
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ jobs:
123123
- uses: actions/checkout@v3
124124
- uses: actions/setup-python@v4
125125
with:
126-
python-version: 3.7
126+
python-version: "3.10"
127127
- name: lint
128128
shell: bash
129129
run: src/ci/check-check-pr.sh
@@ -137,7 +137,7 @@ jobs:
137137
shell: bash
138138
- uses: actions/setup-python@v4
139139
with:
140-
python-version: 3.7
140+
python-version: "3.10"
141141
- uses: actions/download-artifact@v3
142142
with:
143143
name: artifact-onefuzztypes
@@ -190,7 +190,7 @@ jobs:
190190
- uses: actions/checkout@v3
191191
- uses: actions/setup-python@v4
192192
with:
193-
python-version: 3.8
193+
python-version: "3.10"
194194
- name: lint
195195
shell: bash
196196
run: |
@@ -208,7 +208,7 @@ jobs:
208208
- uses: actions/checkout@v3
209209
- uses: actions/setup-python@v4
210210
with:
211-
python-version: 3.8
211+
python-version: "3.10"
212212
- name: lint
213213
shell: bash
214214
run: |
@@ -224,7 +224,7 @@ jobs:
224224
- run: src/ci/set-versions.sh
225225
- uses: actions/setup-python@v4
226226
with:
227-
python-version: 3.7
227+
python-version: "3.10"
228228
- run: src/ci/onefuzztypes.sh
229229
- uses: actions/upload-artifact@v3
230230
with:
@@ -481,7 +481,7 @@ jobs:
481481
path: artifacts
482482
- uses: actions/setup-python@v4
483483
with:
484-
python-version: 3.7
484+
python-version: "3.10"
485485
- name: Lint
486486
shell: bash
487487
run: |

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# <img src="docs/onefuzz_text.svg" height="120" alt="OneFuzz" />
22

3-
# IMPORTANT NOTICE
3+
# :exclamation: IMPORTANT NOTICE :exclamation:
4+
5+
**_August 31, 2023_**.
46

57
**_Since September 2020 when OneFuzz was first open sourced, we’ve been on a journey to create a best-in-class orchestrator for running fuzzers, driving security and quality into our products._**
68

@@ -13,6 +15,10 @@
1315

1416
**_The OneFuzz team._**
1517

18+
---
19+
**_Update: September 15 2023:_**
20+
**_Our current target to archive the project is September 30th, 2023._**
21+
1622
---
1723

1824
[![Onefuzz build status](https://github.com/microsoft/onefuzz/workflows/Build/badge.svg?branch=main)](https://github.com/microsoft/onefuzz/actions/workflows/ci.yml?query=branch%3Amain)

src/ApiService/ApiService/FeatureFlags.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ public static class FeatureFlagConstants {
88
public const string EnableBlobRetentionPolicy = "EnableBlobRetentionPolicy";
99
public const string EnableDryRunBlobRetention = "EnableDryRunBlobRetention";
1010
public const string EnableWorkItemCreation = "EnableWorkItemCreation";
11+
public const string EnableContainerRetentionPolicies = "EnableContainerRetentionPolicies";
1112
}

src/ApiService/ApiService/Functions/Jobs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private async Task<HttpResponseData> Post(HttpRequestData req, FunctionContext c
8383
"job");
8484
}
8585

86-
await _context.Events.SendEvent(new EventJobCreated(job.JobId, job.Config, job.UserInfo));
86+
await _context.Events.SendEvent(new EventJobCreated(job.JobId, job.Config, job.UserInfo, _context.ServiceConfiguration.OneFuzzVersion));
8787
return await RequestHandling.Ok(req, JobResponse.ForJob(job, taskInfo: null));
8888
}
8989

src/ApiService/ApiService/Functions/QueueFileChanges.cs

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Text.Json;
22
using System.Text.Json.Nodes;
3+
using System.Threading.Tasks;
34
using Azure.Core;
45
using Microsoft.Azure.Functions.Worker;
56
using Microsoft.Extensions.Logging;
@@ -54,14 +55,16 @@ public async Async.Task Run(
5455
return;
5556
}
5657

58+
var storageAccount = new ResourceIdentifier(topicElement.GetString()!);
59+
5760
try {
5861
// Setting isLastRetryAttempt to false will rethrow any exceptions
5962
// With the intention that the azure functions runtime will handle requeing
6063
// the message for us. The difference is for the poison queue, we're handling the
6164
// requeuing ourselves because azure functions doesn't support retry policies
6265
// for queue based functions.
6366

64-
var result = await FileAdded(fileChangeEvent, isLastRetryAttempt: false);
67+
var result = await FileAdded(storageAccount, fileChangeEvent, isLastRetryAttempt: false);
6568
if (!result.IsOk && result.ErrorV.Code == ErrorCode.ADO_WORKITEM_PROCESSING_DISABLED) {
6669
await RequeueMessage(msg, TimeSpan.FromDays(1));
6770
}
@@ -71,16 +74,47 @@ public async Async.Task Run(
7174
}
7275
}
7376

74-
private async Async.Task<OneFuzzResultVoid> FileAdded(JsonDocument fileChangeEvent, bool isLastRetryAttempt) {
77+
private async Async.Task<OneFuzzResultVoid> FileAdded(ResourceIdentifier storageAccount, JsonDocument fileChangeEvent, bool isLastRetryAttempt) {
7578
var data = fileChangeEvent.RootElement.GetProperty("data");
7679
var url = data.GetProperty("url").GetString()!;
7780
var parts = url.Split("/").Skip(3).ToList();
7881

79-
var container = parts[0];
82+
var container = Container.Parse(parts[0]);
8083
var path = string.Join('/', parts.Skip(1));
8184

82-
_log.LogInformation("file added : {Container} - {Path}", container, path);
83-
return await _notificationOperations.NewFiles(Container.Parse(container), path, isLastRetryAttempt);
85+
_log.LogInformation("file added : {Container} - {Path}", container.String, path);
86+
87+
var (_, result) = await (
88+
ApplyRetentionPolicy(storageAccount, container, path),
89+
_notificationOperations.NewFiles(container, path, isLastRetryAttempt));
90+
91+
return result;
92+
}
93+
94+
private async Async.Task<bool> ApplyRetentionPolicy(ResourceIdentifier storageAccount, Container container, string path) {
95+
if (await _context.FeatureManagerSnapshot.IsEnabledAsync(FeatureFlagConstants.EnableContainerRetentionPolicies)) {
96+
// default retention period can be applied to the container
97+
// if one exists, we will set the expiry date on the newly-created blob, if it doesn't already have one
98+
var account = await _storage.GetBlobServiceClientForAccount(storageAccount);
99+
var containerClient = account.GetBlobContainerClient(container.String);
100+
var containerProps = await containerClient.GetPropertiesAsync();
101+
var retentionPeriod = RetentionPolicyUtils.GetContainerRetentionPeriodFromMetadata(containerProps.Value.Metadata);
102+
if (!retentionPeriod.IsOk) {
103+
_log.LogError("invalid retention period: {Error}", retentionPeriod.ErrorV);
104+
} else if (retentionPeriod.OkV is TimeSpan period) {
105+
var blobClient = containerClient.GetBlobClient(path);
106+
var tags = (await blobClient.GetTagsAsync()).Value.Tags;
107+
var expiryDate = DateTime.UtcNow + period;
108+
var tag = RetentionPolicyUtils.CreateExpiryDateTag(DateOnly.FromDateTime(expiryDate));
109+
if (tags.TryAdd(tag.Key, tag.Value)) {
110+
_ = await blobClient.SetTagsAsync(tags);
111+
_log.LogInformation("applied container retention policy ({Policy}) to {Path}", period, path);
112+
return true;
113+
}
114+
}
115+
}
116+
117+
return false;
84118
}
85119

86120
private async Async.Task RequeueMessage(string msg, TimeSpan? visibilityTimeout = null) {

src/ApiService/ApiService/Functions/QueueNodeHeartbeat.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ public async Async.Task Run([QueueTrigger("node-heartbeat", Connection = "AzureW
4141
var nodeHeartbeatEvent = new EventNodeHeartbeat(node.MachineId, node.ScalesetId, node.PoolName, node.State);
4242
// TODO: do we still send event if we fail do update the table ?
4343
await events.SendEvent(nodeHeartbeatEvent);
44-
if (await _context.FeatureManagerSnapshot.IsEnabledAsync(FeatureFlagConstants.EnableCustomMetricTelemetry)) {
45-
metrics.SendMetric(1, nodeHeartbeatEvent);
46-
}
44+
metrics.SendMetric(1, nodeHeartbeatEvent);
45+
4746

4847
}
4948
}

src/ApiService/ApiService/Functions/QueueTaskHeartbeat.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public async Async.Task Run([QueueTrigger("task-heartbeat", Connection = "AzureW
4545

4646
var taskHeartBeatEvent = new EventTaskHeartbeat(newTask.JobId, newTask.TaskId, job.Config.Project, job.Config.Name, newTask.State, newTask.Config);
4747
await _events.SendEvent(taskHeartBeatEvent);
48-
if (await _context.FeatureManagerSnapshot.IsEnabledAsync(FeatureFlagConstants.EnableCustomMetricTelemetry)) {
49-
_metrics.SendMetric(1, taskHeartBeatEvent);
50-
}
48+
_metrics.SendMetric(1, taskHeartBeatEvent);
49+
5150
}
5251
}

src/ApiService/ApiService/OneFuzzTypes/Enums.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public enum ErrorCode {
5050
ADO_WORKITEM_PROCESSING_DISABLED = 494,
5151
ADO_VALIDATION_INVALID_PATH = 495,
5252
ADO_VALIDATION_INVALID_PROJECT = 496,
53+
INVALID_RETENTION_PERIOD = 497,
5354
// NB: if you update this enum, also update enums.py
5455
}
5556

src/ApiService/ApiService/OneFuzzTypes/Events.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ TaskConfig Config
124124
public record EventJobCreated(
125125
Guid JobId,
126126
JobConfig Config,
127-
StoredUserInfo? UserInfo
127+
StoredUserInfo? UserInfo,
128+
string OneFuzzVersion
128129
) : BaseEvent();
129130

130131

src/ApiService/ApiService/onefuzzlib/NotificationOperations.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ public NotificationOperations(ILogger<NotificationOperations> log, IOnefuzzConte
2222

2323
}
2424
public async Async.Task<OneFuzzResultVoid> NewFiles(Container container, string filename, bool isLastRetryAttempt) {
25-
var result = OneFuzzResultVoid.Ok;
26-
2725
// We don't want to store file added events for the events container because that causes an infinite loop
2826
if (container == WellKnownContainers.Events) {
29-
return result;
27+
return Result.Ok();
3028
}
3129

30+
var result = OneFuzzResultVoid.Ok;
3231
var notifications = GetNotifications(container);
3332
var hasNotifications = await notifications.AnyAsync();
3433
var reportOrRegression = await _context.Reports.GetReportOrRegression(container, filename, expectReports: hasNotifications);

0 commit comments

Comments
 (0)