Skip to content
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

[IMP] auth_saml: download the provider metadata #602

Merged
merged 2 commits into from
May 14, 2024

Conversation

gurneyalex
Copy link
Member

On Office365, what you get when configuring an application for SAML authentication is the URL of the federation metadata document. This URL is stable, but the content of the document is not. I suspect some of the encryption keys can be updated / renewed over time. The result is that the configured provider in Odoo suddenly stops working, because the messages sent by the Office365 provider can no longer be validated by Odoo (because the federation document is out of date). Downloading the new version and updating the auth.saml.provider record fixes the issue.

This PR adds a new field to store the URL of the metadata document. When this field is set on a provider, you get a button next to it in the form view to download the document from the URL. The button will not update the document if it has not changed.

Additionally, when a SignatureError happens, we check if downloading the document again fixes the issue.

@OCA-git-bot
Copy link
Contributor

Hi @sbidoul, @vincent-hatakeyama,
some modules you are maintaining are being modified, check this out!

@gurneyalex gurneyalex force-pushed the 15.0-auth_saml-download_metadata branch from 89ad9e2 to 0bed723 Compare January 9, 2024 12:36
@vincent-hatakeyama
Copy link
Contributor

I don’t think the changes to auth_oidc should be included.

Keycloak also provides a link to the metadata (in the form https:///realms//protocol/saml/descriptor). I’m not sure giving specific configuration information like this is pertinent.

Coverage can be improved by using a mock and the fake idp already in the tests.

@gurneyalex gurneyalex force-pushed the 15.0-auth_saml-download_metadata branch from 0bed723 to 984a1fe Compare January 11, 2024 12:59
@gurneyalex
Copy link
Member Author

Thanks @vincent-hatakeyama I'll update the PR. I guess you are refering to the "help" message? The issue we are facing with Office365 is real: the provided metadata suddenly stops being able to validate the saml messages, and noone can authenticate. Updating the metadata with the content served from the original URL does solve the problem.

Comment on lines +376 to +407
settings = deepcopy(CONFIG)
settings["key_file"] = osp.join(
osp.dirname(__file__), "data", "key_idp_expired.pem"
)
settings["cert"] = osp.join(
osp.dirname(__file__), "data", "key_idp_expired.pem"
)
expired_idp = FakeIDP(settings=settings)
self.saml_provider.idp_metadata = expired_idp.get_metadata()
Copy link
Member Author

Choose a reason for hiding this comment

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

@vincent-hatakeyama I think this is not the correct way to trigger an error when checking the signature to test the refresh (I'm not familiar enough with the SAML idp vs. sp internals). Could you offer a suggestion?

The goal is to get this https://github.com/OCA/server-auth/pull/602/files#diff-19fdbbb274613d822573aba74ad5575708e31bddf1688f6d909e589370f6ec3fR311 covered by a test.

Copy link
Member Author

Choose a reason for hiding this comment

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

And indeed, the block is not tested

@apf-c2c
Copy link

apf-c2c commented Apr 2, 2024

Looks good from functional point of view 👍

On Office365, what you get when configuring an application for SAML
authentication is the URL of the federation metadata document. This URL
is stable, but the content of the document is not. I suspect some of the
encryption keys can be updated / renewed over time. The result is that
the configured provider in Odoo suddenly stops working, because the
messages sent by the Office365 provider can no longer be validated by
Odoo (because the federation document is out of date). Downloading the
new version and updating the auth.saml.provider record fixes the issue.

This PR adds a new field to store the URL of the metadata document. When
this field is set on a provider, you get a button next to it in the form
view to download the document from the URL. The button will not update
the document if it has not changed.

Additionally, when a SignatureError happens, we check if downloading the
document again fixes the issue.
@gurneyalex gurneyalex force-pushed the 15.0-auth_saml-download_metadata branch from 92fed8b to 31441ef Compare May 14, 2024 07:19
1. download the metadata with a timeout to avoid getting stuck
2. lock the record after completing the download
@gurneyalex
Copy link
Member Author

/ocabot merge patch

@OCA-git-bot
Copy link
Contributor

On my way to merge this fine PR!
Prepared branch 15.0-ocabot-merge-pr-602-by-gurneyalex-bump-patch, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit b979548 into OCA:15.0 May 14, 2024
5 of 7 checks passed
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at 300557b. Thanks a lot for contributing to OCA. ❤️

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.

6 participants