diff --git a/CHANGELOG.md b/CHANGELOG.md index a1fb5cdd1..2b44c8da1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,13 +12,14 @@ into fixing the issue #512. - Teams can be renamed. See PR [#536](https://github.com/SUSE/Portus/pull/536). - Users can be created from the admin page. - See PR [543](https://github.com/SUSE/Portus/pull/543). This is a first step + See PR [#543](https://github.com/SUSE/Portus/pull/543). This is a first step into fixing the issues #283 and #179. - Team and namespace descriptions can be written using Markdown. See pull requests: [#546](https://github.com/SUSE/Portus/pull/546) and [#531](https://github.com/SUSE/Portus/pull/531). - Team members can comment on repositories. See pull request: [#538](https://github.com/SUSE/Portus/pull/583) -- Users can create security tokens to use instead of their credentials. See pull request: [625](https://github.com/SUSE/Portus/pull/625) +- Users can create security tokens to use instead of their credentials. See pull request: [#625](https://github.com/SUSE/Portus/pull/625) +- Added the `portus:info` rake task. See PR [#799](https://github.com/SUSE/Portus/pull/799). ## 2.0.3 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f93ea5504..cefd546f7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,6 +26,8 @@ points if your issue is about Portus behaving in an unexpected manner: That being said, if you are using a custom setup explain to us how all the pieces are glued together (you don't have to be too verbose, just specify the most important stuff like configurations, etc.). +- Paste the output of `rake portus:info` (or `portusctl rake portus:info` if + you are using the RPM). - If relevant, provide the related logs. If you are using the provided RPM, this is as simple as just calling `portusctl logs`. Otherwise, provide the contents of your `log/$environment.log` file, and the contents of the logs of diff --git a/lib/portus/config.rb b/lib/portus/config.rb index babc51c58..f9dd56222 100644 --- a/lib/portus/config.rb +++ b/lib/portus/config.rb @@ -27,6 +27,11 @@ def fetch add_enabled(hsh) end + # Returns a string representation of the evaluated configuration. + def to_s + hide_password(fetch.dup).to_yaml + end + protected include ::Portus::HashUtils diff --git a/lib/portus/hash_utils.rb b/lib/portus/hash_utils.rb index b3686365e..8b74ed554 100644 --- a/lib/portus/hash_utils.rb +++ b/lib/portus/hash_utils.rb @@ -38,6 +38,18 @@ def strict_merge_with_env(cfg, local, prefix = "portus") hsh end + # Hide any sensitive value, replacing it with "*" characters. + def hide_password(hsh) + hsh.each do |k, v| + if v.is_a?(Hash) + hsh[k] = hide_password(v) + elsif k == "password" + hsh[k] = "****" + end + end + hsh + end + private # Get the typed value of the specified environment variable. If it doesn't diff --git a/lib/tasks/info.rake b/lib/tasks/info.rake new file mode 100644 index 000000000..90a15f1d5 --- /dev/null +++ b/lib/tasks/info.rake @@ -0,0 +1,10 @@ +namespace :portus do + desc "Get general info about the running instance" + task info: :environment do + puts "\nPortus version: #{Version.value}" + default = File.join(Rails.root, "config", "config.yml") + local = File.join(Rails.root, "config", "config-local.yml") + cfg = Portus::Config.new(default, local) + puts "Portus has evaluated the following configuration:\n#{cfg}" + end +end diff --git a/spec/fixtures/config.yml b/spec/fixtures/config.yml index 0918ff9c5..840fb7fdb 100644 --- a/spec/fixtures/config.yml +++ b/spec/fixtures/config.yml @@ -6,3 +6,7 @@ ldap: hostname: "ldap_hostname" port: 389 base: "" + authentication: + enabled: false + bind_dn: "" + password: "mypassword" diff --git a/spec/lib/portus/config_spec.rb b/spec/lib/portus/config_spec.rb index cf8b0a34c..8264a4651 100644 --- a/spec/lib/portus/config_spec.rb +++ b/spec/lib/portus/config_spec.rb @@ -78,4 +78,14 @@ def strict_merge_with_env(cfg, local, prefix = "portus") expect(cfg["ldap"]["count"]).to eq 2 # env expect(cfg["ldap"]["string"]).to eq "string" # env end + + it "returns the proper config while hiding passwords" do + cfg = get_config("config.yml", "local.yml") + fetched = cfg.fetch + evaled = YAML.load(cfg.to_s) + + expect(fetched).to_not eq(evaled) + fetched["ldap"]["authentication"]["password"] = "****" + expect(fetched).to eq(evaled) + end end diff --git a/spec/models/registry_spec.rb b/spec/models/registry_spec.rb index 107799257..24f35f8f1 100644 --- a/spec/models/registry_spec.rb +++ b/spec/models/registry_spec.rb @@ -218,7 +218,7 @@ def create_empty_namespace mock.get_tag_from_target_test(nil, "busybox", "a", "sha:1234") end - it "fetches the tag from the target if it exists", focus: true do + it "fetches the tag from the target if it exists" do mock = RegistryMock.new(false) # We leave everything empty to show that if the tag is provided, we pick