Skip to content

Commit 8998fca

Browse files
GUACAMOLE-2219: Fix vault token resolution for BALANCING connection groups
When connecting through a BALANCING connection group, the JDBC layer internally selects and connects a child connection, bypassing the vault extension's TokenInjectingConnection wrapper. This means addTokens(Connection) is never called for the selected child, and vault-managed tokens (e.g. KEEPER_USER_PASSWORD) are not resolved, causing authentication failures on the child connection. This commit addresses two issues: 1. VaultUserContext.addTokens(ConnectionGroup) now detects BALANCING groups and pre-resolves vault tokens for all child connections, ensuring tokens are available when the JDBC layer applies them to the selected child's configuration. 2. KsmSecretService.getTokens() now guards against null GuacamoleConfiguration, which is always null for connection groups since they have no protocol configuration. Previously this caused a NullPointerException.
1 parent 90a938c commit 8998fca

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

  • extensions/guacamole-vault/modules

extensions/guacamole-vault/modules/guacamole-vault-base/src/main/java/org/apache/guacamole/vault/user/VaultUserContext.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.Collections;
2828
import java.util.HashMap;
2929
import java.util.Map;
30+
import java.util.Set;
3031
import java.util.concurrent.ExecutionException;
3132
import java.util.concurrent.Future;
3233
import java.util.stream.Collectors;
@@ -357,6 +358,72 @@ protected void addTokens(ConnectionGroup connectionGroup,
357358
connectionGroup, confService.getTokenMapping(), filter,
358359
null, new TokenFilter(tokens))));
359360

361+
// For BALANCING groups, the JDBC layer selects and connects a child
362+
// connection internally, bypassing the vault's addTokens(Connection).
363+
// Pre-resolve vault tokens for child connections here so they are
364+
// available when the JDBC layer applies tokens to the child's config.
365+
if (connectionGroup.getType() == ConnectionGroup.Type.BALANCING) {
366+
367+
Set<String> childIds;
368+
try {
369+
childIds = connectionGroup.getConnectionIdentifiers();
370+
}
371+
catch (GuacamoleException e) {
372+
logger.debug("Unable to retrieve child connection identifiers "
373+
+ "for BALANCING group \"{}\": {}", identifier,
374+
e.getMessage());
375+
return;
376+
}
377+
378+
for (String childId : childIds) {
379+
try {
380+
381+
Connection child = getPrivileged()
382+
.getConnectionDirectory().get(childId);
383+
if (child == null)
384+
continue;
385+
386+
GuacamoleConfiguration childConfig =
387+
child.getConfiguration();
388+
if (childConfig == null)
389+
continue;
390+
391+
logger.debug("Resolving vault tokens for BALANCING "
392+
+ "child connection \"{}\" (\"{}\").",
393+
child.getIdentifier(), child.getName());
394+
395+
TokenFilter childFilter = createFilter();
396+
childFilter.setToken(CONNECTION_NAME_TOKEN,
397+
child.getName());
398+
childFilter.setToken(CONNECTION_IDENTIFIER_TOKEN,
399+
child.getIdentifier());
400+
401+
Map<String, String> parameters =
402+
childConfig.getParameters();
403+
404+
String hostname = parameters.get("hostname");
405+
if (hostname != null && !hostname.isEmpty())
406+
childFilter.setToken(CONNECTION_HOSTNAME_TOKEN,
407+
hostname);
408+
409+
String username = parameters.get("username");
410+
if (username != null && !username.isEmpty())
411+
childFilter.setToken(CONNECTION_USERNAME_TOKEN,
412+
username);
413+
414+
tokens.putAll(resolve(getTokens(child,
415+
confService.getTokenMapping(), childFilter,
416+
childConfig, new TokenFilter(tokens))));
417+
418+
}
419+
catch (GuacamoleException e) {
420+
logger.debug("Unable to resolve vault tokens for "
421+
+ "child connection \"{}\": {}",
422+
childId, e.getMessage());
423+
}
424+
}
425+
}
426+
360427
}
361428

362429
/**

extensions/guacamole-vault/modules/guacamole-vault-ksm/src/main/java/org/apache/guacamole/vault/ksm/secret/KsmSecretService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,11 @@ public Map<String, Future<String>> getTokens(UserContext userContext, Connectabl
520520
GuacamoleConfiguration config, TokenFilter filter) throws GuacamoleException {
521521

522522
Map<String, Future<String>> tokens = new HashMap<>();
523+
524+
// Connection groups have no GuacamoleConfiguration — nothing to resolve
525+
if (config == null)
526+
return tokens;
527+
523528
Map<String, String> parameters = config.getParameters();
524529

525530
// Only use the user-specific KSM config if explicitly enabled in the global

0 commit comments

Comments
 (0)