Skip to content

feat: secret-store implementation#9775

Closed
srebhan wants to merge 49 commits intoinfluxdata:masterfrom
HRI-EU:secret_store
Closed

feat: secret-store implementation#9775
srebhan wants to merge 49 commits intoinfluxdata:masterfrom
HRI-EU:secret_store

Conversation

@srebhan
Copy link
Copy Markdown
Member

@srebhan srebhan commented Sep 17, 2021

Required for all PRs:

  • Updated associated README.md.
  • Wrote appropriate unit tests.
  • Pull request title or commits are in conventional commit format (e.g. feat: or fix:)

resolves #3124

This PR implements a secret-store able to store secrets (e.g. usernames, passwords, tokens,...) that can referenced in the telegraf config. This effectively allows to remove secrets from config file(s) and store them in a "safe" place.
The secret-store can be configured using the "global" [[secretstore]] section(s) and allows different backends to be used e.g. OS native stores (kernel keyrings for linux, Windows credential manager and keychain for MacOS), encrypted files and other services. Further implementation may be added later.

The stored secrets can be easily referenced via an @{<secretstore name>:<secret identifier>} pattern, with <secretstore name> being the name you give to the secret-store and secret identifier being the unique key for the secret. To enable secret references in a config option you need to change the type to Secret, which will also make static secrets stored encrypted in memory. This has be done in this PR for inputs.http and inputs.sql for reference.
Multiple secret stores can be defined and referenced by the name specified in the secret-store config. This name has to be unique for the telegraf instance.

Secrets can be either managed using the tools native to the backend (e.g. using keyctl) or using telegraf. Commands for getting/setting and listing secrets have been added (e.g. ./telegraf secret set <secretstore name> sqlthing "incredible"). When using telegraf, the config is parsed and must contain an uncommented [[secretstore]] section.

Limitations

  • There is no access control, i.e. if a plugin references a secret it will get that secret no matter if it was intended by the user as secrets are simply injected into the structure. We might work out an access-control regime here, but it is not yet in place (suggestions welcome).
  • Currently, all @{\w+:\w+} patterns are replaced (in the tagged fields). There is currently no way to escape that pattern.
  • tested with Linux kernel user-session keyring and file keyring ONLY
  • no unit-tests yet

Suggestions, comments and critique is welcome!

@telegraf-tiger telegraf-tiger bot added the feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin label Sep 17, 2021
@srebhan srebhan force-pushed the secret_store branch 2 times, most recently from 13e3bbe to ee6789a Compare September 21, 2021 09:06
@powersj powersj requested a review from sspaink September 22, 2021 15:34
Copy link
Copy Markdown
Contributor

@sspaink sspaink left a comment

Choose a reason for hiding this comment

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

Minor requested changes, I couldn't get it working on Windows and shame github.com/99designs/keyring documentation is sparse. Definitely worth trying to setup some scripts in CI to test this, looks like for Windows you can use powershell to setup a windows credential manager: https://stackoverflow.com/questions/29103238/accessing-windows-credential-manager-from-powershell

I know you haven't tried Windows yet, but maybe you can spot my mistake:

The config I setup

[[secretstore]]
name = "secretstore"
service = "os://telegraf"

The credentials I setup in windows credential manager

image

Returns empty secrets:

❯ ./telegraf.exe --config telegraf.conf secret list secretstore                                                                                                             ─╯ 
Known secrets:

if err != nil {
log.Fatalf("E! Listing keys failed: %v", err)
}
//nolint:revive // If print fails we will notice
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe we should disable linting return errors for fmt

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That would be great.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Any update here @sspaink?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Done: #9967

@crflanigan
Copy link
Copy Markdown
Contributor

crflanigan commented Oct 22, 2021

This looks awesome!

I have a use case for this right now for protecting a private key Telegraf references to start off an OAuth flow using a new output plugin my partner and I are working on.

Can't wait to start playing with this,

Have a wonderful day and good luck with your pull request!

