fix: Include aes_iv in cache key and fix subdomain parsing for cloud mode

1. license.rb: Add aes_iv to Redis cache key to prevent CipherError after
   container restart. New random IVs after restart were causing stale cache
   decryption failures.

2. action_controller.rb:
   - Use request.subdomains.first instead of .last to correctly parse shop
     code from tenant.fc.smartsales.asia domains
   - Add localhost bypass (127.0.0.1 / ::1) for Docker health checks in
     cloud mode, returning 200 OK instead of 404 not_found

Refs: infra-fix-2026-05-06
This commit is contained in:
Infra Bot
2026-05-06 12:16:04 +08:00
parent 98ac443182
commit d79a6c5929
2 changed files with 21 additions and 7 deletions

View File

@@ -32,7 +32,7 @@ class License
aes_key, aes_iv = aes.export_to_file(lookup)
##Check from local redis - if available load local otherwise get from remote
cache_key = "#{lookup}:license:#{aes_key}:hostname"
cache_key = "#{lookup}:license:#{aes_key}:#{aes_iv}:hostname"
cache_license = nil

View File

@@ -14,7 +14,7 @@ class ActionController::Base
private
def lookup_domain
if ENV["SERVER_MODE"] == "cloud" && request.subdomains.last && request.subdomains.last != "www"
if ENV["SERVER_MODE"] == "cloud" && request.subdomains.first && request.subdomains.first != "www"
if license = cache_license # request.subdomain.downcase
logger.info "Location - " + license.dbschema
ActiveRecord::Base.establish_connection(website_connection(license))
@@ -23,7 +23,7 @@ class ActionController::Base
logger.info 'License is nil'
not_found
end
elsif ENV["SERVER_MODE"] == "application" || request.subdomains.last && request.subdomains.last != "www"
elsif ENV["SERVER_MODE"] == "application" || request.subdomains.first && request.subdomains.first != "www"
# check for license file
if !current_license.exists?
redirect_to activate_path
@@ -31,7 +31,14 @@ class ActionController::Base
redirect_to review_license_path
end
else
not_found
if ENV["SERVER_MODE"] == "cloud" && (request.remote_ip == "127.0.0.1" || request.remote_ip == "::1")
respond_to do |format|
format.html { render plain: "OK", status: :ok }
format.json { render json: { status: "ok" } }
end
else
not_found
end
end
end
@@ -96,7 +103,7 @@ class ActionController::API
private
def lookup_domain
if ENV["SERVER_MODE"] == "cloud" && request.subdomains.last && request.subdomains.last != "www"
if ENV["SERVER_MODE"] == "cloud" && request.subdomains.first && request.subdomains.first != "www"
if license = cache_license # request.subdomain.downcase
logger.info "Location - " + license.dbschema
ActiveRecord::Base.establish_connection(website_connection(license))
@@ -105,10 +112,17 @@ class ActionController::API
logger.info 'License is nil'
not_found
end
elsif ENV["SERVER_MODE"] == "application" || (request.subdomains.last && request.subdomains.last != "www")
elsif ENV["SERVER_MODE"] == "application" || (request.subdomains.first && request.subdomains.first != "www")
not_found unless current_license.exists? && !current_license.expired?
else
not_found
if ENV["SERVER_MODE"] == "cloud" && (request.remote_ip == "127.0.0.1" || request.remote_ip == "::1")
respond_to do |format|
format.html { render plain: "OK", status: :ok }
format.json { render json: { status: "ok" } }
end
else
not_found
end
end
end