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

Resolve secrets in ERB strings #30228

Merged
merged 2 commits into from
Aug 21, 2019
Merged

Resolve secrets in ERB strings #30228

merged 2 commits into from
Aug 21, 2019

Conversation

wjordan
Copy link
Contributor

@wjordan wjordan commented Aug 9, 2019

Allow configuration values to depend on secrets within interpolated strings (such as db_reader: !Secret referenced within dashboard_db_reader: '<%="#{db_reader}#{dashboard_db_name}"%>'.

For the implementation, I've added an internal string representation of the secret as ${secretkey}, which is matched in the lazy_load_secrets! method enhanced to regex-replace (gsub) all secrets found within string values.

Added a test (test_erb_string_secret) to verify the new functionality, and I also added some extra coverage around json secrets (test_json_secret) and fixed a related bug in how json secrets get passed through the system.

Allow keys such as dashboard_db_reader to depend on db_reader secret.
add test_erb_string_secret
@codecov-io
Copy link

codecov-io commented Aug 9, 2019

Codecov Report

❗ No coverage uploaded for pull request base (staging@2272520). Click here to learn what that means.
The diff coverage is 60%.

Impacted file tree graph

@@            Coverage Diff             @@
##             staging   #30228   +/-   ##
==========================================
  Coverage           ?   76.52%           
==========================================
  Files              ?      677           
  Lines              ?    27679           
  Branches           ?        0           
==========================================
  Hits               ?    21181           
  Misses             ?     6498           
  Partials           ?        0
Impacted Files Coverage Δ
lib/cdo/secrets_config.rb 66% <50%> (ø)
lib/cdo/secrets.rb 61.42% <66.66%> (ø)
lib/cdo/lazy.rb 85.71% <71.42%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2272520...4e330b6. Read the comment docs.

Copy link

@uponthesun uponthesun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • This change explicitly only allows interpolation of config values if those values come from secrets, is that right?

  • We should take a minute to discuss possible alternatives, since the more features we add the more complex our mini config language is going to get. What if instead we had these as methods on the CDO object, similar to dashboard_hostname?

    def dashboard_hostname

@wjordan
Copy link
Contributor Author

wjordan commented Aug 19, 2019

We should take a minute to discuss possible alternatives, since the more features we add the more complex our mini config language is going to get.

I believe this change (basically a bug-fix) is much more narrowly scoped compared to any of the alternatives I considered.

This change explicitly only allows interpolation of config values if those values come from secrets, is that right?

Prior to this change, references to Secret values resolved to nil. With this change, references to Secret values will resolve to the value of the secret just like all other config values.

What if instead we had these as methods on the CDO object, similar to dashboard_hostname?

Adding global CDO methods to resolve values referencing Secrets would mean two ways to reference a config value (ERB or CDO method), depending on whether the value to be referenced is defined as (or might possibly be overridden to be) a Secret. I think this would be more complicated to work with than the change in this PR.

A possibly simpler alternative would be to replace all ERB tags in the config with global CDO methods (get rid of the ERB layer entirely), but that would be an even more challenging task.

More generally, I've been trying to eliminate/refactor all of the legacy global methods in the CDO config for a few reasons:

  • Global CDO methods aren't declared in the same config file as the other configuration values, so it becomes more complex to locate config values.
  • Global CDO methods don't currently support the configuration-override hierarchy, so e.g., allowing a global method to be optionally customized/overridden by local config would take extra work.
  • Global CDO methods get executed on every reference, which means the return value of a method might change from one call to another. Mixing dynamic method calls alongside static configuration properties adds complexity and makes it harder to reason about config behavior in general.

@wjordan
Copy link
Contributor Author

wjordan commented Aug 21, 2019

Happy to followup on any remaining design questions, but I'm going to merge this PR now to fix the specific issue and unblock ongoing work.

@wjordan wjordan merged commit f44b23b into staging Aug 21, 2019
@wjordan wjordan deleted the secrets_erb branch August 21, 2019 23:07
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.

3 participants