@aratik711
Copy link
Copy Markdown
Contributor

@sspaink @srebhan when would this get merged in a release, any ETA?

@srebhan
Copy link
Copy Markdown
Member Author

srebhan commented Dec 3, 2021

@aratik711 no ETA from my side, let me explain. I first would need to find out what is going on in Windows (see Sebastian's comment above), then fix the panic and some other small things that came up during review.
As this is not my day-job, I would appreciate some help especially with testing the windows part. My guess there is that the credentials are not found by telegraf as the external library expects some prefixes in front. If you can help me with this, I can try to fix the other parts within the next week.... The rest is the up to Influx people... ;-P

@aratik711
Copy link
Copy Markdown
Contributor

@srebhan I haven't got any exposure to windows unfortunately :(
Would be able to help with Linux OS though.

@srebhan
Copy link
Copy Markdown
Member Author

srebhan commented Dec 7, 2021

@aratik711 same here. Maybe I can setup some virtual machine next week, but I would hope someone shows up to test this in other OSes... :-)

@srebhan
Copy link
Copy Markdown
Member Author

srebhan commented Dec 8, 2021

@sspaink I updated the PR a bit. Regarding the Windows credential my first guess was correct. The underlying library adds a prefix to the secret-key. If you do not follow this convention, you will not see this key in telegraf. Here is an example (in German unfortunately)

image

where you see http_user_1 (created with telegraf) and http_pass_1 (created with the Windows credential tool) that are both accessible in telegraf.

@srebhan srebhan requested a review from sspaink December 8, 2021 22:39
@telegraf-tiger
Copy link
Copy Markdown
Contributor

telegraf-tiger bot commented Dec 8, 2021

@srebhan
Copy link
Copy Markdown
Member Author

srebhan commented Dec 8, 2021

@aratik711 you can use the binary built by telegraf-tiger above to play around with the PR...

@aratik711
Copy link
Copy Markdown
Contributor

Thanks @srebhan, appreciate it. Will try it out.

@sspaink
Copy link
Copy Markdown
Contributor

sspaink commented Apr 11, 2022

Using the suggested name with the prefix: keyring:telegraf seems to work!

The output for running get looks a bit strange, but not sure if that is intended:

❯ ./telegraf.exe --config test.conf secret get secretstore
t e s t                                                                            

I think this is amazing work! Could you perhaps add a doc giving a step-by-step example on using [[secretstore]] with a native store?

@srebhan
Copy link
Copy Markdown
Member Author

srebhan commented Apr 18, 2022

@sspaink can you please provide a way to reproduce your setup? On linux I get:

./telegraf --config test_configs/secretstore_test.conf secret get secretstore                                                         1853ms  Mon 18 Apr 2022 06:34:59 PM CEST
+--------------------------------+--------------------------------+
| key                            | secret                         |
+--------------------------------+--------------------------------+
| http_pass_1                    | the secret one                 |
| http_pass_2                    | the secret two                 |
+--------------------------------+--------------------------------+

@telegraf-tiger
Copy link
Copy Markdown
Contributor

@srebhan
Copy link
Copy Markdown
Member Author

srebhan commented Apr 28, 2022

The output for running get looks a bit strange, but not sure if that is intended:

❯ ./telegraf.exe --config test.conf secret get secretstore
t e s t                                                                            

Can you please outline on what you are doing in which environment and how you do get this output? I'm asking because I cannot reproduce this with a Linux machine yet...

I think this is amazing work! Could you perhaps add a doc giving a step-by-step example on using [[secretstore]] with a native store?

Yeah let's get the implementation straight and then I'll definitively add an example for each store type.

@srebhan srebhan mentioned this pull request Jun 1, 2022
3 tasks
@srebhan
Copy link
Copy Markdown
Member Author

srebhan commented Jun 1, 2022

An improved version (plugin structure, unit tests, docu,...) can be found in #11232.

@srebhan srebhan closed this Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hide passwords in Telegraf config

4 participants