-
Notifications
You must be signed in to change notification settings - Fork 723
Fix plugin secrets in config #6249
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
Open
bentsherman
wants to merge
1
commit into
master
Choose a base branch
from
fix-plugin-secrets-config
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -13,6 +13,8 @@ This feature allows you to decouple the use of secrets in your pipelines from th | |||||
|
||||||
When a pipeline is launched, Nextflow injects the secrets into the run without leaking them into temporary execution files. Secrets are provided to tasks as environment variables. | ||||||
|
||||||
Secrets can be used with the local executor and the grid executors (e.g., Slurm or Grid Engine). Secrets can be used with the AWS Batch executor when launched from [Seqera Platform](https://seqera.io/blog/pipeline-secrets-secure-handling-of-sensitive-information-in-tower/). | ||||||
|
||||||
## Command line | ||||||
|
||||||
The Nextflow {ref}`cli-secrets` sub-command can be used to manage secrets: | ||||||
|
@@ -45,9 +47,32 @@ aws { | |||||
The above snippet accesses the secrets `MY_ACCESS_KEY` and `MY_SECRET_KEY` and assigns them to the corresponding AWS config settings. | ||||||
|
||||||
:::{warning} | ||||||
Secrets cannot be assigned to pipeline parameters. | ||||||
Secrets should not be assigned to pipeline parameters, as they can be easily leaked by the pipeline. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Highly optional suggestion |
||||||
::: | ||||||
|
||||||
:::{versionadded} 25.10.0 | ||||||
::: | ||||||
|
||||||
Nextflow supports the use of secrets provided by plugins (e.g., AWS secrets) in configuration. However, due to the way that plugins are loaded, there are specific considerations when using config secrets: | ||||||
|
||||||
- **Initial config load**: Nextflow first loads the configuration _without_ secrets enabled. Any reference to a secret will return the empty string `''`. | ||||||
|
||||||
- **Plugin resolution**: Plugins are resolved after the initial configuration load. This is because the configuration can specify additional plugins. | ||||||
|
||||||
- **Config reloading**: If secrets are accessed during configuration and the initial load succeeds, Nextflow will reload the configuration with secrets enabled. | ||||||
|
||||||
As a result, config secrets must be used in a way that does not cause the config resolution to fail when secrets are not present. | ||||||
|
||||||
For example: | ||||||
|
||||||
```groovy | ||||||
includeConfig secrets.MY_SECRET | ||||||
? "https://example.com/extra.config?secret=${secrets.MY_SECRET}" | ||||||
: '/dev/null' | ||||||
``` | ||||||
|
||||||
The above snippet includes a secured config only if the secret is present. Otherwise, it includes `/dev/null`, which is equivalent to including an empty file. The reference to `secrets.MY_SECRET` in the condition causes the config to be reloaded with secrets enabled, including secrets from plugins such as AWS secrets. | ||||||
|
||||||
(secrets-pipeline-script)= | ||||||
|
||||||
## Pipeline script | ||||||
|
@@ -67,10 +92,6 @@ workflow { | |||||
The above example is only meant to demonstrate how to access a secret, not how to use it. In practice, sensitive information should not be printed to the console or output files. | ||||||
::: | ||||||
|
||||||
:::{note} | ||||||
Secrets can only be used with the local or grid executors (e.g., Slurm or Grid Engine). Secrets can be used with the AWS Batch executor when launched from [Seqera Platform](https://seqera.io/blog/pipeline-secrets-secure-handling-of-sensitive-information-in-tower/). | ||||||
::: | ||||||
|
||||||
## Process directive | ||||||
|
||||||
Secrets can be accesses by processes using the {ref}`process-secret` directive. For example: | ||||||
|
@@ -92,7 +113,3 @@ In the above example, the secrets `MY_ACCESS_KEY` and `MY_SECRET_KEY` are inject | |||||
:::{warning} | ||||||
Secrets are made available as environment variables in the process script. To prevent evaluation in the Nextflow script context, escape variable names with a backslash (e.g., `\$MY_ACCESS_KEY`) as shown above. | ||||||
::: | ||||||
|
||||||
:::{note} | ||||||
Secrets can only be used with the local or grid executors (e.g., Slurm or Grid Engine). Secrets can be used with the AWS Batch executor when launched from [Seqera Platform](https://seqera.io/blog/pipeline-secrets-secure-handling-of-sensitive-information-in-tower/). | ||||||
::: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
modules/nextflow/src/main/groovy/nextflow/secret/ConfigNullProvider.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2013-2024, Seqera Labs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package nextflow.secret | ||
|
||
import groovy.transform.CompileStatic | ||
|
||
/** | ||
* Specialization of the null secrets provider that is used to | ||
* determine whether secrets are required in the config. | ||
* | ||
* @author Ben Sherman <[email protected]> | ||
*/ | ||
@CompileStatic | ||
class ConfigNullProvider extends NullProvider { | ||
|
||
private boolean accessed | ||
|
||
@Override | ||
Secret getSecret(String name) { | ||
accessed = true | ||
return new SecretImpl(name, '') | ||
} | ||
|
||
boolean usedSecrets() { | ||
return accessed | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ import org.pf4j.ExtensionPoint | |
/** | ||
* Factory class for creating {@link TraceObserverV2} instances | ||
* | ||
* @author Ben Shermann <[email protected]> | ||
* @author Ben Sherman <[email protected]> | ||
*/ | ||
interface TraceObserverFactoryV2 extends ExtensionPoint { | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
set -e | ||
|
||
$NXF_CMD secrets set MY_SECRET hello-world | ||
|
||
$NXF_RUN -c ../../config-secrets.config | tee stdout | ||
|
||
< .nextflow.log grep "Config file used secrets -- reloading config with secrets provider" || false | ||
< stdout grep "outputDir: results-hello-world" || false | ||
|
||
$NXF_CMD secrets delete MY_SECRET |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
outputDir = secrets.MY_SECRET ? "results-$secrets.MY_SECRET" : 'results' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
workflow { | ||
println "outputDir: ${workflow.outputDir.name}" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.