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

feat: Allow checking that the DNS configuration is correct #52

Merged
merged 40 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
d55f7f6
chore: Format OpenAPI description whitespaces
RemiBardon Jul 29, 2024
71cd8f0
docs(dns): WIP Add DNS routes to the OpenAPI description
RemiBardon Aug 3, 2024
b4f1455
wip: Add DNS instructions route
RemiBardon Aug 29, 2024
44dfc24
wip: Add DNS instructions route
RemiBardon Aug 31, 2024
8598933
chore: Update dependencies
RemiBardon Aug 31, 2024
ba223aa
feat: Pass all DNS setup tests
RemiBardon Aug 31, 2024
2ad8d0f
fix: Fix `task open-api-docs-ui`
RemiBardon Sep 2, 2024
ff25b2e
docs(dns): Add network config checking routes to the OpenAPI description
RemiBardon Sep 2, 2024
a1c1c94
chore: Remove outdated comment
RemiBardon Sep 2, 2024
800583d
fix: Update route according to OpenApi description
RemiBardon Sep 2, 2024
796cff3
chore: Specify the YAML schema to use in integration test files
RemiBardon Sep 2, 2024
94ec2ed
chore: Update `integration-test` to better run integration tests on a…
RemiBardon Sep 3, 2024
f073a53
chore: Update network config integration tests
RemiBardon Sep 3, 2024
62bc4f3
chore: Remove code related to running network checks integration tests
RemiBardon Sep 3, 2024
23a908f
wip: feat: Add routes to perform network checks
RemiBardon Oct 8, 2024
173f82a
fixup! wip: feat: Add routes to perform network checks
RemiBardon Oct 8, 2024
4ab04b6
fixup! wip: feat: Add routes to perform network checks
RemiBardon Oct 8, 2024
a4642b7
fixup! wip: feat: Add routes to perform network checks
RemiBardon Oct 8, 2024
fbb3d2a
fixup! wip: feat: Add routes to perform network checks
RemiBardon Oct 8, 2024
f64e44b
fixup! wip: feat: Add routes to perform network checks
RemiBardon Oct 8, 2024
2a0ca36
fixup! wip: feat: Add routes to perform network checks
RemiBardon Oct 8, 2024
faa1e71
fixup! wip: feat: Add routes to perform network checks
RemiBardon Oct 8, 2024
2b0f7da
fixup! wip: feat: Add routes to perform network checks
RemiBardon Oct 8, 2024
0b148f9
fixup! wip: feat: Add routes to perform network checks
RemiBardon Oct 8, 2024
0a968be
Merge branch 'master' into 2024-07-26-dns
RemiBardon Oct 8, 2024
1e1a909
feat: Add `GET /v1/pod/config/address` and document GET and PUT routes
RemiBardon Oct 9, 2024
b7bc184
chore: Remove useless import
RemiBardon Oct 9, 2024
322889d
fixup! feat: Add `GET /v1/pod/config/address` and document GET and PU…
RemiBardon Oct 9, 2024
2235d24
feat: Pevent non-admins from updating the Pod address
RemiBardon Oct 9, 2024
795aeaf
chore: Remove useless dependency
RemiBardon Oct 9, 2024
5138f44
chore: Fix doc comment
RemiBardon Oct 9, 2024
3a11310
chore: Fix doc comment
RemiBardon Oct 9, 2024
232f265
chore: Parse values in `SetPodAddressRequest`
RemiBardon Oct 9, 2024
563caec
chore: Simplify code
RemiBardon Oct 9, 2024
a99c3a2
chore: Rename macro
RemiBardon Oct 9, 2024
568f8a3
chore: Add macro
RemiBardon Oct 9, 2024
8d490d7
chore: Remove TODO
RemiBardon Oct 9, 2024
719057d
chore: Fix tests in `service` crate
RemiBardon Oct 10, 2024
a6a276c
docs: Fix response types of route `/v1/network/dns/records`
RemiBardon Oct 13, 2024
143592e
feat: Use the DNS configuration from `/etc/resolv.conf` instead of Go…
RemiBardon Oct 13, 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
1,401 changes: 782 additions & 619 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,17 @@ chrono = "0.4"
cucumber = "0.21"
# See <https://github.com/johnstonskj/rust-email_address/issues/29>.
email_address = { git = "https://github.com/johnstonskj/rust-email_address.git", rev = "b4296cd4ff621b27da55bb5182558e0ce691c611" }
figment = { version = "0.10", features = ["toml"] }
figment = { version = "0.10", features = ["env", "toml"] }
form_urlencoded = "1"
futures = "0.3"
futures-util = { version = "0.3" }
hickory-proto = { version = "0.24", default-features = false, features = [
"tokio-runtime",
"serde-config",
] }
hickory-resolver = { version = "0.24", default-features = false, features = [
"tokio-runtime",
] }
hmac = "0.12"
http-auth-basic = "0.3"
insta = "1"
Expand Down Expand Up @@ -66,12 +73,12 @@ reqwest = { version = "0.12", features = [
"trust-dns",
], default-features = false }
rocket = { version = "0.5", features = ["json"] }
sea-orm = { version = "1.0.0-rc.7", features = [
sea-orm = { version = "1.0.1", features = [
"runtime-tokio-rustls",
"sqlx-sqlite",
#"macros",
] }
sea-orm-migration = { version = "1.0.0-rc.7", features = [
sea-orm-migration = { version = "1.0.1", features = [
"runtime-tokio-rustls",
"sqlx-sqlite",
] }
Expand Down Expand Up @@ -102,16 +109,20 @@ base64 = { workspace = true }
chrono = { workspace = true }
futures = { workspace = true }
futures-util = { workspace = true }
hickory-resolver = { workspace = true }
http-auth-basic = { workspace = true }
iso8601-duration = { workspace = true }
iso8601-timestamp = { workspace = true }
lazy_static = { workspace = true }
migration = { workspace = true }
rocket = { workspace = true }
sea-orm-rocket = { workspace = true }
secrecy = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
serde_with = { workspace = true }
service = { workspace = true }
strum = { workspace = true }
thiserror = { workspace = true }
time = { workspace = true }
tokio = { workspace = true }
Expand All @@ -121,6 +132,7 @@ uuid = { workspace = true }

[dev-dependencies]
cucumber = { workspace = true, features = ["tracing"] }
hickory-proto = { workspace = true }
lazy_static = { workspace = true }
linked-hash-map = { workspace = true }
regex = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Copyright 2022-2024, Prose Foundation - Released under the [Mozilla Public License 2.0](./LICENSE.md).

_Tested at Rust version: `rustc 1.79.0 (129f3b996 2024-06-10)`_
_Tested at Rust version: `rustc 1.81.0 (eeb90cda1 2024-09-04)`_

## License

Expand Down
10 changes: 8 additions & 2 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ tasks:
deps: [smoke-test, integration-test]
cmds:
# NOTE: This is macOS `sed`, out of simplicity since all maintainers use macOS
- 'sed -i '''' ''s/Tested at Rust version: `.+`/Tested at Rust version: `''"$(rustc --version)"''`/g'' README.md'
- 'sed -i '''' -E ''s/Tested at Rust version: `.+`/Tested at Rust version: `''"$(rustc --version)"''`/g'' README.md'
smoke-test:
desc: Runs smoke tests.
cmds:
Expand All @@ -52,6 +52,9 @@ tasks:
- echo '[INFO] Updating Rust dependencies…'
- rustup upgrade
- cargo update
check-for-outdated-dependencies:
desc: Check for outdated dependencies.
cmds:
# Check for outdated dependencies
- "if cargo install --list | grep -q '^cargo-edit v'; then \
echo '[INFO] Checking for outdated dependencies…'; \
Expand All @@ -63,7 +66,10 @@ tasks:
desc: Updates Redoc.
cmds:
- echo '[INFO] Updating Redoc…'
- wget -q https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js -O static/api-docs/redoc.standalone.js
#- wget -q https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js -O static/api-docs/redoc.standalone.js
# NOTE(RemiBardon): I replaced `wget` by `curl` because `wget` fails with exit code 5 (SSL verification failure)
# on my machine while `curl` does not.
- curl https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js --output static/api-docs/redoc.standalone.js 2>/dev/null
build-image:
desc: Builds the Prose Pod API Docker image. Run `task build-image -- --help` for more info.
env:
Expand Down
2 changes: 2 additions & 0 deletions migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod m20240220_171150_create_member;
mod m20240320_095326_create_workspace_invitation;
mod m20240326_160834_create_notification;
mod m20240506_080027_create_workspace;
mod m20240830_080808_create_pod_config;

pub struct Migrator;

Expand All @@ -17,6 +18,7 @@ impl MigratorTrait for Migrator {
Box::new(m20240320_095326_create_workspace_invitation::Migration),
Box::new(m20240326_160834_create_notification::Migration),
Box::new(m20240506_080027_create_workspace::Migration),
Box::new(m20240830_080808_create_pod_config::Migration),
]
}
}
37 changes: 37 additions & 0 deletions migration/src/m20240830_080808_create_pod_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use sea_orm_migration::{prelude::*, schema::*};

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(PodConfig::Table)
.if_not_exists()
.col(pk_auto(PodConfig::Id))
.col(string_null(PodConfig::Ipv4))
.col(string_null(PodConfig::Ipv6))
.col(string_null(PodConfig::Hostname))
.to_owned(),
)
.await
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(PodConfig::Table).to_owned())
.await
}
}

