Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[SecurityBundle] Make security schema deterministic#57493

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:5.4fromMatTheCat:ticket_57463
Aug 19, 2024

Conversation

MatTheCat
Copy link
Contributor

@MatTheCatMatTheCat commentedJun 22, 2024
edited
Loading

QA
Branch?5.4
Bug fix?yes
New feature?no
Deprecations?no
IssuesFix#57463
LicenseMIT

Currently you cannot put a namespace on custom providers/authenticators because theXmlFileLoader will ignore every element whose namespace is not its parent’s. This means the only way to configure e.g.SymfonyConnect’s provider is

<providername="connect_memory">    <connect_memory>        <userusername="whatever">ROLE_ADMIN</user>    </connect_memory></provider>

This requires providers and authenticatorsxsd:any’snamespace to be##any, which is no longer possible with libxml ≥ 2.12 (already available on Alpine 3.20 and Arch Linux e.g.) because it will report their content model as non-determinist.

Unable to parse file "/srv/backend/config/packages/security.xml": [ERROR 3070] complex type 'provider': The content model is not determinist. (in file:////srv/backend/vendor/symfony/security-bundle/DependencyInjection/../Resources/config/schema//security-1.0.xsd - line 88, column 0)
[ERROR 3070] complex type 'firewall': The content model is not determinist. (in file:////srv/backend/vendor/symfony/security-bundle/DependencyInjection/../Resources/config/schema//security-1.0.xsd - line 134, column 0) in /srv/backend/config/packages/security.xml (which is being imported from "/srv/backend/src/Kernel.php").

As a result, any XML security config will fail to be loaded once libxml is updated.

Fixing this issue requires to changexsd:anys’namespace to##other so that content models become deterministic.
A side-effect is that any custom providers/authenticators XML configuration will become invalid.

Unable to parse file "/srv/backend/config/packages/security.xml": [ERROR 1871] Element '{http://symfony.com/schema/dic/security}connect_memory': This element is not expected. Expected is one of ( {http://symfony.com/schema/dic/security}chain, {http://symfony.com/schema/dic/security}memory, {http://symfony.com/schema/dic/security}ldap, ##other{http://symfony.com/schema/dic/security}* ). (in /srv/backend/public/ - line 13, column 0) in /srv/backend/config/packages/security.xml (which is being imported from "/srv/backend/src/Kernel.php").

To avoid a BC break this PR allows such errors to occur. A deprecation will have to be triggered on 7.2 for users to namespace their custom providers/authenticators elements, e.g.

<providername="symfony_connect">    <connect_memoryxmlns="whatever">        <userusername="whatever">ROLE_ADMIN</custom:user>    </connect_memory></provider>

Because custom providers/authenticators’processContents islax there won’t be any validation if the namespace has no schema. If it has, it will be better to provide it:

<srv:container xmlns="http://symfony.com/schema/dic/security"               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"               xmlns:srv="http://symfony.com/schema/dic/services"+              xmlns:custom="whatever"               xsi:schemaLocation="http://symfony.com/schema/dic/services        https://symfony.com/schema/dic/services/services-1.0.xsd        http://symfony.com/schema/dic/security        https://symfony.com/schema/dic/security/security-1.0.xsd+       whatever the/schema.xsd">    <config>        <provider name="symfony_connect">-           <connect_memory xmlns="whatever">-               <user username="whatever">ROLE_ADMIN</custom:user>-           </connect_memory>+           <custom:connect_memory>+               <custom:user username="whatever">ROLE_ADMIN</custom:user>+           </custom:connect_memory>        </provider></srv:container>

@wouterj
Copy link
Member

wouterj commentedJun 22, 2024
edited
Loading

Uh-oh, this sounds like a really tricky situation. Breaking changes on an LTS version is a no-go, but we have to fix this somehow.

While searching forxsd:any in the code-base, as I'm sure more places are affected, I came across the Xliff 1.2 schema. It uses<xsd:any maxOccurs="unbounded" minOccurs="0" namespace="##other" processContents="skip"/> (processContent=skip is the relevant bit). Can you maybe verify if this could fix the issue in a BC way?

@MatTheCat
Copy link
ContributorAuthor

MatTheCat commentedJun 22, 2024
edited
Loading

I clarified the PR description: BC break would impact users configuring custom user providers and/or authenticators using XML, while the issue will impact users configuring security using XML (meaning e.g.XmlCompleteConfigurationTest will always fail once it is tested against an up-to-date libxml).

processContents="skip" is the same thanlax when you don’t have an XSD so that wouldn’t change anything (confirmed after testing).

For completeness, I thought about two others solutions which would keep BC (in a sub-optimal way):

  • remove all provider and authenticator types from the XSD. You wouldn’t get any validation or code autocompletion anymore but this would allow to keepnamespace="##any" while being deterministic.
  • disable validation in theXmlFileLoader. No validation => no validation error… Config would still be validated though.

@nicolas-grekas
Copy link
Member

If there is no other choice than this BC break, then at least it happens at compile time so that it's going to be easy to spot, isn't it?
Then, we should make the solution super obvious, with clear explanations, before/after example, anything that can help make the situation actionable. Can you think of ways to do that?

@carsonbotcarsonbot changed the titleMake security schema deterministic[SecurityBundle] Make security schema deterministicJun 24, 2024
@MatTheCat
Copy link
ContributorAuthor

MatTheCat commentedJun 24, 2024
edited
Loading

I clarified that the two other solutions I thought of (removing types from the XSD or disabling XML validation) would keep BC, so maybe they should be preferred?

If not, the simplest fix is to add a namespace to custom providers/authenticators, like

<provider name="default">-    <my-provider />+    <custom:my-provider xmlns:custom="my.custom.namespace" /></provider>

Thanks toprocessContents="lax" you don’t need an XSD, but thanks to this PR you could now reference one:

+ xmlns:custom="my.custom.namespace"  xsi:schemaLocation="http://symfony.com/schema/dic/services     https://symfony.com/schema/dic/services/services-1.0.xsd     http://symfony.com/schema/dic/security-    https://symfony.com/schema/dic/security/security-1.0.xsd">+    https://symfony.com/schema/dic/security/security-1.0.xsd+    my.custom.namespace+    /path/to/my.xsd    <config>        <provider name="default">-          <my-provider />+          <custom:my-provider  />        </provider>    </config></srv:container>

Don’t really know how to advertise this; I guess the upgrade guide and a blog post would be a good start. Surely there have been similar cases in the past?

@stof
Copy link
Member

Given that any bundle can register extra settings for the security-bundle configuration (it has an extension config) and we were not requiring a custom namespace until now (and they probably never documented using one), I don't think we can require one (especially not in a patch version of an old LTS)

@wouterj
Copy link
Member

I'm leaning towards going for "remove all provider and authenticator types from the XSD". This means we'll loose validation and autocompletion of build-in user provider configuration, but it is not a BC break.

Then, maybe we can find a nice upgrade path to reintroduce this in Symfony 8 (e.g. first deprecating custom user providers/authenticators without namespace?).

@stof
Copy link
Member

note that we don't loose all validation. We loose the XSD-based validation, but we still process the config with the Configuration class.

wouterj reacted with thumbs up emoji

@MatTheCat
Copy link
ContributorAuthor

MatTheCat commentedJun 25, 2024
edited
Loading

In fact if we’re going to disable validation, we can make our XSD valid as well. That way there is no BC break and users are free to make their config valid or not. Updated the PR this way.

It would be even better to check for validation errors related to custom providers/authenticators (and trigger a deprecation?) but I’m not sure it is possible yet.

@stof
Copy link
Member

I don't think disabling XML validation in the XmlFileLoader is a good idea (this won't be only for the SecurityBundle configuration but for any configuration). And I don't think the answer about IDEs is right: they would report any configuration for third-party providers as invalid, which will confuse developers.

This would also make it even more likely to have outdated XSD files for our bundle configuration schemas as they would not be validated anymore (which would also lead to bad IDE support for them if they are based on XSD files).

@MatTheCat
Copy link
ContributorAuthor

[IDEs] would report any configuration for third-party providers as invalid, which will confuse developers.

Only as long as they stay invalid. Once we offer the possibility to namespace them, developers should update them so that they aren’t invalid anymore. But this means we must support these invalid.

If we can detect these cases when validating, we could allow them and trigger a deprecation or something to tell the user to update its config (for now I managed to detect invalid providers from the exception message, but not authenticators yet).

Would that be a viable solution?

@stof
Copy link
Member

@MatTheCat you disabled validation forall XML configuration affectingall bundles of the ecosystem.

@MatTheCat
Copy link
ContributorAuthor

@stof yes this is the PR actual state while I’m investigating how to implement the idea I presented.

@MatTheCat
Copy link
ContributorAuthor

Okay I re-enabled Symfony’s XML validation while allowing invalid providers/authenticators; these will only trigger a deprecation.

Not sure this is the best way and it’s missing tests, but do you agree with this solution?

@MatTheCat
Copy link
ContributorAuthor

Ubuntu will join impacted systems on October 10 when 24.10 is released.

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

LGTM, let's add some tests?

@MatTheCat
Copy link
ContributorAuthor

Will add some

@MatTheCatMatTheCatforce-pushed theticket_57463 branch 7 times, most recently fromdd2c047 to038825fCompareAugust 17, 2024 07:45
@MatTheCat
Copy link
ContributorAuthor

Hm not sure what to do because there are changes both insymfony/dependency-injection andsymfony/security-bundle 🤔

Should I makesymfony/security-bundle a dev dependency ofsymfony/dependency-injection, or is there a way to restrict the version ofsymfony/dependency-injection when testingsymfony/security-bundle?

@OskarStark
Copy link
Contributor

Just for testing or in general? In this case a conflict rule could help, or do I miss sth?

@MatTheCat
Copy link
ContributorAuthor

This PR’s SecurityBundle changes require the DependencyInjection’s (but not the other way around), so I would need a way to force this dependency to be up-to-date, even though those changes are not part of any version yet (I think high and low-deps failures are related) 🤔

@stof
Copy link
Member

Bumping the min version of thesymfony/dependency-injection requirement in security-bundle is valid as a way to fix the lowest-deps job (this is usually the way to go). The highest-deps job will probably be solved once the change in DI is merged up in 6.4.

@MatTheCat
Copy link
ContributorAuthor

Bumping the min version of thesymfony/dependency-injection requirement in security-bundle is valid as a way to fix the lowest-deps job (this is usually the way to go).

But here the required changes are not part of any release yet; how can I bump the min version to “this PR”?

@xabbuh
Copy link
Member

use the next patch release version (i.e.^5.4.43|^6.4.11)

MatTheCat reacted with thumbs up emoji

Copy link
Member

@fabpotfabpot left a comment

Choose a reason for hiding this comment

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

Minor CS issue.

@fabpot
Copy link
Member

Thank you@MatTheCat.

@fabpotfabpot merged commitca84bcc intosymfony:5.4Aug 19, 2024
10 of 12 checks passed
@MatTheCatMatTheCat deleted the ticket_57463 branchAugust 19, 2024 09:23
This was referencedAug 30, 2024
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull requestSep 2, 2024
We just updated to 5.4.42 but 3 days ago symfony put out 5.4.43 - seems sillyto upgrade but not to the one that is the latest when we tagThe key PR issymfony/symfony#57493And I note that it seems like a sleeper bug depending on server config- iesymfony/symfony#57493 (comment)"Ubuntu will join impacted systems on October 10 when 24.10 is released."The final summary says there are no deprecations but thiscommentsymfony/symfony#57493 (comment)suggests there might beI don't really know if we have security bundles but it seems likethis fixes a bug that occurs when libxml libraries are used butit adds a deprecation. Also our composer-installing instances will begetting this fix so it will be less confusing to patch the tarballcomposer update -W symfony/*Gathering patches for root package.Loading composer repositories with package informationUpdating dependenciesLock file operations: 0 installs, 3 updates, 0 removals  - Upgrading symfony/dependency-injection (v5.4.42 => v5.4.43)  - Upgrading symfony/finder (v5.4.42 => v5.4.43)  - Upgrading symfony/var-dumper (v5.4.42 => v5.4.43)
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@OskarStarkOskarStarkOskarStark left review comments

@fabpotfabpotfabpot approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@chalasrchalasrAwaiting requested review from chalasrchalasr is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
5.4
Development

Successfully merging this pull request may close these issues.

8 participants
@MatTheCat@wouterj@nicolas-grekas@stof@OskarStark@xabbuh@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp