Skip to content

Commit

Permalink
fix: fix port auth sql (#1296)
Browse files Browse the repository at this point in the history
<!-- Please make sure there is an issue that this PR is correlated to. -->
**Manually tested**
Fixes RVT-3887
## Changes

<!-- If there are frontend changes, please include screenshots. -->
  • Loading branch information
MasterPtato committed Oct 31, 2024
1 parent 472c54f commit 688f76a
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ pub async fn build_ds(
gg.port_name,
gg.protocol,
gga.auth_type,
gga.auth_key,
gga.auth_value
gga.key AS auth_key,
gga.value AS auth_value
FROM db_ds.server_proxied_ports AS pp
JOIN db_ds.servers AS s
ON pp.server_id = s.server_id
Expand Down
2 changes: 1 addition & 1 deletion packages/api/traefik-provider/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const CDN_POLL_INTERVAL: Duration = Duration::from_millis(500);
static GLOBAL_INIT: Once = Once::new();

const API_TRAEFIK_PROVIDER_URL: &str =
"http://rivet-api-internal.rivet-service.svc.cluster.local/traefik-provider";
"http://rivet-api-edge.rivet-service.svc.cluster.local/traefik-provider";

struct Ctx {
op_ctx: OperationContext<()>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub mod traefik;
pub mod traffic_server;
pub mod vector;

pub const TUNNEL_API_INTERNAL_PORT: u16 = 5010;
pub const TUNNEL_API_EDGE_PORT: u16 = 5010;

pub fn common() -> String {
indoc!(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use chirp_workflow::prelude::*;

use super::TUNNEL_API_INTERNAL_PORT;
use super::TUNNEL_API_EDGE_PORT;

pub fn create_hook(tunnel_name: &str, initialize_immediately: bool) -> GlobalResult<String> {
let mut script =
Expand All @@ -17,8 +17,8 @@ pub fn fetch_info(server_token: &str) -> GlobalResult<String> {
Ok(include_str!("../files/rivet_fetch_info.sh")
.replace("__SERVER_TOKEN__", server_token)
.replace(
"__TUNNEL_API_INTERNAL_PORT__",
&TUNNEL_API_INTERNAL_PORT.to_string(),
"__TUNNEL_API_EDGE_PORT__",
&TUNNEL_API_EDGE_PORT.to_string(),
))
}

Expand All @@ -32,8 +32,8 @@ pub fn fetch_tls(
.replace("__NAME__", traefik_instance_name)
.replace("__SERVER_TOKEN__", server_token)
.replace(
"__TUNNEL_API_INTERNAL_PORT__",
&TUNNEL_API_INTERNAL_PORT.to_string(),
"__TUNNEL_API_EDGE_PORT__",
&TUNNEL_API_EDGE_PORT.to_string(),
)
.replace("__DATACENTER_ID__", &datacenter_id.to_string());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use indoc::formatdoc;
use super::{
ok_server::OK_SERVER_PORT,
vector::{TUNNEL_VECTOR_PORT, TUNNEL_VECTOR_TCP_JSON_PORT},
TUNNEL_API_INTERNAL_PORT,
TUNNEL_API_EDGE_PORT,
};

pub const TUNNEL_SERVICES: &[TunnelService] = &[
Expand All @@ -23,8 +23,8 @@ pub const TUNNEL_SERVICES: &[TunnelService] = &[
port: 5002,
},
TunnelService {
name: "api-internal",
port: TUNNEL_API_INTERNAL_PORT,
name: "api-edge",
port: TUNNEL_API_EDGE_PORT,
},
TunnelService {
name: "vector",
Expand Down Expand Up @@ -228,13 +228,13 @@ pub async fn gg_static_config(config: &rivet_config::Config) -> GlobalResult<Str
{
format!(
"http://127.0.0.1:{port}/traefik-provider/config/game-guard?token={token}&datacenter=___DATACENTER_ID___",
port = TUNNEL_API_INTERNAL_PORT,
port = TUNNEL_API_EDGE_PORT,
token = api_traefik_provider_token.read(),
)
} else {
format!(
"http://127.0.0.1:{port}/traefik-provider/config/game-guard?datacenter=___DATACENTER_ID___",
port = TUNNEL_API_INTERNAL_PORT,
port = TUNNEL_API_EDGE_PORT,
)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ PUBLIC_IP=$(ip -4 route get 1.0.0.0 | awk '{print $7; exit}')
response=$(
curl -f \
-H "Authorization: Bearer __SERVER_TOKEN__" \
"http://127.0.0.1:__TUNNEL_API_INTERNAL_PORT__/provision/servers/$PUBLIC_IP/info"
"http://127.0.0.1:__TUNNEL_API_EDGE_PORT__/provision/servers/$PUBLIC_IP/info"
)

# Fetch data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ while true; do
response=$(
curl -f \
-H "Authorization: Bearer __SERVER_TOKEN__" \
"http://127.0.0.1:__TUNNEL_API_INTERNAL_PORT__/provision/datacenters/__DATACENTER_ID__/tls"
"http://127.0.0.1:__TUNNEL_API_EDGE_PORT__/provision/datacenters/__DATACENTER_ID__/tls"
) && break || sleep 5
done
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CREATE TABLE server_ports_gg_auth (
server_id UUID NOT NULL,
port_name UUID NOT NULL,
port_name TEXT NOT NULL,
auth_type INT NOT NULL,
key TEXT,
value TEXT NOT NULL,
Expand Down
4 changes: 2 additions & 2 deletions packages/services/ds/src/ops/server/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ pub async fn ds_server_get(ctx: &OperationCtx, input: &Input) -> GlobalResult<Ou
p.gg_port,
p.protocol,
a.auth_type,
a.auth_key,
a.auth_value
a.key AS auth_key,
a.value AS auth_value
FROM db_ds.server_ports_gg AS p
LEFT JOIN db_ds.server_ports_gg_auth AS a
ON
Expand Down
11 changes: 8 additions & 3 deletions packages/services/ds/src/workflows/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ pub(crate) async fn insert_db(ctx: &ActivityCtx, input: &InsertDbInput) -> Globa
let input = input.clone();
let host_unnest = host_unnest.clone();
let gg_unnest = gg_unnest.clone();
let gg_auth_unnest = gg_auth_unnest.clone();

async move {
sql_execute!(
Expand Down Expand Up @@ -246,11 +247,11 @@ pub(crate) async fn insert_db(ctx: &ActivityCtx, input: &InsertDbInput) -> Globa
server_id,
port_name,
auth_type,
auth_key,
auth_value
key,
value
)
SELECT $1, t.*
FROM unnest($17, $18, $19, $20) AS t(port_name, auth_type, auth_key, auth_value)
FROM unnest($21, $22, $23, $24) AS t(port_name, auth_type, auth_key, auth_value)
RETURNING 1
)
SELECT 1
Expand All @@ -275,6 +276,10 @@ pub(crate) async fn insert_db(ctx: &ActivityCtx, input: &InsertDbInput) -> Globa
gg_unnest.port_numbers,
gg_unnest.protocols,
gg_unnest.gg_ports, // 20
gg_auth_unnest.port_names,
gg_auth_unnest.port_auth_types,
gg_auth_unnest.port_auth_keys,
gg_auth_unnest.port_auth_values, // 20
)
.await
}
Expand Down
3 changes: 3 additions & 0 deletions packages/services/ds/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl Setup {
internal_port: Some(8001),
routing: types::Routing::GameGuard {
protocol: types::GameGuardProtocol::Http,
authorization: types::PortAuthorization::None,
},
},
),
Expand All @@ -85,6 +86,7 @@ impl Setup {
internal_port: Some(8002),
routing: types::Routing::GameGuard {
protocol: types::GameGuardProtocol::Tcp,
authorization: types::PortAuthorization::None,
},
},
),
Expand All @@ -94,6 +96,7 @@ impl Setup {
internal_port: Some(8003),
routing: types::Routing::GameGuard {
protocol: types::GameGuardProtocol::Udp,
authorization: types::PortAuthorization::None,
},
},
),
Expand Down
1 change: 1 addition & 0 deletions packages/services/ds/tests/print_test_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ async fn print_test_data(ctx: TestCtx) {
internal_port: Some(28234),
routing: types::Routing::GameGuard {
protocol: types::GameGuardProtocol::Http,
authorization: types::PortAuthorization::None,
},
},
)]
Expand Down
5 changes: 3 additions & 2 deletions packages/services/ds/tests/server_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ async fn server_create(ctx: TestCtx) {
let ports = vec![(
"testing2".to_string(),
ds::workflows::server::Port {
internal_port: None,
internal_port: Some(28234),
routing: types::Routing::GameGuard {
protocol: types::GameGuardProtocol::Http,
authorization: types::PortAuthorization::None,
},
},
)]
Expand Down Expand Up @@ -124,7 +125,7 @@ async fn server_create(ctx: TestCtx) {
loop {
// Create a new client each time to prevent cache
let client = reqwest::Client::new();
let res = tokio::time::timeout(std::time::Duration::from_secs(2), async {
let res = tokio::time::timeout(std::time::Duration::from_secs(3), async {
client
.post(format!("http://{hostname}:{port}"))
.body(random_body.clone())
Expand Down
1 change: 1 addition & 0 deletions packages/services/ds/tests/server_drain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ async fn server_drain(ctx: TestCtx) {
internal_port: Some(28234),
routing: types::Routing::GameGuard {
protocol: types::GameGuardProtocol::Http,
authorization: types::PortAuthorization::None,
},
},
)]
Expand Down
1 change: 1 addition & 0 deletions packages/services/ds/tests/server_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ async fn server_get(ctx: TestCtx) {
internal_port: Some(28234),
routing: types::Routing::GameGuard {
protocol: types::GameGuardProtocol::Http,
authorization: types::PortAuthorization::None,
},
},
)]
Expand Down

0 comments on commit 688f76a

Please sign in to comment.