#[derive(DeriveIden)]
enum PodConfig {
Table,
Id,
Ipv4,
Ipv6,
Hostname,
}
29 changes: 16 additions & 13 deletions scripts/integration-test
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ set -e
: ${SCRIPTS_ROOT:="$(dirname $0)"}
export SCRIPTS_ROOT
source "${SCRIPTS_ROOT:?}"/util.sh
source "${SCRIPTS_ROOT:?}"/prose-pod-on-rpi/util.sh

SSH_TUNNEL_SOCKET=/tmp/prose-tests

Expand Down Expand Up @@ -37,6 +36,13 @@ test-env-vars \

# TODO(low): Allow overriding through a flag.
: ${PROFILE:=local}
case "$PROFILE" in
rpi)
source "${SCRIPTS_ROOT:?}"/prose-pod-on-rpi/util.sh
source "${SCRIPTS_ROOT:?}"/prose-pod-on-rpi/constants.sh ;;
*) ;;
esac

default-host() {
case "$PROFILE" in
local) echo "http://127.0.0.1:8000" ;;
Expand All @@ -56,7 +62,7 @@ before-all-local() { :; }
before-all-rpi() {
# Cleanup just in case the socket file still exists.
traced close-ssh-tunnel
# Create a SSH tunnel between the machin running the tests and the Raspberry Pi.
# Create a SSH tunnel between the machine running the tests and the Raspberry Pi.
# This allows us to hardcode `127.0.0.1:8000` in Step CI files to work around a limitation
# (see [stepci/runner#124](https://github.com/stepci/runner/pull/124#issuecomment-2310901815)).
# NOTE: `-f` makes `ssh` run in the background and `-N` tells it not to execute a remote command.
Expand Down Expand Up @@ -120,11 +126,17 @@ stop() {
"stop-${PROFILE:?}"
}

show-logs-local() {
edo docker compose -f "${COMPOSE_FILE:?}" logs --since "${elapsed_time}s" server api
}
show-logs-rpi() {
rpi_ssh docker compose -f "${REMOTE_PROSE_POD_SYSTEM_DIR:?}"/compose.yaml logs --since "${elapsed_time}s" server api
}
abort() {
stop
local current_time=$(date +%s)
local elapsed_time=$((current_time - ${START_TIME:?}))
edo docker compose -f "${COMPOSE_FILE:?}" logs --since "${elapsed_time}s" server api
ELAPSED_TIME="${elapsed_time}" "show-logs-${PROFILE:?}"
exit 1
}

Expand All @@ -139,7 +151,7 @@ stepci_run() {
export PROSE_CONFIG_FILE="${INTEGRATION_TESTS_DIR:?}/Prose-${config_options:?}.toml"
# NOTE: We have to `cd $STEPCI_DIR` because transitive `$ref`s are not processed correctly otherwise.
start && \
(cd "${STEPCI_DIR:?}" && edo stepci run "${test_file#"${STEPCI_DIR:?}/"}" --env host="${INTEGRATION_TEST_HOST}") \
(cd "${STEPCI_DIR:?}" && edo stepci run "${test_file#"${STEPCI_DIR:?}/"}" --env host="${INTEGRATION_TEST_HOST:?}") \
&& stop || abort
}

Expand All @@ -162,15 +174,6 @@ for arg in "$@"; do
continue
fi

case $arg in
dns)
if [[ "${PROFILE:?}" == "local" ]]; then
warn "Test $(format_code "$arg") cannot be ran locally, skipping."
continue
fi ;;
*) ;;
esac

