Commit Graph

522 Commits

Author SHA1 Message Date
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
Jamil
6978504da0 Allow IPv6 remote_ips in StatsUpdater (#1206)
This fixes a bug where we assumed a peer's `endpoint`
(and therefore device `remote_ip`) would always be
an IPv4 address.
2022-12-18 18:10:22 -06:00
Jamil
0a19c67cd1 Use application_version() to link back to repo (#1181) 2022-12-07 11:11:30 -08:00
Andrew Dryga
28fe571543 Small improvements to make setup process easier for OS contributors (#1171)
* Remove _build folders for umbrella apps

For umbrella apps everything goes into /_build directory so there no need to ignore directories that should never be created

* Change mix aliases to be more aligned with what OS community would expect

1. We want ecto.create and ecto.migrate to be run on each tests, this will simplify setup steps (no need to run migrations manually)

2. ecto.remigrate is not needed because now you can just run ecto.drop and on tests migrations would be executed anyways.

* Rename docker-compose step name in CONTRIBUTING.md

The step was renamed here: dd67baf629 (diff-67a4805fdcc6145d7b3ada2a6099a9b2e91c9d0fd108c22f95d2f01d219793d1R10)

* Remove .devcontainer

This an is opinionated change. Right now devcontainer doesn't work but should be easy to fix (with renaming step name), but at the same time it forces developers that use VS code to have unified development environment (including plugins for the editor itself).

I feel like it's not a good path to go for OS and for small team - everyone should be allowed to use setup they like. Especially for people like me that tend to recompile ls-elixir for Elixir plugin from master branch.

Plus it's yet another thing to maintain while nobody on the team is using it, which means it will be always causing issues.

* Make fz_http mix.exs aliases aligned with umbrella app ones

* Redirect stderr to stdout in a command called from dev.exs

Otherwise I'm getting this on my MacOS (that has a `route` implementation that doesn't show interfaces) when `mix phx.server` is executed:
```
usage: route [-dnqtv] command [[modifiers] args]
```

* Fix race condition due to static device field values

Both public_key and name are unique and we should not use static values for field covered by unique index, otherwise deadlocks and slow tests are expected.

* Remove unwanted transaction block

The changeset code doesn't have any code that accesses the database and individual Ecto.SQL commands are already wrapped in transactions by default, so there is no need to start it manually and hold for longer than expected (while irrelevant Elixir code is running).

* Use netstat to identify egress interface on MacOS

* Rename uninstall.sh to omnibus-uninstall.sh

* Fix uninstall path in omnibus_build.yml
2022-12-06 15:07:45 -08:00
dependabot[bot]
94061a3581 Bump hammer_plug from 2.1.1 to 3.0.0 (#1176)
Bumps [hammer_plug](https://github.com/ExHammer/hammer-plug) from 2.1.1 to 3.0.0.
- [Release notes](https://github.com/ExHammer/hammer-plug/releases)
- [Changelog](https://github.com/ExHammer/hammer-plug/blob/master/CHANGELOG.md)
- [Commits](https://github.com/ExHammer/hammer-plug/compare/v2.1.1...v3.0.0)

---
updated-dependencies:
- dependency-name: hammer_plug
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-06 14:32:58 -08:00
Jamil
f4cc03454e Wrap magic link with url() (#1170)
This broke when I introduced ~p across the codebase.
2022-12-03 08:19:21 -08:00
Jamil
6d1010c21b Use complete Firezone URL for post_logout_uri (#1160) 2022-11-30 22:27:21 -08:00
Gabi
116de06bf4 Disallow netmasks in devices' ip to prevent overlaps in firewall (#1140)
* fix: disallow netmasks in devices' ip to prevent overlaps in firewall

/32 is still allowed for ipv4 and /128 is still allowed for ipv6.
No migration is needed since netmasks for devices ips were broken
before-hand.

* chore: rename `validate_single_ip` function and reword its error message

* Update pre-commit to allow slash

* fix restore cache

* Refactor a bit

* Fix clobbered restore-keys

* Break cache

Co-authored-by: Jamil Bou Kheir <jamilbk@users.noreply.github.com>
2022-11-23 22:56:22 -08:00
Kian-Meng Ang
ec5f0e24ae Fix typos (#1141)
Found via `codespell -S omnibus,*.json,yarn.lock,seeds.exs -L keypair,keypairs,iif,statics,wee`
2022-11-23 21:42:54 -08:00
Jamil
50b2ab83a0 Only test when view is mounted (#1130) 2022-11-18 11:18:17 -08:00
Jamil
340ec59109 Ensure phoenix 1.7 is in subproject (#1128) 2022-11-18 08:01:27 -08:00
Jamil
1054de6585 Fix intermittent assert_{patched,redirected} failures (#1125)
* Fix intermittent assert_{patched,redirected} failures

* Split into two

* Remove empty file dope
2022-11-17 11:58:58 -08:00
Jamil
11695393f7 Update Phoenix to 1.7.0-rc.0 (#1119)
* Update Phoenix to 1.7.0-rc.0

* Should maybe compile without warnings now

* step 1: verified routes

* Use verified routes sigil

* Fix typos

* Formatter not working\?

* Fix formatter

* fix formatter file list
2022-11-17 07:06:39 -08:00
Tore Anderson
6a3fb2bfc2 Allow btree_gist extension to preexist (#1122)
This commit has the exact same rationale as cc280dae, just for a
different extension that I unfortunately missed the first time around.

This time I searched the repo for occurrences of `CREATE EXTENSION`
instead of the name of the extension causing the error, so hopefully I
did not miss anything else.
2022-11-17 06:24:34 -08:00
Tore Anderson
cc280dae50 Allow pgcrypto extension to preexist (#1114)
The CREATE EXTENSION query requires superuser privileges, which means
that the Firezone container may not be allowed to execute it when
accessing an externally hosted database, resulting in the database
failing to initialise properly.

One potential workaround to this problem is to have the database admin
ascertain that the pgcrypto extension is already present and ready for
use, prior to starting the Firezone container for the first time.

Unfortunately, however, this currently fails in the following manner:

14:42:44.731 [info] execute "CREATE EXTENSION pgcrypto"
** (Postgrex.Error) ERROR 42710 (duplicate_object) extension "pgcrypto" already exists

Adding the IF NOT EXISTS condition to the CREATE EXTENSION query should
allow it to succeed.
2022-11-16 07:28:06 -08:00
Jamil
a994f3f350 Update esaml to properly parse signed assertions (#1113)
* Update esaml to properly parse signed assertions

* Add Jumpcloud SAML doc

* Add required fields to config

* Add required fields to config

* Fix typo

* Formatting

* Minor fixes

* More clarifying

* yet more typo fixes

* Fix test
2022-11-15 21:34:31 -08:00
Jamil
1df5db4251 Support end_session_uri, custom redirect_uri and PKCE (#1110)
* Checkpoint PKCE; Refactor state

* tests passing

* id_token_hint working

* Fix WGAdapter setting

* what happened to redirect_uri

* Add redirect_uri custom

* Remove dbg

* Fix nil logout

* session cleanup

* Remove unneeded fixtures

* redis disable

* Fix tests
2022-11-15 18:28:26 -08:00
(╯°□°)╯︵ uᴉǝssnH ɐɟɐʇsoW
4de45306be fetch logo from config instead of default image (#1098)
Signed-off-by: (╯°□°)╯︵ uᴉǝssnH ɐɟɐʇsoW <mostafa.hussein91@gmail.com>

Signed-off-by: (╯°□°)╯︵ uᴉǝssnH ɐɟɐʇsoW <mostafa.hussein91@gmail.com>
2022-11-07 09:55:26 -08:00
Gabi
029891c69e Build/fix no prefix (#1089)
* fix: use caddy in host network_mode and make sure urls have a scheme

* fix: remove unnecesary exposed ports

* fix: remove support for hostnames begining with // since caddy doesn't support it

* Fix schemeless external URLs; error on invalid ones (#1090)

* Fix schemeless external URLs; error on invalid ones

* use different dockerfile for linux vs non-linux

* Use conditional EXTERNAL_URL defaults

* suppress empty warning

* postgres volume location

* Use inline Caddyfile

Co-authored-by: Jamil <jamilbk@users.noreply.github.com>
2022-11-03 19:36:37 -07:00
Jamil
5e5c2d35ac Use :live, not live.html (#1069) 2022-10-27 15:24:52 -07:00
Jamil
27e6ddc293 Fix configure bug for admins (#1045)
* Allow admins to configure devices

* Disable SSL certs

* Update scripts/install.sh

Signed-off-by: Jamil <jamilbk@users.noreply.github.com>

Signed-off-by: Jamil <jamilbk@users.noreply.github.com>
2022-10-18 22:20:16 -07:00
Jamil
0455ee8373 Use /contact/sales over typeform (#1039) 2022-10-18 08:17:10 -07:00
Jamil
3bc19c4c9f allow dns hosts; fix notifications concurrency issues (#1027)
* allow dns hosts; fix notifications concurrency issues

* Make notifications tests a little more robust
2022-10-16 13:44:59 -07:00
Jamil
dd11c728b0 Better validate OIDC and SAML configs (#1026)
* Bump postgres to release; Note on Caddy cert

* default auto_create_users

* Validate SAML and OIDC configs better

* Fix failing test
2022-10-15 18:33:32 -07:00
Jamil
0cf0a82194 Swallow OIDC errors (#1025) 2022-10-14 16:05:10 -07:00
Jamil
aa67b689e5 Add keycloak dev (#1023)
* Add keycloak dev

* Fix test using string keys
2022-10-14 14:19:24 -07:00
Jamil
d963929c07 0.6.0 (#1004)
* 0.6.0

* Make OIDC and SAML user provisioning configurable per-provider (#1015)

* Got ugly migration to work

* Move auto_create_users to per-provider config

* Update deps to bust cache

* Update Process sleep

* Update docs with Auto create users

* working migration script (#1013)

* Add telem for Docker and SAML (#1020)

* Add telem for Docker and SAML

* Omit unneeded format
2022-10-13 15:22:53 -07:00
Jamil
448ef072e5 Docs sec controls (#1018)
* add security controls document

* Add sec controls doc
2022-10-13 12:59:41 -07:00
Jamil
08bf880547 Move persistent term cache to cachex (#1003)
* Move persistent term cache to cachex

* Rename Conf -> Configurations
2022-10-05 05:28:50 -05:00
Jamil
185790dd0f Fix error due to updated LiveView (#1001) 2022-10-03 22:47:34 -05:00