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

Change secret keys docs to recommend registering an interceptor #841

Merged
merged 4 commits into from
Nov 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions documentation/src/main/docs/config/secret-keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ accidental exposure of such values.
secrets. However, there is still the basic problem that passwords and secrets are generally encoded simply as strings.
Secret Keys provides a way to "lock" the configuration so that secrets do not appear unless explicitly enabled.

Secret Keys requires the list of the configuration property names that must be hidden. This can be supplied
in `SmallRyeConfigBuilder#withSecretKeys`.
To mark specific keys as secret, register an instance of `io.smallrye.config.SecretKeysConfigSourceInterceptor`
using your own interceptor factory, like this:

```java
SmallRyeConfig config = new SmallRyeConfigBuilder()
.addDefaultSources()
.addDefaultInterceptors()
.withSources(KeyValuesConfigSource.config(keyValues))
.withSecretKeys("secret")
.build()
public class SecretKeysConfigInterceptorFactory implements ConfigSourceInterceptorFactory {
@Override
public ConfigSourceInterceptor getInterceptor(ConfigSourceInterceptorContext context) {
return new SecretKeysConfigSourceInterceptor(Set.of("secret"));
}
}
```

You will need to register this factory to be found at runtime by creating a `META-INF/services/io.smallrye.config.ConfigSourceInterceptorFactory`
file containing the fully qualified name of this factory class.

From this point forward, every lookup to the configuration name `secret` will throw a `SecurityException`.

Access to the Secret Keys, is available via the APIs `io.smallrye.config.SecretKeys#doUnlocked(java.lang.Runnable)`
Expand Down