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

Support SAML 2.0 as Login-Source (Service Provider) #5512

Open
frostieDE opened this issue Dec 10, 2018 · 24 comments · Fixed by #25165 · May be fixed by #29403
Open

Support SAML 2.0 as Login-Source (Service Provider) #5512

frostieDE opened this issue Dec 10, 2018 · 24 comments · Fixed by #25165 · May be fixed by #29403
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented type/feature Completely new functionality. Can only be merged if feature freeze is not active. type/proposal The new feature has not been accepted yet but needs to be discussed first.

Comments

@frostieDE
Copy link

It would be nice to be able to configure Gitea as a SAML service provider in order to integrate Gitea with a corporate Single-Sign-On mechanism.

@techknowlogick techknowlogick added type/proposal The new feature has not been accepted yet but needs to be discussed first. type/feature Completely new functionality. Can only be merged if feature freeze is not active. labels Dec 12, 2018
@techknowlogick
Copy link
Member

@frostieDE which IDP are you using (so that it can be tested against)?

@nigeltiany
Copy link

nigeltiany commented Dec 12, 2018

gSuite/Google Admin is a good test

@frostieDE
Copy link
Author

We are using an own implementation of a SAML IdP, you may use https://github.com/capriza/samling or https://simplesamlphp.org/ for testing (but I hope there is a library for SAML stuff) :-)

@jtl999
Copy link

jtl999 commented Jan 6, 2019

@frostieDE Very interesting with regards to your IdP implementation. I too think this would be a great feature for Gitea.

@frostieDE
Copy link
Author

This library looks promising: https://github.com/crewjam/saml

Unfortunately, I do not have any experience with Go programming 😄

@d-Pixie
Copy link

d-Pixie commented Feb 6, 2019

I was also looking for a good way to extend our G Suite identities into Gitea. Any thoughts on this internally @techknowlogick ?

@lpar
Copy link

lpar commented Apr 24, 2019

I have experience integrating Go web applications with IBM's SAML infrastructure. I've successfully used https://github.com/russellhaering/gosaml2 for the task.

@techknowlogick techknowlogick added the issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented label Apr 24, 2019
@techknowlogick
Copy link
Member

@d-Pixie you could use OpenID Connect (Oauth2) for GSuite for now.

I second @lpar's suggestion of https://github.com/russellhaering/gosaml2 as having used it and crewjam's, I prefer ressell's.

@chb0github
Copy link

Is SAML supported? I'm confused.

@fuero
Copy link

fuero commented May 18, 2021

As SAML based authentication has lots of login flow scenarios with libraries in different languages supporting them often poorly, I'd suggest leaving the heavy SAML2 lifting to a proxy/preauthentication scenario.
Examples given are for the Shibboleth SAML2 reference SP implementation.

