-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Validate role templates before saving role mapping #52636
Changes from 13 commits
3cce84d
07c7819
a593def
3e2e4b4
46cc8d3
e07b243
51d9c20
18333bb
e4f8ec2
d58a4c8
4587f14
7ed5322
59b8405
2f44946
2f84c1e
3f2512f
f9c0b48
b6f68ba
c86d09b
d464d73
fe0da67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ Creates and updates role mappings. | |
[[security-api-put-role-mapping-desc]] | ||
==== {api-description-title} | ||
|
||
Role mappings define which roles are assigned to each user. Each mapping has | ||
Role mappings define which roles are assigned to each user. Each mapping has | ||
_rules_ that identify users and a list of _roles_ that are granted to those users. | ||
|
||
The role mapping APIs are generally the preferred way to manage role mappings | ||
|
@@ -77,10 +77,14 @@ _Exactly one of `roles` or `role_templates` must be specified_. | |
`rules`:: | ||
(Required, object) The rules that determine which users should be matched by the | ||
mapping. A rule is a logical condition that is expressed by using a JSON DSL. | ||
See <<role-mapping-resources>>. | ||
See <<role-mapping-resources>>. | ||
|
||
==== Role Templates | ||
|
||
NOTE: Role templates require the relevant scripting feature to be enabled, | ||
ywangd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
otherwise the creation of a role mapping with role templates will fail. | ||
ywangd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
See <<allowed-script-types-setting>>. | ||
|
||
The most common use for role mappings is to create a mapping from a known value | ||
on the user to a fixed role name. | ||
For example, all users in the `cn=admin,dc=example,dc=com` LDAP group should be | ||
|
@@ -233,6 +237,38 @@ POST /_security/role_mapping/mapping5 | |
<2> Because the template produces a JSON array, the format must be | ||
set to `json`. | ||
|
||
In addition to inline script, we can also use stored script for the | ||
ywangd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
`template` field. Above role mapping can also be created with the follows: | ||
|
||
[source,console] | ||
------------------------------------------------------------ | ||
POST /_scripts/derive-roles | ||
{ | ||
"script": { | ||
"lang": "mustache", | ||
"source" : "{{#tojson}}groups{{/tojson}}" | ||
} | ||
} | ||
------------------------------------------------------------ | ||
|
||
[source,console] | ||
------------------------------------------------------------ | ||
POST /_security/role_mapping/mapping5 | ||
{ | ||
"role_templates": [ | ||
{ | ||
"template": { "id": "derive-roles" }, | ||
"format" : "json" | ||
} | ||
], | ||
"rules": { | ||
"field" : { "realm.name" : "saml1" } | ||
}, | ||
"enabled": true | ||
} | ||
------------------------------------------------------------ | ||
// TEST[continued] | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we think carefully about whether we really want to document & support this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm good question. One issue of using stored script is consistency, i.e. the script can change without the role-mapping being aware of it. This could potentially creates confusion and support time frustration. Is this the reason why we may not want to "officially" support it? (I assume adding it to official docs means offical support). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Can I flip the question ? Why do we "unofficially' support this already ? Why not disallow it instead ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I undersetand there are cases where we intentionally left them as a grey area, i.e. "unofficially supported". But I feel this is not the case here because:
So overall, I'd prefer to have it documented. Thanks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not convinced. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there some context that I am not aware of, e.g. any past discussions about not having this documented in the first place? I admit that I don't have a strong reason other than "completeness" to add this in. But are there strong reasons to not add it? I can think of a few candidates:
I'd be happy to go with item 1, 2, 3, but not particularly convinced by 4 and 5. I cannot say user would see value in this, but cannot say they would not either, unless there are past evidents of this being no value. Also the time and effort for this additional docs are not really significant. I am not really attached to this snippet of docs. I am happy to either remove or keep it. Just like to clear my thought process. I'd appreicate if you could elaborate it a bit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Less is more. One of our recurring experiences is that people try and configure ES security based on blogs because they seem simpler. The official docs have "more steps" so they follow a blog and then get stuck because those steps were actually necessarily and the blog skipped over them (or made assumptions that allowed them to ignore the steps) to keep it short. Documenting something, tells people "this might be helpful to you" and also "you should read this if you want to understand how to use this feature". But I don't see any argument for why either of those are true here. So what's the reason to do it? Or, put another way, if a customer raises a support ticket saying "I'm trying to use a role mapping with a stored script as the template" my immediate reaction would be "Why on earth would you do that? That's a terrible idea!"
Then don't do it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I can resonate with this argument. I do agree it's not a good idea to make a role template depend on external stuff. Since we cannot or don't want to recommend this usage ourselves, it makes sense to leave it out. Will update accordingly. Thanks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For what it’s worth, the role mapping UI in Kibana attempts to support the entire API surface. In other words, any valid role mapping created via the API should render and be editable in the UI. We of course default to inline scripts for these templates in the interface, but since stored scripts are technically available, we have to know how to render those as well, so there are UI controls to edit them. I personally agree that these stored templates don’t make a lot of sense. Even if they aren’t documented, they’re more discoverable than they used to be because we now have a dedicated UI. For some folks, the UI will become the documentation, so like it or not, I fear we end up (currently) with the appearance that this is a first-class feature of role mappings. We can consider changes to the UI which only surface these controls when editing an exiting mapping which already contains a stored script, but not without additional complexity There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the insights @legrego For now, we are trying to not actively promote it. I wonder whether we could afford to disable it in 8.0. But I suspect that the solution could end up being adding more machinery to make this feature more robust, e.g. reference counting a stored script. |
||
The following example matches users within a specific LDAP sub-tree: | ||
|
||
[source,console] | ||
|
@@ -339,4 +375,3 @@ POST /_security/role_mapping/mapping9 | |
<1> Because it is not possible to specify both `roles` and `role_templates` in | ||
the same role mapping, we can apply a "fixed name" role by using a template | ||
that has no substitutions. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this NOTE should move below the introductory paragraph, since at this point we haven't defined role templates yet. I actually also think this whole "Role templates" subsection should be moved into the "Description" section. If you're willing to let me add that change to this PR, let me know and I'll push a commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Lisa. Please make changes as you see fit. Thanks a lot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks!