<div dir="ltr">Using the domain name + group name pairing also allows for things like:<div><br></div><div><ns0:Attribute Name="openstack_groups"><br>    <ns0:AttributeValue xsi:type="xs:string">JSON:{"group_name": "C", "domain_name": "X"}</ns0:AttributeValue><br>    <ns0:AttributeValue xsi:type="xs:string">JSON:{"group_name": "C", "domain_name": "Y"}</ns0:AttributeValue><br></ns0:Attribute><br></div><div><br></div><div>To showcase how we solve the ambiguity in group names by namespacing them with domains.</div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Sep 27, 2018 at 3:11 AM Colleen Murphy <<a href="mailto:colleen@gazlene.net">colleen@gazlene.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
On Thu, Sep 27, 2018, at 5:09 AM, vishakha agarwal wrote:<br>
> > From : Colleen Murphy <<a href="mailto:colleen@gazlene.net" target="_blank">colleen@gazlene.net</a>><br>
> > To : <<a href="mailto:openstack-dev@lists.openstack.org" target="_blank">openstack-dev@lists.openstack.org</a>><br>
> > Date : Tue, 25 Sep 2018 18:33:30 +0900<br>
> > Subject : Re: [openstack-dev] [keystone] Domain-namespaced user attributes in SAML assertions from Keystone IdPs<br>
> > ============ Forwarded message ============<br>
> >  > On Mon, Sep 24, 2018, at 8:40 PM, John Dennis wrote:<br>
> >  > > On 9/24/18 8:00 AM, Colleen Murphy wrote:<br>
> >  > > > This is in regard to <a href="https://launchpad.net/bugs/1641625" rel="noreferrer" target="_blank">https://launchpad.net/bugs/1641625</a> and the proposed patch <a href="https://review.openstack.org/588211" rel="noreferrer" target="_blank">https://review.openstack.org/588211</a> for it. Thanks Vishakha for getting the ball rolling.<br>
> >  > > ><br>
> >  > > > tl;dr: Keystone as an IdP should support sending non-strings/lists-of-strings as user attribute values, specifically lists of keystone groups, here's how that might happen.<br>
> >  > > ><br>
> >  > > > Problem statement:<br>
> >  > > ><br>
> >  > > > When keystone is set up as a service provider with an external non-keystone identity provider, it is common to configure the mapping rules to accept a list of group names from the IdP and map them to some property of a local keystone user, usually also a keystone group name. When keystone acts as the IdP, it's not currently possible to send a group name as a user property in the assertion. There are a few problems:<br>
> >  > > ><br>
> >  > > >      1. We haven't added any openstack_groups key in the creation of the SAML assertion (<a href="http://git.openstack.org/cgit/openstack/keystone/tree/keystone/federation/idp.py?h=14.0.0#n164" rel="noreferrer" target="_blank">http://git.openstack.org/cgit/openstack/keystone/tree/keystone/federation/idp.py?h=14.0.0#n164</a>).<br>
> >  > > >      2. If we did, this would not be enough. Unlike other IdPs, in keystone there can be multiple groups with the same name, namespaced by domain. So it's not enough for the SAML AttributeStatement to contain a semi-colon-separated list of group names, since a user could theoretically be a member of two or more groups with the same name.<br>
> >  > > >     * Why can't we just send group IDs, which are unique? Because two different keystones are not going to have independent groups with the same UUID, so we cannot possibly map an ID of a group from keystone A to the ID of a different group in keystone B. We could map the ID of the group in in A to the name of a group in B but then operators need to create groups with UUIDs as names which is a little awkward for both the operator and the user who now is a member of groups with nondescriptive names.<br>
> >  > > >      3. If we then were able to encode a complex type like a group dict in a SAML assertion, we'd have to deal with it on the service provider side by being able to parse such an environment variable from the Apache headers.<br>
> >  > > >      4. The current mapping rules engine uses basic python string formatting to translate remote key-value pairs to local rules. We would need to change the mapping API to work with values more complex than strings and lists of strings.<br>
> >  > > ><br>
> >  > > > Possible solution:<br>
> >  > > ><br>
> >  > > > Vishakha's patch (<a href="https://review.openstack.org/588211" rel="noreferrer" target="_blank">https://review.openstack.org/588211</a>) starts to solve (1) but it doesn't go far enough to solve (2-4). What we talked about at the PTG was:<br>
> >  > > ><br>
> >  > > >      2. Encode the group+domain as a string, for example by using the dict string repr or a string representation of some custom XML and maybe base64 encoding it.<br>
> >  > > >          * It's not totally clear whether the AttributeValue class of the pysaml2 library supports any data types outside of the xmlns:xs namespace or whether nested XML is an option, so encoding the whole thing as an xs:string seems like the simplest solution.<br>
> >  > > >      3. The SP will have to be aware that openstack_groups is a special key that needs the encoding reversed.<br>
> >  > > >          * I wrote down "MultiDict" in my notes but I don't recall exactly what format the environment variable would take that would make a MultiDict make sense here, in any case I think encoding the whole thing as a string eliminates the need for this.<br>
> >  > > >      4. We didn't talk about the mapping API, but here's what I think. If we were just talking about group names, the mapping API today would work like this (slight oversimplification for brevity):<br>
> >  > > ><br>
> >  > > > Given a list of openstack_groups like ["A", "B", "C"], it would work like this:<br>
> >  > > ><br>
> >  > > > [<br>
> >  > > >    {<br>
> >  > > >      "local":<br>
> >  > > >      [<br>
> >  > > >        {<br>
> >  > > >          "group":<br>
> >  > > >          {<br>
> >  > > >            "name": "{0}",<br>
> >  > > >            "domain":<br>
> >  > > >            {<br>
> >  > > >              "name": "federated_domain"<br>
> >  > > >            }<br>
> >  > > >          }<br>
> >  > > >        }<br>
> >  > > >      ], "remote":<br>
> >  > > >      [<br>
> >  > > >        {<br>
> >  > > >          "type": "openstack_groups"<br>
> >  > > >        }<br>
> >  > > >      ]<br>
> >  > > >    }<br>
> >  > > > ]<br>
> >  > > > (paste in case the spacing makes this unreadable: <a href="http://paste.openstack.org/show/730623/" rel="noreferrer" target="_blank">http://paste.openstack.org/show/730623/</a> )<br>
> >  > > ><br>
> >  > > > But now, we no longer have a list of strings but something more like [{"name": "A", "domain_name": "Default"} {"name": "B", "domain_name": "Default", "name": "A", "domain_name": "domainB"}]. Since {0} isn't a string, this example doesn't really work. Instead, let's assume that in step (3) we converted the decoded AttributeValue text to an object. Then the mapping could look more like this:<br>
> >  > > ><br>
> >  > > > [<br>
> >  > > >    {<br>
> >  > > >      "local":<br>
> >  > > >      [<br>
> >  > > >        {<br>
> >  > > >          "group":<br>
> >  > > >          {<br>
> >  > > >            "name": "{<a href="http://0.name" rel="noreferrer" target="_blank">0.name</a>}",<br>
> >  > > >            "domain":<br>
> >  > > >            {<br>
> >  > > >              "name": "{0.domain_name}"<br>
> >  > > >            }<br>
> >  > > >          }<br>
> >  > > >        }<br>
> >  > > >      ], "remote":<br>
> >  > > >      [<br>
> >  > > >        {<br>
> >  > > >          "type": "openstack_groups"<br>
> >  > > >        }<br>
> >  > > >      ]<br>
> >  > > >    }<br>
> >  > > > ]<br>
> >  > > > (paste: <a href="http://paste.openstack.org/show/730622/" rel="noreferrer" target="_blank">http://paste.openstack.org/show/730622/</a> )<br>
> >  > > ><br>
> >  > > > Alternatively, we could forget about the namespacing problem and simply say we only pass group names in the assertion, and if you have ambiguous group names you're on your own. We could also try to support both, e.g. have an openstack_groups mean a list of group names for simpler use cases, and openstack_groups_unique mean the list of encoded group+domain strings for advanced use cases.<br>
> >  > > ><br>
> >  > > > Finally, whatever we decide for groups we should also apply to openstack_roles which currently only supports global roles and not domain-specific roles.<br>
> >  > > ><br>
> >  > > > (It's also worth noting, for clarity, that the samlize function does handle namespaced projects, but this is because it's retrieving the project from the token and therefore there is only ever one project and one project domain so there is no ambiguity.)<br>
> >  > > ><br>
> >  > ><br>
> >  > > A few thoughts to help focus the discussion:<br>
> >  > ><br>
> >  > > * Namespacing is critical, no design should be permitted which allows<br>
> >  > > for ambiguous names. Ambiguous names are a security issue and can be<br>
> >  > > used by an attacker. The SAML designers recognized the importance to<br>
> >  > > disambiguate names. In SAML names are conveyed inside a NameIdentifier<br>
> >  > > element which (optionally) includes "name qualifier" attributes which in<br>
> >  > > SAML lingo is a namespace name.<br>
> >  > ><br>
> >  > > * SAML does not define the format of an attribute value. You can use<br>
> >  > > anything you want as long as it can be expressed in valid XML as long as<br>
> >  > > the cooperating parties know how to interpret the XML content. But<br>
> >  > > herein lies the problem. Very few SAML implementations know how to<br>
> >  > > consume an attribute value other than a string. In the real world,<br>
> >  > > despite what the SAML spec says is permitted is the constraint attribute<br>
> >  > > values is a string.<br>
> >  > ><br>
> >  > > * I haven't looked at the pysaml implementation but I'd be surprised if<br>
> >  > > it treated attribute values as anything other than a string. In theory<br>
> >  > > it could take any Python object (or JSON) and serialize it into XML but<br>
> >  > > you would still be stuck with the receiver being unable to parse the<br>
> >  > > attribute value (see above point).<br>
> >  > ><br>
> >  > > * You can encode complex data in an attribute value while only using a<br>
> >  > > simple string. The only requirement is the relying party knowing how to<br>
> >  > > interpret the string value. Note, this is distinctly different than<br>
> >  > > using non-string attribute values because of who is responsible for<br>
> >  > > parsing the value. If you use a non-string attribute value the SAML<br>
> >  > > library need to know how to parse it, none or very few will know how to<br>
> >  > > process that element. But if it's a string value the SAML library will<br>
> >  > > happily pass that string back up to the application who can then<br>
> >  > > interpret it. The easiest way to embed complex data in a string is with<br>
> >  > > JSON, we do it all the time, all over the place in OpenStack. [1][2]<br>
> >  > ><br>
> >  > > So my suggestion would be to give the attribute a meaningful name.<br>
> >  > > Define a JSON schema for the data and then let the upper layers decode<br>
> >  > > the JSON and operate on it. This is no different than any other SAML<br>
> >  > > attribute passed as a string, the receive MUST know how to interpret the<br>
> >  > > string value.<br>
> >  > ><br>
> >  > > [1] We already pass complex data in a SAML attribute string value. We<br>
> >  > > permit a comma separated list of group names to appear in the 'groups'<br>
> >  > > mapping rule (although I don't think this feature is documented in our<br>
> >  > > mapping rules documentation). The receiver (our mapping engine) has<br>
> >  > > hard-coded logic to look for a list of names.<br>
> >  > ><br>
> >  > > [2] We might want to prepend a format specifier to string containing<br>
> >  > > complex data, e.g. "JSON:{json object}". Our parser could then look for<br>
> >  > > a leading format tag and if if finds one strip it off and pass the rest<br>
> >  > > of the string into the proper parser.<br>
> >  > ><br>
> >  > > --<br>
> >  > > John Dennis<br>
> >  > ><br>
> >  ><br>
> >  > Thanks for this response, John. I think serializing to JSON and prepending a format specifier makes sense.<br>
> >  ><br>
> >  > Colleen<br>
> <br>
> Thanks for the response Colleen, John. After reading the above mails,<br>
> what I understood is to pass list of group names specific to a<br>
> keystone in to a JSON schema prepending a tag. e.g - groups_names =<br>
> "JSON:{groups_names:[a,b,c]}". IN SAML assertion Attribute_name can be<br>
> openstack_groups and Attribute_value will be<br>
> "JSON:{groups_names:[a,b,c]}".<br>
<br>
Not quite. The important part is that the group name needs to be tied to a domain name. The attribute statement generator can already produce a list of attributes of one type by just adding new attribute values to the attribute, see for example openstack_roles[1]. The attribute value then needs to be a single group + domain JSON blob.<br>
<br>
As an example, if a user is a member of group A in domain X and also a member of group B in domain Y, the attribute could look like this:<br>
<br>
<ns0:Attribute Name="openstack_groups"><br>
    <ns0:AttributeValue xsi:type="xs:string">JSON:{"group_name": "A", "domain_name": "X"}</ns0:AttributeValue><br>
    <ns0:AttributeValue xsi:type="xs:string">JSON:{"group_name": "B", "domain_name": "Y"}</ns0:AttributeValue><br>
</ns0:Attribute><br>
<br>
[1] <a href="http://git.openstack.org/cgit/openstack/keystone/tree/keystone/federation/idp.py?h=14.0.0#n177" rel="noreferrer" target="_blank">http://git.openstack.org/cgit/openstack/keystone/tree/keystone/federation/idp.py?h=14.0.0#n177</a><br>
<br>
Colleen<br>
<br>
__________________________________________________________________________<br>
OpenStack Development Mailing List (not for usage questions)<br>
Unsubscribe: <a href="http://OpenStack-dev-request@lists.openstack.org?subject:unsubscribe" rel="noreferrer" target="_blank">OpenStack-dev-request@lists.openstack.org?subject:unsubscribe</a><br>
<a href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev" rel="noreferrer" target="_blank">http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev</a><br>
</blockquote></div>