Skip to content

Add ability to specify multiple Keycloak client templates - #49

Open
HappyTetrahedron wants to merge 3 commits into
deps/updatefrom
feat/multiple_clients
Open

HappyTetrahedron wants to merge 3 commits into
deps/updatefrom
feat/multiple_clients

Conversation

@HappyTetrahedron

@HappyTetrahedron HappyTetrahedron commented Aug 28, 2026

Copy link
Copy Markdown

Summary

  • The client template can now generate a list (instead of a single client instance) - if it does, multiple Keycloak clients are created.
    • It's up to the user to ensure each client gets a unique ID
  • A single instance (without a list) is still accepted, for backwards compatibility.
  • We still only accept a single role mapping - the same role mapping is configured in all clients.
  • Since we now potentially need to create multiple secrets in Vault, the client ID is included in the secret path. This will require updates in the Syn hierarchy.

Open questions

  • This is a pretty quick-and-dirty implementation at the moment. Is this good enough, or should I flesh it out more?
  • Any better ideas for the test case that do not involve duplicating the whole E2E test?
  • Is re-using the same role mapping for everything good enough?
  • Is the new secret naming OK or should the path be different?

Checklist

  • Categorize the PR by setting a good title and adding one of the labels:
    bug, enhancement, documentation, change, breaking, dependency
    as they show up in the changelog
  • Update tests.

@HappyTetrahedron HappyTetrahedron added the enhancement New feature or request label Aug 28, 2026
@HappyTetrahedron
HappyTetrahedron changed the base branch from master to deps/update August 28, 2026 14:59
@HappyTetrahedron
HappyTetrahedron requested a review from a team August 28, 2026 15:00

@simu simu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is a good start.

Is re-using the same role mapping for everything good enough?

Right now, it's probably fine, but eventually, we may want to be able to not give customers access to everything that we can access.

Is the new secret naming OK or should the path be different?

See inline suggestion for a couple alternatives.

Overall, I think we should keep this open until @bastjan has a chance to review it.

Comment thread controllers/cluster_controller.go Outdated
Comment thread controllers/cluster_controller.go Outdated
return ctrl.Result{}, fmt.Errorf("unable to template keycloak clients: %w", err)
}
// template client roles
rolesRaw, err := jvm.EvaluateFile(r.ClientRoleMappingTemplateFile)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We probably could pass the templated client while evaluating the roles so we can have different mappings for different clients.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Smart. I hope it's ok to reuse the JVM the way I did?

Comment thread controllers/cluster_controller.go Outdated
return []gocloak.Client{}, fmt.Errorf("unable to evaluate jsonnet: %w", err)
}
var cs []gocloak.Client
if err := json.Unmarshal([]byte(cRaw), &cs); err != nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

While good enough this could be done slightly nicer with jsontext.Decoder.PeekKind().

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This necessitated an update to go 1.27, I hope I did that right

@bastjan

bastjan commented Sep 10, 2026

Copy link
Copy Markdown
Member

Looks pretty good. But: I'd pass the client to the mapping Jsonnet (evaluate once per client) so we can have individual mappings.

Use jsontext.PeekKind to distinguish between single client and client
list

Update go to 1.27.1 for jsontext support

Provide current client as context when rendering client role mappings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants