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

Add gateway authentication #1067

Open
wants to merge 152 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 140 commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
8281475
Start with identity providers
afsalthaj Nov 14, 2024
3e0fa04
Add session store for gateway to manage CSRF attacks
afsalthaj Nov 14, 2024
be5877f
Fix async in gateway
afsalthaj Nov 14, 2024
ec34aac
Finish auth gateway
afsalthaj Nov 14, 2024
54584df
Add async
afsalthaj Nov 14, 2024
ae0db84
Add gateway auth
afsalthaj Nov 14, 2024
c008e66
Add to_response
afsalthaj Nov 14, 2024
736c191
Add security scheme
afsalthaj Nov 14, 2024
c58502d
Add comments
afsalthaj Nov 15, 2024
7859230
Reformat code
afsalthaj Nov 15, 2024
ba7eb81
Reformat code
afsalthaj Nov 15, 2024
e7e84df
Add auth workflow
afsalthaj Nov 15, 2024
f548319
Introduce middleware in and out
afsalthaj Nov 15, 2024
1dce158
Add middleware transformation once and for all
afsalthaj Nov 15, 2024
f37a883
Add middleware input
afsalthaj Nov 15, 2024
c221a56
Add middleware in
afsalthaj Nov 15, 2024
3a05c4b
Add full workflow
afsalthaj Nov 15, 2024
ffcfc11
Static binding
afsalthaj Nov 15, 2024
27d3882
Add middleware input
afsalthaj Nov 15, 2024
95c61b1
Reformat code
afsalthaj Nov 15, 2024
7c4b17e
Start fixing compile time errors
afsalthaj Nov 15, 2024
379ad2e
Apply middlewares
afsalthaj Nov 16, 2024
4ee964a
Start fixing compile time errors
afsalthaj Nov 16, 2024
d8ffb51
Make redirect or continue
afsalthaj Nov 16, 2024
da5773f
Make redirect or continue
afsalthaj Nov 16, 2024
a679ec3
Add evaluation error
afsalthaj Nov 16, 2024
4cf7509
Make redirects easier without clones
afsalthaj Nov 16, 2024
75396e5
Fix all compiler errors
afsalthaj Nov 16, 2024
576819e
Make sure cargo build works
afsalthaj Nov 16, 2024
b97ed1b
Remove the confusing security scheme internal
afsalthaj Nov 16, 2024
373106e
Add auth call back data
afsalthaj Nov 16, 2024
38803d4
Remove expect
afsalthaj Nov 16, 2024
c263f8d
Integrate with oas
afsalthaj Nov 17, 2024
1c319c8
Start fixing grpc and other wirings
afsalthaj Nov 17, 2024
60ecf0a
Start fixing more errors
afsalthaj Nov 17, 2024
4b2a42f
Integrate openapi with http api request
afsalthaj Nov 18, 2024
2b98fff
Add security method
afsalthaj Nov 18, 2024
600642e
Add gateway binding type
afsalthaj Nov 18, 2024
a24ebb3
Reformat code
afsalthaj Nov 18, 2024
02195f8
Start fixing
afsalthaj Nov 18, 2024
c1c1365
Fix imports
afsalthaj Nov 18, 2024
8e16e19
Fix all existing tests
afsalthaj Nov 18, 2024
f3323be
Fix end to end tests
afsalthaj Nov 18, 2024
3ed985a
Use boxed static binding
afsalthaj Nov 18, 2024
c90ddf0
Fix service tests
afsalthaj Nov 18, 2024
fc3bc60
Fix service tests
afsalthaj Nov 18, 2024
7f7195f
Use boxed type for static binding
afsalthaj Nov 18, 2024
9627d8e
Use boxed type for large enums
afsalthaj Nov 18, 2024
036fe2d
Start applying clippy
afsalthaj Nov 18, 2024
3edf067
Add testing
afsalthaj Nov 18, 2024
0391533
Use transformations
afsalthaj Nov 18, 2024
f77368a
Add transformer
afsalthaj Nov 18, 2024
3f2b398
Add transformer
afsalthaj Nov 18, 2024
1bfc332
Add bettertransformations
afsalthaj Nov 18, 2024
b1cac5c
Remove extra lines
afsalthaj Nov 18, 2024
4f5c54b
Add auth endpoints
afsalthaj Nov 18, 2024
4a4130d
Add auth transformations
afsalthaj Nov 18, 2024
e9487b9
Fix lambda
afsalthaj Nov 18, 2024
741cba2
Add auth transformations
afsalthaj Nov 18, 2024
3ac0689
Make sure only global variable is required for OAS version and avoid …
afsalthaj Nov 18, 2024
aad6398
Fix worker service
afsalthaj Nov 18, 2024
0660b7e
Provider
afsalthaj Nov 19, 2024
306f44a
Dynamic dispatch to identity provider
afsalthaj Nov 19, 2024
111c950
Fix base
afsalthaj Nov 19, 2024
bec3dd3
Add security scheme API
afsalthaj Nov 20, 2024
71910c1
Add security scheme API
afsalthaj Nov 20, 2024
9e572cb
Cleanup
afsalthaj Nov 20, 2024
c25901f
Cleanup
afsalthaj Nov 20, 2024
cf621b2
Add security scheme API
afsalthaj Nov 20, 2024
8058a55
Use readable type parameter
afsalthaj Nov 20, 2024
4fe8071
Add security scheme repo
afsalthaj Nov 21, 2024
0c0d81d
Add repo
afsalthaj Nov 21, 2024
48976f0
Add logged with id
afsalthaj Nov 21, 2024
68999d6
Add auth
afsalthaj Nov 21, 2024
2e57f45
Add security scheme service
afsalthaj Nov 21, 2024
8c0b931
Add security scheme service
afsalthaj Nov 21, 2024
c2d53fc
Merge branch 'main' into add_gateway_auth
afsalthaj Nov 21, 2024
42c1141
Resolve conflicts
afsalthaj Nov 21, 2024
23f2c91
Resolve conflicts
afsalthaj Nov 21, 2024
b5c4d9c
Resolve conflicts
afsalthaj Nov 21, 2024
88660af
Add security tests
afsalthaj Nov 21, 2024
8ad47e2
Add test provider metadata
afsalthaj Nov 21, 2024
0347fe4
Add test provider metadata
afsalthaj Nov 21, 2024
adfa904
Add test provider metadata
afsalthaj Nov 22, 2024
b5eae26
Use testable identity provider resolver
afsalthaj Nov 22, 2024
a619d15
Resolve conflicts
afsalthaj Nov 22, 2024
c991617
Add TestIdentityProvider
afsalthaj Nov 22, 2024
7859450
Add tests
afsalthaj Nov 22, 2024
9383b84
Add tests
afsalthaj Nov 22, 2024
b31b0a0
Add gateway binding tests
afsalthaj Nov 22, 2024
459d5c9
Add gateway binding tests
afsalthaj Nov 22, 2024
fa89f32
Add end to end tests
afsalthaj Nov 22, 2024
4ee2b27
Add end to end tests
afsalthaj Nov 22, 2024
78e97e9
Reformat code
afsalthaj Nov 22, 2024
786c4a1
Add safer mecahnism in api definition lookup
afsalthaj Nov 24, 2024
4a7bb20
Add safer lookup
afsalthaj Nov 24, 2024
469d5f8
Start fixing tests
afsalthaj Nov 24, 2024
98a8440
Start fixing tests
afsalthaj Nov 24, 2024
2aa905f
Fix bug on redirect url transformation
afsalthaj Nov 24, 2024
4ffb99c
Use own public key private key
afsalthaj Nov 24, 2024
7aef567
Make sure to verify state and nonce
afsalthaj Nov 25, 2024
23eac45
Make sure auth call back endpoint is tested
afsalthaj Nov 25, 2024
3895b4d
Add security
afsalthaj Nov 25, 2024
370c42a
Add cookie and session info
afsalthaj Nov 25, 2024
9c4a87c
Make sure to pass tests
afsalthaj Nov 25, 2024
cb449af
Fix clippy
afsalthaj Nov 25, 2024
bba0373
Reformat code
afsalthaj Nov 25, 2024
bdeaec6
Add full workflow test
afsalthaj Nov 25, 2024
db69227
Renamings
afsalthaj Nov 25, 2024
ef442e5
Add gateway testing
afsalthaj Nov 25, 2024
b98fc69
Add expiry tests
afsalthaj Nov 25, 2024
c6b8370
Make sure expired token tests work
afsalthaj Nov 25, 2024
352455b
Make sure expired token tests work
afsalthaj Nov 25, 2024
532ffef
Add test response
afsalthaj Nov 25, 2024
917a09f
Clean up tests
afsalthaj Nov 25, 2024
fc1f577
Add test response
afsalthaj Nov 25, 2024
1fcc8f4
Renamings
afsalthaj Nov 25, 2024
968dba8
Better typesafety (#1086)
afsalthaj Nov 26, 2024
66ef880
Merge branch 'main' into add_gateway_auth
afsalthaj Nov 26, 2024
a5559c8
Fix all tests
afsalthaj Nov 26, 2024
b32b379
Fix all tests
afsalthaj Nov 26, 2024
94e42c3
Fix all tests
afsalthaj Nov 26, 2024
e3d7914
Reformat
afsalthaj Nov 26, 2024
7d9f4b9
Reformat
afsalthaj Nov 26, 2024
c875ed8
Add eviction strategy
afsalthaj Nov 26, 2024
3fd03ac
Fix
afsalthaj Nov 26, 2024
61f4ba0
Merge branch 'main' into add_gateway_auth
afsalthaj Nov 26, 2024
ebfc776
Fix cargo lock
afsalthaj Nov 26, 2024
774241e
Add golem cli
afsalthaj Nov 26, 2024
9a409d2
Update golem cli
afsalthaj Nov 27, 2024
3794822
Update golem cli
afsalthaj Nov 27, 2024
0432042
Update golem cli
afsalthaj Nov 27, 2024
ab2e28c
Update golem cli
afsalthaj Nov 27, 2024
88b213d
Propagate session information
afsalthaj Nov 27, 2024
91a82cd
Add a test for auth.email
afsalthaj Nov 27, 2024
276f1b3
Remove redundant dependencies
afsalthaj Nov 27, 2024
c2a5bcf
Session expiry test
afsalthaj Nov 27, 2024
54f42bd
Merge branch 'main' into add_gateway_auth
afsalthaj Nov 27, 2024
10fa557
Fix conflicts
afsalthaj Nov 27, 2024
1ff0c99
Make same site strict
afsalthaj Nov 27, 2024
85ded9d
Fix inmemory`
afsalthaj Nov 28, 2024
50592bb
Remove identity provider resolver
afsalthaj Nov 28, 2024
49f4164
Make transformers top level functions
afsalthaj Nov 29, 2024
062139e
Remove http middleware in and out
afsalthaj Nov 29, 2024
d100fda
Merge branch 'main' into add_gateway_auth
afsalthaj Nov 29, 2024
d6e6792
Use middleware error instead of out and in
afsalthaj Nov 29, 2024
7fe3717
Add redis backend (#1094)
afsalthaj Nov 29, 2024
50d3de5
Add prepend gateway_session
afsalthaj Nov 29, 2024
53b56f8
Reformat
afsalthaj Nov 29, 2024
c3d7de3
Update configs
afsalthaj Nov 29, 2024
89eb978
Move to workspace
afsalthaj Nov 30, 2024
85399c3
Update golem examples
afsalthaj Nov 30, 2024
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
243 changes: 235 additions & 8 deletions Cargo.lock

Large diffs are not rendered by default.

52 changes: 48 additions & 4 deletions golem-api-grpc/proto/golem/apidefinition/api_definition.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ message HttpApiDefinition {
repeated HttpRoute routes = 1;
}

// Used in api definition repo and needs to be backward compatible
message SecuritySchemeReference {
string security_scheme_identifier = 1;
}

// Used in api definition repo and needs to be backward compatible
message CompiledHttpApiDefinition {
repeated CompiledHttpRoute routes = 1;
Expand All @@ -46,13 +51,15 @@ message HttpRoute {
HttpMethod method = 1;
string path = 2;
GatewayBinding binding = 3;
Middleware middleware = 4;
}

// Used in api definition repo and needs to be backward compatible
message CompiledHttpRoute {
HttpMethod method = 1;
string path = 2;
CompiledGatewayBinding binding = 3;
Middleware middleware = 4;
}

// Used in api definition repo and needs to be backward compatible
Expand All @@ -79,7 +86,6 @@ message GatewayBinding {
// type discriminator to keep backward compatibility
optional GatewayBindingType binding_type = 5;
optional StaticBinding static_binding = 6;
optional Middleware middleware = 7;
}

// Used in api definition repo and needs to be backward compatible
Expand All @@ -99,8 +105,10 @@ message CompiledGatewayBinding {
// type discriminator to keep backward compatibility
optional GatewayBindingType binding_type = 12;
optional StaticBinding static_binding = 13;
// middleware
optional Middleware middleware = 14;
}

message SecuritySchemaReference {
string security_scheme_identifier = 1;
}

// Used in api definition repo and needs to be backward compatible
Expand All @@ -113,15 +121,19 @@ enum GatewayBindingType {
// Used in api definition repo and needs to be backward compatible
message Middleware {
optional CorsPreflight cors = 1;
optional SecurityWithProviderMetadata http_authentication = 2;
}

// Used in api definition repo and needs to be backward compatible
message StaticBinding {
oneof static_binding {
CorsPreflight http_cors_preflight = 1;
AuthCallBack auth_callback = 2;
}
}

message AuthCallBack {}

// Used in api definition repo and needs to be backward compatible
message CorsPreflight {
optional string allow_origin = 1;
Expand All @@ -130,4 +142,36 @@ message CorsPreflight {
optional string expose_headers = 4;
optional uint64 max_age = 5;
optional bool allow_credentials = 6;
}
}

message SecurityWithProviderMetadata {
SecurityScheme security_scheme = 1;
IdentityProviderMetadata identity_provider_metadata = 2;
}

message SecurityScheme {
Provider provider = 1;
string scheme_identifier = 2;
string client_id = 3;
string client_secret = 4;
string redirect_url = 5;
repeated string scopes = 6;
}

message Provider {
oneof provider {
Google google = 1;
Facebook facebook = 2;
Microsoft microsoft = 3;
Gitlab gitlab = 4;
}
}

message Google{}
message Facebook{}
message Microsoft{}
message Gitlab{}

message IdentityProviderMetadata {
string metadata = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ message ApiDefinitionError {
}

message RouteValidationErrorsBody {
repeated RouteValidationError errors = 1;
repeated string errors = 1;
}

message RouteValidationError {
Expand Down
1 change: 1 addition & 0 deletions golem-cli/src/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

pub mod api_definition;
pub mod api_deployment;
pub mod api_security;
pub mod component;
pub mod file_download;
pub mod health_check;
Expand Down
12 changes: 6 additions & 6 deletions golem-cli/src/clients/api_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::model::{
ApiDefinitionFileFormat, ApiDefinitionId, ApiDefinitionVersion, GolemError, PathBufOrStdin,
};
use async_trait::async_trait;
use golem_client::model::HttpApiDefinitionWithTypeInfo;
use golem_client::model::HttpApiDefinitionResponseData;

#[async_trait]
pub trait ApiDefinitionClient {
Expand All @@ -26,31 +26,31 @@ pub trait ApiDefinitionClient {
&self,
id: Option<&ApiDefinitionId>,
project: &Self::ProjectContext,
) -> Result<Vec<HttpApiDefinitionWithTypeInfo>, GolemError>;
) -> Result<Vec<HttpApiDefinitionResponseData>, GolemError>;
async fn get(
&self,
id: ApiDefinitionId,
version: ApiDefinitionVersion,
project: &Self::ProjectContext,
) -> Result<HttpApiDefinitionWithTypeInfo, GolemError>;
) -> Result<HttpApiDefinitionResponseData, GolemError>;
async fn create(
&self,
path: PathBufOrStdin,
project: &Self::ProjectContext,
format: &ApiDefinitionFileFormat,
) -> Result<HttpApiDefinitionWithTypeInfo, GolemError>;
) -> Result<HttpApiDefinitionResponseData, GolemError>;
async fn update(
&self,
path: PathBufOrStdin,
project: &Self::ProjectContext,
format: &ApiDefinitionFileFormat,
) -> Result<HttpApiDefinitionWithTypeInfo, GolemError>;
) -> Result<HttpApiDefinitionResponseData, GolemError>;
async fn import(
&self,
path: PathBufOrStdin,
project: &Self::ProjectContext,
format: &ApiDefinitionFileFormat,
) -> Result<HttpApiDefinitionWithTypeInfo, GolemError>;
) -> Result<HttpApiDefinitionResponseData, GolemError>;
async fn delete(
&self,
id: ApiDefinitionId,
Expand Down
35 changes: 35 additions & 0 deletions golem-cli/src/clients/api_security.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2024 Golem Cloud
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::model::{ApiSecurityScheme, GolemError};
use async_trait::async_trait;
use golem_client::model::Provider;

#[async_trait]
pub trait ApiSecurityClient {
type ProjectContext;

async fn create(
&self,
id: String,
provider_type: Provider,
client_id: String,
client_secret: String,
scope: Vec<String>,
redirect_url: String,
project: &Self::ProjectContext,
) -> Result<ApiSecurityScheme, GolemError>;

async fn get(&self, id: &str) -> Result<ApiSecurityScheme, GolemError>;
}
1 change: 1 addition & 0 deletions golem-cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use golem_common::uri::oss::uri::ComponentUri;

pub mod api_definition;
pub mod api_deployment;
pub mod api_security;
pub mod component;
pub mod plugin;
pub mod profile;
Expand Down
95 changes: 95 additions & 0 deletions golem-cli/src/command/api_security.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright 2024 Golem Cloud
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::model::{GolemError, GolemResult, IdentityProviderType};
use crate::service::api_security::ApiSecuritySchemeService;
use crate::service::project::ProjectResolver;
use clap::Subcommand;

#[derive(Subcommand, Debug)]
#[command()]
pub enum ApiSecuritySchemeSubcommand<ProjectRef: clap::Args> {
/// Create or update deployment
#[command()]
Create {
/// The newly created component's owner project
#[command(flatten)]
project_ref: ProjectRef,

/// Api definition id with version
#[arg(short = 'i', long = "scheme.id")]
id: String,

#[arg(short = 'p', long = "provider.type")]
provider_type: IdentityProviderType,

#[arg(long = "client.id")]
client_id: String,

#[arg(long = "client.secret")]
client_secret: String,

#[arg(short = 's', long = "scopes")]
scopes: Vec<String>,

#[arg(short = 'r', long = "redirect.url")]
redirect_url: String,
},

/// Get api security
#[command()]
Get {
/// The newly created component's owner project
#[command(flatten)]
project_ref: ProjectRef,

/// Security Scheme Id
#[arg(value_name = "scheme.id")]
id: String,
},
}

impl<ProjectRef: clap::Args + Send + Sync + 'static> ApiSecuritySchemeSubcommand<ProjectRef> {
pub async fn handle<ProjectContext>(
self,
service: &(dyn ApiSecuritySchemeService<ProjectContext = ProjectContext> + Send + Sync),
projects: &(dyn ProjectResolver<ProjectRef, ProjectContext> + Send + Sync),
) -> Result<GolemResult, GolemError> {
match self {
ApiSecuritySchemeSubcommand::Create {
project_ref,
id,
provider_type,
client_id,
client_secret,
scopes,
redirect_url,
} => {
let project_id = projects.resolve_id_or_default(project_ref).await?;
service
.create(
id,
provider_type.into(),
client_id,
client_secret,
scopes,
redirect_url,
&project_id,
)
.await
}
ApiSecuritySchemeSubcommand::Get { id, .. } => service.get(id).await,
}
}
}
18 changes: 18 additions & 0 deletions golem-cli/src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::clients::plugin::PluginClient;
use crate::clients::worker::WorkerClient;
use crate::service::api_definition::{ApiDefinitionService, ApiDefinitionServiceLive};
use crate::service::api_deployment::{ApiDeploymentService, ApiDeploymentServiceLive};
use crate::service::api_security::{ApiSecuritySchemeService, ApiSecuritySchemeServiceLive};
use crate::service::component::{ComponentService, ComponentServiceLive};
use crate::service::deploy::{DeployService, DeployServiceLive};
use crate::service::project::ProjectResolver;
Expand Down Expand Up @@ -94,6 +95,23 @@ pub trait ServiceFactory {
})
}

fn api_security_scheme_client(
&self,
) -> Box<
dyn crate::clients::api_security::ApiSecurityClient<ProjectContext = Self::ProjectContext>
+ Send
+ Sync,
>;

fn api_security_scheme_service(
&self,
) -> Arc<dyn ApiSecuritySchemeService<ProjectContext = Self::ProjectContext> + Send + Sync>
{
Arc::new(ApiSecuritySchemeServiceLive {
client: self.api_security_scheme_client(),
})
}

fn health_check_clients(&self) -> Vec<Arc<dyn HealthCheckClient + Send + Sync>>;

fn version_service(&self) -> Arc<dyn VersionService + Send + Sync> {
Expand Down
8 changes: 8 additions & 0 deletions golem-cli/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use crate::command::api_definition::ApiDefinitionSubcommand;
use crate::command::api_deployment::ApiDeploymentSubcommand;
use crate::command::api_security::ApiSecuritySchemeSubcommand;
use crate::command::component::ComponentSubCommand;
use crate::command::plugin::PluginSubcommand;
use crate::command::profile::{ProfileSubCommand, UniversalProfileAdd};
Expand Down Expand Up @@ -107,6 +108,13 @@ pub enum InitCommand<ProfileAdd: clap::Args> {
subcommand: ApiDeploymentSubcommand<OssContext>,
},

// Manage Api Security Schemes
#[command()]
ApiSecurityScheme {
#[command(subcommand)]
subcommand: ApiSecuritySchemeSubcommand<OssContext>,
},

/// Manage plugins
#[command()]
Plugin {
Expand Down
Loading