Skip to content

Commit e511b71

Browse files
authored
Merge pull request #395 from serverlessworkflow/feat-secrets
Add secrets support
2 parents dd2e75f + 6f57090 commit e511b71

File tree

28 files changed

+477
-60
lines changed

28 files changed

+477
-60
lines changed

.dockerignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@
2121
**/obj
2222
**/secrets.dev.yaml
2323
**/values.dev.yaml
24-
LICENSE
25-
README.md
24+
LICENSE

README.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<p align="center">
2-
<img src="assets/images/transparent_logo.png" height="350px" alt="Synapse Logo"/>
1+
<p align="center">
2+
<img src="./assets/images/transparent_logo.png" height="350px" alt="Synapse Logo"/>
33
</p>
44

55
---
@@ -19,6 +19,10 @@ It enables developers and organizations to define and execute workflows effortle
1919

2020
With Synapse, you can create powerful workflows that are cloud vendor-agnostic, easily scalable, and highly customizable.
2121

22+
<p align="center">
23+
<img src="./assets/images/preview.gif" alt="Synapse Preview"/>
24+
</p>
25+
2226
### Features
2327

2428
- **Easy to Use**: The Serverless Workflow DSL is designed for universal understanding, enabling users to quickly grasp workflow concepts and create complex workflows effortlessly.
@@ -33,7 +37,7 @@ With Synapse, you can create powerful workflows that are cloud vendor-agnostic,
3337
- **Scalable**: Promotes code reusability, maintainability, and scalability across different environments.
3438
- **Cross-Platform**: Runs on various operating systems, providing flexibility and ease of integration.
3539

36-
### Microservices
40+
### Architecture
3741

3842
Synapse is composed of several specialized applications, allowing for atomic scalability, resilience, and ease of maintenance:
3943

@@ -43,6 +47,12 @@ Synapse is composed of several specialized applications, allowing for atomic sca
4347
- **Correlator**: Performs Complex Event Processing (CEP) and correlates ingested events.
4448
- **CLI**: Allows interaction with the Synapse API via the command line interface.
4549