How it would work:

  • Set up a webserver in front of gitea with lazy saml2 session initialization
  • Introduce config settings in gitea to map HTTP Headers to user id and roles/groups, similar to the attribute mapping done for LDAP. (e.g. REMOTE_USER, uid, entitlement, X-Forwarded-*, etc.)
  • Make header name and header value to group mapping configurable (e.g.: entitlement = https://gitea.example.com/role/([^/]+) -> $1, mapping https://gitea.example.com/role/admin to the admin group)
  • Redirect the user on login to a configurable "magic url" (e.g. /Shibboleth.sso/Login)
  • Verify a SAML session via presence of a configurable HTTP Header (e.g. Shib_Session_ID)

@Zocker1999NET
Copy link

@fuero Good idea, this would allow Gitea to "support" any authentication scheme available. To extend this approach:

  • make it possible to create or reconfigure a user using this scheme (a cool feature nearly every SAML implementation I use does support, e.g. Nextcloud)
    • if a user does not exist, create it with the given configuration parameters
    • if a user does exist, update the given parameters if required
    • X-GITEA-USERNAME configures username
    • X-GITEA-FULLNAME configures display/full name
    • X-GITEA-MAIL configures mail address

@nlincke
Copy link

nlincke commented Apr 15, 2022

This is a bad idea! This would blow GITEA up alot! SAML2, or OIDC for that matter, are quite simple (you do not have to integrate everithing since gitea needs to act as a service and not as an IDP. And since oAuth is already incoperated into gitea OIDC is just a "small" addon. If you are making use of well known libaries like (https://github.com/crewjam/saml), it will be mor complicatetd to come up with a well designed user admin interface....

I am always a fan of doing the security right in the application not infront of the application.

@MohammedNoureldin
Copy link

MohammedNoureldin commented Aug 27, 2022

Isn't there at the moment any workaround to get SSO in GitTea?

@Zocker1999NET
Copy link

Isn't there at the moment any workaround to get SSO in GitTea?

Gitea already supports OpenID Connect (OIDC) / OAuth2. If your identity provider does only support SAML, you can implement a middle-man service to "translate" between SAML & OIDC. Keycloak can do that, it is a little bit heavy to configure but it does its job well. There are maybe also alternatives to Keycloak which can do the same.

@MohammedNoureldin
Copy link

MohammedNoureldin commented Aug 27, 2022

Isn't there at the moment any workaround to get SSO in GitTea?

Gitea already supports OpenID Connect (OIDC) / OAuth2. If your identity provider does only support SAML, you can implement a middle-man service to "translate" between SAML & OIDC. Keycloak can do that, it is a little bit heavy to configure but it does its job well. There are maybe also alternatives to Keycloak which can do the same.

Thanks! I am still a noob in SSO, SAML and OIDC. I have to educate myself a bit more in these topics.

Does it have to be KeyCloak for some reason? Or does Authentik for example also work?

@Zocker1999NET
Copy link

Thanks! I am still a noob in SSO, SAML and OIDC. I have to educate myself a bit more in these topics.

Does it have to be KeyCloak for some reason? Or does Authentik for example also work?

Following their comparison chart, Authentik seems to support this as they can provide OIDC and support federating with SAML. So it should be possible.

@timka
Copy link

timka commented Oct 20, 2022

Isn't there at the moment any workaround to get SSO in GitTea?

Gitea already supports OpenID Connect (OIDC) / OAuth2. If your identity provider does only support SAML, you can implement a middle-man service to "translate" between SAML & OIDC. Keycloak can do that, it is a little bit heavy to configure but it does its job well. There are maybe also alternatives to Keycloak which can do the same.

Thanks! I am still a noob in SSO, SAML and OIDC. I have to educate myself a bit more in these topics.

Does it have to be KeyCloak for some reason? Or does Authentik for example also work?

I'm using Gitea with Authentic OpenID as in their docs. It works but I still have some issues which at the first glance don't have anything to do with this auth provider. Namely Gitea doesn't set session cookie expiration time and my users keep complaining they need to do 5 click sign-in too often. Obviously this isn't quite SSO yet but this shouldn't be hard to fix.

@MohammedNoureldin
Copy link

MohammedNoureldin commented Oct 25, 2022

@timka @Zocker1999NET , thank you both! Should there be any difference between using Authentik or KeyCloak for this puprose? I don't think so right?

@timka
Copy link

timka commented Oct 26, 2022 via email

@Zocker1999NET
Copy link

@timka @Zocker1999NET , thank you both! Should there be any difference between using Authentik or KeyCloak for this puprose? I don't think so right?

Don't know much about Authentik (have only used Keycloak until now) but it seems to me that Keycloak is the "can more than you need & want" solution (highly adaptable but sometimes a mess to configure & some features require custom JavaScript code extensions) and Authentik looks more like the "Apple" solution to me (may has not all features you may dream of, but is much easier to configure). I think for your use case, Authentik should be good enough & the better choice.

@6543 6543 changed the title Gitea as SAML SP Support SAML 2.0 as Login-Source Feb 20, 2023
@6543 6543 changed the title Support SAML 2.0 as Login-Source Gitea as SAML Service Provider Feb 20, 2023
@6543

This comment was marked as outdated.

@6543 6543 changed the title Gitea as SAML Service Provider Support SAML 2.0 as Login-Source Feb 20, 2023
@6543 6543 changed the title Support SAML 2.0 as Login-Source Support SAML 2.0 as Login-Source (Service Provider) Feb 20, 2023
@6543
Copy link
Member

6543 commented Feb 20, 2023

saml:Attribute Name="memberOf" is also interesting to do some mapping to org/team memberships ...

... but that's an addition to the initial support I would say :)

@bwinston-sdp
Copy link

hey @wfjake let me know if you'd like some help, i'm definitely interested in this feature as well!

6543 added a commit that referenced this issue Feb 23, 2024
Closes #5512

This PR adds basic SAML support
- Adds SAML 2.0 as an auth source
- Adds SAML configuration documentation
- Adds integration test:
- Use bare-bones SAML IdP to test protocol flow and test account is
linked successfully (only runs on Postgres by default)
- Adds documentation for configuring and running SAML integration test
locally

Future PRs:
- Support group mapping
- Support auto-registration (account linking)

Co-Authored-By: @jackHay22

---------

Co-authored-by: jackHay22 <jack@allspice.io>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: Jason Song <i@wolfogre.com>
Co-authored-by: morphelinho <morphelinho@users.noreply.github.com>
Co-authored-by: Zettat123 <zettat123@gmail.com>
Co-authored-by: Yarden Shoham <git@yardenshoham.com>
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: silverwind <me@silverwind.io>
lunny pushed a commit that referenced this issue Feb 24, 2024
This reverts #25165 (5bb8d19), as there
was a chance some important reviews got missed.

so after reverting this patch it will be resubmitted for reviewing again

#25165 (comment)

temporary Open #5512 again
@6543 6543 reopened this Feb 24, 2024
6543 added a commit to 6543-forks/gitea that referenced this issue Feb 25, 2024
Closes go-gitea#5512

This PR adds basic SAML support
- Adds SAML 2.0 as an auth source
- Adds SAML configuration documentation
- Adds integration test:
- Use bare-bones SAML IdP to test protocol flow and test account is
linked successfully (only runs on Postgres by default)
- Adds documentation for configuring and running SAML integration test
locally

Future PRs:
- Support group mapping
- Support auto-registration (account linking)

Co-Authored-By: @jackHay22

---------

Co-authored-by: jackHay22 <jack@allspice.io>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: Jason Song <i@wolfogre.com>
Co-authored-by: morphelinho <morphelinho@users.noreply.github.com>
Co-authored-by: Zettat123 <zettat123@gmail.com>
Co-authored-by: Yarden Shoham <git@yardenshoham.com>
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: silverwind <me@silverwind.io>
@6543 6543 linked a pull request Feb 25, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented type/feature Completely new functionality. Can only be merged if feature freeze is not active. type/proposal The new feature has not been accepted yet but needs to be discussed first.
Projects
None yet
Development

Successfully merging a pull request may close this issue.