Skip to content

Commit

Permalink
Merge pull request #426 from serverlessworkflow/fix-runner-jwt-issuer…
Browse files Browse the repository at this point in the history
…-validation

Fixed the `OAuth2TokenManager` to not validate access token issuer name
  • Loading branch information
cdavernas authored Oct 14, 2024
2 parents a611bcb + ed9c5b9 commit 288dd84
Show file tree
Hide file tree
Showing 23 changed files with 60 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,25 @@ public AuthenticationPolicyOptions()
this.Jwt ??= new();
this.Jwt.Audience = env;
}
env = Environment.GetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Api.Authentication.Jwt.SigningKey);
if (!string.IsNullOrWhiteSpace(env))
{
this.Jwt ??= new();
this.Jwt.SigningKey = env;
}
env = Environment.GetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Api.Authentication.Jwt.Issuer);
if (!string.IsNullOrWhiteSpace(env))
{
this.Jwt ??= new();
this.Jwt.Issuer = env;
}
env = Environment.GetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Api.Authentication.Jwt.ValidateIssuer);
if (!string.IsNullOrWhiteSpace(env))
{
if (!bool.TryParse(env, out var validateIssuer)) throw new Exception($"Failed to parse the specified value '{env}' into a boolean");
this.Jwt ??= new();
this.Jwt.ValidateIssuer = validateIssuer;
}
env = Environment.GetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Api.Authentication.Oidc.Authority);
if (!string.IsNullOrWhiteSpace(env))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public class JwtBearerAuthenticationOptions
/// </summary>
public virtual string? Issuer { get; set; }

/// <summary>
/// Gets/sets a boolean indicating whether or not to validate the issuer of JWT tokens
/// </summary>
public virtual bool ValidateIssuer { get; set; } = true;

/// <summary>
/// Gets the configured issuer signing key
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha3.1</VersionSuffix>
<VersionSuffix>alpha3.2</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha3.1</VersionSuffix>
<VersionSuffix>alpha3.2</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha3.1</VersionSuffix>
<VersionSuffix>alpha3.2</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
2 changes: 1 addition & 1 deletion src/api/Synapse.Api.Http/Synapse.Api.Http.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OutputType>Library</OutputType>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha3.1</VersionSuffix>
<VersionSuffix>alpha3.2</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
2 changes: 1 addition & 1 deletion src/api/Synapse.Api.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
ValidAudience = applicationOptions.Authentication.Jwt.Audience,
ValidateAudience = !string.IsNullOrWhiteSpace(applicationOptions.Authentication.Jwt.Audience),
ValidIssuer = applicationOptions.Authentication.Jwt.Issuer,
ValidateIssuer = !string.IsNullOrWhiteSpace(applicationOptions.Authentication.Jwt.Issuer),
ValidateIssuer = applicationOptions.Authentication.Jwt.ValidateIssuer,
IssuerSigningKey = applicationOptions.Authentication.Jwt.GetSigningKey()
};
});
Expand Down
2 changes: 1 addition & 1 deletion src/api/Synapse.Api.Server/Synapse.Api.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha3.1</VersionSuffix>
<VersionSuffix>alpha3.2</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
2 changes: 1 addition & 1 deletion src/cli/Synapse.Cli/Synapse.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha3.1</VersionSuffix>
<VersionSuffix>alpha3.2</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha3.1</VersionSuffix>
<VersionSuffix>alpha3.2</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha3.1</VersionSuffix>
<VersionSuffix>alpha3.2</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha3.1</VersionSuffix>
<VersionSuffix>alpha3.2</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
2 changes: 1 addition & 1 deletion src/core/Synapse.Core/Synapse.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha3.1</VersionSuffix>
<VersionSuffix>alpha3.2</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
18 changes: 15 additions & 3 deletions src/core/Synapse.Core/SynapseDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -440,18 +440,30 @@ public static class Jwt
{

/// <summary>
/// Gets the prefix for all JWT Bearer related environment variables
/// Gets the prefix for all JWT related environment variables
/// </summary>
public const string Prefix = Authentication.Prefix + "JWT_";

/// <summary>
/// Gets the name of the environment variables used to specify the JWT Bearer authority to use
/// Gets the name of the environment variables used to specify the JWT authority to use
/// </summary>
public const string Authority = Prefix + "AUTHORITY";
/// <summary>
/// Gets the name of the environment variables used to specify the JWT Bearer audience
/// Gets the name of the environment variables used to specify the JWT audience
/// </summary>
public const string Audience = Prefix + "AUDIENCE";
/// <summary>
/// Gets the name of the environment variables used to configure the key used to verify the signature of JWT tokens
/// </summary>
public const string SigningKey = Prefix + "SIGNING_KEY";
/// <summary>
/// Gets the name of the environment variables used to configure the expected issuer of JWT tokens
/// </summary>
public const string Issuer = Prefix + "ISSUER";
/// <summary>
/// Gets the name of the environment variables used to configure whether or not to validate the issuer of JWT tokens
/// </summary>
public const string ValidateIssuer = Prefix + "VALIDATE_ISSUER";

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha3.1</VersionSuffix>
<VersionSuffix>alpha3.2</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
2 changes: 1 addition & 1 deletion src/operator/Synapse.Operator/Synapse.Operator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha3.1</VersionSuffix>
<VersionSuffix>alpha3.2</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

using ServerlessWorkflow.Sdk.Models.Authentication;

namespace Synapse.Core.Infrastructure.Services;
namespace Synapse.Runner.Services;

/// <summary>
/// Defines the fundamentals of a service used to manage <see cref="OAuth2Token"/>s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@
// limitations under the License.

using IdentityModel.Client;
using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.JsonWebTokens;
using Microsoft.IdentityModel.Tokens;
using Neuroglia.Serialization;
using ServerlessWorkflow.Sdk;
using ServerlessWorkflow.Sdk.Models.Authentication;
using System.Collections.Concurrent;
using System.Net.Mime;
using System.Security.Claims;
using System.Text;

namespace Synapse.Core.Infrastructure.Services;
namespace Synapse.Runner.Services;

/// <summary>
/// Represents the default implementation of the <see cref="IOAuth2TokenManager"/> interface
Expand Down Expand Up @@ -69,6 +66,7 @@ public virtual async Task<OAuth2Token> GetTokenAsync(OAuth2AuthenticationSchemeD
Address = configuration.Authority!.OriginalString,
Policy = new()
{
ValidateIssuerName = false,
RequireHttps = false
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/runner/Synapse.Runner/Synapse.Runner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha3.1</VersionSuffix>
<VersionSuffix>alpha3.2</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha3.1</VersionSuffix>
<VersionSuffix>alpha3.2</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha3.1</VersionSuffix>
<VersionSuffix>alpha3.2</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha3.1</VersionSuffix>
<VersionSuffix>alpha3.2</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha3.1</VersionSuffix>
<VersionSuffix>alpha3.2</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down

0 comments on commit 288dd84

Please sign in to comment.