Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit f085045

Browse files
committed
Allow the FQDN to be specified through config
This is something in between to what we have on the `v2.0` branch and the `master` branch. This way we have the behavior from `master` while not breaking what we had in previous patch-level releases. This commit is largely based on 9846716 in the `master` branch. Signed-off-by: Miquel Sabaté Solà <msabate@suse.com>
1 parent 7e9e014 commit f085045

10 files changed

Lines changed: 26 additions & 8 deletions

File tree

app/controllers/application_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def fixes
3232
{}.tap do |fix|
3333
fix[:ssl] = check_ssl
3434
fix[:secret_key_base] = secrets.secret_key_base == "CHANGE_ME"
35-
fix[:secret_machine_fqdn] = secrets.machine_fqdn.nil?
35+
fix[:secret_machine_fqdn] = fqdn.blank?
3636
fix[:secret_encryption_private_key_path] = secrets.encryption_private_key_path.nil?
3737
fix[:secret_portus_password] = secrets.portus_password.nil?
3838
fix

app/views/errors/500.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<% if Rails.env.production? %>
2424
Set <i>PORTUS_MACHINE_FQDN</i> environment variable.
2525
<% else %>
26-
Set <i>machine_fqdn</i> in <i>config/secrets.yml</i>.
26+
Set <i>machine_fqdn</i> in <i>config/secrets.yml</i> or <i>config/config-local.yml</i>.
2727
<% end %>
2828
<% end %>
2929
<% if @fix[:secret_encryption_private_key_path] %>

app/views/errors/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<% if Rails.env.production? %>
4747
Set <i>PORTUS_MACHINE_FQDN</i> environment variable.
4848
<% else %>
49-
Set <i>machine_fqdn</i> in <i>config/secrets.yml</i>.
49+
Set <i>machine_fqdn</i> in <i>config/secrets.yml</i> or <i>config/config-local.yml</i>.
5050
<% end %>
5151
<% end %>
5252
<% if @fix[:secret_encryption_private_key_path] %>

config/config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,8 @@ check_ssl_usage:
9191
# See: https://github.com/SUSE/Portus/issues/510
9292
jwt_expiration_time:
9393
value: "5.minutes"
94+
95+
# The FQDN of the machine where Portus is being deployed. The default is kept
96+
# empty to make sure that backwards-compatibility is not broken.
97+
machine_fqdn:
98+
value: ""

config/initializers/config.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,12 @@
22
local = ENV["PORTUS_LOCAL_CONFIG_PATH"] || File.join(Rails.root, "config", "config-local.yml")
33
cfg = Portus::Config.new(default, local)
44
APP_CONFIG = cfg.fetch
5+
6+
# This method consumes the value of the FQDN from the app config if possible
7+
# (as implement in Portus v2.1.x). Otherwise, it falls back to the current way
8+
# of fetching it.
9+
def fqdn
10+
mconf = APP_CONFIG["machine_fqdn"]
11+
return Rails.application.secrets.machine_fqdn if mconf.nil? || mconf["value"].blank?
12+
mconf["value"]
13+
end

config/initializers/mailer_url_options.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# If you're on staging/production, then you must be using SSL. Otherwise, if
22
# you're on development mode and you have set your own FQDN, then we assume
33
# that SSL is in place too. Otherwise, SSL is not setup.
4-
if !Rails.env.development? || !ENV["PORTUS_MACHINE_FQDN"].nil?
4+
if !Rails.env.development? || !ENV["PORTUS_USE_SSL"].nil?
55
protocol = "https://"
66
else
77
protocol = "http://"
88
end
99

10-
host = Rails.application.secrets.machine_fqdn
10+
host = fqdn
1111
ActionMailer::Base.default_url_options[:host] = host
1212
ActionMailer::Base.default_url_options[:protocol] = protocol
1313

lib/portus/jwt_token.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def encoded_hash
2929
# specification.
3030
def claim
3131
@claim ||= {}.tap do |hash|
32-
hash[:iss] = Rails.application.secrets.machine_fqdn
32+
hash[:iss] = fqdn
3333
hash[:sub] = @account
3434
hash[:aud] = @service
3535
hash[:iat] = issued_at

packaging/suse/portusctl/templates/config-local.yml.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,7 @@ first_user_admin:
7676
# By default require ssl to be enabled when running on production
7777
check_ssl_usage:
7878
enabled: <%= @options["secure"] %>
79+
80+
# The FQDN of the machine where Portus is being deployed.
81+
machine_fqdn:
82+
value: <%= HOSTNAME %>

spec/controllers/errors_controller_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
before :all do
77
secrets = Rails.application.secrets
88
@secret_key_base = secrets.secret_key_base
9-
@secret_machine_fqdn = secrets.machine_fqdn
9+
@secret_machine_fqdn = fqdn
1010
@secret_encryption_private_key_path = secrets.encryption_private_key_path
1111
@secret_portus_password = secrets.portus_password
1212
end

spec/lib/portus/jwt_token_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
describe "basic fields" do
5757
describe ":iss" do
5858
it "is set to portus fqdn" do
59-
expect(subject.claim[:iss]).to eq Rails.application.secrets.machine_fqdn
59+
expect(subject.claim[:iss]).to eq fqdn
6060
end
6161
end
6262

0 commit comments

Comments
 (0)