Commit Graph

551 Commits

Author SHA1 Message Date
Jamil
69335153ce Remove docs.firezone.dev CNAME (#1418)
This corresponds to step (1) of #1417
2023-02-09 15:19:19 -08:00
Jamil
888eac8703 Fix recursive conncheck timer (#1416)
Fixes #1414
2023-02-08 10:57:39 -08:00
Jamil
8e73b1b8bb Refactor docs for REST API and consistency (#1404)
Also will include the following:

- [x] Fixes #1281
- [x] Fixes #1218
2023-02-07 08:24:11 -08:00
Jamil
7e2d2f35c6 Fix recursive ping timer (#1408)
Fixes recursively initializing the ping timer...
2023-02-06 12:01:57 -08:00
Andrew Dryga
29a74502a9 Fix unique name constraint and render error on MFA register form (#1403)
Closes #1402
2023-02-03 09:16:27 -06:00
Andrew Dryga
aa7a43dc70 Reorganise auth routes to make sure that plugs do not block OIDC/SAML when local auth is disabled (#1399)
And fix acceptance test assertion on the wrong broken behavior.

Closes: #1398
Ref:
https://firezone-users.slack.com/archives/C02PV412LGZ/p1674718310558799
2023-02-01 15:12:46 -08:00
Jamil
b64adda2ce Increase load peer timeout (#1396)
Temporary workaround for a rare issue where many peers (> hundreds)
cause a timeout for the `GenServer.call` function, preventing the
`wireguard_public_key` from being set properly.

This will be removed in 0.8, so only an increased timeout is needed for
now.
2023-01-31 18:56:23 -08:00
Andrew Dryga
497429dc03 Change default_client_allowed_ips type to string (#1387)
Closes #1374
2023-01-27 10:50:14 -06:00
Jamil
9801617ef5 Fix LiveView disconnect when config is downloaded (#1384)
Fixes #1353
2023-01-26 14:40:22 -08:00
Jamil
e4854902cd Revert to old Project API key (#1379)
Also update ping event timer to 1 day, with a 1 minute delay on boot.

Waiting on PostHog to confirm old API key is set.
2023-01-26 12:49:11 -08:00
Andrew Dryga
4e2a62af71 Fix bugs with OIDC and SAML forms (#1383)
1. When OIDC/SAML is deleted the state of the LV socket becomes invalid
and basically makes it looks like everything was deleted
2. When there is more than one OIDC/SAML config trying to delete it
leads to a crash
3. Updates of OIDC/SAML were messy and hard to follow, they are reworked
and more tests are added around them

Closes #1382
2023-01-26 14:21:59 -06:00
Andrew Dryga
8a5dd8a5dd Improve seeds to test config migrations 2023-01-25 10:54:54 -06:00
Andrew Dryga
cce70cf552 Fix SAML regression (#1371)
Regression was introduced in #1350: the path order did not allow auth
callback to be ever called.

Additionally, acceptance tests for SAML are added and we added a
blacklist of SAML config ids to prevent further route collisions.

Fixes #1362
2023-01-23 15:28:25 -06:00
Andrew Dryga
34cddcdbd4 Refactor api tokens (#1370)
Related to #1364

Co-authored-by: Jamil Bou Kheir <jamilbk@users.noreply.github.com>
2023-01-23 13:39:34 -06:00
Andrew Dryga
999ea1e43d Add version suffix to cookie signing salt (#1369)
This will make sure that users need to reauthenticate every time a new
version is deployed.

Closes https://github.com/firezone/firezone/issues/1358
2023-01-23 13:38:57 -06:00
Andrew Dryga
4a2864f9a1 Fix rendering for logo struct in REST API (#1367)
Closes #1363
2023-01-23 13:38:31 -06:00
Jamil
ddc8b32970 Add tests to ensure path changes when modal is dismissed (#1356)
Refs #1353 

I was looking for a `refute_el` helper to check for `.modal.is-active`
*not* being on the page, but that would take time to write 😅

This checks to ensure the URL is updated, which should cause the
`@live_action` to change, the view to be patched, and the modal to be
dismissed, but isn't the most straightforward way to make sure the modal
isn't visible.

We've hit this problem twice before (am not successful this morning
finding the relevant issues):

* If the WebSocket is flapping, the event may not register. But usually
the browser will refresh if this is the case (we have a red indicator in
the upper-right to indicate if the websocket is not connected, i.e. the
views aren't "live")
* A CSS bug caused the click event to target the wrong LiveView PID (the
modal's parent I believe), which ended up crashing it because it didn't
have the "close" event handler defined. I believe the escape keydown
still closed the view though in that case.

This feels more like the first issue, given the acceptance test is
passing.

Co-authored-by: Andrew Dryga <andrew@dryga.com>
2023-01-23 09:31:37 -06:00
Andrew Dryga
8a02629163 Start testing migrations and seeds on CI (#1359)
Ref: #1316

This additionally adds static-analysis and type-check steps to `test`
workflow. Even though they run in a separate workflow I feel like we
might want to remove dialyzer from pre-commit hook as it sometimes takes
a lot of time, especially if you do checkout between branches that
change deps often and slows down when you commit rapidly.
2023-01-22 22:01:58 -06:00
Andrew Dryga
e43ef06115 Rework MFA methods (#1339)
1. We enforce `last_used_at` to be not nil at the database level
2. The `name` is now unique to prevent ambiguity, it also can't be
longer than 255 chars
3. The MFA module was rewritten to follow the style applied to Users
before with much better test coverage, its API changed to be less
generic (like just create/update -> create/use_code)
4. The multi-step form was reworked to use new methods instead of
changeset and doing direct `Repo.insert/1`.

Closes #1323
2023-01-20 12:02:46 -08:00
Jamil
9efdfa10ff Fix SAML restart and remove test env code path (#1350)
This codepath was being skipped in the `test` env, which is no longer
necessary. This caused a runtime error that failed to show up in tests
because the codepath was being skipped.

Refs #1341
2023-01-20 10:00:10 -08:00
Jamil
931029b2ac Better outbound email config parsing (#1346)
This also refactors local auth routes to protect them using Plug.
2023-01-20 07:16:23 -08:00
Andrew Dryga
48a3621aed Soft limit CIDR range for IPv6 network to 288230376151711744 devices (#1344)
That should be enough for most of users (c).

Closes #1340
2023-01-19 17:16:16 -08:00
Andrew Dryga
03100df545 Add e2e test for magic links (#1345)
Related to #1342
2023-01-19 12:57:43 -08:00
Jamil
547b3bbf65 Don't override SAML config booleans (#1333)
Fixes #1321 

Also updates a couple tests to read from `EXTERNAL_URL` instead of
`http://localhost:4002` (these were failing in my env because I have a
different value set)

Signed-off-by: Jamil <jamilbk@users.noreply.github.com>
Co-authored-by: Andrew Dryga <andrew@dryga.com>
2023-01-18 12:44:57 -08:00
Jamil
8166bd7ce5 Filter out nil IPs before adding to the nftables ruleset (#1332)
This edgecase happens when `WIREGUARD_IPV4_ENABLED` or
`WIREGUARD_IPV6_ENABLED` are set to `false`; when a new device is
generated, we don't allocate an IP for it. This causes a failed function
match, and should be handled instead by simply skipping the `nil` IP
from being added to the user's `nftables` group.

**Note**: This functionality will be removed with the release of the
gateway's eBPF packet filter in 0.8.

Fixes #1331
2023-01-18 12:00:04 -08:00
Jamil
421d56b0ea Handle EXTERNAL_URL missing scheme (#1326)
Fixes #1314
2023-01-17 10:46:52 -08:00
Andrew Dryga
7ece067333 Bump Elixir deps
This replaces two PRs from dependabot.
2023-01-16 13:15:32 -06:00
Andrew Dryga
218ad006af Revisit Users context, cover UI with e2e tests and introduce first AuditLog features (#1267)
1. `auto_create_users` default value is removed. We want to avoid
situations when admins integrate OIDC/SAML providers and don't expect
anyone that has access to it to automatically gain access to VPN, which
is especially critical for providers like Google Workspace, where all
employees typically have access.
2. OpenID library was completely rewritten and a new version is
integrated. It will allow async tests and better scales for the cloud
version of the panel.
3. `Mox` was removed, we don't test modules by overriding them to
prevent breaking changes that tests can't capture.
4. Deps are reordered and unused ones are removed.
5. Browser/e2e tests are added to ensure we won't break UI features in
the future, allowing for front-end refactoring.
6. Users context was overhauled for better code clarity.
2023-01-16 13:04:59 -06:00
Jamil
ec321c5619 Update default REST API docs path; Note on stdout api tokens (#1306) 2023-01-13 17:23:21 -06:00
Jamil
330cafbbe5 Boot minimal app for DB changes (#1305)
Adds a minimal supervision tree for making DB changes from the
`FzHttp.Release` module. This allows the `bin/create-or-reset-admin` and
`bin/create-api-token` commands to be with `docker compose exec` or
`docker compose run --rm` indiscriminately.

Starting the FzHttp.Repo directly is more involved it's not compiled
into the release as an OTP app.
2023-01-13 13:45:18 -08:00
Andrew Dryga
7760817191 Hotfix default PK values on connectivity_checks table (#1300)
The migration is edited in place. Otherwise, the users that partially
upgraded to 0.7 won't be able to proceed.

Another migration is added to add default values for every table that
did not have it to make things consistent and make sure that both users
that have failed migration executed and the ones that executed it
successfully will end up with the same schema.

Closes #1295
2023-01-13 11:48:13 -08:00
Jamil
51a0cf251e Bump to 0.7.0 release (#1291)
Bumps Release Drafter to 0.7.0 for publish
2023-01-12 22:52:50 -08:00
Andrew Dryga
6003ea7e26 Generate API docs from tests and Phoenix Controller docs (#1286)
1. The test data is taken from tests, you can override attributes by
adding keyword params to `doc` macro;
2. Additionally, you can add a section title using a `@moduledoc` in a
controller and a controller action title using `@doc` on a controller
function. (It will be added to all instances of its usage).
3. To make parameters nice a helper was added to build it using
`DocHelper`, you can find an example in UserController.

Overall, the code is messy, I'll need to revisit it, but was doing it in
a rush so hope it's good enough for v0.

Results you can see at https://firezone.docs.apiary.io/.

To generate it locally run `DOC=1 mix test
test/fz_http_web/controllers/json`.

Co-authored-by: Jamil Bou Kheir <jamilbk@users.noreply.github.com>
2023-01-12 22:40:21 -08:00
Jamil
ed23d9f346 Use eval for create-or-reset-admin; expose with RESET_ADMIN_ON_BOOT (#1287)
Fixes #1285
2023-01-11 19:55:18 -08:00
Jamil
b3ae440a36 API Token CLI (#1271)
Adds a mechanism for generating API tokens from the CLI. Requires the
default admin user to be present. From there the token can be used to
create additional admins. In the future, we could allow specifying a
user's email to generate the token for.

Generate like so:

```
docker compose run --rm firezone bin/create-api-token
```
2023-01-09 14:59:18 -08:00
Jamil
17b4f321df Add more comprehensive REST API tests (#1269)
- [x] Call API plug pipeline in test env
- [x] Add missing token tests
- [x] Add 404 tests
- [x] Add comprehensive user tests
- [x] Add comprehensive rule tests
- [x] Add comprehensive device tests
- [x] Add comprehensive configuration tests
2023-01-09 11:51:44 -08:00
Andrew Dryga
4fe6b5ec31 Allow running Firezone in a non-root directory (#1248) 2023-01-03 13:48:01 -06:00
Jamil
9a4103318d Expose some http client ssl opts via HTTP_CLIENT_SSL_OPTS (#1221)
Expose the most commonly-used SSL client options to our OIDC and
ConnectivityChecks HTTP clients. Resolves some lingering issues some
users were facing with OIDC where they needed a custom TLS version
enforced or cacert file used to fetch the `discovery_document` and
resulting keys.

SSL misconfiguration can be a security concern, so we intentionally puke
when an unexpected key is passed. This should result in a new GitHub
issue being opened and dialog created to learn more about the use-case.

Fixes #996
2023-01-03 07:38:24 -08:00
Jamil
56ec179a83 [Supercedes #1255] Replace npm with yarn (#1256)
Renamed branch prefix to `build/` to build in CI
2022-12-31 15:44:23 -06:00
Jamil
1de24ff77e REST API (#1155)
### TODO

- [x] "/v0"
- [x] Double-check migration order; re-timestamp if necessary
- [x] Move `sites` fields to `configurations` so they can be updated
from API
- [x] #1240 -- it introduces possible race conditions for API requests
- [x] #1249 
- [ ] #1008 
- [ ] Final review

Signed-off-by: Jamil <jamilbk@users.noreply.github.com>
Co-authored-by: Andrew Dryga <andrew@dryga.com>
2022-12-31 12:58:11 -06:00
Jamil
8fa280691d Conditionally append port to endpoint (#1247)
Fixes a bug where generated configs have an extra port added in some
cases.
2022-12-26 15:19:08 -06:00
Jamil
fbb05b9e7e Fix sites.endpoint default when EXTERNAL_URL is missing (#1238)
This populates the `sites.endpoint` field with the WIREGUARD_ENDPOINT
variable and removes it from env vars reference.

cc @conectado 
Fixes #1237
2022-12-24 18:16:55 -06:00
Jamil
de3919fb69 Add SupportOptions component and utm_source for links (#1219)
This PR also moves to `yarn` for docs package management for improved
speed, security, and developer experience. Docusaurus prefers yarn.

Refs firezone/marketing#126
2022-12-24 16:16:55 -06:00
Jamil
f749ba2bb2 Change foreign key constraint to cascading delete (#1235)
Fixes #1234
2022-12-24 07:09:37 -06:00
Austin Saunders
9eb622fe39 Removes hammer and hammer_plug deps and their code references (#1230)
Resolves Issue https://github.com/firezone/firezone/issues/1216

Co-authored-by: Austin Saunders <austinsaunders@paczek.lan>
2022-12-24 05:32:01 -06:00
Gabi
e49d5631a5 fix: endpoint migration when EXTERNAL_URL is not present (#1232)
For `URI.parse` to work the URI needs to be a FQDN otherwise `nil` is
returned.
2022-12-23 18:13:11 -06:00
Jamil
26cb59d74b Fix rollback for release_test.exs due to Ecto 3.9.2 (#1223)
* Fix rollback for release_test.exs due to Ecto 3.9.2

4371bb7de8

* We don't support rollbacks

* Update .github/workflows/static_analysis.yml

Co-authored-by: Andrew Dryga <andrew@dryga.com>
Signed-off-by: Jamil <jamilbk@users.noreply.github.com>

Signed-off-by: Jamil <jamilbk@users.noreply.github.com>
Co-authored-by: Andrew Dryga <andrew@dryga.com>
2022-12-21 13:42:31 -06:00
Jamil
495109a418 Support more dense QR codes with error correction level L (#1222)
This also removes the QR code <canvas> from the DOM if there's a
render error.

Fixes #1217
2022-12-21 13:10:41 -06:00
Jamil
ccf2ecd633 Document WIREGUARD_MTU is for server interface only (#1212)
Client configs will be generated based on runtime configuration
stored in the `sites` table, while server configuration (which
requires a restart of the server) will be configurable via ENV vars.

Refs #1270
2022-12-19 07:37:56 -06:00
Jamil
ec3c075c67 Use site table fields, not ENV vars for optional WireGuard config (#1207)
This takes us a step closer to having all runtime config
in the DB as opposed to ENV vars.

Fixes #1197
2022-12-18 21:39:33 -06:00