-
Notifications
You must be signed in to change notification settings - Fork 641
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore auto-add co-owner feature (#6289)
- Loading branch information
1 parent
a9379ee
commit ac9e62d
Showing
45 changed files
with
1,633 additions
and
229 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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,56 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace NuGetGallery.Security | ||
{ | ||
public class MicrosoftTeamSubscription : IUserSecurityPolicySubscription | ||
{ | ||
private Lazy<List<UserSecurityPolicy>> _policies = new Lazy<List<UserSecurityPolicy>>(InitializePoliciesList, isThreadSafe: true); | ||
|
||
internal const string MicrosoftUsername = "Microsoft"; | ||
internal const string Name = "MicrosoftTeamSubscription"; | ||
|
||
public string SubscriptionName => Name; | ||
|
||
public MicrosoftTeamSubscription() | ||
{ | ||
} | ||
|
||
public IEnumerable<UserSecurityPolicy> Policies => _policies.Value; | ||
|
||
public Task OnSubscribeAsync(UserSecurityPolicySubscriptionContext context) | ||
{ | ||
// Todo: | ||
// Maybe we should enumerate through the user's packages and add Microsoft as a package owner if the package passes the metadata requirements when a user is onboarded to this policy. | ||
// We should also unlock the package if it is locked as part of adding Microsoft as co-owner. | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Task OnUnsubscribeAsync(UserSecurityPolicySubscriptionContext context) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
private static List<UserSecurityPolicy> InitializePoliciesList() | ||
{ | ||
return new List<UserSecurityPolicy>() | ||
{ | ||
RequirePackageMetadataCompliancePolicy.CreatePolicy( | ||
Name, | ||
MicrosoftUsername, | ||
allowedCopyrightNotices: new string[] | ||
{ | ||
"(c) Microsoft Corporation. All rights reserved.", | ||
"© Microsoft Corporation. All rights reserved." | ||
}, | ||
isLicenseUrlRequired: true, | ||
isProjectUrlRequired: true, | ||
errorMessageFormat: Strings.SecurityPolicy_RequireMicrosoftPackageMetadataComplianceForPush) | ||
}; | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/NuGetGallery/Security/PackageSecurityPolicyEvaluationContext.cs
This file contains 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,49 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Web; | ||
|
||
namespace NuGetGallery.Security | ||
{ | ||
public class PackageSecurityPolicyEvaluationContext : UserSecurityPolicyEvaluationContext | ||
{ | ||
public PackageSecurityPolicyEvaluationContext( | ||
IUserService userService, | ||
IPackageOwnershipManagementService packageOwnershipManagementService, | ||
IEnumerable<UserSecurityPolicy> policies, | ||
Package package, | ||
HttpContextBase httpContext) | ||
: base(policies, httpContext) | ||
{ | ||
Package = package ?? throw new ArgumentNullException(nameof(package)); | ||
UserService = userService ?? throw new ArgumentNullException(nameof(userService)); | ||
PackageOwnershipManagementService = packageOwnershipManagementService ?? throw new ArgumentNullException(nameof(packageOwnershipManagementService)); | ||
} | ||
|
||
public PackageSecurityPolicyEvaluationContext( | ||
IUserService userService, | ||
IPackageOwnershipManagementService packageOwnershipManagementService, | ||
IEnumerable<UserSecurityPolicy> policies, | ||
Package package, | ||
User sourceAccount, | ||
User targetAccount, | ||
HttpContextBase httpContext = null) | ||
: base(policies, sourceAccount, targetAccount, httpContext) | ||
{ | ||
Package = package ?? throw new ArgumentNullException(nameof(package)); | ||
UserService = userService ?? throw new ArgumentNullException(nameof(userService)); | ||
PackageOwnershipManagementService = packageOwnershipManagementService ?? throw new ArgumentNullException(nameof(packageOwnershipManagementService)); | ||
} | ||
|
||
/// <summary> | ||
/// Package under evaluation. | ||
/// </summary> | ||
public Package Package { get; } | ||
|
||
public IUserService UserService { get; } | ||
|
||
public IPackageOwnershipManagementService PackageOwnershipManagementService { get; } | ||
} | ||
} |
This file contains 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,16 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace NuGetGallery.Security | ||
{ | ||
/// <summary> | ||
/// Policy handler that defines behavior for specific user policy types requiring package policy evaluation. | ||
/// </summary> | ||
public abstract class PackageSecurityPolicyHandler : SecurityPolicyHandler<PackageSecurityPolicyEvaluationContext> | ||
{ | ||
public PackageSecurityPolicyHandler(string name, SecurityPolicyAction action) | ||
: base(name, action) | ||
{ | ||
} | ||
} | ||
} |
This file contains 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
Oops, something went wrong.