case $arg in
members)
stepci_run "$test_file" test-auto_accept_invitations ;;
Expand Down
14 changes: 11 additions & 3 deletions scripts/open-api-docs-ui
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
#!/bin/bash

: ${SCRIPTS_ROOT:="$(dirname $0)"}
: ${BASH_TOOLBOX:="${SCRIPTS_ROOT:?}"/bash-toolbox}
# NOTE: `log.sh` provides utility for logging at different levels.
source "${BASH_TOOLBOX:?}"/log.sh

URL='http://127.0.0.1:8000/api-docs/redoc'
if command -v xdg-open &>/dev/null; then
xdg-open "$URL" &
elif command -v open &>/dev/null; then
open "$URL" &
else
echo "Neither xdg-open nor open command found. Cannot open URL."
exit 1
die "Neither $(format_code xdg-open) nor $(format_code open) command found. Cannot open URL."
fi

cargo run
warn "Because the Prose Pod API cannot be started alone, this script uses the local $(format_code proseim/prose-pod-api:latest) image. This means the OpenAPI description will not reload until you run $(format_code 'task build-image -- --debug') again."

ENV_FILE="${PROSE_POD_API_DIR:?}"/tests/integration/in-memory.env \
SERVER_ROOT="${PROSE_POD_SYSTEM_DIR:?}"/server/pod \
docker compose -f "${PROSE_POD_SYSTEM_DIR:?}"/compose.yaml up
2 changes: 2 additions & 0 deletions service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ chrono = { workspace = true }
email_address = { workspace = true }
figment = { workspace = true }
form_urlencoded = { workspace = true }
hickory-proto = { workspace = true }
hickory-resolver = { workspace = true }
hmac = { workspace = true }
iso8601-duration = { workspace = true }
jid = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions service/src/entity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

pub mod member;
pub mod notification;
pub mod pod_config;
pub mod server_config;
pub mod workspace;
pub mod workspace_invitation;
22 changes: 22 additions & 0 deletions service/src/entity/pod_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// prose-pod-api
//
// Copyright: 2024, Rémi Bardon <[email protected]>
// License: Mozilla Public License v2.0 (MPL v2.0)

use sea_orm::entity::prelude::*;

/// Prose Pod configuration, as stored in the database.
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "pod_config")]
pub struct Model {
#[sea_orm(primary_key)]
id: i32,
pub ipv4: Option<String>,
pub ipv6: Option<String>,
pub hostname: Option<String>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}
Loading
Loading