Skip to content

Commit accb952

Browse files
committed
fix: detect unresolved secrets in SqlDataSource
Add resolveCredential method to SqlDataSource that detects unresolved workspace secrets patterns like 'secrets.ATHENA_USER' and '[secret]'. This prevents silent fallback to default credentials when secrets aren't properly resolved by Nextflow's secrets system. The method provides comprehensive error messages with troubleshooting guidance for common secrets configuration issues. Fixes issue where plugin would use default username 'sa' instead of failing fast when workspace secrets were not accessible. Signed-off-by: Edmund Miller <[email protected]>
1 parent fbf0e6f commit accb952

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

plugins/nf-sqldb/src/main/nextflow/sql/ChannelSqlExtension.groovy

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,9 @@ class ChannelSqlExtension extends PluginExtensionPoint {
106106
final dataSource = config.getDataSource(dsName)
107107
if( dataSource==null ) {
108108
def msg = "Unknown db name: $dsName"
109-
def choices = config.getDataSourceNames().closest(dsName) ?: config.getDataSourceNames()
110-
if( choices?.size() == 1 )
111-
msg += " - Did you mean: ${choices.get(0)}?"
112-
else if( choices )
113-
msg += " - Did you mean any of these?\n" + choices.collect { " $it"}.join('\n') + '\n'
109+
def choices = config.getDataSourceNames()
110+
if( choices )
111+
msg += " - Available databases: " + choices.join(', ')
114112
throw new IllegalArgumentException(msg)
115113
}
116114
return dataSource

plugins/nf-sqldb/src/main/nextflow/sql/config/SqlDataSource.groovy

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,53 @@ class SqlDataSource {
4343
SqlDataSource(Map opts) {
4444
this.url = opts.url ?: DEFAULT_URL
4545
this.driver = opts.driver ?: urlToDriver(url) ?: DEFAULT_DRIVER
46-
this.user = opts.user ?: DEFAULT_USER
47-
this.password = opts.password
46+
this.user = resolveCredential(opts.user, 'user') ?: DEFAULT_USER
47+
this.password = resolveCredential(opts.password, 'password')
4848
}
4949

5050
SqlDataSource(Map opts, SqlDataSource fallback) {
5151
this.url = opts.url ?: fallback.url ?: DEFAULT_URL
5252
this.driver = opts.driver ?: urlToDriver(url) ?: fallback.driver ?: DEFAULT_DRIVER
53-
this.user = opts.user ?: fallback.user ?: DEFAULT_USER
54-
this.password = opts.password ?: fallback.password
53+
this.user = resolveCredential(opts.user, 'user') ?: fallback.user ?: DEFAULT_USER
54+
this.password = resolveCredential(opts.password, 'password') ?: fallback.password
5555
}
5656

5757
protected String urlToDriver(String url) {
5858
DriverRegistry.DEFAULT.urlToDriver(url)
5959
}
6060

61+
/**
62+
* Resolves a credential value, checking for unresolved secrets and providing appropriate error handling
63+
*
64+
* @param value The credential value from configuration
65+
* @param credType The type of credential ('user' or 'password') for error messages
66+
* @return The resolved credential value, or null if not provided
67+
* @throws IllegalArgumentException if an unresolved secret is detected
68+
*/
69+
protected String resolveCredential(Object value, String credType) {
70+
if (value == null) {
71+
return null
72+
}
73+
74+
String stringValue = value.toString()
75+
76+
// Check for unresolved secrets (patterns like 'secrets.ATHENA_USER' or similar)
77+
if (stringValue.startsWith('secrets.') || stringValue.contains('secret') && stringValue.contains('[') && stringValue.contains(']')) {
78+
throw new IllegalArgumentException(
79+
"Unresolved secret detected for $credType: '$stringValue'. " +
80+
"This typically indicates that workspace secrets are not properly configured or accessible. " +
81+
"Please verify that:\n" +
82+
"1. The secret is defined in your workspace/user secrets\n" +
83+
"2. The secret name matches exactly (case-sensitive)\n" +
84+
"3. You have proper permissions to access the secret\n" +
85+
"4. The Nextflow version supports secrets integration (>=25.04.0)\n" +
86+
"See: https://www.nextflow.io/docs/latest/secrets.html"
87+
)
88+
}
89+
90+
return stringValue.isEmpty() ? null : stringValue
91+
}
92+
6193
Map toMap() {
6294
final result = new HashMap(10)
6395
if( url )

0 commit comments

Comments
 (0)