Skip to content

Commit

Permalink
chore(webserver): warn if security group is wet without a jwt secret (#…
Browse files Browse the repository at this point in the history
…1412)

close #1395
  • Loading branch information
Lazzaretti authored and tchiotludo committed Apr 4, 2023
1 parent 7a2cad4 commit 911ed5e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
5 changes: 5 additions & 0 deletions docs/docs/configuration/authentifications/groups.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ Define groups with specific roles for your users
If you have `topics/create` or `connect/create` roles and you try to create a resource that doesn't follow the regexp, that resource **WILL** be created.
:::

::: warning
Please also set the `micronaut.security.token.jwt.signatures.secret.generator.secret` if you set a group.
If the secret is not set, the API will not enforce the group role, and the restriction is in the UI only.
:::

3 defaults group are available :
- `admin` with all right
- `reader` with only read access on all AKHQ
Expand Down
39 changes: 28 additions & 11 deletions src/main/java/org/akhq/configs/JwtSecurityWarning.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import lombok.extern.slf4j.Slf4j;

import javax.annotation.PostConstruct;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import java.lang.Runnable;

@Singleton
@Slf4j
Expand All @@ -21,20 +23,35 @@ public class JwtSecurityWarning {
@Value("${micronaut.security.enabled:false}")
protected Boolean enabled;

@Inject
protected SecurityProperties securityProperties;

@PostConstruct
public void start() {
if (enabled && secret.equals(DEFAULT)) {
log.warn("");
log.warn("##############################################################");
log.warn("# SECURITY WARNING #");
log.warn("##############################################################");
log.warn("");
log.warn("You still use the default jwt secret.");
log.warn("This known secret can be used to impersonate anyone.");
log.warn("Please change 'micronaut.security.token.jwt.signatures.secret.generator.secret' configuration, or ask your administrator to do it !");
log.warn("");
log.warn("##############################################################");
log.warn("");
logSecurityWarning(() -> {
log.warn("You still use the default jwt secret.");
log.warn("This known secret can be used to impersonate anyone.");
log.warn("Please change 'micronaut.security.token.jwt.signatures.secret.generator.secret' configuration, or ask your administrator to do it !");
});
} else if (!enabled && securityProperties.getGroups() != null && !securityProperties.getGroups().isEmpty()){
logSecurityWarning(() -> {
log.warn("You have set a security group config but did not set the jwt secret.");
log.warn("This means that the API request will not be checked against the security group config.");
log.warn("Please set the 'micronaut.security.token.jwt.signatures.secret.generator.secret' configuration, or ask your administrator to do it !");
});
}
}

private static void logSecurityWarning(Runnable printBody) {
log.warn("");
log.warn("##############################################################");
log.warn("# SECURITY WARNING #");
log.warn("##############################################################");
log.warn("");
printBody.run();
log.warn("");
log.warn("##############################################################");
log.warn("");
}
}

0 comments on commit 911ed5e

Please sign in to comment.