Skip to content

Commit

Permalink
Merge pull request #5 from eko/openid-connect
Browse files Browse the repository at this point in the history
Added SSO OpenID Connect authentication
  • Loading branch information
eko authored Jan 18, 2023
2 parents 06b6f30 + 536344e commit c678941
Show file tree
Hide file tree
Showing 125 changed files with 22,709 additions and 441 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ You can use both Role-Based Acccess Control (RBAC) and Attribute-Based Access Co

🔍 Audit: We log each check decisions and which policy matched

🔐 Single Sign-On: Use your enterprise SSO to log into the web UI, using OpenID Connect

## How it works?

Authorization is simple: a `principal` wants to make an `action` on a `resource`. That's it.
Expand Down
7 changes: 7 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ Here are the available configuration options available as environment variable:
| HTTP_SERVER_CORS_CACHE_MAX_AGE | `12h` | CORS cache max age value to be returned by server |
| LOGGER_LEVEL | `INFO` | Log level, could be `DEBUG`, `INFO`, `WARN` or `ERROR` |
| USER_ADMIN_DEFAULT_PASSWORD | `changeme` | Default admin password updated on app launch |
| OAUTH_CLIENT_ID | N/A | OAuth client ID provided by your issuer |
| OAUTH_CLIENT_SECRET | N/A | OAuth client Secret provider by your issuer |
| OAUTH_COOKIES_DOMAIN_NAME | `localhost` | OAuth domain name on which cookies will be stored |
| OAUTH_FRONTEND_REDIRECT_URL | `http://localhost:3000` | Frontend redirect URL when OAuth authentication is successful |
| OAUTH_ISSUER_URL | N/A | Issuer OpenID Connect URL (will be used to retrieve /.well-known/openid-configuration) |
| OAUTH_REDIRECT_URL | `[12h](http://localhost:8080/v1/oauth/callback)` | Backend OAuth callback URL |
| OAUTH_SCOPES | `profile,email` | OAuth scopes to be retrieved from your issuer |

## Tests

Expand Down
2 changes: 2 additions & 0 deletions backend/configs/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Base struct {
Logger *Logger
GRPCServer *GRPCServer
HTTPServer *HTTPServer
OAuth *OAuth
User *User
}

Expand All @@ -30,6 +31,7 @@ func Load(ctx context.Context) *Base {
Logger: newLogger(),
GRPCServer: newGRPCServer(),
HTTPServer: newHTTPServer(),
OAuth: newOAuth(),
User: newUser(),
}

Expand Down
1 change: 1 addition & 0 deletions backend/configs/fx.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func FxModule() fx.Option {
func(cfg *Base) *GRPCServer { return cfg.GRPCServer },
func(cfg *Base) *HTTPServer { return cfg.HTTPServer },
func(cfg *Base) *Logger { return cfg.Logger },
func(cfg *Base) *OAuth { return cfg.OAuth },
func(cfg *Base) *User { return cfg.User },
),
)
Expand Down
20 changes: 20 additions & 0 deletions backend/configs/oauth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package configs

type OAuth struct {
ClientID string `config:"oauth_client_id"`
ClientSecret string `config:"oauth_client_secret"`
CookiesDomainName string `config:"oauth_cookies_domain_name"`
FrontendRedirectURL string `config:"oauth_frontend_redirect_url"`
IssuerURL string `config:"oauth_issuer_url"`
RedirectURL string `config:"oauth_redirect_url"`
Scopes []string `config:"oauth_scopes"`
}

func newOAuth() *OAuth {
return &OAuth{
CookiesDomainName: "localhost",
FrontendRedirectURL: "http://localhost:3000",
RedirectURL: "http://localhost:8080/v1/oauth/callback",
Scopes: []string{"profile", "email"},
}
}
12 changes: 4 additions & 8 deletions backend/functional/fx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func FxApp() *fx.App {
database.FxModule(),
entity.FxModule(),
event.FxModule(),
// helper.FxModule(),
http.FxModule(),
log.FxModule(),
oauth.FxModule(),
Expand Down Expand Up @@ -67,17 +66,14 @@ func FxApp() *fx.App {
func(cfg *configs.Base) *configs.App {
return cfg.App
},
func(cfg *configs.Base) *configs.Database {
return cfg.Database
},
func(cfg *configs.Base) *configs.HTTPServer {
return cfg.HTTPServer
},
func(cfg *configs.Base) *configs.Auth { return cfg.Auth },
func(cfg *configs.Base) *configs.Database { return cfg.Database },
func(cfg *configs.Base) *configs.HTTPServer { return cfg.HTTPServer },
func(cfg *configs.Base) *configs.Logger {
cfg.Logger.Level = "ERROR"
return cfg.Logger
},
func(cfg *configs.Base) *configs.Auth { return cfg.Auth },
func(cfg *configs.Base) *configs.OAuth { return cfg.OAuth },
func(cfg *configs.Base) *configs.User { return cfg.User },
),

Expand Down
4 changes: 3 additions & 1 deletion backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/eko/authz/backend
go 1.19

require (
github.com/coreos/go-oidc/v3 v3.5.0
github.com/cucumber/godog v0.12.5
github.com/glebarez/sqlite v1.6.0
github.com/go-oauth2/oauth2/v4 v4.5.1
Expand All @@ -21,6 +22,7 @@ require (
go.uber.org/fx v1.18.2
golang.org/x/crypto v0.4.0
golang.org/x/exp v0.0.0-20221208152030-732eee02a75a
golang.org/x/oauth2 v0.3.0
google.golang.org/grpc v1.51.0
google.golang.org/protobuf v1.28.1
gorm.io/datatypes v1.1.0
Expand All @@ -39,6 +41,7 @@ require (
github.com/cucumber/messages-go/v16 v16.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/glebarez/go-sqlite v1.20.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.6 // indirect
github.com/go-openapi/spec v0.20.4 // indirect
Expand Down Expand Up @@ -77,7 +80,6 @@ require (
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/text v0.6.0 // indirect
golang.org/x/tools v0.5.0 // indirect
Expand Down
13 changes: 11 additions & 2 deletions backend/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvf
cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg=
cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc=
cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ=
cloud.google.com/go/compute/metadata v0.2.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k=
cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk=
cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk=
Expand Down Expand Up @@ -77,6 +78,8 @@ github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnht
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.3+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-oidc/v3 v3.5.0 h1:VxKtbccHZxs8juq7RdJntSqtXFtde9YpNpGn0yqgEHw=
github.com/coreos/go-oidc/v3 v3.5.0/go.mod h1:ecXRtV4romGPeO6ieExAsUK9cb/3fp9hXNz1tlv8PIM=
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
Expand Down Expand Up @@ -117,6 +120,8 @@ github.com/glebarez/sqlite v1.6.0/go.mod h1:6D6zPU/HTrFlYmVDKqBJlmQvma90P6r7sRRd
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-jose/go-jose/v3 v3.0.0 h1:s6rrhirfEP/CGIoc6p+PZAeogN2SxKav6Wp7+dyMWVo=
github.com/go-jose/go-jose/v3 v3.0.0/go.mod h1:RNkWWRld676jZEYoV3+XK8L2ZnNSvIsxFMht0mSX+u8=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-ldap/ldap v3.0.2+incompatible/go.mod h1:qfd9rJvER9Q0/D/Sqn1DfHRoBp40uXYvFoEVrNEPqRc=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
Expand Down Expand Up @@ -207,6 +212,7 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
Expand Down Expand Up @@ -538,6 +544,7 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20190506204251-e1dfcc566284/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
Expand Down Expand Up @@ -626,6 +633,7 @@ golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.0.0-20220906165146-f3363e06e74c/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
Expand All @@ -636,8 +644,8 @@ golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4Iltr
golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99 h1:5vD4XjIc0X5+kHZjx4UecYdjA6mJo+XXNoaW0EjU5Os=
golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.3.0 h1:6l90koy8/LaBLmLu8jpHeHexzMwEita0zFfYlggy2F8=
golang.org/x/oauth2 v0.3.0/go.mod h1:rQrIauxkUhJ6CuwEXwymO2/eh4xz2ZWF1nBkcxS+tGk=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -873,6 +881,7 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
Expand Down
57 changes: 57 additions & 0 deletions backend/internal/http/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,63 @@ const docTemplate = `{
}
}
},
"/v1/oauth": {
"get": {
"security": [
{
"Authentication": []
}
],
"tags": [
"Auth"
],
"summary": "Authenticates a user using an OAuth OpenID Connect provider",
"responses": {
"302": {
"description": "Found"
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/model.ErrorResponse"
}
}
}
}
},
"/v1/oauth/callback": {
"get": {
"security": [
{
"Authentication": []
}
],
"tags": [
"Auth"
],
"summary": "Callback of the OAuth OpenID Connect provider authentication",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/handler.AuthResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/model.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/model.ErrorResponse"
}
}
}
}
},
"/v1/policies": {
"get": {
"security": [
Expand Down
57 changes: 57 additions & 0 deletions backend/internal/http/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,63 @@
}
}
},
"/v1/oauth": {
"get": {
"security": [
{
"Authentication": []
}
],
"tags": [
"Auth"
],
"summary": "Authenticates a user using an OAuth OpenID Connect provider",
"responses": {
"302": {
"description": "Found"
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/model.ErrorResponse"
}
}
}
}
},
"/v1/oauth/callback": {
"get": {
"security": [
{
"Authentication": []
}
],
"tags": [
"Auth"
],
"summary": "Callback of the OAuth OpenID Connect provider authentication",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/handler.AuthResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/model.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/model.ErrorResponse"
}
}
}
}
},
"/v1/policies": {
"get": {
"security": [
Expand Down
34 changes: 34 additions & 0 deletions backend/internal/http/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,40 @@ paths:
summary: Retrieve a client
tags:
- Client
/v1/oauth:
get:
responses:
"302":
description: Found
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/model.ErrorResponse'
security:
- Authentication: []
summary: Authenticates a user using an OAuth OpenID Connect provider
tags:
- Auth
/v1/oauth/callback:
get:
responses:
"200":
description: OK
schema:
$ref: '#/definitions/handler.AuthResponse'
"400":
description: Bad Request
schema:
$ref: '#/definitions/model.ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/model.ErrorResponse'
security:
- Authentication: []
summary: Callback of the OAuth OpenID Connect provider authentication
tags:
- Auth
/v1/policies:
get:
parameters:
Expand Down
Loading

0 comments on commit c678941

Please sign in to comment.