8000 [Security][SecurityBundle] Dump role hierarchy as mermaid chart by damienfern · Pull Request #61034 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Security][SecurityBundle] Dump role hierarchy as mermaid chart #61034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: 7.4
Choose a base branch
from

Conversation

damienfern
Copy link
Contributor
Q A
Branch? 7.4
Bug fix? no
New feature? yes
Deprecations? no
License MIT

From a developer POV, Roles and the SecurityBundle are so convenient, specially role hierarchy in the config. But as a web app grows, the number of roles also grows and with role inheritance, it can be painful to clearly see which role implies another which implies another which implies another (and its possible consequences).

I'm proposing a new command in the security bundle to generate a Mermaid flowchart, easing the understanding of the roles and its hierarchy. An example of the graph generated from the role hierarchy in the doc :

# config/packages/security.yaml
security:
    # ...

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
graph TB
    ROLE_ADMIN
    ROLE_USER
    ROLE_SUPER_ADMIN
    ROLE_ALLOWED_TO_SWITCH
    ROLE_ADMIN --> ROLE_USER
    ROLE_SUPER_ADMIN --> ROLE_ADMIN
    ROLE_SUPER_ADMIN --> ROLE_ALLOWED_TO_SWITCH
Loading

For now, only the mermaid format is suggested (the only format I know) but as the worfklow dump command, we could implement graphviz and plantuml format later.

@damienfern damienfern requested a review from chalasr as a code owner July 4, 2025 10:01
@carsonbot carsonbot added this to the 7.4 milestone Jul 4, 2025
@carsonbot carsonbot changed the title [Security] [SecurityBundle] Dump role hierarchy as mermaid chart [Security][SecurityBundle] Dump role hierarchy as mermaid chart Jul 4, 2025
];

public function __construct(
private readonly string $direction = self::DIRECTION_TOP_TO_BOTTOM,
Copy link
Member

Choose a reason for hiding this comment

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

Moving $direction argument to dump method would allow to dump multiple times the same role hierarchy in different directions without the need to instanciate multiple dumpers. WDYT?

7.4
---

* Added `MermaidDumper` to dump Role Hierarchy graphs in the Mermaid.js flowchart format
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Added `MermaidDumper` to dump Role Hierarchy graphs in the Mermaid.js flowchart format
* Add `MermaidDumper` to dump Role Hierarchy graphs in the Mermaid.js flowchart format

@94noni
Copy link
Contributor
94noni commented Jul 6, 2025

Nice one 👍🏻
Question: would it be possible to include this in the profiler like the workflow dump ?
We can even imagine each role box colored depending on the current user roles from this config map

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0