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

chores: migrate PEP #118

Merged
merged 5 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Altinn.Authorization.sln
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{35FE03F3
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Altinn.Authorization.Hosting.Tests", "src\libs\Altinn.Authorization.Hosting\tests\Altinn.Authorization.Hosting.Tests\Altinn.Authorization.Hosting.Tests.csproj", "{95DC14A3-43E1-4DE8-8C40-3DAF2719B864}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "pkgs", "pkgs", "{CA323293-CA35-413A-8EE2-F33902239D11}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Altinn.Authorization.PEP", "Altinn.Authorization.PEP", "{B1E3ACAE-89C4-4693-95D0-A71DDFA728C7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A6AC78FE-D74C-4759-9467-087DFB70D5B6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Altinn.Authorization.PEP", "src\pkgs\Altinn.Authorization.PEP\src\Altinn.Authorization.PEP\Altinn.Authorization.PEP.csproj", "{874B5EF3-BA5F-41F3-B97D-3EC6DF383BA2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{355D903B-A1F0-4640-A528-2DB546AA76AE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Altinn.Authorization.PEP.Tests", "src\pkgs\Altinn.Authorization.PEP\tests\Altinn.Authorization.PEP.Tests\Altinn.Authorization.PEP.Tests.csproj", "{6CD7B4EE-5AE6-4940-9EC9-3000E5F3E9D0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -130,6 +142,14 @@ Global
{95DC14A3-43E1-4DE8-8C40-3DAF2719B864}.Debug|Any CPU.Build.0 = Debug|Any CPU
{95DC14A3-43E1-4DE8-8C40-3DAF2719B864}.Release|Any CPU.ActiveCfg = Release|Any CPU
{95DC14A3-43E1-4DE8-8C40-3DAF2719B864}.Release|Any CPU.Build.0 = Release|Any CPU
{874B5EF3-BA5F-41F3-B97D-3EC6DF383BA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{874B5EF3-BA5F-41F3-B97D-3EC6DF383BA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{874B5EF3-BA5F-41F3-B97D-3EC6DF383BA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{874B5EF3-BA5F-41F3-B97D-3EC6DF383BA2}.Release|Any CPU.Build.0 = Release|Any CPU
{6CD7B4EE-5AE6-4940-9EC9-3000E5F3E9D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6CD7B4EE-5AE6-4940-9EC9-3000E5F3E9D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CD7B4EE-5AE6-4940-9EC9-3000E5F3E9D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6CD7B4EE-5AE6-4940-9EC9-3000E5F3E9D0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{E9D041A5-2AB6-45FD-8D24-EF552025539E} = {2891B160-9E46-42E5-95FF-08523A3192EF}
Expand Down Expand Up @@ -162,5 +182,11 @@ Global
{57E22F21-9A30-4753-851F-AB061A0EA683} = {5AF3188D-BF17-404A-A949-6A88527B61CD}
{35FE03F3-263C-4C98-ABB1-B64BE2FB70CF} = {3C5636A1-2425-49FD-96F9-7884BA3F3797}
{95DC14A3-43E1-4DE8-8C40-3DAF2719B864} = {35FE03F3-263C-4C98-ABB1-B64BE2FB70CF}
{CA323293-CA35-413A-8EE2-F33902239D11} = {2891B160-9E46-42E5-95FF-08523A3192EF}
{B1E3ACAE-89C4-4693-95D0-A71DDFA728C7} = {CA323293-CA35-413A-8EE2-F33902239D11}
{A6AC78FE-D74C-4759-9467-087DFB70D5B6} = {B1E3ACAE-89C4-4693-95D0-A71DDFA728C7}
{874B5EF3-BA5F-41F3-B97D-3EC6DF383BA2} = {A6AC78FE-D74C-4759-9467-087DFB70D5B6}
{355D903B-A1F0-4640-A528-2DB546AA76AE} = {B1E3ACAE-89C4-4693-95D0-A71DDFA728C7}
{6CD7B4EE-5AE6-4940-9EC9-3000E5F3E9D0} = {355D903B-A1F0-4640-A528-2DB546AA76AE}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"local>Altinn/renovate-config"
]
}
3 changes: 1 addition & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Authors>Altinn Authorization</Authors>
<UserSecretsId>Altinn-Authorization</UserSecretsId>
</PropertyGroup>

</Project>
</Project>
57 changes: 29 additions & 28 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="Altinn.Authorization.ABAC" Version="0.0.8" />
<PackageVersion Include="Altinn.Authorization.ProblemDetails" Version="3.0.1" />
<PackageVersion Include="Altinn.Authorization.ProblemDetails.Abstractions"
Version="3.0.1" />
<PackageVersion Include="Altinn.Authorization.ProblemDetails.Abstractions" Version="3.0.1" />
<PackageVersion Include="Altinn.Authorization.ServiceDefaults" Version="2.7.0" />
<PackageVersion Include="Altinn.Authorization.ServiceDefaults.Npgsql.Yuniql"
Version="2.7.0" />
<PackageVersion Include="Altinn.Authorization.ServiceDefaults.Npgsql.Yuniql" Version="2.7.0" />
<PackageVersion Include="Altinn.Common.AccessToken" Version="4.5.4" />
<PackageVersion Include="Altinn.Common.AccessTokenClient" Version="3.0.10" />
<PackageVersion Include="Altinn.Common.PEP" Version="4.1.2" />
Expand All @@ -17,10 +19,8 @@
<PackageVersion Include="Altinn.Urn" Version="2.5.1" />
<PackageVersion Include="Altinn.Urn.Swashbuckle" Version="2.5.1" />
<PackageVersion Include="AutoMapper" Version="13.0.1" />
<PackageVersion Include="AutoMapper.Extensions.Microsoft.DependencyInjection"
Version="12.0.1" />
<PackageVersion Include="Azure.Extensions.AspNetCore.Configuration.Secrets"
Version="1.3.2" />
<PackageVersion Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageVersion Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.3.2" />
<PackageVersion Include="Azure.Identity" Version="1.13.1" />
<PackageVersion Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.3.0-beta.2" />
<PackageVersion Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.3.0" />
Expand All @@ -33,42 +33,44 @@
<PackageVersion Include="coverlet.collector" Version=" 6.0.2" />
<PackageVersion Include="Dapper" Version="2.1.35" />
<PackageVersion Include="JWTCookieAuthentication" Version="4.0.1" />
<PackageVersion Include="MassTransit.Azure.ServiceBus.Core"
Version=" 8.2.6-develop.1998" />
<PackageVersion Include="MassTransit.Azure.ServiceBus.Core" Version=" 8.2.6-develop.1998" />
<PackageVersion Include="MassTransit.Extensions.DependencyInjection" Version=" 7.3.1" />
<PackageVersion Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />

<PackageVersion Include="Microsoft.AspNetCore.Authorization" Version="9.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.OpenIdConnect"
Version="9.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="9.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Http.Abstractions" Version="3.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Http.Extensions" Version="2.2.0" />
<PackageVersion Include="Microsoft.AspNetCore.Routing.Abstractions" Version="2.2.0" />
<PackageVersion Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />

<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
<PackageVersion Include="Microsoft.Azure.AppConfiguration.AspNetCore"
Version="8.1.0-preview" />

<PackageVersion Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="8.1.0-preview" />

<PackageVersion Include="Microsoft.Build.Artifacts" Version="6.1.47" />
<PackageVersion Include="Microsoft.Extensions.Azure" Version="1.9.0" />
<PackageVersion Include="Microsoft.Extensions.Caching.Abstractions" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.AzureKeyVault"
Version="3.1.24" />
<PackageVersion Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="3.1.24" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="8.0.8" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions"
Version="8.0.8" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions" Version="8.0.8" />
<PackageVersion Include="Microsoft.Extensions.FileProviders.Embedded" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.ApplicationInsights"
Version="2.22.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.22.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Telemetry.Abstractions" Version="9.0.0" />
<PackageVersion Include="Microsoft.FeatureManagement.AspNetCore" Version="4.0.0" />
<PackageVersion Include="Microsoft.IdentityModel.Logging" Version="8.2.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets"
Version="1.21.0" />
<PackageVersion Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="Nerdbank.Streams" Version="2.11.79" />
<PackageVersion Include="Npgsql" Version="8.0.5" />
Expand All @@ -83,8 +85,6 @@
<PackageVersion Include="Swashbuckle.AspNetCore" Version="7.1.0" />
<PackageVersion Include="Swashbuckle.AspNetCore.Annotations" Version="7.1.0" />
<PackageVersion Include="Swashbuckle.AspNetCore.Filters" Version="8.0.2" />
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
<PackageVersion Include="System.Text.Json" Version="9.0.0" />
<PackageVersion Include="Testcontainers.PostgreSql" Version="4.0.0" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
Expand All @@ -98,8 +98,9 @@
<PackageVersion Include="Microsoft.Azure.Services.AppAuthentication" Version="1.6.2" />
<PackageVersion Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="8.2.1" />

<PackageVersion Include="DotNet.ReproducibleBuilds" Version="1.2.25" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />

</ItemGroup>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
<PackageReference Include="Swashbuckle.AspNetCore" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" />
<PackageReference Include="System.Text.Json" />
<PackageReference Include="Yuniql.AspNetCore" />
<PackageReference Include="Yuniql.PostgreSql" />
</ItemGroup>
Expand All @@ -41,4 +40,4 @@
Include="..\Altinn.AccessManagement.Persistence\Altinn.AccessManagement.Persistence.csproj" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
<PackageReference Include="Swashbuckle.AspNetCore" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" />
<PackageReference Include="System.Text.Json" />
<PackageReference Include="Yuniql.AspNetCore" />
<PackageReference Include="Yuniql.PostgreSql" />
</ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/apps/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<Project>

<Import Project="..\Directory.Build.props" />

</Project>
</Project>
36 changes: 36 additions & 0 deletions src/pkgs/Altinn.Authorization.PEP/Altinn.Authorization.PEP.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{DA970EDE-848F-4A7A-8F67-13835BD4DA89}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Altinn.Authorization.PEP", "src\Altinn.Authorization.PEP\Altinn.Authorization.PEP.csproj", "{C99D2680-4A77-40E4-99E0-C2FBBB4C709C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{DDA3BB50-F068-4BDB-8684-CBF68ECDE9FC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Altinn.Authorization.PEP.Tests", "tests\Altinn.Authorization.PEP.Tests\Altinn.Authorization.PEP.Tests.csproj", "{9005F003-ECD8-4EA7-9149-F47F4FEC5697}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C99D2680-4A77-40E4-99E0-C2FBBB4C709C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C99D2680-4A77-40E4-99E0-C2FBBB4C709C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C99D2680-4A77-40E4-99E0-C2FBBB4C709C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C99D2680-4A77-40E4-99E0-C2FBBB4C709C}.Release|Any CPU.Build.0 = Release|Any CPU
{9005F003-ECD8-4EA7-9149-F47F4FEC5697}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9005F003-ECD8-4EA7-9149-F47F4FEC5697}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9005F003-ECD8-4EA7-9149-F47F4FEC5697}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9005F003-ECD8-4EA7-9149-F47F4FEC5697}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{C99D2680-4A77-40E4-99E0-C2FBBB4C709C} = {DA970EDE-848F-4A7A-8F67-13835BD4DA89}
{9005F003-ECD8-4EA7-9149-F47F4FEC5697} = {DDA3BB50-F068-4BDB-8684-CBF68ECDE9FC}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<!-- NuGet package properties -->
<IsPackageProject>true</IsPackageProject>
<PackageId>Altinn.Authorization.PEP</PackageId>
<PackageTags>Altinn;Studio;Authorization;Policy;Enforcement;Point</PackageTags>
<Description>
Policy Enforcement Point for Attribute-based authorization using
Altinn.Authorization.ABAC in ASP.Net apps.
See our repository for the full documentation.
</Description>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="all" />
<PackageReference Include="DotNet.ReproducibleBuilds" PrivateAssets="all" />
<PackageReference Include="Altinn.Authorization.ABAC" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using System.Threading.Tasks;
using Altinn.Authorization.ABAC.Xacml.JsonProfile;
using Altinn.Common.PEP.Helpers;
using Altinn.Common.PEP.Interfaces;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Logging;

namespace Altinn.Common.PEP.Authorization
{
/// <summary>
/// AuthorizationHandler that is created for handling access to app.
/// Authorizes based om AppAccessRequirement and app id from route
/// <see href="https://docs.asp.net/en/latest/security/authorization/policies.html"/> for details about authorization
/// in asp.net core
/// </summary>
public class AppAccessHandler : AuthorizationHandler<AppAccessRequirement>
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IPDP _pdp;
private readonly ILogger _logger;

/// <summary>
/// Initializes a new instance of the <see cref="AppAccessHandler"/> class.
/// </summary>
/// <param name="httpContextAccessor">The http context accessor</param>
/// <param name="pdp">The pdp</param>
/// <param name="logger">The logger. </param>
public AppAccessHandler(
IHttpContextAccessor httpContextAccessor,
IPDP pdp,
ILogger<AppAccessHandler> logger)
{
_httpContextAccessor = httpContextAccessor;
_pdp = pdp;
_logger = logger;
}

/// <summary>
/// This method authorize access bases on context and requirement
/// Is triggered by annotation on MVC action and setup in startup.
/// </summary>
/// <param name="context">The context</param>
/// <param name="requirement">The requirement</param>
/// <returns>A Task</returns>
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, AppAccessRequirement requirement)
{
HttpContext httpContext = _httpContextAccessor.HttpContext;

XacmlJsonRequestRoot request = DecisionHelper.CreateDecisionRequest(context, requirement, _httpContextAccessor.HttpContext.GetRouteData());

XacmlJsonResponse response = await _pdp.GetDecisionForRequest(request);

if (response?.Response == null)
{
throw new ArgumentNullException("response");
}

if (!DecisionHelper.ValidatePdpDecision(response.Response, context.User))
{
context.Fail();
}

context.Succeed(requirement);
await Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Authorization;

namespace Altinn.Common.PEP.Authorization
{
/// <summary>
/// Requirement for authorization policies used for accessing apps.
/// <see href="https://docs.asp.net/en/latest/security/authorization/policies.html"/> for details about authorization
/// in asp.net core.
/// </summary>
public class AppAccessRequirement : IAuthorizationRequirement
{
/// <summary>
/// Initializes a new instance of the <see cref="AppAccessRequirement"/> class
/// </summary>
/// <param name="actionType">The Action type for this requirement</param>
public AppAccessRequirement(string actionType)
{
this.ActionType = actionType;
}

/// <summary>
/// Gets or sets The Action type defined for the policy using this requirement
/// </summary>
public string ActionType { get; set; }
}
}
Loading
Loading