Skip to content

Abort server startup on invalid SolutionTemplate configuration#3159

Merged
havetisyan merged 4 commits intoAthenZ:masterfrom
gyakami:fix/solution-template/20251212
Dec 20, 2025
Merged

Abort server startup on invalid SolutionTemplate configuration#3159
havetisyan merged 4 commits intoAthenZ:masterfrom
gyakami:fix/solution-template/20251212

Conversation

@gyakami
Copy link
Copy Markdown
Contributor

@gyakami gyakami commented Dec 15, 2025

Description

Modified the server startup process to abort if a SolutionTemplate is found with both Trust and RoleMembers configured.

Additionally, a warning message is now logged in the following scenarios:

  • When applying a SolutionTemplate that sets Trust to a role that already has existing RoleMembers.
  • When applying a SolutionTemplate that sets RoleMembers to a role that already has Trust configured.

Contribution Checklist:

  • The pull request does not introduce any breaking changes
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Attach Screenshots (Optional)

…Template

Signed-off-by: Go Yakami <gyakami@lycorp.co.jp>
…tion templates

Signed-off-by: Go Yakami <gyakami@lycorp.co.jp>
…embers and trusted roles

ZMSImplTest: add test for loading solution templates with null roles
solution_templates.json: add templates for testing role members addition and trust settings

Signed-off-by: Go Yakami <gyakami@lycorp.co.jp>
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @gyakami, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the robustness and reliability of the server by introducing critical validation and warning mechanisms for SolutionTemplate configurations. It prevents the server from initializing with SolutionTemplates that define roles with conflicting 'Trust' and 'RoleMembers' attributes, thereby ensuring data integrity and system stability. Furthermore, it provides runtime warnings when SolutionTemplates are applied in a manner that would create these conflicting states on existing roles, empowering administrators to proactively identify and rectify potential misconfigurations.

Highlights

  • Server Startup Validation: The server startup process will now abort if a SolutionTemplate is found to have a role configured with both 'Trust' and 'RoleMembers', preventing the loading of invalid configurations.
  • Runtime Conflict Warnings: Warning messages are now logged when applying a SolutionTemplate that attempts to set 'Trust' on a role that already has members, or attempts to add members to a role that already has 'Trust'.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces important validation to prevent conflicting configurations in SolutionTemplates, specifically ensuring a role does not have both trust and roleMembers defined. It also adds warnings for applying templates that could lead to such conflicts. The changes are well-implemented and include corresponding tests. My review includes suggestions to improve code readability and maintainability by refactoring nested conditional statements and optimizing map iterations. I've also noted an opportunity to reduce code duplication in the new test methods.

Comment on lines +1316 to +1328
for (String templateName : serverSolutionTemplates.getTemplates().keySet()) {
Template template = serverSolutionTemplates.get(templateName);
if (template.getRoles() == null) {
continue;
}
for (Role role : template.getRoles()) {
if (!StringUtil.isEmpty(role.getTrust()) && role.getRoleMembers() != null && !role.getRoleMembers().isEmpty()) {
LOG.error("Solution Template {} role {} has both trust and members defined. Exiting...",
templateName, role.getName());
throw new RuntimeException("Solution Template " + templateName + " role " + role.getName() + " has both trust and members defined");
}
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better performance and code style, it's recommended to iterate over the map's entrySet instead of its keySet. This avoids the extra get() call for each key in the loop.

Suggested change
for (String templateName : serverSolutionTemplates.getTemplates().keySet()) {
Template template = serverSolutionTemplates.get(templateName);
if (template.getRoles() == null) {
continue;
}
for (Role role : template.getRoles()) {
if (!StringUtil.isEmpty(role.getTrust()) && role.getRoleMembers() != null && !role.getRoleMembers().isEmpty()) {
LOG.error("Solution Template {} role {} has both trust and members defined. Exiting...",
templateName, role.getName());
throw new RuntimeException("Solution Template " + templateName + " role " + role.getName() + " has both trust and members defined");
}
}
}
for (Map.Entry<String, Template> entry : serverSolutionTemplates.getTemplates().entrySet()) {
final String templateName = entry.getKey();
final Template template = entry.getValue();
if (template.getRoles() == null) {
continue;
}
for (Role role : template.getRoles()) {
if (!StringUtil.isEmpty(role.getTrust()) && role.getRoleMembers() != null && !role.getRoleMembers().isEmpty()) {
LOG.error("Solution Template {} role {} has both trust and members defined. Exiting...",
templateName, role.getName());
throw new RuntimeException("Solution Template " + templateName + " role " + role.getName() + " has both trust and members defined");
}
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in a4751d7

Comment on lines +3301 to +3343
public void testAddSolutionTemplateSettingTrustOnRoleWithMembers() throws ServerResourceException {
String domainName = "warn-trust-on-role-with-members";
TopLevelDomain dom1 = createTopLevelDomainObject(domainName, "Test Domain1", "testOrg", adminUser);
zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, null, dom1);

// Create role-with-members-test role with members first
List<RoleMember> members = new ArrayList<>();
members.add(new RoleMember().setMemberName("user.joe"));
Role role = createRoleObject(domainName, "role-with-members-test", null, members);
zms.putRole(mockDomRsrcCtx, domainName, "role-with-members-test", auditRef, false, null, role);

// Setup log appender to capture warning messages
boolean[] warningLogged = new boolean[1];
Logger dbServiceLogger = (Logger) LoggerFactory.getLogger(DBService.class);
AppenderBase testAppender = new AppenderBase() {
@Override
protected void append(Object o) {
if (o instanceof LoggingEvent) {
String message = ((LoggingEvent) o).getMessage();
if (message.contains("SolutionTemplate is setting trust on role") &&
message.contains("which already has members")) {
warningLogged[0] = true;
}
}
}
};
testAppender.start();
dbServiceLogger.addAppender(testAppender);

// Apply template which tries to set trust on this role
List<String> templates = new ArrayList<>();
templates.add("templateWithTrustRoleTest");
DomainTemplate domainTemplate = new DomainTemplate().setTemplateNames(templates);
zms.dbService.executePutDomainTemplate(mockDomRsrcCtx, domainName, domainTemplate, auditRef, "testCaller");

testAppender.stop();
dbServiceLogger.detachAppender(testAppender);

// Verify the warning was logged
assertTrue(warningLogged[0], "Expected warning log about setting trust on role with members");

zms.deleteTopLevelDomain(mockDomRsrcCtx, domainName, auditRef, null);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This test method contains significant boilerplate code for setting up a log appender to capture warnings. This same logic is duplicated in testAddSolutionTemplateAddingMembersToTrustedRole. To improve maintainability and reduce code duplication, consider refactoring this logging setup and teardown into a private helper method within this test class.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the log output is a temporary measure, I'd like to leave this as is.

Signed-off-by: Go Yakami <gyakami@lycorp.co.jp>
@havetisyan havetisyan merged commit 9d8700a into AthenZ:master Dec 20, 2025
3 checks passed
@gyakami gyakami deleted the fix/solution-template/20251212 branch December 22, 2025 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants