Rename the update auth switch to application_token_source and drop its ENV default
This commit is contained in:
@@ -184,9 +184,8 @@ Rails.application.config.to_prepare do
|
|||||||
# :database — only WarpEngine::ApplicationToken records with the
|
# :database — only WarpEngine::ApplicationToken records with the
|
||||||
# "update" scope are accepted; the shared secret stops
|
# "update" scope are accepted; the shared secret stops
|
||||||
# working the moment you switch.
|
# working the moment you switch.
|
||||||
# Defaults to ENV["UPDATE_SECRET_SOURCE"] (:env when unset).
|
|
||||||
# :database mode also requires the owner class every token belongs to:
|
# :database mode also requires the owner class every token belongs to:
|
||||||
# c.update_secret_source = :database
|
# c.application_token_source = :database
|
||||||
# c.application_token_owner_class = "AdminUser"
|
# c.application_token_owner_class = "AdminUser"
|
||||||
|
|
||||||
# If your app's own models reference catalog images, register them so the
|
# If your app's own models reference catalog images, register them so the
|
||||||
@@ -225,7 +224,7 @@ deleted records are resurrected on re-ingest.
|
|||||||
### Updater authentication
|
### Updater authentication
|
||||||
|
|
||||||
The `X-Update-Secret` header (or the `?secret=` query param) carries one of
|
The `X-Update-Secret` header (or the `?secret=` query param) carries one of
|
||||||
two credentials, selected by `update_secret_source` — the modes are
|
two credentials, selected by `application_token_source` — the modes are
|
||||||
exclusive, the endpoint never accepts both:
|
exclusive, the endpoint never accepts both:
|
||||||
|
|
||||||
- **`:env`** (default): the single shared secret from `update_secret`.
|
- **`:env`** (default): the single shared secret from `update_secret`.
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ module WarpEngine
|
|||||||
token = request.headers["X-Update-Secret"].presence || params[:secret].presence
|
token = request.headers["X-Update-Secret"].presence || params[:secret].presence
|
||||||
return false if token.blank?
|
return false if token.blank?
|
||||||
|
|
||||||
case WarpEngine.config.update_secret_source
|
case WarpEngine.config.application_token_source
|
||||||
when :database then database_token_authorized?(token)
|
when :database then database_token_authorized?(token)
|
||||||
else env_secret_authorized?(token)
|
else env_secret_authorized?(token)
|
||||||
end
|
end
|
||||||
@@ -59,7 +59,7 @@ module WarpEngine
|
|||||||
|
|
||||||
def database_token_authorized?(token)
|
def database_token_authorized?(token)
|
||||||
if WarpEngine.config.application_token_owner_class.blank?
|
if WarpEngine.config.application_token_owner_class.blank?
|
||||||
Rails.logger.error("[UpdateController] update_secret_source=:database, de application_token_owner_class nincs beállítva — minden kérés elutasítva")
|
Rails.logger.error("[UpdateController] application_token_source=:database, de application_token_owner_class nincs beállítva — minden kérés elutasítva")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -13,9 +13,8 @@ Rails.application.config.to_prepare do
|
|||||||
# :env — a fenti shared secret érvényes (default)
|
# :env — a fenti shared secret érvényes (default)
|
||||||
# :database — csak DB-tárolt WarpEngine::ApplicationToken érvényes
|
# :database — csak DB-tárolt WarpEngine::ApplicationToken érvényes
|
||||||
# ("update" scope-pal); a shared secret ilyenkor NEM működik.
|
# ("update" scope-pal); a shared secret ilyenkor NEM működik.
|
||||||
# Default: ENV["UPDATE_SECRET_SOURCE"] (beállítatlanul :env).
|
|
||||||
# A :database módhoz kötelező a tokenek tulajdonos-osztálya is:
|
# A :database módhoz kötelező a tokenek tulajdonos-osztálya is:
|
||||||
# c.update_secret_source = :database
|
# c.application_token_source = :database
|
||||||
# c.application_token_owner_class = "AdminUser"
|
# c.application_token_owner_class = "AdminUser"
|
||||||
|
|
||||||
# Ha a host modelljei is hivatkoznak katalógus-képekre, regisztráld őket,
|
# Ha a host modelljei is hivatkoznak katalógus-képekre, regisztráld őket,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ module WarpEngine
|
|||||||
# label: String
|
# label: String
|
||||||
# image_ids: -> { Array<Integer> } — az owner által használt image id-k
|
# image_ids: -> { Array<Integer> } — az owner által használt image id-k
|
||||||
# usage_label: ->(image) { String vagy nil } — megjelenítendő címke, ha használja
|
# usage_label: ->(image) { String vagy nil } — megjelenítendő címke, ha használja
|
||||||
# update_secret_source: a /update endpoint hitelesítési forrása, kizárólagos.
|
# application_token_source: a /update endpoint hitelesítési forrása, kizárólagos.
|
||||||
# :env — a shared secret (update_secret) érvényes, a DB-tokenek nem
|
# :env — a shared secret (update_secret) érvényes, a DB-tokenek nem
|
||||||
# :database — csak WarpEngine::ApplicationToken érvényes, a shared secret nem
|
# :database — csak WarpEngine::ApplicationToken érvényes, a shared secret nem
|
||||||
# application_token_owner_class: a tokenek kötelező tulajdonosának osztályneve
|
# application_token_owner_class: a tokenek kötelező tulajdonosának osztályneve
|
||||||
@@ -12,7 +12,7 @@ module WarpEngine
|
|||||||
attr_accessor :file_container_path,
|
attr_accessor :file_container_path,
|
||||||
:image_container_path,
|
:image_container_path,
|
||||||
:update_secret,
|
:update_secret,
|
||||||
:update_secret_source,
|
:application_token_source,
|
||||||
:application_token_owner_class,
|
:application_token_owner_class,
|
||||||
:image_owners
|
:image_owners
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ module WarpEngine
|
|||||||
@file_container_path = ENV.fetch("FILE_CONTAINER_PATH", "/softwares")
|
@file_container_path = ENV.fetch("FILE_CONTAINER_PATH", "/softwares")
|
||||||
@image_container_path = ENV.fetch("IMAGE_CONTAINER_PATH", "/images")
|
@image_container_path = ENV.fetch("IMAGE_CONTAINER_PATH", "/images")
|
||||||
@update_secret = ENV["UPDATE_SECRET"]
|
@update_secret = ENV["UPDATE_SECRET"]
|
||||||
@update_secret_source = ENV.fetch("UPDATE_SECRET_SOURCE", "env").to_sym
|
@application_token_source = :env
|
||||||
@application_token_owner_class = nil
|
@application_token_owner_class = nil
|
||||||
@image_owners = []
|
@image_owners = []
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -54,9 +54,9 @@ RSpec.describe "GET /update", type: :request do
|
|||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with update_secret_source :database" do
|
context "with application_token_source :database" do
|
||||||
before do
|
before do
|
||||||
allow(WarpEngine.config).to receive(:update_secret_source).and_return(:database)
|
allow(WarpEngine.config).to receive(:application_token_source).and_return(:database)
|
||||||
allow(WarpEngine.config).to receive(:application_token_owner_class).and_return("TestOwner")
|
allow(WarpEngine.config).to receive(:application_token_owner_class).and_return("TestOwner")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user