Skip to content

Commit b44968d

Browse files
committed
feat: basic auth, headers in serverless config
1 parent f7750cd commit b44968d

File tree

28 files changed

+293
-42
lines changed

28 files changed

+293
-42
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/openapi.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/common/api-types/src/runners/list.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use rivet_util::Id;
21
use serde::{Deserialize, Serialize};
32
use utoipa::{IntoParams, ToSchema};
43

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use schemars::JsonSchema;
2+
use serde::{Deserialize, Serialize};
3+
4+
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
5+
#[serde(deny_unknown_fields)]
6+
pub struct Auth {
7+
pub admin_token: String,
8+
}
9+
10+
impl Default for Auth {
11+
fn default() -> Self {
12+
Auth {
13+
admin_token: "admin".to_string(),
14+
}
15+
}
16+
}

packages/common/config/src/config/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::sync::LazyLock;
55

66
pub mod api_peer;
77
pub mod api_public;
8+
pub mod auth;
89
pub mod cache;
910
pub mod clickhouse;
1011
pub mod db;
@@ -17,6 +18,7 @@ pub mod vector;
1718

1819
pub use api_peer::*;
1920
pub use api_public::*;
21+
pub use auth::*;
2022
pub use cache::*;
2123
pub use clickhouse::*;
2224
pub use db::Database;
@@ -58,6 +60,9 @@ pub use vector::*;
5860
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
5961
#[serde(rename_all = "snake_case", deny_unknown_fields)]
6062
pub struct Root {
63+
#[serde(default)]
64+
pub auth: Option<Auth>,
65+
6166
#[serde(default)]
6267
pub guard: Option<Guard>,
6368

@@ -95,6 +100,7 @@ pub struct Root {
95100
impl Default for Root {
96101
fn default() -> Self {
97102
Root {
103+
auth: None,
98104
guard: None,
99105
api_public: None,
100106
api_peer: None,

packages/common/types/src/namespaces.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::collections::HashMap;
2+
13
use gas::prelude::*;
24
use utoipa::ToSchema;
35

@@ -9,11 +11,12 @@ pub struct Namespace {
911
pub create_ts: i64,
1012
}
1113

12-
#[derive(Debug, Clone, Serialize, Deserialize, Hash, ToSchema)]
14+
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
1315
#[serde(rename_all = "snake_case")]
1416
pub enum RunnerConfig {
1517
Serverless {
1618
url: String,
19+
headers: HashMap<String, String>,
1720
/// Seconds.
1821
request_lifespan: u32,
1922
slots_per_runner: u32,
@@ -28,6 +31,7 @@ impl From<RunnerConfig> for rivet_data::generated::namespace_runner_config_v1::D
2831
match value {
2932
RunnerConfig::Serverless {
3033
url,
34+
headers,
3135
request_lifespan,
3236
slots_per_runner,
3337
min_runners,
@@ -36,6 +40,7 @@ impl From<RunnerConfig> for rivet_data::generated::namespace_runner_config_v1::D
3640
} => rivet_data::generated::namespace_runner_config_v1::Data::Serverless(
3741
rivet_data::generated::namespace_runner_config_v1::Serverless {
3842
url,
43+
headers: headers.into(),
3944
request_lifespan,
4045
slots_per_runner,
4146
min_runners,
@@ -53,6 +58,7 @@ impl From<rivet_data::generated::namespace_runner_config_v1::Data> for RunnerCon
5358
rivet_data::generated::namespace_runner_config_v1::Data::Serverless(o) => {
5459
RunnerConfig::Serverless {
5560
url: o.url,
61+
headers: o.headers.into(),
5662
request_lifespan: o.request_lifespan,
5763
slots_per_runner: o.slots_per_runner,
5864
min_runners: o.min_runners,

packages/core/api-peer/src/runner_configs.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use anyhow::Result;
44
use namespace::utils::runner_config_variant;
55
use rivet_api_builder::ApiCtx;
66
use rivet_api_types::pagination::Pagination;
7-
use rivet_util::Id;
87
use serde::{Deserialize, Serialize};
98
use utoipa::{IntoParams, ToSchema};
109

packages/core/api-public/src/actors/create.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ use axum::{
44
http::HeaderMap,
55
response::{IntoResponse, Json, Response},
66
};
7-
use rivet_api_builder::{ApiCtx, ApiError};
7+
use rivet_api_builder::ApiError;
88
use rivet_api_types::actors::create::{CreateRequest, CreateResponse};
99
use rivet_api_util::request_remote_datacenter;
10-
use rivet_types::actors::CrashPolicy;
1110
use serde::{Deserialize, Serialize};
1211
use utoipa::IntoParams;
1312

13+
use crate::ctx::ApiCtx;
14+
1415
#[derive(Debug, Serialize, Deserialize, IntoParams)]
1516
#[serde(deny_unknown_fields)]
1617
#[into_params(parameter_in = Query)]
@@ -63,6 +64,8 @@ async fn create_inner(
6364
query: CreateQuery,
6465
body: CreateRequest,
6566
) -> Result<CreateResponse> {
67+
ctx.skip_auth();
68+
6669
// Determine which datacenter to create the actor in
6770
let target_dc_label = if let Some(dc_name) = &query.datacenter {
6871
ctx.config()
@@ -78,7 +81,7 @@ async fn create_inner(
7881
};
7982

8083
if target_dc_label == ctx.config().dc_label() {
81-
rivet_api_peer::actors::create::create(ctx, (), query, body).await
84+
rivet_api_peer::actors::create::create(ctx.into(), (), query, body).await
8285
} else {
8386
request_remote_datacenter::<CreateResponse>(
8487
ctx.config(),

packages/core/api-public/src/actors/delete.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ use axum::{
44
http::HeaderMap,
55
response::{IntoResponse, Json, Response},
66
};
7-
use rivet_api_builder::{ApiCtx, ApiError};
7+
use rivet_api_builder::ApiError;
88
use rivet_api_util::request_remote_datacenter_raw;
99
use rivet_util::Id;
1010
use serde::{Deserialize, Serialize};
1111
use utoipa::{IntoParams, ToSchema};
1212

13+
use crate::ctx::ApiCtx;
14+
1315
#[derive(Debug, Deserialize, Serialize, IntoParams)]
1416
#[serde(deny_unknown_fields)]
1517
#[into_params(parameter_in = Query)]
@@ -62,14 +64,16 @@ async fn delete_inner(
6264
path: DeletePath,
6365
query: DeleteQuery,
6466
) -> Result<Response> {
67+
ctx.auth().await?;
68+
6569
if path.actor_id.label() == ctx.config().dc_label() {
6670
let peer_path = rivet_api_peer::actors::delete::DeletePath {
6771
actor_id: path.actor_id,
6872
};
6973
let peer_query = rivet_api_peer::actors::delete::DeleteQuery {
7074
namespace: query.namespace,
7175
};
72-
let res = rivet_api_peer::actors::delete::delete(ctx, peer_path, peer_query).await?;
76+
let res = rivet_api_peer::actors::delete::delete(ctx.into(), peer_path, peer_query).await?;
7377

7478
Ok(Json(res).into_response())
7579
} else {

packages/core/api-public/src/actors/get_or_create.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ use axum::{
44
http::HeaderMap,
55
response::{IntoResponse, Json, Response},
66
};
7-
use rivet_api_builder::{ApiCtx, ApiError};
7+
use rivet_api_builder::ApiError;
88
use rivet_types::actors::CrashPolicy;
99
use rivet_util::Id;
1010
use serde::{Deserialize, Serialize};
1111
use utoipa::{IntoParams, ToSchema};
1212

1313
use crate::actors::utils;
14+
use crate::ctx::ApiCtx;
1415
use crate::errors;
1516

1617
#[derive(Debug, Deserialize, IntoParams)]
@@ -91,6 +92,8 @@ async fn get_or_create_inner(
9192
query: GetOrCreateQuery,
9293
body: GetOrCreateRequest,
9394
) -> Result<GetOrCreateResponse> {
95+
ctx.skip_auth();
96+
9497
// Resolve namespace
9598
let namespace = ctx
9699
.op(namespace::ops::resolve_for_name_global::Input {

0 commit comments

Comments
 (0)