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

Device Shared Secret Authentication #1139

Merged
merged 35 commits into from
Dec 28, 2023
Merged

Conversation

joshk
Copy link
Collaborator

@joshk joshk commented Dec 10, 2023

This adds support for Shared Secret authentication, which allows Devices to connect to Nerves Hub using a shared key and secret. This is similar to the AWS HMAC signatures used for S3.

This is based on #1136

Some key highlights:

  • If you use the Shared Secrets strategy, you won't need to run the Device Endpoint, and thus you won't need to setup custom SSL certs.
  • Which also means you can run this entirely behind a load balancer and let it take care of TLS termination.
  • Which makes this a lot easier to run on a PaaS. (eg. Heroku, Fly.io, Render)
  • When a Device connects for the first time the Device will be registered with the Product ("Just-in-Time registration").

This feature is opt-in, on the server level, using the environment variable DEVICE_SHARED_SECRET_AUTH.

Some tech bits

I've added a series of useful mounts which are used by a live_session. As we expand LiveView usage we can reuse a lot of this structure.

And I've added a centralized permissions checking module, abstracting away from checking for :admin, :manage, and :view.

Not included in this PR, but to be added in a future PR...

  • When setting up a Product, you have to select if the it will use Cert auth or Shared Secret auth.

Screenshots

Updated Product Settings page (now using LiveView)
Screenshot 2023-12-15 at 9 43 26 PM

One active Shared Secret
Screenshot 2023-12-15 at 9 44 11 PM

Two active Shared Secrets, one deactivated
Screenshot 2023-12-15 at 9 44 40 PM

Feature not enabled for the server
Screenshot 2023-12-15 at 10 12 28 PM

@joshk joshk changed the title Device token experiment (#1136) Device token experiment Dec 10, 2023
@joshk joshk force-pushed the alt-device-auth-jk-twist branch 4 times, most recently from c986666 to c91fd09 Compare December 10, 2023 07:59
lib/nerves_hub/devices.ex Outdated Show resolved Hide resolved
lib/nerves_hub_web/channels/device_socket_token_auth.ex Outdated Show resolved Hide resolved
lib/nerves_hub_web/channels/device_socket_token_auth.ex Outdated Show resolved Hide resolved
lib/nerves_hub_web/channels/device_socket_token_auth.ex Outdated Show resolved Hide resolved
lib/nerves_hub_web/channels/device_socket_token_auth.ex Outdated Show resolved Hide resolved
lib/nerves_hub/devices.ex Outdated Show resolved Hide resolved
@joshk joshk force-pushed the alt-device-auth-jk-twist branch 2 times, most recently from ff1a94e to 93f55db Compare December 12, 2023 03:58
config/runtime.exs Outdated Show resolved Hide resolved
@joshk joshk force-pushed the alt-device-auth-jk-twist branch 6 times, most recently from 0f8941d to 7ccb6c6 Compare December 15, 2023 05:20
@joshk joshk changed the title Device token experiment Device Shared Secret Authentication Dec 15, 2023
@joshk joshk marked this pull request as ready for review December 17, 2023 21:06
@fhunleth
Copy link
Contributor

All least from my level of review, this looks great, and I think it's really going to help people get started. Thank you so much for all of the effort to push this feature through.

@joshk
Copy link
Collaborator Author

joshk commented Dec 18, 2023

All least from my level of review, this looks great, and I think it's really going to help people get started. Thank you so much for all of the effort to push this feature through.

Thanks @fhunleth, its been my pleasure to get involved. More to come soon!

config/runtime.exs Outdated Show resolved Hide resolved
@jjcarstens jjcarstens force-pushed the alt-device-auth-jk-twist branch 3 times, most recently from faebc83 to b220a04 Compare December 28, 2023 17:19
lib/nerves_hub/products/product.ex Outdated Show resolved Hide resolved
lib/nerves_hub/application.ex Outdated Show resolved Hide resolved
lib/nerves_hub_web/helpers/authorization.ex Outdated Show resolved Hide resolved
@joshk joshk merged commit a4793f2 into shared-secret-auth Dec 28, 2023
2 checks passed
@joshk joshk deleted the alt-device-auth-jk-twist branch December 28, 2023 22:23
jjcarstens added a commit that referenced this pull request Jan 7, 2024
this is based upon 0d44fc2 with the addition of Product Shared Secrets

* device token auth strategy requires opt in during runtime
* add an `Experimental` badge
* improvements to the shared secrets UI
* add authorization to the Product Settings LiveView

---------

Co-authored-by: Jon Carstens <[email protected]>
joshk added a commit that referenced this pull request Jan 13, 2024
* Device Shared Secret Authentication (#1139)

this is based upon 0d44fc2 with the addition of Product Shared Secrets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants