gitea icon indicating copy to clipboard operation
gitea copied to clipboard

Gitea as SAML SP

Open frostieDE opened this issue 6 years ago • 16 comments

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.

frostieDE avatar Dec 10 '18 13:12 frostieDE

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

techknowlogick avatar Dec 12 '18 00:12 techknowlogick

gSuite/Google Admin is a good test

nigeltiany avatar Dec 12 '18 03:12 nigeltiany

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) :-)

frostieDE avatar Dec 12 '18 15:12 frostieDE

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

jtl999 avatar Jan 06 '19 05:01 jtl999

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

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

frostieDE avatar Jan 06 '19 15:01 frostieDE

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

d-Pixie avatar Feb 06 '19 09:02 d-Pixie

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

lpar avatar Apr 24 '19 16:04 lpar

@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.

techknowlogick avatar Apr 24 '19 16:04 techknowlogick

Is SAML supported? I'm confused.

chb0github avatar Apr 21 '20 07:04 chb0github

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)

fuero avatar May 18 '21 19:05 fuero

@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

Zocker1999NET avatar May 24 '21 11:05 Zocker1999NET

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.

nlincke avatar Apr 15 '22 18:04 nlincke

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

MohammedNoureldin avatar Aug 27 '22 08:08 MohammedNoureldin

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.

Zocker1999NET avatar Aug 27 '22 08:08 Zocker1999NET

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?

MohammedNoureldin avatar Aug 27 '22 08:08 MohammedNoureldin

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.

Zocker1999NET avatar Sep 11 '22 10:09 Zocker1999NET

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.

timka avatar Oct 20 '22 14:10 timka

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

MohammedNoureldin avatar Oct 25 '22 17:10 MohammedNoureldin

I haven't used KeyCloak. I've chosen Authentic simply b/c it's not Java and has more features.

On Tue, 25 Oct 2022 at 20:50, Mohammed Noureldin @.***> wrote:

@timka https://github.com/timka @Zocker1999NET https://github.com/Zocker1999NET , thank you both! Should there be any difference between using Authentik or KeyCloak? I don't think so right?

— Reply to this email directly, view it on GitHub https://github.com/go-gitea/gitea/issues/5512#issuecomment-1290935320, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAU6AR2J37MSRILO5IXPVTWFAMV3ANCNFSM4GJNSWCQ . You are receiving this because you were mentioned.Message ID: @.***>

-- Timur Izhbulatov +7 (910) 4604059

timka avatar Oct 26 '22 07:10 timka

@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.

Zocker1999NET avatar Nov 02 '22 20:11 Zocker1999NET

sorry that's a new FR ... -> #23016

6543 avatar Feb 20 '23 17:02 6543

need to look at https://github.com/mattermost/gosaml2, https://github.com/russellhaering/gosaml2, https://github.com/crewjam/saml ...

6543 avatar Feb 20 '23 20:02 6543

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 :)

6543 avatar Feb 20 '23 20:02 6543

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

bwinston-sdp avatar Jul 07 '23 19:07 bwinston-sdp