Skip to content

Update SAML2 auth sessionkey cookie path - #6149

Merged
yadvr merged 1 commit into
apache:mainfrom
kohrar:kohrar-fix-saml2-auth
Apr 18, 2022
Merged

Update SAML2 auth sessionkey cookie path#6149
yadvr merged 1 commit into
apache:mainfrom
kohrar:kohrar-fix-saml2-auth

Conversation

@kohrar

Copy link
Copy Markdown
Contributor

Description

This change will set the sessionkey under the /client/api path. This commit should prevent duplicate sessionkey cookies from being set on both /client (incorrect) and /client/api (correct). Prior to this commit, the /client version was being set while the /client/api version remained unchanged with an invalid sessionkey. As a result, subsequent requests after the SAML2 authentication would immediately fail with an invalid session and results in the user being logged out.

The sessionkey is now set explicitly for the /client/api path which should fix this issue, regardless of the SSO URL and path that's being used.

Fixes: #6127

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

I've built 4.16.1.0 with this change and SAML2 auth is now working as expected again.

This change will set the sessionkey under the /client/api path. This commit should prevent duplicate sessionkey cookies from being set on both /client (incorrect) and /client/api (correct). Prior to this commit, the /client version was being set while the /client/api version remained unchanged with an invalid sessionkey. As a result, subsequent requests after the SAML2 authentication would immediately fail with an invalid session and results in the user being logged out.
The sessionkey is now set explicitly for the /client/api path which should fix this issue, regardless of the SSO URL and path that's being used.
}
resp.addCookie(new Cookie("userfullname", URLEncoder.encode(loginResponse.getFirstName() + " " + loginResponse.getLastName(), HttpUtils.UTF_8).replace("+", "%20")));
resp.addHeader("SET-COOKIE", String.format("%s=%s;HttpOnly", ApiConstants.SESSIONKEY, loginResponse.getSessionKey()));
resp.addHeader("SET-COOKIE", String.format("%s=%s;HttpOnly;Path=/client/api", ApiConstants.SESSIONKEY, loginResponse.getSessionKey()));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we might want to take the path from the configurable setting? cc @Pearl1594 to check if it makes sense to read the variable defined in server.properties

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM otherwise

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nevermind, my comment- Based on https://github.com/apache/cloudstack/blob/main/server/src/main/java/com/cloud/api/ApiServlet.java#L224 your changes LGTM (the Path /client/api is more restrictive than /client but should work and ensure all APIs function. The only issue is when the path isn't /client/api which is not a case I think think of as all APIs calls are handled at /client/api)

@nvazquez

Copy link
Copy Markdown
Contributor

Hi @kohrar is this PR still valid after the UI fixes?

@kohrar

kohrar commented Apr 8, 2022

Copy link
Copy Markdown
ContributorAuthor

I would think so. The UI issue is a separate issue. The original issue was that the session key cookie was set with a different path by the browser, resulting in the valid session key being ignored in favor for the invalid key set previously.

The UI issue is merely an interface issue with the login page which can be worked around by refreshing the login page. The cookie issue here can't be worked around unless cookies are cleared completely.

@nvazquez

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@nvazquez a Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result: ✖️ el7 ✔️ el8 ✔️ debian ✔️ suse15. SL-JID 3124

@nvazquez

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@nvazquez a Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result: ✔️ el7 ✔️ el8 ✔️ debian ✔️ suse15. SL-JID 3131

@nvazquez

Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@nvazquez a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

Trillian test result (tid-3868)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 35798 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr6149-t3868-kvm-centos7.zip
Smoke tests completed. 88 look OK, 5 have errors
Only failed tests results shown below:

TestResultTime (s)Test File
test_01_add_primary_storage_disabled_hostError0.57test_primary_storage.py
test_01_primary_storage_nfsError0.11test_primary_storage.py
ContextSuite context=TestStorageTags>:setupError0.19test_primary_storage.py
test_03_deploy_and_scale_kubernetes_clusterFailure34.14test_kubernetes_clusters.py
test_04_autoscale_kubernetes_clusterFailure685.81test_kubernetes_clusters.py
test_07_deploy_kubernetes_ha_clusterFailure62.51test_kubernetes_clusters.py
test_08_upgrade_kubernetes_ha_clusterFailure36.05test_kubernetes_clusters.py
test_09_delete_kubernetes_ha_clusterFailure33.86test_kubernetes_clusters.py
ContextSuite context=TestKubernetesCluster>:teardownError130.03test_kubernetes_clusters.py
test_01_secure_vm_migrationError155.55test_vm_life_cycle.py
test_02_unsecure_vm_migrationError270.22test_vm_life_cycle.py
test_03_secured_to_nonsecured_vm_migrationError144.95test_vm_life_cycle.py
test_08_migrate_vmError43.71test_vm_life_cycle.py
test_02_list_snapshots_with_removed_data_storeError8.45test_snapshots.py
test_02_list_snapshots_with_removed_data_storeError8.45test_snapshots.py
test_hostha_enable_ha_when_host_in_maintenanceError307.04test_hostha_kvm.py

@yadvr

Copy link
Copy Markdown
Member

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@rohityadavcloud a Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result: ✔️ el7 ✔️ el8 ✔️ debian ✔️ suse15. SL-JID 3158

@nvazquez

Copy link
Copy Markdown
Contributor

@blueorangutan test

1 similar comment
@yadvr

Copy link
Copy Markdown
Member

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@rohityadavcloud a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

Trillian test result (tid-3920)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 31620 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr6149-t3920-kvm-centos7.zip
Smoke tests completed. 93 look OK, 0 have errors
Only failed tests results shown below:

TestResultTime (s)Test File

@yadvr
yadvr merged commit 7012200 into apache:mainApr 18, 2022
@boring-cyborg

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request!

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

SSO fails with error "Expired session, missing signature, or missing apiKey"

5 participants

@kohrar@nvazquez@blueorangutan@yadvr@weizhouapache