50+
<p align="center">
51+
<img src="./assets/images/architecture-c4-l2.png" alt="Synapse Architecture C4 Diagram - Container Layer"/>
52+
</p>
53+
54+
*For more information about the Synapse architecture, please refer to the [wiki](https://github.com/serverlessworkflow/synapse/wiki/Architecture).* 📖
55+
4656
## Getting Started
4757

4858
### Prerequisites
@@ -79,6 +89,8 @@ The simplest way to get started is by using the provided Docker Compose setup.
7989

8090
This will pull the necessary Docker images and start the Synapse services as defined in the `docker-compose.yml` file. You can then access the Synapse API and dashboard as configured.
8191

92+
*For more information about installing Synapse, please refer to the [wiki](https://github.com/serverlessworkflow/synapse/wiki/Installation)*. 📖
93+
8294
### Run using `synctl` Command-line Interface
8395

8496
First, set up the Synapse API server to use with `synctl`:
@@ -120,15 +132,15 @@ The command above will provide the fully qualified name of the created workflow
120132
synctl workflow-instance get-output greeter-uk58h3dssqp620a --namespace default --output yaml
121133
```
122134

123-
For more information about `synctl`, please refer to the [documentation](#synctl).
135+
*For more information about `synctl`, please refer to the [wiki](https://github.com/serverlessworkflow/synapse/wiki/CLI-Usage).* 📖
124136

125137
## Community
126138

127139
The Synapse project has a vibrant and growing community dedicated to building a community-driven and vendor-neutral workflow runtime ecosystem. Contributions from the community are encouraged and essential to the continued growth and success of the project.
128140

129-
A list of community members who have contributed to Synapse can be found [here](./community/README.md).
141+
A list of community members who have contributed to Synapse can be found [here](./community/README.md). 👥
130142

131-
To learn how to contribute to Synapse, please refer to the [contribution guidelines](CONTRIBUTING.md).
143+
To learn how to contribute to Synapse, please refer to the [contribution guidelines](CONTRIBUTING.md). 📝
132144

133145
For any copyright-related questions when contributing to a CNCF project like Synapse, please refer to the [Ownership of Copyrights in CNCF Project Contributions](https://github.com/cncf/foundation/blob/master/copyright-notices.md) document.
134146

@@ -138,5 +150,5 @@ As contributors and maintainers of Synapse, and in the interest of fostering an
138150

139151
The project is committed to making participation in Synapse a harassment-free experience for everyone, regardless of experience level, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
140152

141-
For more detailed information, please see the full project Code of Conduct [here](code-of-conduct.md).
153+
For more detailed information, please see the full project Code of Conduct [here](code-of-conduct.md). 🛡️
142154

assets/images/architecture-c4-l2.png

337 KB
Loading

assets/images/preview.gif

1.68 MB
Loading

deployments/docker-compose/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ services:
2929
SYNAPSE_RUNNER_API: http://api:8080
3030
SYNAPSE_RUNNER_LIFECYCLE_EVENTS: true
3131
SYNAPSE_RUNNER_CONTAINER_PLATFORM: docker
32+
SYNAPSE_RUNTIME_DOCKER_SECRETS_DIRECTORY: C:\Users\User\.synapse\secrets
3233
DOCKER_HOST: unix:///var/run/docker.sock
3334
extra_hosts:
3435
- "host.docker.internal:host-gateway"

src/api/Synapse.Api.Server/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ EXPOSE 8080
66
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
77
ARG BUILD_CONFIGURATION=Release
88
WORKDIR /src
9+
COPY ["README.md", "README.md"]
10+
COPY ["assets/images/transparent_logomark_256.png", "assets/images/transparent_logomark_256.png"]
911
COPY ["src/api/Synapse.Api.Server/Synapse.Api.Server.csproj", "src/api/Synapse.Api.Server/"]
1012
RUN dotnet restore "./src/api/Synapse.Api.Server/Synapse.Api.Server.csproj"
1113
COPY . .

src/core/Synapse.Core.Infrastructure/Services/OAuth2TokenManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public virtual async Task<OAuth2Token> GetTokenAsync(OAuth2AuthenticationSchemeD
6666
{
6767
var discoveryRequest = new DiscoveryDocumentRequest()
6868
{
69-
Address = configuration.Authority.OriginalString,
69+
Address = configuration.Authority!.OriginalString,
7070
Policy = new()
7171
{
7272
RequireHttps = false
@@ -80,7 +80,7 @@ public virtual async Task<OAuth2Token> GetTokenAsync(OAuth2AuthenticationSchemeD
8080
else throw new NotSupportedException($"The specified scheme type '{configuration.GetType().FullName}' is not supported in this context");
8181
var properties = new Dictionary<string, string>()
8282
{
83-
{ "grant_type", configuration.Grant }
83+
{ "grant_type", configuration.Grant! }
8484
};
8585
switch (configuration.Client?.Authentication)
8686
{
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright © 2024-Present The Synapse Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace Synapse;
15+
16+
/// <summary>
17+
/// Defines extensions for <see cref="AuthenticationPolicyDefinition"/>s
18+
/// </summary>
19+
public static class AuthenticationPolicyDefinitionExtensions
20+
{
21+
22+
/// <summary>
23+
/// Attempts to get the name of the secret, if any, on which the <see cref="AuthenticationPolicyDefinition"/> is based
24+
/// </summary>
25+
/// <param name="authentication">The extended <see cref="AuthenticationPolicyDefinition"/></param>
26+
/// <param name="secretName">The name of the secret, if any, on which the <see cref="AuthenticationPolicyDefinition"/> is based</param>
27+
/// <returns>A boolean indicating whether or not the <see cref="AuthenticationPolicyDefinition"/> is secret based</returns>
28+
public static bool TryGetBaseSecret(this AuthenticationPolicyDefinition authentication, out string? secretName)
29+
{
30+
secretName = authentication.Scheme switch
31+
{
32+
AuthenticationScheme.Basic => authentication.Basic?.Use,
33+
AuthenticationScheme.Bearer => authentication.Bearer?.Use,
34+
AuthenticationScheme.Certificate => authentication.Certificate?.Use,
35+
AuthenticationScheme.Digest => authentication.Digest?.Use,
36+
AuthenticationScheme.OAuth2 => authentication.OAuth2?.Use,
37+
AuthenticationScheme.OpenIDConnect => authentication.Oidc?.Use,
38+
_ => throw new NotSupportedException($"The specified authentication schema '{authentication.Scheme}' is not supported")
39+
};
40+
return !string.IsNullOrWhiteSpace(secretName);
41+
}
42+
43+
}

src/core/Synapse.Core/Resources/DockerRuntimeConfiguration.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,38 @@ public record DockerRuntimeConfiguration
3535
Image = SynapseDefaults.Containers.Images.Runner
3636
};
3737

38+
/// <summary>
39+
/// Initializes a new <see cref="DockerRuntimeConfiguration"/>
40+
/// </summary>
41+
public DockerRuntimeConfiguration()
42+
{
43+
var env = Environment.GetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Runtime.Docker.Api.Endpoint);
44+
if (!string.IsNullOrWhiteSpace(env) && Uri.TryCreate(env, UriKind.RelativeOrAbsolute, out var uri)) this.Api.Endpoint = uri;
45+
env = Environment.GetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Runtime.Docker.Api.Version);
46+
if (!string.IsNullOrWhiteSpace(env)) this.Api.Version = env;
47+
env = Environment.GetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Runtime.Docker.Image.Registry);
48+
if (!string.IsNullOrWhiteSpace(env)) this.ImageRegistry = env;
49+
env = Environment.GetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Runtime.Docker.Image.PullPolicy);
50+
if (!string.IsNullOrWhiteSpace(env)) this.ImagePullPolicy = env;
51+
env = Environment.GetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Runtime.Docker.Secrets.Directory);
52+
if (!string.IsNullOrWhiteSpace(env)) this.Secrets.Directory = env;
53+
env = Environment.GetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Runtime.Docker.Secrets.MountPath);
54+
if (!string.IsNullOrWhiteSpace(env)) this.Secrets.MountPath = env;
55+
env = Environment.GetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Runtime.Docker.Network);
56+
if (!string.IsNullOrWhiteSpace(env)) this.Network = env;
57+
}
58+
3859
/// <summary>
3960
/// Gets/sets the Docker API to use
4061
/// </summary>
4162
[DataMember(Order = 1, Name = "api"), JsonPropertyOrder(1), JsonPropertyName("api"), YamlMember(Order = 1, Alias = "api")]
4263
public virtual DockerApiConfiguration Api { get; set; } = new();
4364

4465
/// <summary>
45-
/// Gets/sets the name of the image repository to use when pulling the runtime's container image
66+
/// Gets/sets the name of the image registry to use when pulling the runtime's container image
4667
/// </summary>
47-
[DataMember(Order = 2, Name = "imageRepository"), JsonPropertyOrder(2), JsonPropertyName("imageRepository"), YamlMember(Order = 2, Alias = "imageRepository")]
48-
public virtual string? ImageRepository { get; set; }
68+
[DataMember(Order = 2, Name = "imageRegistry"), JsonPropertyOrder(2), JsonPropertyName("imageRegistry"), YamlMember(Order = 2, Alias = "imageRegistry")]
69+
public virtual string? ImageRegistry { get; set; }
4970

5071
/// <summary>
5172
/// Gets/sets the Docker image pull policy. Supported values are 'Always', 'IfNotPresent' and 'Never'. Defaults to 'Always'.

src/core/Synapse.Core/Resources/KubernetesRuntimeConfiguration.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ public record KubernetesRuntimeConfiguration
5252
}
5353
};
5454

55+
/// <summary>
56+
/// Initializes a new <see cref="KubernetesRuntimeConfiguration"/>
57+
/// </summary>
58+
public KubernetesRuntimeConfiguration()
59+
{
60+
var env = Environment.GetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Runtime.Kubernetes.Kubeconfig);
61+
if (!string.IsNullOrWhiteSpace(env)) this.Kubeconfig = env;
62+
env = Environment.GetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Runtime.Kubernetes.Secrets.VolumeName);
63+
if (!string.IsNullOrWhiteSpace(env)) this.Secrets.VolumeName = env;
64+
env = Environment.GetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Runtime.Kubernetes.Secrets.MountPath);
65+
if (!string.IsNullOrWhiteSpace(env)) this.Secrets.MountPath = env;
66+
}
67+
5568
/// <summary>
5669
/// Gets/sets the path to the Kubeconfig file to use, if any. If not set, defaults to 'InCluster' configuration
5770
/// </summary>
@@ -76,7 +89,7 @@ public record KubernetesRuntimeConfiguration
7689
/// <returns>The runner container template</returns>
7790
public static V1Pod LoadPodTemplate()
7891
{
79-
var templateFilePath = Environment.GetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Runtime.Docker.Container);
92+
var templateFilePath = Environment.GetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Runtime.Kubernetes.Pod);
8093
if (string.IsNullOrWhiteSpace(templateFilePath) || !File.Exists(templateFilePath)) return DefaultPodTemplate;
8194
var yaml = File.ReadAllText(templateFilePath);
8295
return YamlSerializer.Default.Deserialize<V1Pod>(yaml)!;

src/core/Synapse.Core/Resources/KubernetesRuntimeSecretsConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public record KubernetesRuntimeSecretsConfiguration
3030
public const string DefaultMountPath = "/run/secrets/synapse";
3131

3232
/// <summary>
33-
/// Gets/sets the name on which to mounts secrets
33+
/// Gets/sets the name of the volume on which to mounts secrets
3434
/// </summary>
3535
[DataMember(Order = 1, Name = "volumeName"), JsonPropertyOrder(1), JsonPropertyName("volumeName"), YamlMember(Order = 1, Alias = "volumeName")]
3636
public virtual string VolumeName { get; set; } = DefaultVolumeName;

src/core/Synapse.Core/SynapseDefaults.cs

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,125 @@ public static class Docker
585585
/// Gets the prefix for all Docker runtime related environment variables
586586
/// </summary>
587587
public const string Prefix = Runtime.Prefix + "DOCKER_";
588+
588589
/// <summary>
589590
/// Gets the environment variable used to specify the YAML file used to configure the Docker runner container
590591
/// </summary>
591592
public const string Container = Prefix + "CONTAINER";
593+
/// <summary>
594+
/// Gets the environment variable used to configure the network runner containers should be connected to
595+
/// </summary>
596+
public const string Network = Prefix + "NETWORK";
597+
598+
/// <summary>
599+
/// Exposes constants about environment variables used to configure the API of a Docker runtime
600+
/// </summary>
601+
public static class Api
602+
{
603+
604+
/// <summary>
605+
/// Gets the prefix for all Docker runtime API related environment variables
606+
/// </summary>
607+
public const string Prefix = Docker.Prefix + "API_";
608+
609+
/// <summary>
610+
/// Gets the environment variable used to configure the endpoint of the Docker API to use
611+
/// </summary>
612+
public const string Endpoint = Prefix + "ENDPOINT";
613+
/// <summary>
614+
/// Gets the environment variable used to configure the version of the Docker API to use
615+
/// </summary>
616+
public const string Version = Prefix + "VERSION";
617+
618+
}
619+
620+
/// <summary>
621+
/// Exposes constants about environment variables used to configure the runner images of a Docker runtime
622+
/// </summary>
623+
public static class Image
624+
{
625+
626+
/// <summary>
627+
/// Gets the prefix for all Docker runtime image related environment variables
628+
/// </summary>
629+
public const string Prefix = Docker.Prefix + "IMAGE_";
630+
631+
/// <summary>
632+
/// Gets the environment variable used to configure the image registry to use when pulling runner images
633+
/// </summary>
634+
public const string Registry = Prefix + "REGISTRY";
635+
/// <summary>
636+
/// Gets the environment variable used to configure the policy to use when pulling runner images
637+
/// </summary>
638+
public const string PullPolicy = Prefix + "PULL_POLICY";
639+
640+
}
641+
642+
/// <summary>
643+
/// Exposes constants about environment variables used to configure the secrets used by a Docker runtime
644+
/// </summary>
645+
public static class Secrets
646+
{
647+
648+
/// <summary>
649+
/// Gets the prefix for all Docker runtime secrets related environment variables
650+
/// </summary>
651+
public const string Prefix = Docker.Prefix + "SECRETS_";
652+
653+
/// <summary>
654+
/// Gets the environment variable used to configure the directory that contains the secrets to mount onto runner containers
655+
/// </summary>
656+
public const string Directory = Prefix + "DIRECTORY";
657+
/// <summary>
658+
/// Gets the environment variable used to configure the directory to mount the secrets volume to
659+
/// </summary>
660+
public const string MountPath = Prefix + "MOUNT_PATH";
661+
662+
}
663+
664+
}
665+
666+
/// <summary>
667+
/// Exposes constants about Kubernetes runtime-related environment variables
668+
/// </summary>
669+
public static class Kubernetes
670+
{
671+
672+
/// <summary>
673+
/// Gets the prefix for all Kubernetes runtime related environment variables
674+
/// </summary>
675+
public const string Prefix = Runtime.Prefix + "K8S_";
676+
677+
/// <summary>
678+
/// Gets the environment variable used to configure the path to the Kubeconfig file to use
679+
/// </summary>
680+
public const string Kubeconfig = Prefix + "KUBECONFIG";
681+
/// <summary>
682+
/// Gets the environment variable used to specify the YAML file used to configure the Kubernetes runner pod
683+
/// </summary>
684+
public const string Pod = Prefix + "POD";
685+
686+
/// <summary>
687+
/// Exposes constants about environment variables used to configure the secrets used by a Docker runtime
688+
/// </summary>
689+
public static class Secrets
690+
{
691+
692+
/// <summary>
693+
/// Gets the prefix for all Kubernetes runtime secrets related environment variables
694+
/// </summary>
695+
public const string Prefix = Kubernetes.Prefix + "SECRETS_";
696+
697+
/// <summary>
698+
/// Gets the environment variable used to configure the name of the volume onto which to mount secrets
699+
/// </summary>
700+
public const string VolumeName = Prefix + "VOLUME_NAME";
701+
/// <summary>
702+
/// Gets the environment variable used to configure the directory to mount the secrets volume to
703+
/// </summary>
704+
public const string MountPath = Prefix + "MOUNT_PATH";
705+
706+
}
592707

593708
}
594709

@@ -672,7 +787,7 @@ public static class Images
672787
/// <summary>
673788
/// Gets the current version of Synapse container images
674789
/// </summary>
675-
public static string Version = typeof(SynapseDefaults).Assembly.GetName().Version?.ToString(3) ?? "latest";
790+
public static readonly string Version = typeof(SynapseDefaults).Assembly.GetName().Version?.ToString(3) ?? "latest";
676791
/// <summary>
677792
/// Gets the name of the Synapse API container image
678793
/// </summary>
@@ -688,7 +803,7 @@ public static class Images
688803
/// <summary>
689804
/// Gets the name of the Synapse Runner container image
690805
/// </summary>
691-
public static readonly string Runner = $"{ImageRegistry}/runner:{Version}";
806+
public static readonly string Runner = $"{ImageRegistry}/runner:latest"; //todo: $"{ImageRegistry}/runner:{Version}";
692807

693808
}
694809

0 commit comments

Comments
 (0)